Compare commits
105 Commits
features/m
...
clients/bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9989bac01 | ||
|
|
24cf9dcb0f | ||
|
|
9b7f133249 | ||
|
|
5227e196d0 | ||
|
|
b98807b336 | ||
|
|
21bda59787 | ||
|
|
b2390843ab | ||
|
|
fc14341d40 | ||
|
|
57dd5b1bca | ||
|
|
0d209b33cb | ||
|
|
5bf86c82e2 | ||
|
|
b83c14bd36 | ||
|
|
8aa5c31431 | ||
|
|
9d13fdd9ce | ||
|
|
bba956a65e | ||
|
|
0699ad0556 | ||
|
|
4a99a9df3e | ||
|
|
f0ca92c06b | ||
|
|
69086d87dd | ||
|
|
89f05aeaa1 | ||
|
|
a966d6c8cf | ||
|
|
cf18e99caa | ||
|
|
f87454c0b6 | ||
|
|
b7febc8df5 | ||
|
|
f4b34bf48d | ||
|
|
d2fd865b68 | ||
|
|
a5e00ceba9 | ||
|
|
f09fec0aff | ||
|
|
ce7c805251 | ||
|
|
1bcc9332b2 | ||
|
|
e3267d3973 | ||
|
|
eb7cbc73ee | ||
|
|
596b5ccf67 | ||
|
|
34838a438d | ||
|
|
572690e2bc | ||
|
|
303e34299a | ||
|
|
c628de9ede | ||
|
|
e73be6bbab | ||
|
|
c9fd8b02e3 | ||
|
|
e1a63064dc | ||
|
|
42db8255d1 | ||
|
|
22ba6cfb49 | ||
|
|
02bba73ca7 | ||
|
|
d0daf559c7 | ||
|
|
f8f6700459 | ||
|
|
c318d37445 | ||
|
|
246fc15988 | ||
|
|
14d45cbe90 | ||
|
|
42a544c6e3 | ||
|
|
75be11bc96 | ||
|
|
ebf29d0eed | ||
|
|
a391d27b44 | ||
|
|
753c9b8b4b | ||
|
|
9cb6c6599d | ||
|
|
8bd0d0166b | ||
|
|
bee0c0b189 | ||
|
|
744bfefa5c | ||
|
|
850fb16c8c | ||
|
|
72ba805fbb | ||
|
|
3d7b40f029 | ||
|
|
2039a9f13b | ||
|
|
bb8f12dd7a | ||
|
|
40ab1f3665 | ||
|
|
fdef757fd0 | ||
|
|
3608ee1141 | ||
|
|
7fb3d61dff | ||
|
|
e9aa11673b | ||
|
|
03a7aa5daf | ||
|
|
755f20c5c4 | ||
|
|
64772e2e90 | ||
|
|
75a4a426e0 | ||
|
|
42a7ebeea2 | ||
|
|
3d22f48555 | ||
|
|
488e048d8f | ||
|
|
2f82559a5c | ||
|
|
7d5b7b9fc4 | ||
|
|
7aa68b8bbf | ||
|
|
aecde926f2 | ||
|
|
6b95628e56 | ||
|
|
56a1b97b46 | ||
|
|
34a5a54c8b | ||
|
|
0c17ab3f8a | ||
|
|
c967a25f82 | ||
|
|
7562588c42 | ||
|
|
a1a706b7b9 | ||
|
|
d623cb2df5 | ||
|
|
488ddcf1e1 | ||
|
|
3d39893f17 | ||
|
|
3694839d97 | ||
|
|
cce27aceca | ||
|
|
c73d251370 | ||
|
|
091f0d1cfd | ||
|
|
d2affdcf21 | ||
|
|
885d430b98 | ||
|
|
39eabe1c54 | ||
|
|
f6ad579829 | ||
|
|
6fc9e46882 | ||
|
|
2d326a679d | ||
|
|
aa8c2db446 | ||
|
|
925b55d76d | ||
|
|
5808d3653d | ||
|
|
bc072f7b7e | ||
|
|
b3d59eee39 | ||
|
|
7d379a52af | ||
|
|
499ab1f3e7 |
@@ -63,6 +63,7 @@ job_docker_nightly:
|
|||||||
only:
|
only:
|
||||||
- nightly
|
- nightly
|
||||||
- staging
|
- staging
|
||||||
|
- /^clients\/.+$/
|
||||||
|
|
||||||
job_documentation_build:
|
job_documentation_build:
|
||||||
stage: build_documentation
|
stage: build_documentation
|
||||||
@@ -162,6 +163,7 @@ job_push_python:
|
|||||||
- releases/python
|
- releases/python
|
||||||
- staging
|
- staging
|
||||||
- nightly
|
- nightly
|
||||||
|
- /^clients\/.+$/
|
||||||
|
|
||||||
test-mysql:
|
test-mysql:
|
||||||
<<: *test_base
|
<<: *test_base
|
||||||
|
|||||||
20
CHANGES_BC.rst
Normal file
20
CHANGES_BC.rst
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
- Use Select2 widget for the document type selection form.
|
||||||
|
- Update source column matching to be additive and not exclusive.
|
||||||
|
- Add two columns to show the number of documents per workflow and
|
||||||
|
workflow state.
|
||||||
|
- Sort module.
|
||||||
|
- Add link to sort individual indexes.
|
||||||
|
- Support exclusions from source columns.
|
||||||
|
- Improve source column exclusion. Improve for model subclasses in partial querysets.
|
||||||
|
- Add sortable index instance label column.
|
||||||
|
- Add rectangle drawing transformation.
|
||||||
|
- Redactions app.
|
||||||
|
- Remove duplicated trashed document preview.
|
||||||
|
- Add label to trashed date and time document source column.
|
||||||
|
- Tag created event fix.
|
||||||
|
|
||||||
|
3.2.3 (2019-06-21)
|
||||||
|
* Add a reusable task to upload documents.
|
||||||
|
* Add MVP of the importer app.
|
||||||
|
|
||||||
|
3.2.4-3.2.8 (2019-10-07)
|
||||||
@@ -83,6 +83,8 @@
|
|||||||
- Remove the DOCUMENTS_DISABLE_BASE_IMAGE_CACHE,
|
- Remove the DOCUMENTS_DISABLE_BASE_IMAGE_CACHE,
|
||||||
DOCUMENTS_DISABLE_TRANSFORMED_IMAGE_CACHE, and
|
DOCUMENTS_DISABLE_TRANSFORMED_IMAGE_CACHE, and
|
||||||
DOCUMENTS_FIX_ORIENTATION settings.
|
DOCUMENTS_FIX_ORIENTATION settings.
|
||||||
|
- Support simple search disable via the new
|
||||||
|
SEARCH_DISABLE_SIMPLE_SEARCH setting.
|
||||||
|
|
||||||
3.2.8 (2019-10-01)
|
3.2.8 (2019-10-01)
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
3.3beta1
|
3.3beta1-bc
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ Changes
|
|||||||
GitLab issue #625. Thanks to Jesaja Everling (@jeverling)
|
GitLab issue #625. Thanks to Jesaja Everling (@jeverling)
|
||||||
for the report and the research.
|
for the report and the research.
|
||||||
|
|
||||||
|
|
||||||
Removals
|
Removals
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ Changes
|
|||||||
- Fix help text of the platformtemplate command.
|
- Fix help text of the platformtemplate command.
|
||||||
- Fix IMAP4 mailbox.store flags argument. Python's documentation
|
- Fix IMAP4 mailbox.store flags argument. Python's documentation
|
||||||
incorrectly state it is named flag_list. Closes GitLab issue
|
incorrectly state it is named flag_list. Closes GitLab issue
|
||||||
#606. Thanks to Samuel Aebi (@samuelaebi) for the report and
|
#606. Thanks to Samuel Aebi (@samuelaebi) for the report and
|
||||||
|
debug information.
|
||||||
debug information.
|
debug information.
|
||||||
- Support configurable GUnicorn timeouts. Defaults to
|
- Support configurable GUnicorn timeouts. Defaults to
|
||||||
current value of 120 seconds.
|
current value of 120 seconds.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
|||||||
__title__ = 'Mayan EDMS'
|
__title__ = 'Mayan EDMS'
|
||||||
__version__ = '3.3beta1'
|
__version__ = '3.3beta1'
|
||||||
__build__ = 0x030300
|
__build__ = 0x030300
|
||||||
__build_string__ = 'v3.3beta1-9-g1b327b99f0_Tue Oct 8 15:15:08 2019 -0400'
|
__build_string__ = 'v3.3beta1-260-g9d13fdd9ce_Thu Oct 10 12:17:38 2019 -0400'
|
||||||
__django_version__ = '1.11'
|
__django_version__ = '1.11'
|
||||||
__author__ = 'Roberto Rosario'
|
__author__ = 'Roberto Rosario'
|
||||||
__author_email__ = 'roberto.rosario@mayan-edms.com'
|
__author_email__ = 'roberto.rosario@mayan-edms.com'
|
||||||
|
|||||||
19
mayan/apps/authentication/events.py
Normal file
19
mayan/apps/authentication/events.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.events.classes import EventTypeNamespace
|
||||||
|
|
||||||
|
namespace = EventTypeNamespace(
|
||||||
|
label=_('Authentication'), name='authentication'
|
||||||
|
)
|
||||||
|
|
||||||
|
event_user_authentication_error = namespace.add_event_type(
|
||||||
|
label=_('User authentication error'), name='user_authentication_error'
|
||||||
|
)
|
||||||
|
event_user_password_reset_started = namespace.add_event_type(
|
||||||
|
label=_('User password reset started'), name='user_password_reset_started'
|
||||||
|
)
|
||||||
|
event_user_password_reset_complete = namespace.add_event_type(
|
||||||
|
label=_('User password reset complete'), name='user_password_reset_complete'
|
||||||
|
)
|
||||||
82
mayan/apps/authentication/tests/test_events.py
Normal file
82
mayan/apps/authentication/tests/test_events.py
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.views import (
|
||||||
|
INTERNAL_RESET_SESSION_TOKEN, INTERNAL_RESET_URL_TOKEN,
|
||||||
|
)
|
||||||
|
from django.core import mail
|
||||||
|
|
||||||
|
from actstream.models import Action
|
||||||
|
|
||||||
|
from mayan.apps.common.tests.base import GenericViewTestCase
|
||||||
|
from mayan.apps.events.utils import create_system_user
|
||||||
|
|
||||||
|
from ..events import (
|
||||||
|
event_user_authentication_error, event_user_password_reset_complete,
|
||||||
|
event_user_password_reset_started
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AuthenticationEventsTestCase(GenericViewTestCase):
|
||||||
|
auto_login_user = False
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(AuthenticationEventsTestCase, self).setUp()
|
||||||
|
create_system_user()
|
||||||
|
|
||||||
|
def test_user_authentication_failure_event(self):
|
||||||
|
Action.objects.all().delete()
|
||||||
|
response = self.post(viewname=settings.LOGIN_URL)
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
action = Action.objects.last()
|
||||||
|
self.assertEqual(action.verb, event_user_authentication_error.id)
|
||||||
|
|
||||||
|
def test_user_password_reset_started_event(self):
|
||||||
|
Action.objects.all().delete()
|
||||||
|
response = self.post(
|
||||||
|
viewname='authentication:password_reset_view', data={
|
||||||
|
'email': self._test_case_user.email,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
|
||||||
|
action = Action.objects.last()
|
||||||
|
self.assertEqual(action.verb, event_user_password_reset_started.id)
|
||||||
|
|
||||||
|
def test_user_password_reset_complete_event(self):
|
||||||
|
response = self.post(
|
||||||
|
viewname='authentication:password_reset_view', data={
|
||||||
|
'email': self._test_case_user.email,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
|
self.assertEqual(len(mail.outbox), 1)
|
||||||
|
|
||||||
|
email_parts = mail.outbox[0].body.replace('\n', '').split('/')
|
||||||
|
uidb64 = email_parts[-3]
|
||||||
|
token = email_parts[-2]
|
||||||
|
|
||||||
|
# Add the token to the session
|
||||||
|
session = self.client.session
|
||||||
|
session[INTERNAL_RESET_SESSION_TOKEN] = token
|
||||||
|
session.save()
|
||||||
|
|
||||||
|
Action.objects.all().delete()
|
||||||
|
|
||||||
|
new_password = 'new_password_123'
|
||||||
|
response = self.post(
|
||||||
|
viewname='authentication:password_reset_confirm_view',
|
||||||
|
kwargs={'uidb64': uidb64, 'token': INTERNAL_RESET_URL_TOKEN}, data={
|
||||||
|
'new_password1': new_password,
|
||||||
|
'new_password2': new_password
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertNotIn(INTERNAL_RESET_SESSION_TOKEN, self.client.session)
|
||||||
|
|
||||||
|
action = Action.objects.last()
|
||||||
|
self.assertEqual(action.verb, event_user_password_reset_complete.id)
|
||||||
@@ -21,8 +21,13 @@ from mayan.apps.common.generics import MultipleObjectFormActionView
|
|||||||
from mayan.apps.common.settings import (
|
from mayan.apps.common.settings import (
|
||||||
setting_home_view, setting_project_title, setting_project_url
|
setting_home_view, setting_project_title, setting_project_url
|
||||||
)
|
)
|
||||||
|
from mayan.apps.events.utils import get_system_user
|
||||||
from mayan.apps.user_management.permissions import permission_user_edit
|
from mayan.apps.user_management.permissions import permission_user_edit
|
||||||
|
|
||||||
|
from .events import (
|
||||||
|
event_user_authentication_error, event_user_password_reset_complete,
|
||||||
|
event_user_password_reset_started
|
||||||
|
)
|
||||||
from .forms import EmailAuthenticationForm, UsernameAuthenticationForm
|
from .forms import EmailAuthenticationForm, UsernameAuthenticationForm
|
||||||
from .settings import setting_login_method, setting_maximum_session_length
|
from .settings import setting_login_method, setting_maximum_session_length
|
||||||
|
|
||||||
@@ -57,6 +62,10 @@ class MayanLoginView(StrongholdPublicMixin, LoginView):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def form_invalid(self, form):
|
||||||
|
event_user_authentication_error.commit(actor=get_system_user())
|
||||||
|
return super(MayanLoginView, self).form_invalid(form=form)
|
||||||
|
|
||||||
def get_form_class(self):
|
def get_form_class(self):
|
||||||
if setting_login_method.value == 'email':
|
if setting_login_method.value == 'email':
|
||||||
return EmailAuthenticationForm
|
return EmailAuthenticationForm
|
||||||
@@ -112,6 +121,10 @@ class MayanPasswordResetConfirmView(StrongholdPublicMixin, PasswordResetConfirmV
|
|||||||
)
|
)
|
||||||
template_name = 'authentication/password_reset_confirm.html'
|
template_name = 'authentication/password_reset_confirm.html'
|
||||||
|
|
||||||
|
def post(self, *args, **kwargs):
|
||||||
|
event_user_password_reset_complete.commit(actor=get_system_user())
|
||||||
|
return super(MayanPasswordResetConfirmView, self).post(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class MayanPasswordResetDoneView(StrongholdPublicMixin, PasswordResetDoneView):
|
class MayanPasswordResetDoneView(StrongholdPublicMixin, PasswordResetDoneView):
|
||||||
extra_context = {
|
extra_context = {
|
||||||
@@ -137,6 +150,10 @@ class MayanPasswordResetView(StrongholdPublicMixin, PasswordResetView):
|
|||||||
)
|
)
|
||||||
template_name = 'authentication/password_reset_form.html'
|
template_name = 'authentication/password_reset_form.html'
|
||||||
|
|
||||||
|
def post(self, *args, **kwargs):
|
||||||
|
event_user_password_reset_started.commit(actor=get_system_user())
|
||||||
|
return super(MayanPasswordResetView, self).post(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class UserSetPasswordView(MultipleObjectFormActionView):
|
class UserSetPasswordView(MultipleObjectFormActionView):
|
||||||
form_class = SetPasswordForm
|
form_class = SetPasswordForm
|
||||||
|
|||||||
@@ -199,3 +199,36 @@ class IndexToolsViewTestCase(
|
|||||||
|
|
||||||
# An instance root exists
|
# An instance root exists
|
||||||
self.assertTrue(self.test_index.instance_root.pk)
|
self.assertTrue(self.test_index.instance_root.pk)
|
||||||
|
|
||||||
|
def test_index_rebuild_view_no_permission(self):
|
||||||
|
self._create_test_index()
|
||||||
|
|
||||||
|
self.test_index.node_templates.create(
|
||||||
|
parent=self.test_index.template_root,
|
||||||
|
expression=TEST_INDEX_TEMPLATE_DOCUMENT_LABEL_EXPRESSION,
|
||||||
|
link_documents=True
|
||||||
|
)
|
||||||
|
|
||||||
|
response = self._request_test_index_rebuild_view()
|
||||||
|
self.assertEqual(response.status_code, 404)
|
||||||
|
|
||||||
|
self.assertEqual(IndexInstanceNode.objects.count(), 0)
|
||||||
|
|
||||||
|
def test_index_rebuild_view_with_access(self):
|
||||||
|
self._create_test_index()
|
||||||
|
|
||||||
|
self.test_index.node_templates.create(
|
||||||
|
parent=self.test_index.template_root,
|
||||||
|
expression=TEST_INDEX_TEMPLATE_DOCUMENT_LABEL_EXPRESSION,
|
||||||
|
link_documents=True
|
||||||
|
)
|
||||||
|
|
||||||
|
self.grant_access(
|
||||||
|
obj=self.test_index,
|
||||||
|
permission=permission_document_indexing_rebuild
|
||||||
|
)
|
||||||
|
|
||||||
|
response = self._request_test_index_rebuild_view()
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
|
self.assertNotEqual(IndexInstanceNode.objects.count(), 0)
|
||||||
|
|||||||
@@ -205,10 +205,10 @@ class DocumentStatesApp(MayanAppConfig):
|
|||||||
|
|
||||||
SourceColumn(
|
SourceColumn(
|
||||||
source=WorkflowInstanceLogEntry, label=_('Date and time'),
|
source=WorkflowInstanceLogEntry, label=_('Date and time'),
|
||||||
attribute='datetime'
|
attribute='datetime', is_sortable=True
|
||||||
)
|
)
|
||||||
SourceColumn(
|
SourceColumn(
|
||||||
source=WorkflowInstanceLogEntry, label=_('User'), attribute='user'
|
source=WorkflowInstanceLogEntry, attribute='user', is_sortable=True
|
||||||
)
|
)
|
||||||
SourceColumn(
|
SourceColumn(
|
||||||
source=WorkflowInstanceLogEntry,
|
source=WorkflowInstanceLogEntry,
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ link_workflow_template_transition_field_delete = Link(
|
|||||||
tags='dangerous', text=_('Delete'),
|
tags='dangerous', text=_('Delete'),
|
||||||
view='document_states:workflow_template_transition_field_delete',
|
view='document_states:workflow_template_transition_field_delete',
|
||||||
)
|
)
|
||||||
|
|
||||||
link_workflow_template_transition_field_edit = Link(
|
link_workflow_template_transition_field_edit = Link(
|
||||||
args='resolved_object.pk',
|
args='resolved_object.pk',
|
||||||
icon_class_path='mayan.apps.document_states.icons.icon_workflow_transition_field_edit',
|
icon_class_path='mayan.apps.document_states.icons.icon_workflow_transition_field_edit',
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ import logging
|
|||||||
|
|
||||||
from furl import furl
|
from furl import furl
|
||||||
from graphviz import Digraph
|
from graphviz import Digraph
|
||||||
|
import yaml
|
||||||
|
try:
|
||||||
|
from yaml import CSafeLoader as SafeLoader
|
||||||
|
except ImportError:
|
||||||
|
from yaml import SafeLoader
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@@ -328,8 +333,8 @@ class WorkflowState(models.Model):
|
|||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
# Solve issue #557 "Break workflows with invalid input"
|
# Solve issue #557 "Break workflows with invalid input"
|
||||||
# without using a migration.
|
# without using a migration.
|
||||||
# Remove blank=True, remove this, and create a migration in the next
|
# TODO: Remove blank=True, remove this, and create a migration in the
|
||||||
# minor version.
|
# next minor version.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.completion = int(self.completion)
|
self.completion = int(self.completion)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||||||
from mayan.apps.common.tests.base import GenericViewTestCase
|
from mayan.apps.common.tests.base import GenericViewTestCase
|
||||||
from mayan.apps.documents.tests.base import GenericDocumentViewTestCase
|
from mayan.apps.documents.tests.base import GenericDocumentViewTestCase
|
||||||
|
|
||||||
|
from ..literals import FIELD_TYPE_CHOICE_CHAR
|
||||||
from ..models import WorkflowTransition
|
from ..models import WorkflowTransition
|
||||||
from ..permissions import (
|
from ..permissions import (
|
||||||
permission_workflow_edit, permission_workflow_view,
|
permission_workflow_edit, permission_workflow_view,
|
||||||
@@ -19,6 +20,11 @@ from .mixins import (
|
|||||||
WorkflowTestMixin, WorkflowViewTestMixin, WorkflowTransitionViewTestMixin
|
WorkflowTestMixin, WorkflowViewTestMixin, WorkflowTransitionViewTestMixin
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TEST_WORKFLOW_TRANSITION_FIELD_NAME = 'test_workflow_transition_field'
|
||||||
|
TEST_WORKFLOW_TRANSITION_FIELD_LABEL = 'test workflow transition field'
|
||||||
|
TEST_WORKFLOW_TRANSITION_FIELD_HELP_TEXT = 'test workflow transition field help test'
|
||||||
|
TEST_WORKFLOW_TRANSITION_FIELD_TYPE = FIELD_TYPE_CHOICE_CHAR
|
||||||
|
|
||||||
|
|
||||||
class WorkflowTransitionViewTestCase(
|
class WorkflowTransitionViewTestCase(
|
||||||
WorkflowTestMixin, WorkflowViewTestMixin, WorkflowTransitionViewTestMixin,
|
WorkflowTestMixin, WorkflowViewTestMixin, WorkflowTransitionViewTestMixin,
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ DOCUMENT_IMAGES_CACHE_NAME = 'document_images'
|
|||||||
DOCUMENT_CACHE_STORAGE_INSTANCE_PATH = 'mayan.apps.documents.storages.storage_documentimagecache'
|
DOCUMENT_CACHE_STORAGE_INSTANCE_PATH = 'mayan.apps.documents.storages.storage_documentimagecache'
|
||||||
STUB_EXPIRATION_INTERVAL = 60 * 60 * 24 # 24 hours
|
STUB_EXPIRATION_INTERVAL = 60 * 60 * 24 # 24 hours
|
||||||
UPDATE_PAGE_COUNT_RETRY_DELAY = 10
|
UPDATE_PAGE_COUNT_RETRY_DELAY = 10
|
||||||
|
UPLOAD_NEW_DOCUMENT_RETRY_DELAY = 10
|
||||||
UPLOAD_NEW_VERSION_RETRY_DELAY = 10
|
UPLOAD_NEW_VERSION_RETRY_DELAY = 10
|
||||||
|
|
||||||
PAGE_RANGE_ALL = 'all'
|
PAGE_RANGE_ALL = 'all'
|
||||||
|
|||||||
@@ -86,3 +86,7 @@ queue_uploads.add_task_type(
|
|||||||
dotted_path='mayan.apps.documents.tasks.task_scan_duplicates_for',
|
dotted_path='mayan.apps.documents.tasks.task_scan_duplicates_for',
|
||||||
label=_('Scan document duplicates')
|
label=_('Scan document duplicates')
|
||||||
)
|
)
|
||||||
|
queue_uploads.add_task_type(
|
||||||
|
dotted_path='mayan.apps.documents.tasks.task_upload_new_document',
|
||||||
|
label=_('Upload new document')
|
||||||
|
)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from mayan.celery import app
|
|||||||
|
|
||||||
from .literals import (
|
from .literals import (
|
||||||
RETRY_DELAY_DOCUMENT_RESET_PAGES, UPDATE_PAGE_COUNT_RETRY_DELAY,
|
RETRY_DELAY_DOCUMENT_RESET_PAGES, UPDATE_PAGE_COUNT_RETRY_DELAY,
|
||||||
UPLOAD_NEW_VERSION_RETRY_DELAY
|
UPLOAD_NEW_DOCUMENT_RETRY_DELAY, UPLOAD_NEW_VERSION_RETRY_DELAY
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -157,6 +157,60 @@ def task_update_page_count(self, version_id):
|
|||||||
raise self.retry(exc=exception)
|
raise self.retry(exc=exception)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(bind=True, default_retry_delay=UPLOAD_NEW_DOCUMENT_RETRY_DELAY, ignore_result=True)
|
||||||
|
def task_upload_new_document(self, document_type_id, shared_uploaded_file_id):
|
||||||
|
DocumentType = apps.get_model(
|
||||||
|
app_label='documents', model_name='DocumentType'
|
||||||
|
)
|
||||||
|
|
||||||
|
SharedUploadedFile = apps.get_model(
|
||||||
|
app_label='common', model_name='SharedUploadedFile'
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
document_type = DocumentType.objects.get(pk=document_type_id)
|
||||||
|
shared_file = SharedUploadedFile.objects.get(
|
||||||
|
pk=shared_uploaded_file_id
|
||||||
|
)
|
||||||
|
except OperationalError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Operational error during attempt to retrieve shared data for '
|
||||||
|
'new document of type: %s; %s. Retrying.', document_type, exception
|
||||||
|
)
|
||||||
|
raise self.retry(exc=exception)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with shared_file.open() as file_object:
|
||||||
|
document_type.new_document(file_object=file_object)
|
||||||
|
except OperationalError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Operational error during attempt to create new document '
|
||||||
|
'of type: %s; %s. Retrying.', document_type, exception
|
||||||
|
)
|
||||||
|
raise self.retry(exc=exception)
|
||||||
|
except Exception as exception:
|
||||||
|
# This except and else block emulate a finally:
|
||||||
|
logger.error(
|
||||||
|
'Unexpected error during attempt to create new document '
|
||||||
|
'of type: %s; %s', document_type, exception
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
shared_file.delete()
|
||||||
|
except OperationalError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Operational error during attempt to delete shared '
|
||||||
|
'file: %s; %s.', shared_file, exception
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
shared_file.delete()
|
||||||
|
except OperationalError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Operational error during attempt to delete shared '
|
||||||
|
'file: %s; %s.', shared_file, exception
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.task(bind=True, default_retry_delay=UPLOAD_NEW_VERSION_RETRY_DELAY, ignore_result=True)
|
@app.task(bind=True, default_retry_delay=UPLOAD_NEW_VERSION_RETRY_DELAY, ignore_result=True)
|
||||||
def task_upload_new_version(self, document_id, shared_uploaded_file_id, user_id, append_pages=False, comment=None):
|
def task_upload_new_version(self, document_id, shared_uploaded_file_id, user_id, append_pages=False, comment=None):
|
||||||
SharedUploadedFile = apps.get_model(
|
SharedUploadedFile = apps.get_model(
|
||||||
|
|||||||
17
mayan/apps/dynamic_search/settings.py
Normal file
17
mayan/apps/dynamic_search/settings.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.smart_settings.classes import Namespace
|
||||||
|
|
||||||
|
namespace = Namespace(label=_('Search'), name='search')
|
||||||
|
|
||||||
|
setting_disable_simple_search = namespace.add_setting(
|
||||||
|
global_name='SEARCH_DISABLE_SIMPLE_SEARCH',
|
||||||
|
default=False, help_text=_(
|
||||||
|
'Disables the single term bar search leaving only the advanced '
|
||||||
|
'search button.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@@ -1,13 +1,25 @@
|
|||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
|
||||||
{% load search_tags %}
|
{% load search_tags %}
|
||||||
|
{% load smart_settings_tags %}
|
||||||
|
|
||||||
{% get_search_models as search_models %}
|
{% get_search_models as search_models %}
|
||||||
|
{% smart_setting global_name="SEARCH_DISABLE_SIMPLE_SEARCH" as setting_disable_simple_search %}
|
||||||
|
|
||||||
|
{% if setting_disable_simple_search %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-6 col-xs-offset-3">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="well center-block">
|
<div class="well center-block">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<form action="{% url 'search:results' %}" class="form-horizontal" id="formSearch" method="get" role="search">
|
<form action="{% url 'search:results' %}" class="form-horizontal" id="formSearch" method="get" role="search">
|
||||||
<div class="col-sm-2">
|
{% if setting_disable_simple_search == False %}
|
||||||
|
<div class="col-sm-2">
|
||||||
|
{% else %}
|
||||||
|
<div class="col-sm-8">
|
||||||
|
{% endif %}
|
||||||
<select class="form-control" id="selectSearchModel" name="_search_model">
|
<select class="form-control" id="selectSearchModel" name="_search_model">
|
||||||
{% for search_model in search_models %}
|
{% for search_model in search_models %}
|
||||||
{{ search_model.self.get_full_name }}
|
{{ search_model.self.get_full_name }}
|
||||||
@@ -16,12 +28,21 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-10">
|
{% if setting_disable_simple_search == False %}
|
||||||
|
<div class="col-sm-10">
|
||||||
|
{% else %}
|
||||||
|
<div class="col-sm-4">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input class="form-control" name="q" placeholder="{% trans 'Search terms' %}" type="text" value="{{ search_terms|default:'' }}">
|
{% if setting_disable_simple_search == False %}
|
||||||
|
<input class="form-control" name="q" placeholder="{% trans 'Search terms' %}" type="text" value="{{ search_terms|default:'' }}">
|
||||||
|
{% endif %}
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button class="btn btn-default" type="submit">{% trans 'Search' %}</button>
|
{% if setting_disable_simple_search == False %}
|
||||||
<a class="btn btn-primary" href="" id="btnSearchAdvanced" >{% trans 'Advanced' %}</a>
|
<button class="btn btn-default" type="submit">{% trans 'Search' %}</button>
|
||||||
|
{% endif %}
|
||||||
|
<a class="btn btn-primary" href="" id="btnSearchAdvanced" > {% if setting_disable_simple_search == False %}{% trans 'Advanced' %}{% else %}{% trans 'Advanced search' %}{% endif %}</a>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -30,6 +51,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% if setting_disable_simple_search %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
jQuery(document).ready(function() {
|
jQuery(document).ready(function() {
|
||||||
var $selectSearchModel = $('#selectSearchModel');
|
var $selectSearchModel = $('#selectSearchModel');
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.db.models.signals import post_migrate
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from mayan.apps.common.apps import MayanAppConfig
|
from mayan.apps.common.apps import MayanAppConfig
|
||||||
@@ -11,6 +12,7 @@ from mayan.apps.common.menus import (
|
|||||||
from mayan.apps.navigation.classes import SourceColumn
|
from mayan.apps.navigation.classes import SourceColumn
|
||||||
|
|
||||||
from .dependencies import * # NOQA
|
from .dependencies import * # NOQA
|
||||||
|
from .handlers import handler_create_system_user
|
||||||
from .html_widgets import (
|
from .html_widgets import (
|
||||||
ObjectLinkWidget, widget_event_actor_link, widget_event_type_link
|
ObjectLinkWidget, widget_event_actor_link, widget_event_type_link
|
||||||
)
|
)
|
||||||
@@ -101,3 +103,8 @@ class EventsApp(MayanAppConfig):
|
|||||||
link_event_types_subscriptions_list, link_current_user_events
|
link_event_types_subscriptions_list, link_current_user_events
|
||||||
), position=50
|
), position=50
|
||||||
)
|
)
|
||||||
|
|
||||||
|
post_migrate.connect(
|
||||||
|
dispatch_uid='events_create_system_user',
|
||||||
|
receiver=handler_create_system_user,
|
||||||
|
)
|
||||||
|
|||||||
7
mayan/apps/events/handlers.py
Normal file
7
mayan/apps/events/handlers.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from .utils import create_system_user
|
||||||
|
|
||||||
|
|
||||||
|
def handler_create_system_user(sender, **kwargs):
|
||||||
|
create_system_user()
|
||||||
23
mayan/apps/events/utils.py
Normal file
23
mayan/apps/events/utils.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
|
|
||||||
|
def create_system_user():
|
||||||
|
"""
|
||||||
|
User account without a password used to attach events that normally
|
||||||
|
won't have an actor and a target
|
||||||
|
"""
|
||||||
|
user, created = get_user_model().objects.get_or_create(
|
||||||
|
username='system', defaults={
|
||||||
|
'first_name': 'System', 'is_staff': False
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
def get_system_user():
|
||||||
|
user = get_user_model().objects.get(username='system')
|
||||||
|
|
||||||
|
return user
|
||||||
3
mayan/apps/importer/__init__.py
Normal file
3
mayan/apps/importer/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
default_app_config = 'mayan.apps.importer.apps.ImporterApp'
|
||||||
17
mayan/apps/importer/apps.py
Normal file
17
mayan/apps/importer/apps.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.common.apps import MayanAppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class ImporterApp(MayanAppConfig):
|
||||||
|
app_namespace = 'importer'
|
||||||
|
app_url = 'importer'
|
||||||
|
has_rest_api = False
|
||||||
|
has_tests = True
|
||||||
|
name = 'mayan.apps.importer'
|
||||||
|
verbose_name = _('Importer')
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
super(ImporterApp, self).ready()
|
||||||
0
mayan/apps/importer/management/__init__.py
Normal file
0
mayan/apps/importer/management/__init__.py
Normal file
0
mayan/apps/importer/management/commands/__init__.py
Normal file
0
mayan/apps/importer/management/commands/__init__.py
Normal file
152
mayan/apps/importer/management/commands/import.py
Normal file
152
mayan/apps/importer/management/commands/import.py
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import csv
|
||||||
|
import time
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
|
from django.core import management
|
||||||
|
from django.core.files import File
|
||||||
|
|
||||||
|
from ...tasks import task_upload_new_document
|
||||||
|
|
||||||
|
|
||||||
|
class Command(management.BaseCommand):
|
||||||
|
help = 'Import documents from a CSV file.'
|
||||||
|
|
||||||
|
def add_arguments(self, parser):
|
||||||
|
parser.add_argument(
|
||||||
|
'--document_type_column',
|
||||||
|
action='store', dest='document_type_column', default=0,
|
||||||
|
help='Column that contains the document type labels. Column '
|
||||||
|
'numbers start at 0.',
|
||||||
|
type=int
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--document_path_column',
|
||||||
|
action='store', dest='document_path_column', default=1,
|
||||||
|
help='Column that contains the path to the document files. Column '
|
||||||
|
'numbers start at 0.',
|
||||||
|
type=int
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--ignore_errors',
|
||||||
|
action='store_true', dest='ignore_errors', default=False,
|
||||||
|
help='Don\'t stop the import process on common errors like '
|
||||||
|
'incorrect file paths.',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--ignore_rows',
|
||||||
|
action='store', dest='ignore_rows', default='',
|
||||||
|
help='Ignore a set of rows. Row numbers must be separated by commas.'
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--metadata_pairs_column',
|
||||||
|
action='store', dest='metadata_pairs_column',
|
||||||
|
help='Column that contains metadata name and values for the '
|
||||||
|
'documents. Use the form: <label column>:<value column>. Example: '
|
||||||
|
'2:5. Separate multiple pairs with commas. Example: 2:5,7:10',
|
||||||
|
)
|
||||||
|
parser.add_argument('filelist', nargs='?', help='File list')
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
time_start = time.time()
|
||||||
|
time_last_display = time_start
|
||||||
|
document_types = {}
|
||||||
|
uploaded_count = 0
|
||||||
|
row_count = 0
|
||||||
|
rows_to_ignore = []
|
||||||
|
for entry in options['ignore_rows'].split(','):
|
||||||
|
if entry:
|
||||||
|
rows_to_ignore.append(int(entry))
|
||||||
|
|
||||||
|
DocumentType = apps.get_model(
|
||||||
|
app_label='documents', model_name='DocumentType'
|
||||||
|
)
|
||||||
|
SharedUploadedFile = apps.get_model(
|
||||||
|
app_label='common', model_name='SharedUploadedFile'
|
||||||
|
)
|
||||||
|
|
||||||
|
if not options['filelist']:
|
||||||
|
self.stderr.write('Must specify a CSV file path.')
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
with open(options['filelist'], mode='r') as csv_datafile:
|
||||||
|
csv_reader = csv.reader(
|
||||||
|
csv_datafile, delimiter=',', quotechar='"'
|
||||||
|
)
|
||||||
|
for row in csv_reader:
|
||||||
|
# Increase row count here even though start index is 0
|
||||||
|
# purpose is to avoid losing row number increments on
|
||||||
|
# exceptions
|
||||||
|
row_count = row_count + 1
|
||||||
|
if row_count - 1 not in rows_to_ignore:
|
||||||
|
try:
|
||||||
|
with open(row[options['document_path_column']], mode='rb') as file_object:
|
||||||
|
document_type_label = row[options['document_type_column']]
|
||||||
|
|
||||||
|
if document_type_label not in document_types:
|
||||||
|
self.stdout.write(
|
||||||
|
'New document type: {}. Creating and caching.'.format(
|
||||||
|
document_type_label
|
||||||
|
)
|
||||||
|
)
|
||||||
|
document_type, created = DocumentType.objects.get_or_create(
|
||||||
|
label=document_type_label
|
||||||
|
)
|
||||||
|
document_types[document_type_label] = document_type
|
||||||
|
else:
|
||||||
|
document_type = document_types[document_type_label]
|
||||||
|
|
||||||
|
shared_uploaded_file = SharedUploadedFile.objects.create(
|
||||||
|
file=File(file_object)
|
||||||
|
)
|
||||||
|
|
||||||
|
extra_data = {}
|
||||||
|
if options['metadata_pairs_column']:
|
||||||
|
extra_data['metadata_pairs'] = []
|
||||||
|
|
||||||
|
for pair in options['metadata_pairs_column'].split(','):
|
||||||
|
name, value = pair.split(':')
|
||||||
|
extra_data['metadata_pairs'].append(
|
||||||
|
{
|
||||||
|
'name': row[int(name)],
|
||||||
|
'value': row[int(value)]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
task_upload_new_document.apply_async(
|
||||||
|
kwargs=dict(
|
||||||
|
document_type_id=document_type.pk,
|
||||||
|
shared_uploaded_file_id=shared_uploaded_file.pk,
|
||||||
|
extra_data=extra_data
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
uploaded_count = uploaded_count + 1
|
||||||
|
|
||||||
|
if (time.time() - time_last_display) > 1:
|
||||||
|
time_last_display = time.time()
|
||||||
|
self.stdout.write(
|
||||||
|
'Time: {}s, Files copied and queued: {}, files processed per second: {}'.format(
|
||||||
|
int(time.time() - time_start),
|
||||||
|
uploaded_count,
|
||||||
|
uploaded_count / (time.time() - time_start)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
except (IOError, OSError) as exception:
|
||||||
|
if not options['ignore_errors']:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
self.stderr.write(
|
||||||
|
'Error processing row: {}; {}.'.format(
|
||||||
|
row_count - 1, exception
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.stdout.write(
|
||||||
|
'Total files copied and queues: {}'.format(uploaded_count)
|
||||||
|
)
|
||||||
|
self.stdout.write(
|
||||||
|
'Total time: {}'.format(time.time() - time_start)
|
||||||
|
)
|
||||||
10
mayan/apps/importer/queues.py
Normal file
10
mayan/apps/importer/queues.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.documents.queues import queue_uploads
|
||||||
|
|
||||||
|
queue_uploads.add_task_type(
|
||||||
|
dotted_path='mayan.apps.importer.tasks.task_upload_new_document',
|
||||||
|
label=_('Import new document')
|
||||||
|
)
|
||||||
93
mayan/apps/importer/tasks.py
Normal file
93
mayan/apps/importer/tasks.py
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
|
from django.db import OperationalError
|
||||||
|
from django.utils.text import slugify
|
||||||
|
|
||||||
|
from mayan.celery import app
|
||||||
|
|
||||||
|
from mayan.apps.documents.literals import UPLOAD_NEW_DOCUMENT_RETRY_DELAY
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.task(bind=True, default_retry_delay=UPLOAD_NEW_DOCUMENT_RETRY_DELAY, ignore_result=True)
|
||||||
|
def task_upload_new_document(self, document_type_id, shared_uploaded_file_id, extra_data=None):
|
||||||
|
DocumentType = apps.get_model(
|
||||||
|
app_label='documents', model_name='DocumentType'
|
||||||
|
)
|
||||||
|
|
||||||
|
MetadataType = apps.get_model(
|
||||||
|
app_label='metadata', model_name='MetadataType'
|
||||||
|
)
|
||||||
|
|
||||||
|
SharedUploadedFile = apps.get_model(
|
||||||
|
app_label='common', model_name='SharedUploadedFile'
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
document_type = DocumentType.objects.get(pk=document_type_id)
|
||||||
|
shared_file = SharedUploadedFile.objects.get(
|
||||||
|
pk=shared_uploaded_file_id
|
||||||
|
)
|
||||||
|
except OperationalError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Operational error during attempt to retrieve shared data for '
|
||||||
|
'new document of type ID: %d; %s. Retrying.', document_type_id,
|
||||||
|
exception
|
||||||
|
)
|
||||||
|
raise self.retry(exc=exception)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with shared_file.open() as file_object:
|
||||||
|
new_document = document_type.new_document(file_object=file_object)
|
||||||
|
except OperationalError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Operational error during attempt to create new document '
|
||||||
|
'of type: %s; %s. Retrying.', document_type, exception
|
||||||
|
)
|
||||||
|
raise self.retry(exc=exception)
|
||||||
|
except Exception as exception:
|
||||||
|
# This except and else block emulate a finally:
|
||||||
|
logger.error(
|
||||||
|
'Unexpected error during attempt to create new document '
|
||||||
|
'of type: %s; %s', document_type, exception
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
shared_file.delete()
|
||||||
|
except OperationalError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Operational error during attempt to delete shared '
|
||||||
|
'file: %s; %s.', shared_file, exception
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if extra_data:
|
||||||
|
for pair in extra_data.get('metadata_pairs', []):
|
||||||
|
name = slugify(pair['name']).replace('-', '_')
|
||||||
|
logger.debug(
|
||||||
|
'Metadata pair (label, name, value): %s, %s, %s',
|
||||||
|
pair['name'], name, pair['value']
|
||||||
|
)
|
||||||
|
|
||||||
|
metadata_type, created = MetadataType.objects.get_or_create(
|
||||||
|
name=name, defaults={'label': pair['name']}
|
||||||
|
)
|
||||||
|
if not new_document.document_type.metadata.filter(metadata_type=metadata_type).exists():
|
||||||
|
logger.debug('Metadata type created')
|
||||||
|
new_document.document_type.metadata.create(
|
||||||
|
metadata_type=metadata_type, required=False
|
||||||
|
)
|
||||||
|
|
||||||
|
new_document.metadata.create(
|
||||||
|
metadata_type=metadata_type, value=pair['value']
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
shared_file.delete()
|
||||||
|
except OperationalError as exception:
|
||||||
|
logger.warning(
|
||||||
|
'Operational error during attempt to delete shared '
|
||||||
|
'file: %s; %s.', shared_file, exception
|
||||||
|
)
|
||||||
0
mayan/apps/importer/tests/__init__.py
Normal file
0
mayan/apps/importer/tests/__init__.py
Normal file
117
mayan/apps/importer/tests/test_management_commands.py
Normal file
117
mayan/apps/importer/tests/test_management_commands.py
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import csv
|
||||||
|
|
||||||
|
from django.core import management
|
||||||
|
from django.utils.encoding import force_bytes, force_text
|
||||||
|
|
||||||
|
from mayan.apps.documents.models import DocumentType, Document
|
||||||
|
from mayan.apps.documents.tests.base import GenericDocumentTestCase
|
||||||
|
from mayan.apps.documents.tests.literals import TEST_SMALL_DOCUMENT_PATH
|
||||||
|
from mayan.apps.storage.utils import fs_cleanup, mkstemp
|
||||||
|
|
||||||
|
|
||||||
|
class ImportManagementCommandTestCase(GenericDocumentTestCase):
|
||||||
|
auto_generate_test_csv_file = True
|
||||||
|
auto_upload_document = False
|
||||||
|
random_primary_key_enable = False
|
||||||
|
test_import_count = 1
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(ImportManagementCommandTestCase, self).setUp()
|
||||||
|
if self.auto_generate_test_csv_file:
|
||||||
|
self._create_test_csv_file()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self._destroy_test_csv_file()
|
||||||
|
super(ImportManagementCommandTestCase, self).tearDown()
|
||||||
|
|
||||||
|
def _create_test_csv_file(self):
|
||||||
|
self.test_csv_path = mkstemp()[1]
|
||||||
|
|
||||||
|
print('Test CSV file: {}'.format(self.test_csv_path))
|
||||||
|
|
||||||
|
with open(self.test_csv_path, mode='w', newline='') as file_object:
|
||||||
|
filewriter = csv.writer(
|
||||||
|
file_object, delimiter=',', quotechar='"',
|
||||||
|
quoting=csv.QUOTE_MINIMAL
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
'Generating test CSV for {} documents'.format(
|
||||||
|
self.test_import_count
|
||||||
|
)
|
||||||
|
)
|
||||||
|
for times in range(self.test_import_count):
|
||||||
|
filewriter.writerow(
|
||||||
|
[
|
||||||
|
self.test_document_type.label, TEST_SMALL_DOCUMENT_PATH,
|
||||||
|
'column 2', 'column 3', 'column 4', 'column 5',
|
||||||
|
'part #', 'value',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
filewriter.writerow(
|
||||||
|
[
|
||||||
|
self.test_document_type.label, TEST_SMALL_DOCUMENT_PATH,
|
||||||
|
'column 2', 'column 3', 'column 4', 'column 5',
|
||||||
|
'part#', 'value',
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def _destroy_test_csv_file(self):
|
||||||
|
fs_cleanup(filename=self.test_csv_path)
|
||||||
|
|
||||||
|
def test_import_csv_read(self):
|
||||||
|
self.test_document_type.delete()
|
||||||
|
management.call_command('import', self.test_csv_path)
|
||||||
|
|
||||||
|
self.assertTrue(DocumentType.objects.count() > 0)
|
||||||
|
self.assertTrue(Document.objects.count() > 0)
|
||||||
|
|
||||||
|
def test_import_document_type_column_mapping(self):
|
||||||
|
self.test_document_type.delete()
|
||||||
|
management.call_command(
|
||||||
|
'import', self.test_csv_path, '--document_type_column', '2'
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(DocumentType.objects.first().label == 'column 2')
|
||||||
|
self.assertTrue(Document.objects.count() > 0)
|
||||||
|
|
||||||
|
def test_import_document_path_column_mapping(self):
|
||||||
|
self.test_document_type.delete()
|
||||||
|
with self.assertRaises(IOError):
|
||||||
|
management.call_command(
|
||||||
|
'import', self.test_csv_path, '--document_path_column', '2'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_import_metadata_column_mapping(self):
|
||||||
|
self.test_document_type.delete()
|
||||||
|
management.call_command(
|
||||||
|
'import', self.test_csv_path, '--metadata_pairs_column', '2:3,4:5',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(DocumentType.objects.count() > 0)
|
||||||
|
self.assertTrue(Document.objects.count() > 0)
|
||||||
|
self.assertTrue(Document.objects.first().metadata.count() > 0)
|
||||||
|
self.assertEqual(
|
||||||
|
Document.objects.first().metadata.get(
|
||||||
|
metadata_type__name='column_2'
|
||||||
|
).value, 'column 3'
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_import_ambiguous_metadata(self):
|
||||||
|
self.auto_generate_test_csv_file = False
|
||||||
|
self.test_import_count = 2
|
||||||
|
|
||||||
|
self.test_document_type.delete()
|
||||||
|
management.call_command(
|
||||||
|
'import', self.test_csv_path, '--metadata_pairs_column', '6:7',
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(DocumentType.objects.count() > 0)
|
||||||
|
self.assertTrue(Document.objects.count() > 0)
|
||||||
|
self.assertTrue(Document.objects.first().metadata.count() > 0)
|
||||||
|
self.assertEqual(
|
||||||
|
Document.objects.first().metadata.get(
|
||||||
|
metadata_type__name='part'
|
||||||
|
).value, 'value'
|
||||||
|
)
|
||||||
@@ -689,7 +689,7 @@ class SourceColumn(object):
|
|||||||
logger.warning(
|
logger.warning(
|
||||||
'No request variable, aborting request resolution'
|
'No request variable, aborting request resolution'
|
||||||
)
|
)
|
||||||
return result
|
return final_result
|
||||||
|
|
||||||
current_view_name = get_current_view_name(request=request)
|
current_view_name = get_current_view_name(request=request)
|
||||||
for column in columns:
|
for column in columns:
|
||||||
|
|||||||
@@ -108,12 +108,6 @@ def navigation_resolve_menus(context, names, source=None, sort_results=None):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
|
||||||
def resolve_link(context, link):
|
|
||||||
# This can be used to resolve links or menus too
|
|
||||||
return link.resolve(context=context)
|
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def navigation_source_column_resolve(context, column):
|
def navigation_source_column_resolve(context, column):
|
||||||
if column:
|
if column:
|
||||||
@@ -121,3 +115,9 @@ def navigation_source_column_resolve(context, column):
|
|||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def resolve_link(context, link):
|
||||||
|
# This can be used to resolve links or menus too
|
||||||
|
return link.resolve(context=context)
|
||||||
|
|||||||
11
mayan/apps/redactions/icons.py
Normal file
11
mayan/apps/redactions/icons.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from mayan.apps.appearance.classes import Icon
|
||||||
|
|
||||||
|
icon_redaction_create = Icon(
|
||||||
|
driver_name='fontawesome-dual', primary_symbol='highlighter',
|
||||||
|
secondary_symbol='plus'
|
||||||
|
)
|
||||||
|
icon_redaction_delete = Icon(driver_name='fontawesome', symbol='times')
|
||||||
|
icon_redaction_edit = Icon(driver_name='fontawesome', symbol='pencil-alt')
|
||||||
|
icon_redactions = Icon(driver_name='fontawesome', symbol='highlighter')
|
||||||
@@ -8,9 +8,9 @@ from .api_views import (
|
|||||||
)
|
)
|
||||||
from .views import (
|
from .views import (
|
||||||
DocumentPagesAppendView, DocumentVersionUploadInteractiveView,
|
DocumentPagesAppendView, DocumentVersionUploadInteractiveView,
|
||||||
SetupSourceCheckView, SetupSourceCreateView, SetupSourceDeleteView,
|
SetupSourceCheckView, SetupSourceCreateView,
|
||||||
SetupSourceEditView, SetupSourceListView, SourceLogListView,
|
SetupSourceDeleteView, SetupSourceEditView, SetupSourceListView,
|
||||||
StagingFileDeleteView, UploadInteractiveView
|
SourceLogListView, StagingFileDeleteView, UploadInteractiveView
|
||||||
)
|
)
|
||||||
from .wizards import DocumentCreateWizard
|
from .wizards import DocumentCreateWizard
|
||||||
|
|
||||||
@@ -54,6 +54,14 @@ urlpatterns = [
|
|||||||
regex=r'^documents/(?P<document_pk>\d+)/pages/append/interactive/$',
|
regex=r'^documents/(?P<document_pk>\d+)/pages/append/interactive/$',
|
||||||
view=DocumentPagesAppendView.as_view(), name='document_pages_append'
|
view=DocumentPagesAppendView.as_view(), name='document_pages_append'
|
||||||
),
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^documents/(?P<document_pk>\d+)/pages/append/interactive/(?P<source_id>\d+)/$',
|
||||||
|
view=DocumentPagesAppendView.as_view(), name='document_pages_append'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^documents/(?P<document_pk>\d+)/pages/append/interactive/$',
|
||||||
|
view=DocumentPagesAppendView.as_view(), name='document_pages_append'
|
||||||
|
),
|
||||||
|
|
||||||
# Setup views
|
# Setup views
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
3
mayan/apps/weblinks/__init__.py
Normal file
3
mayan/apps/weblinks/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
default_app_config = 'mayan.apps.weblinks.apps.WebLinksApp'
|
||||||
15
mayan/apps/weblinks/admin.py
Normal file
15
mayan/apps/weblinks/admin.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import WebLink
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(WebLink)
|
||||||
|
class WebLinkAdmin(admin.ModelAdmin):
|
||||||
|
def document_type_list(self, instance):
|
||||||
|
return ','.join(
|
||||||
|
instance.document_types.values_list('label', flat=True)
|
||||||
|
)
|
||||||
|
|
||||||
|
filter_horizontal = ('document_types',)
|
||||||
|
list_display = ('label', 'template', 'enabled', 'document_type_list')
|
||||||
123
mayan/apps/weblinks/apps.py
Normal file
123
mayan/apps/weblinks/apps.py
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.acls.classes import ModelPermission
|
||||||
|
from mayan.apps.acls.links import link_acl_list
|
||||||
|
from mayan.apps.acls.permissions import permission_acl_edit, permission_acl_view
|
||||||
|
from mayan.apps.common.apps import MayanAppConfig
|
||||||
|
from mayan.apps.common.html_widgets import TwoStateWidget
|
||||||
|
from mayan.apps.common.menus import (
|
||||||
|
menu_facet, menu_list_facet, menu_object, menu_secondary, menu_setup
|
||||||
|
)
|
||||||
|
from mayan.apps.events.classes import ModelEventType
|
||||||
|
from mayan.apps.events.links import (
|
||||||
|
link_events_for_object, link_object_event_types_user_subcriptions_list
|
||||||
|
)
|
||||||
|
from mayan.apps.navigation.classes import SourceColumn
|
||||||
|
from .events import event_web_link_edited
|
||||||
|
from .links import (
|
||||||
|
link_document_type_web_links, link_document_web_link_list,
|
||||||
|
link_web_link_create, link_web_link_delete, link_web_link_document_types,
|
||||||
|
link_web_link_edit, link_web_link_instance_view,
|
||||||
|
link_web_link_list, link_web_link_setup
|
||||||
|
)
|
||||||
|
from .permissions import (
|
||||||
|
permission_web_link_delete, permission_web_link_edit,
|
||||||
|
permission_web_link_instance_view, permission_web_link_view
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class WebLinksApp(MayanAppConfig):
|
||||||
|
app_namespace = 'weblinks'
|
||||||
|
app_url = 'weblinks'
|
||||||
|
has_rest_api = False
|
||||||
|
has_tests = False
|
||||||
|
name = 'mayan.apps.weblinks'
|
||||||
|
verbose_name = _('Links')
|
||||||
|
|
||||||
|
def ready(self):
|
||||||
|
super(WebLinksApp, self).ready()
|
||||||
|
from actstream import registry
|
||||||
|
|
||||||
|
Document = apps.get_model(
|
||||||
|
app_label='documents', model_name='Document'
|
||||||
|
)
|
||||||
|
DocumentType = apps.get_model(
|
||||||
|
app_label='documents', model_name='DocumentType'
|
||||||
|
)
|
||||||
|
|
||||||
|
ResolvedWebLink = self.get_model(model_name='ResolvedWebLink')
|
||||||
|
WebLink = self.get_model(model_name='WebLink')
|
||||||
|
|
||||||
|
ModelEventType.register(
|
||||||
|
event_types=(
|
||||||
|
event_web_link_edited,
|
||||||
|
), model=WebLink
|
||||||
|
)
|
||||||
|
|
||||||
|
ModelPermission.register(
|
||||||
|
model=Document, permissions=(
|
||||||
|
permission_web_link_instance_view,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
ModelPermission.register(
|
||||||
|
model=DocumentType, permissions=(
|
||||||
|
permission_web_link_instance_view,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
ModelPermission.register(
|
||||||
|
model=WebLink, permissions=(
|
||||||
|
permission_acl_edit, permission_acl_view,
|
||||||
|
permission_web_link_delete, permission_web_link_edit,
|
||||||
|
permission_web_link_view
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
SourceColumn(
|
||||||
|
attribute='label', is_identifier=True, is_sortable=True,
|
||||||
|
source=ResolvedWebLink
|
||||||
|
)
|
||||||
|
SourceColumn(
|
||||||
|
attribute='label', is_identifier=True, is_sortable=True,
|
||||||
|
source=WebLink
|
||||||
|
)
|
||||||
|
SourceColumn(
|
||||||
|
attribute='enabled', is_sortable=True, source=WebLink,
|
||||||
|
widget=TwoStateWidget
|
||||||
|
)
|
||||||
|
|
||||||
|
menu_facet.bind_links(
|
||||||
|
links=(link_document_web_link_list,),
|
||||||
|
sources=(Document,)
|
||||||
|
)
|
||||||
|
menu_list_facet.bind_links(
|
||||||
|
links=(
|
||||||
|
link_acl_list, link_events_for_object,
|
||||||
|
link_web_link_document_types,
|
||||||
|
link_object_event_types_user_subcriptions_list,
|
||||||
|
), sources=(WebLink,)
|
||||||
|
)
|
||||||
|
menu_list_facet.bind_links(
|
||||||
|
links=(link_document_type_web_links,), sources=(DocumentType,)
|
||||||
|
)
|
||||||
|
menu_object.bind_links(
|
||||||
|
links=(
|
||||||
|
link_web_link_delete, link_web_link_edit
|
||||||
|
), sources=(WebLink,)
|
||||||
|
)
|
||||||
|
menu_object.bind_links(
|
||||||
|
links=(link_web_link_instance_view,),
|
||||||
|
sources=(ResolvedWebLink,)
|
||||||
|
)
|
||||||
|
menu_secondary.bind_links(
|
||||||
|
links=(link_web_link_list, link_web_link_create),
|
||||||
|
sources=(
|
||||||
|
WebLink, 'linking:web_link_list',
|
||||||
|
'linking:web_link_create'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
menu_setup.bind_links(links=(link_web_link_setup,))
|
||||||
|
|
||||||
|
registry.register(WebLink)
|
||||||
16
mayan/apps/weblinks/events.py
Normal file
16
mayan/apps/weblinks/events.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.events.classes import EventTypeNamespace
|
||||||
|
|
||||||
|
namespace = EventTypeNamespace(
|
||||||
|
label=_('Web links'), name='linking'
|
||||||
|
)
|
||||||
|
|
||||||
|
event_web_link_created = namespace.add_event_type(
|
||||||
|
label=_('Web link created'), name='web_link_created'
|
||||||
|
)
|
||||||
|
event_web_link_edited = namespace.add_event_type(
|
||||||
|
label=_('Web link edited'), name='web_link_edited'
|
||||||
|
)
|
||||||
11
mayan/apps/weblinks/forms.py
Normal file
11
mayan/apps/weblinks/forms.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
from .models import WebLink
|
||||||
|
|
||||||
|
|
||||||
|
class WebLinkForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
fields = ('label', 'template', 'enabled')
|
||||||
|
model = WebLink
|
||||||
22
mayan/apps/weblinks/icons.py
Normal file
22
mayan/apps/weblinks/icons.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from mayan.apps.appearance.classes import Icon
|
||||||
|
from mayan.apps.documents.icons import icon_document_type
|
||||||
|
|
||||||
|
icon_web_link = Icon(driver_name='fontawesome', symbol='external-link-alt')
|
||||||
|
icon_document_type_web_links = icon_web_link
|
||||||
|
icon_document_web_link_list = Icon(
|
||||||
|
driver_name='fontawesome', symbol='external-link-alt'
|
||||||
|
)
|
||||||
|
icon_web_link_create = Icon(
|
||||||
|
driver_name='fontawesome-dual', primary_symbol='external-link-alt',
|
||||||
|
secondary_symbol='plus'
|
||||||
|
)
|
||||||
|
icon_web_link_delete = Icon(driver_name='fontawesome', symbol='times')
|
||||||
|
icon_web_link_document_types = icon_document_type
|
||||||
|
icon_web_link_edit = Icon(driver_name='fontawesome', symbol='pencil-alt')
|
||||||
|
icon_web_link_instance_view = Icon(
|
||||||
|
driver_name='fontawesome', symbol='external-link-alt'
|
||||||
|
)
|
||||||
|
icon_web_link_setup = icon_web_link
|
||||||
|
icon_web_link_list = icon_web_link
|
||||||
63
mayan/apps/weblinks/links.py
Normal file
63
mayan/apps/weblinks/links.py
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.documents.permissions import permission_document_type_edit
|
||||||
|
from mayan.apps.navigation.classes import Link
|
||||||
|
|
||||||
|
from .permissions import (
|
||||||
|
permission_web_link_create, permission_web_link_delete,
|
||||||
|
permission_web_link_edit, permission_web_link_instance_view,
|
||||||
|
permission_web_link_view
|
||||||
|
)
|
||||||
|
|
||||||
|
link_document_type_web_links = Link(
|
||||||
|
args='resolved_object.pk',
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_document_type_web_links',
|
||||||
|
permissions=(permission_document_type_edit,), text=_('Web links'),
|
||||||
|
view='weblinks:document_type_web_links',
|
||||||
|
)
|
||||||
|
link_web_link_create = Link(
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_web_link_create',
|
||||||
|
permissions=(permission_web_link_create,),
|
||||||
|
text=_('Create new web link'), view='weblinks:web_link_create'
|
||||||
|
)
|
||||||
|
link_web_link_delete = Link(
|
||||||
|
args='object.pk',
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_web_link_delete',
|
||||||
|
permissions=(permission_web_link_delete,),
|
||||||
|
tags='dangerous', text=_('Delete'), view='weblinks:web_link_delete',
|
||||||
|
)
|
||||||
|
link_web_link_document_types = Link(
|
||||||
|
args='object.pk',
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_web_link_document_types',
|
||||||
|
permissions=(permission_web_link_edit,),
|
||||||
|
text=_('Document types'), view='weblinks:web_link_document_types',
|
||||||
|
)
|
||||||
|
link_web_link_edit = Link(
|
||||||
|
args='object.pk',
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_web_link_edit',
|
||||||
|
permissions=(permission_web_link_edit,),
|
||||||
|
text=_('Edit'), view='weblinks:web_link_edit',
|
||||||
|
)
|
||||||
|
link_web_link_instance_view = Link(
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_web_link_instance_view',
|
||||||
|
args=('document.pk', 'object.pk',),
|
||||||
|
permissions=(permission_web_link_instance_view,), tags='new_window',
|
||||||
|
text=_('Navigate'), view='weblinks:web_link_instance_view',
|
||||||
|
)
|
||||||
|
link_document_web_link_list = Link(
|
||||||
|
args='resolved_object.pk',
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_document_web_link_list',
|
||||||
|
permissions=(permission_web_link_instance_view,), text=_('Web links'),
|
||||||
|
view='weblinks:document_web_link_list',
|
||||||
|
)
|
||||||
|
link_web_link_list = Link(
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_web_link_list',
|
||||||
|
text=_('Web links'), view='weblinks:web_link_list'
|
||||||
|
)
|
||||||
|
link_web_link_setup = Link(
|
||||||
|
icon_class_path='mayan.apps.weblinks.icons.icon_web_link_setup',
|
||||||
|
permissions=(permission_web_link_create,), text=_('Web links'),
|
||||||
|
view='weblinks:web_link_list'
|
||||||
|
)
|
||||||
16
mayan/apps/weblinks/managers.py
Normal file
16
mayan/apps/weblinks/managers.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
from mayan.apps.acls.models import AccessControlList
|
||||||
|
|
||||||
|
from .permissions import permission_web_link_instance_view
|
||||||
|
|
||||||
|
|
||||||
|
class WebLinkManager(models.Manager):
|
||||||
|
def get_for(self, document, user):
|
||||||
|
queryset = self.filter(
|
||||||
|
document_types=document.document_type, enabled=True
|
||||||
|
)
|
||||||
|
return AccessControlList.objects.restrict_queryset(
|
||||||
|
permission=permission_web_link_instance_view,
|
||||||
|
queryset=queryset, user=user
|
||||||
|
)
|
||||||
42
mayan/apps/weblinks/migrations/0001_initial.py
Normal file
42
mayan/apps/weblinks/migrations/0001_initial.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.20 on 2019-07-01 19:42
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('documents', '0047_auto_20180917_0737'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='WebLink',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('label', models.CharField(db_index=True, max_length=96, verbose_name='Label')),
|
||||||
|
('template', models.TextField(verbose_name='Template')),
|
||||||
|
('enabled', models.BooleanField(default=True, verbose_name='Enabled')),
|
||||||
|
('document_types', models.ManyToManyField(related_name='web_links', to='documents.DocumentType', verbose_name='Document types')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'ordering': ('label',),
|
||||||
|
'verbose_name': 'Web link',
|
||||||
|
'verbose_name_plural': 'Web links',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='ResolvedWebLink',
|
||||||
|
fields=[
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'proxy': True,
|
||||||
|
'indexes': [],
|
||||||
|
},
|
||||||
|
bases=('weblinks.weblink',),
|
||||||
|
),
|
||||||
|
]
|
||||||
0
mayan/apps/weblinks/migrations/__init__.py
Normal file
0
mayan/apps/weblinks/migrations/__init__.py
Normal file
90
mayan/apps/weblinks/models.py
Normal file
90
mayan/apps/weblinks/models.py
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, transaction
|
||||||
|
from django.template import Context, Template
|
||||||
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.documents.events import event_document_type_edited
|
||||||
|
from mayan.apps.documents.models import DocumentType
|
||||||
|
|
||||||
|
from .events import event_web_link_created, event_web_link_edited
|
||||||
|
from .managers import WebLinkManager
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
|
class WebLink(models.Model):
|
||||||
|
"""
|
||||||
|
This model stores the basic fields for a web link. Web links allow
|
||||||
|
generating links from documents to external resources.
|
||||||
|
"""
|
||||||
|
label = models.CharField(
|
||||||
|
db_index=True, max_length=96, verbose_name=_('Label')
|
||||||
|
)
|
||||||
|
template = models.TextField(verbose_name=_('Template'))
|
||||||
|
enabled = models.BooleanField(default=True, verbose_name=_('Enabled'))
|
||||||
|
document_types = models.ManyToManyField(
|
||||||
|
related_name='web_links', to=DocumentType,
|
||||||
|
verbose_name=_('Document types')
|
||||||
|
)
|
||||||
|
|
||||||
|
objects = WebLinkManager()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('label',)
|
||||||
|
verbose_name = _('Web link')
|
||||||
|
verbose_name_plural = _('Web links')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.label
|
||||||
|
|
||||||
|
def document_types_add(self, queryset, _user=None):
|
||||||
|
with transaction.atomic():
|
||||||
|
event_web_link_edited.commit(
|
||||||
|
actor=_user, target=self
|
||||||
|
)
|
||||||
|
for obj in queryset:
|
||||||
|
self.document_types.add(obj)
|
||||||
|
event_document_type_edited.commit(
|
||||||
|
actor=_user, action_object=self, target=obj
|
||||||
|
)
|
||||||
|
|
||||||
|
def document_types_remove(self, queryset, _user=None):
|
||||||
|
with transaction.atomic():
|
||||||
|
event_web_link_edited.commit(
|
||||||
|
actor=_user, target=self
|
||||||
|
)
|
||||||
|
for obj in queryset:
|
||||||
|
self.document_types.remove(obj)
|
||||||
|
event_document_type_edited.commit(
|
||||||
|
actor=_user, action_object=self, target=obj
|
||||||
|
)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
_user = kwargs.pop('_user', None)
|
||||||
|
|
||||||
|
with transaction.atomic():
|
||||||
|
is_new = not self.pk
|
||||||
|
super(WebLink, self).save(*args, **kwargs)
|
||||||
|
if is_new:
|
||||||
|
event_web_link_created.commit(
|
||||||
|
actor=_user, target=self
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
event_web_link_edited.commit(
|
||||||
|
actor=_user, target=self
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ResolvedWebLink(WebLink):
|
||||||
|
"""
|
||||||
|
Proxy model to represent an already resolved web link. Used for easier
|
||||||
|
colums registration.
|
||||||
|
"""
|
||||||
|
class Meta:
|
||||||
|
proxy = True
|
||||||
|
|
||||||
|
def get_url_for(self, document):
|
||||||
|
context = Context({'document': document})
|
||||||
|
|
||||||
|
return Template(self.template).render(context=context)
|
||||||
23
mayan/apps/weblinks/permissions.py
Normal file
23
mayan/apps/weblinks/permissions.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
from mayan.apps.permissions import PermissionNamespace
|
||||||
|
|
||||||
|
namespace = PermissionNamespace(label=_('Web links'), name='web_links')
|
||||||
|
|
||||||
|
permission_web_link_create = namespace.add_permission(
|
||||||
|
label=_('Create new web links'), name='web_link_create'
|
||||||
|
)
|
||||||
|
permission_web_link_delete = namespace.add_permission(
|
||||||
|
label=_('Delete web links'), name='web_link_delete'
|
||||||
|
)
|
||||||
|
permission_web_link_edit = namespace.add_permission(
|
||||||
|
label=_('Edit web links'), name='web_link_edit'
|
||||||
|
)
|
||||||
|
permission_web_link_view = namespace.add_permission(
|
||||||
|
label=_('View existing web links'), name='web_link_view'
|
||||||
|
)
|
||||||
|
permission_web_link_instance_view = namespace.add_permission(
|
||||||
|
label=_('View web link instances'), name='web_link_instance_view'
|
||||||
|
)
|
||||||
47
mayan/apps/weblinks/urls.py
Normal file
47
mayan/apps/weblinks/urls.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from .views import (
|
||||||
|
DocumentWebLinkListView, DocumentTypeWebLinksView, ResolvedWebLinkView,
|
||||||
|
SetupWebLinkDocumentTypesView, WebLinkCreateView, WebLinkDeleteView,
|
||||||
|
WebLinkEditView, WebLinkListView
|
||||||
|
)
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(
|
||||||
|
regex=r'^document/(?P<pk>\d+)/list/$',
|
||||||
|
view=DocumentWebLinkListView.as_view(),
|
||||||
|
name='document_web_link_list'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^document/(?P<document_pk>\d+)/(?P<web_link_pk>\d+)/$',
|
||||||
|
view=ResolvedWebLinkView.as_view(), name='web_link_instance_view'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^document_types/(?P<pk>\d+)/web_links/$',
|
||||||
|
view=DocumentTypeWebLinksView.as_view(),
|
||||||
|
name='document_type_web_links'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^setup/list/$', view=WebLinkListView.as_view(),
|
||||||
|
name='web_link_list'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^setup/create/$', view=WebLinkCreateView.as_view(),
|
||||||
|
name='web_link_create'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^setup/(?P<pk>\d+)/delete/$',
|
||||||
|
view=WebLinkDeleteView.as_view(), name='web_link_delete'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^setup/(?P<pk>\d+)/edit/$', view=WebLinkEditView.as_view(),
|
||||||
|
name='web_link_edit'
|
||||||
|
),
|
||||||
|
url(
|
||||||
|
regex=r'^setup/(?P<pk>\d+)/document_types/$',
|
||||||
|
view=SetupWebLinkDocumentTypesView.as_view(),
|
||||||
|
name='web_link_document_types'
|
||||||
|
),
|
||||||
|
]
|
||||||
233
mayan/apps/weblinks/views.py
Normal file
233
mayan/apps/weblinks/views.py
Normal file
@@ -0,0 +1,233 @@
|
|||||||
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from django.db import transaction
|
||||||
|
from django.shortcuts import get_object_or_404
|
||||||
|
from django.template import RequestContext
|
||||||
|
from django.urls import reverse_lazy
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
from django.views.generic import RedirectView
|
||||||
|
|
||||||
|
from mayan.apps.acls.models import AccessControlList
|
||||||
|
from mayan.apps.common.generics import (
|
||||||
|
AddRemoveView, SingleObjectCreateView, SingleObjectDeleteView,
|
||||||
|
SingleObjectEditView, SingleObjectListView
|
||||||
|
)
|
||||||
|
from mayan.apps.common.mixins import ExternalObjectMixin
|
||||||
|
from mayan.apps.documents.events import event_document_type_edited
|
||||||
|
from mayan.apps.documents.models import Document, DocumentType
|
||||||
|
from mayan.apps.documents.permissions import permission_document_type_edit
|
||||||
|
|
||||||
|
from .events import event_web_link_edited
|
||||||
|
from .forms import WebLinkForm
|
||||||
|
from .icons import icon_web_link_setup
|
||||||
|
from .links import link_web_link_create
|
||||||
|
from .models import ResolvedWebLink, WebLink
|
||||||
|
from .permissions import (
|
||||||
|
permission_web_link_create, permission_web_link_delete,
|
||||||
|
permission_web_link_edit, permission_web_link_instance_view,
|
||||||
|
permission_web_link_view
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentTypeWebLinksView(AddRemoveView):
|
||||||
|
main_object_method_add = 'web_link_add'
|
||||||
|
main_object_method_remove = 'web_link_remove'
|
||||||
|
main_object_permission = permission_document_type_edit
|
||||||
|
main_object_model = DocumentType
|
||||||
|
main_object_pk_url_kwarg = 'pk'
|
||||||
|
secondary_object_model = WebLink
|
||||||
|
secondary_object_permission = permission_web_link_edit
|
||||||
|
list_available_title = _('Available web links')
|
||||||
|
list_added_title = _('Web links enabled')
|
||||||
|
related_field = 'web_links'
|
||||||
|
|
||||||
|
def action_add(self, queryset, _user):
|
||||||
|
with transaction.atomic():
|
||||||
|
event_document_type_edited.commit(
|
||||||
|
actor=_user, target=self.main_object
|
||||||
|
)
|
||||||
|
for obj in queryset:
|
||||||
|
self.main_object.web_links.add(obj)
|
||||||
|
event_web_link_edited.commit(
|
||||||
|
actor=_user, action_object=self.main_object, target=obj
|
||||||
|
)
|
||||||
|
|
||||||
|
def action_remove(self, queryset, _user):
|
||||||
|
with transaction.atomic():
|
||||||
|
event_document_type_edited.commit(
|
||||||
|
actor=_user, target=self.main_object
|
||||||
|
)
|
||||||
|
for obj in queryset:
|
||||||
|
self.main_object.web_links.remove(obj)
|
||||||
|
event_web_link_edited.commit(
|
||||||
|
actor=_user, action_object=self.main_object, target=obj
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_actions_extra_kwargs(self):
|
||||||
|
return {'_user': self.request.user}
|
||||||
|
|
||||||
|
def get_extra_context(self):
|
||||||
|
return {
|
||||||
|
'object': self.main_object,
|
||||||
|
'title': _(
|
||||||
|
'Web links to enable for document type: %s'
|
||||||
|
) % self.main_object,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ResolvedWebLinkView(ExternalObjectMixin, RedirectView):
|
||||||
|
external_object_class = Document
|
||||||
|
external_object_pk_url_kwarg = 'document_pk'
|
||||||
|
external_object_permission = permission_web_link_instance_view
|
||||||
|
|
||||||
|
def get_redirect_url(self, *args, **kwargs):
|
||||||
|
return self.get_resolved_web_link().get_url_for(
|
||||||
|
document=self.external_object
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_resolved_web_link(self):
|
||||||
|
return get_object_or_404(
|
||||||
|
klass=self.get_web_link_queryset(), pk=self.kwargs['web_link_pk']
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_web_link_queryset(self):
|
||||||
|
return ResolvedWebLink.objects.get_for(
|
||||||
|
document=self.external_object, user=self.request.user
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SetupWebLinkDocumentTypesView(AddRemoveView):
|
||||||
|
main_object_method_add = 'document_types_add'
|
||||||
|
main_object_method_remove = 'document_types_remove'
|
||||||
|
main_object_permission = permission_web_link_edit
|
||||||
|
main_object_model = WebLink
|
||||||
|
main_object_pk_url_kwarg = 'pk'
|
||||||
|
secondary_object_model = DocumentType
|
||||||
|
secondary_object_permission = permission_document_type_edit
|
||||||
|
list_available_title = _('Available document types')
|
||||||
|
list_added_title = _('Document types enabled')
|
||||||
|
related_field = 'document_types'
|
||||||
|
|
||||||
|
def get_actions_extra_kwargs(self):
|
||||||
|
return {'_user': self.request.user}
|
||||||
|
|
||||||
|
def get_extra_context(self):
|
||||||
|
return {
|
||||||
|
'object': self.main_object,
|
||||||
|
'title': _(
|
||||||
|
'Document type for which to enable web link: %s'
|
||||||
|
) % self.main_object,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class WebLinkListView(SingleObjectListView):
|
||||||
|
object_permission = permission_web_link_view
|
||||||
|
|
||||||
|
def get_extra_context(self):
|
||||||
|
return {
|
||||||
|
'hide_link': True,
|
||||||
|
'hide_object': True,
|
||||||
|
'no_results_icon': icon_web_link_setup,
|
||||||
|
'no_results_main_link': link_web_link_create.resolve(
|
||||||
|
context=RequestContext(request=self.request)
|
||||||
|
),
|
||||||
|
'no_results_text': _(
|
||||||
|
'Web links allow generating links from documents to external '
|
||||||
|
'resources.'
|
||||||
|
),
|
||||||
|
'no_results_title': _(
|
||||||
|
'There are no web links'
|
||||||
|
),
|
||||||
|
'title': _('Web links'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_source_queryset(self):
|
||||||
|
return self.get_web_link_queryset()
|
||||||
|
|
||||||
|
def get_web_link_queryset(self):
|
||||||
|
return WebLink.objects.all()
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentWebLinkListView(WebLinkListView):
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
self.document = get_object_or_404(klass=Document, pk=self.kwargs['pk'])
|
||||||
|
|
||||||
|
AccessControlList.objects.check_access(
|
||||||
|
obj=self.document, permissions=(permission_web_link_instance_view,),
|
||||||
|
user=request.user
|
||||||
|
)
|
||||||
|
|
||||||
|
return super(
|
||||||
|
DocumentWebLinkListView, self
|
||||||
|
).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
def get_extra_context(self):
|
||||||
|
return {
|
||||||
|
'document': self.document,
|
||||||
|
'hide_link': True,
|
||||||
|
'hide_object': True,
|
||||||
|
'no_results_icon': icon_web_link_setup,
|
||||||
|
#'no_results_text': _(
|
||||||
|
# 'Web links allow defining relationships between '
|
||||||
|
# 'documents even if they are in different indexes and '
|
||||||
|
# 'are of different types.'
|
||||||
|
#),
|
||||||
|
'no_results_title': _(
|
||||||
|
'There are no web links for this document'
|
||||||
|
),
|
||||||
|
'object': self.document,
|
||||||
|
'title': _('Web links for document: %s') % self.document,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_web_link_queryset(self):
|
||||||
|
return ResolvedWebLink.objects.get_for(
|
||||||
|
document=self.document, user=self.request.user
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class WebLinkCreateView(SingleObjectCreateView):
|
||||||
|
extra_context = {'title': _('Create new web link')}
|
||||||
|
form_class = WebLinkForm
|
||||||
|
post_action_redirect = reverse_lazy(
|
||||||
|
viewname='weblinks:web_link_list'
|
||||||
|
)
|
||||||
|
view_permission = permission_web_link_create
|
||||||
|
|
||||||
|
def get_save_extra_data(self):
|
||||||
|
return {'_user': self.request.user}
|
||||||
|
|
||||||
|
|
||||||
|
class WebLinkDeleteView(SingleObjectDeleteView):
|
||||||
|
model = WebLink
|
||||||
|
object_permission = permission_web_link_delete
|
||||||
|
post_action_redirect = reverse_lazy(
|
||||||
|
viewname='weblinks:web_link_list'
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_extra_context(self):
|
||||||
|
return {
|
||||||
|
'object': self.get_object(),
|
||||||
|
'title': _('Delete web link: %s') % self.get_object()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class WebLinkEditView(SingleObjectEditView):
|
||||||
|
form_class = WebLinkForm
|
||||||
|
model = WebLink
|
||||||
|
object_permission = permission_web_link_edit
|
||||||
|
post_action_redirect = reverse_lazy(
|
||||||
|
viewname='weblinks:web_link_list'
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_extra_context(self):
|
||||||
|
return {
|
||||||
|
'object': self.get_object(),
|
||||||
|
'title': _('Edit web link: %s') % self.get_object()
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_save_extra_data(self):
|
||||||
|
return {'_user': self.request.user}
|
||||||
@@ -117,6 +117,7 @@ INSTALLED_APPS = (
|
|||||||
'mayan.apps.document_states',
|
'mayan.apps.document_states',
|
||||||
'mayan.apps.documents',
|
'mayan.apps.documents',
|
||||||
'mayan.apps.file_metadata',
|
'mayan.apps.file_metadata',
|
||||||
|
'mayan.apps.importer',
|
||||||
'mayan.apps.linking',
|
'mayan.apps.linking',
|
||||||
'mayan.apps.mailer',
|
'mayan.apps.mailer',
|
||||||
'mayan.apps.mayan_statistics',
|
'mayan.apps.mayan_statistics',
|
||||||
|
|||||||
Reference in New Issue
Block a user