From 339b7dd836bcec28223cd72befe8f52a390fe469 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 7 Oct 2019 16:43:00 -0400 Subject: [PATCH 1/8] Add missing dependencies import Signed-off-by: Roberto Rosario --- mayan/apps/task_manager/apps.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mayan/apps/task_manager/apps.py b/mayan/apps/task_manager/apps.py index 51044d3c52..4ae48a9e48 100644 --- a/mayan/apps/task_manager/apps.py +++ b/mayan/apps/task_manager/apps.py @@ -8,6 +8,7 @@ from mayan.apps.common.menus import menu_tools from mayan.apps.navigation.classes import SourceColumn from .classes import CeleryQueue, Task +from .dependencies import * # NOQA from .links import link_task_manager from .settings import * # NOQA From 517bb4e9a203c04679db7db0fc605b8f639f57e8 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 8 Oct 2019 09:33:39 -0400 Subject: [PATCH 2/8] Move Makefile versions to variables Signed-off-by: Roberto Rosario --- Makefile | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index e5de22ab31..489c40d584 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,15 @@ .PHONY: clean-pyc clean-build +DOCKER_MYSQL_IMAGE = mysql:8.0 +DOCKER_ORACLE_IMAGE = wnameless/oracle-xe-11g +DOCKER_POSTGRES_IMAGE = postgres:9.6-alpine +DOCKER_REDIS_IMAGE = redis:5.0-alpine + +PYTHON_MYSQL_VERSION = 1.4.4 +PYTHON_PSYCOPG2_VERSION = 2.8.3 +PYTHON_RABBITMQ_VERSION = 2.0.0 +PYTHON_REDIS_VERSION = 3.2.1 + help: @echo "Usage: make \n" @awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*?## / { printf " * %-40s -%s\n", $$1, $$2 }' $(MAKEFILE_LIST)|sort @@ -18,7 +28,7 @@ clean-pyc: ## Remove Python artifacts. find . -name '*.pyc' -exec rm -f {} + find . -name '*.pyo' -exec rm -f {} + find . -name '*~' -exec rm -f {} + - find . -name '__pycache__' -exec rm -R -f {} + + find . -name '__pycache__' -exec rm -R -f {} + # Testing @@ -33,10 +43,10 @@ test-all: clean-pyc test-launch-postgres: @docker rm -f test-postgres || true @docker volume rm test-postgres || true - docker run -d --name test-postgres -p 5432:5432 -v test-postgres:/var/lib/postgresql/data healthcheck/postgres + docker run -d --name test-postgres -p 5432:5432 -v test-postgres:/var/lib/postgresql/data $(DOCKER_POSTGRES_IMAGE) sudo apt-get install -q libpq-dev - pip install psycopg2 - while ! docker inspect --format='{{json .State.Health}}' test-postgres|grep 'Status":"healthy"'; do sleep 1; done + pip install psycopg2==$(PYTHON_PSYCOPG2_VERSION) + while ! nc -z 127.0.0.1 5432; do sleep 1; done test-with-postgres: ## MODULE= - Run tests for a single app, module or test class against a Postgres database container. test-with-postgres: test-launch-postgres @@ -53,10 +63,10 @@ test-with-postgres-all: test-launch-postgres test-launch-mysql: @docker rm -f test-mysql || true @docker volume rm test-mysql || true - docker run -d --name test-mysql -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=True -e MYSQL_DATABASE=mayan -v test-mysql:/var/lib/mysql healthcheck/mysql + docker run -d --name test-mysql -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=True -e MYSQL_DATABASE=mayan -v test-mysql:/var/lib/mysql $(DOCKER_MYSQL_IMAGE) sudo apt-get install -q libmysqlclient-dev mysql-client - pip install mysqlclient - while ! docker inspect --format='{{json .State.Health}}' test-mysql|grep 'Status":"healthy"'; do sleep 1; done + pip install mysqlclient==$(PYTHON_MYSQL_VERSION) + while ! nc -z 127.0.0.1 3306; do sleep 1; done mysql -h 127.0.0.1 -P 3306 -uroot -e "set global character_set_server=utf8mb4;" test-with-mysql: ## MODULE= - Run tests for a single app, module or test class against a MySQL database container. @@ -75,7 +85,7 @@ test-with-mysql-all: test-launch-mysql test-launch-oracle: @docker rm -f test-oracle || true @docker volume rm test-oracle || true - docker run -d --name test-oracle -p 49160:22 -p 49161:1521 -e ORACLE_ALLOW_REMOTE=true -v test-oracle:/u01/app/oracle wnameless/oracle-xe-11g + docker run -d --name test-oracle -p 49160:22 -p 49161:1521 -e ORACLE_ALLOW_REMOTE=true -v test-oracle:/u01/app/oracle $(DOCKER_ORACLE_IMAGE) # https://gist.github.com/kimus/10012910 pip install cx_Oracle while ! nc -z 127.0.0.1 49161; do sleep 1; done @@ -243,11 +253,12 @@ shell_plus: ## Run the shell_plus command. ./manage.py shell_plus --settings=mayan.settings.development test-with-docker-services-on: ## Launch and initialize production-like services using Docker (Postgres and Redis). - docker run -d --name redis -p 6379:6379 redis - docker run -d --name postgres -p 5432:5432 postgres + docker run -d --name redis -p 6379:6379 $(DOCKER_REDIS_IMAGE) + docker run -d --name postgres -p 5432:5432 $(DOCKER_POSTGRES_IMAGE) while ! nc -z 127.0.0.1 6379; do sleep 1; done while ! nc -z 127.0.0.1 5432; do sleep 1; done sleep 4 + pip install psycopg2==$(PYTHON_PSYCOPG2_VERSION) redis==$(PYTHON_REDIS_VERSION) ./manage.py initialsetup --settings=mayan.settings.staging.docker test-with-docker-services-off: ## Stop and delete the Docker production-like services. @@ -261,7 +272,7 @@ test-with-docker-worker: ## Launch a worker instance that uses the production-li DJANGO_SETTINGS_MODULE=mayan.settings.staging.docker ./manage.py celery worker -A mayan -B -l INFO -O fair docker-mysql-on: ## Launch and initialize a MySQL Docker container. - docker run -d --name mysql -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=True -e MYSQL_DATABASE=mayan_edms mysql + docker run -d --name mysql -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=True -e MYSQL_DATABASE=mayan_edms $(DOCKER_MYSQL_IMAGE) while ! nc -z 127.0.0.1 3306; do sleep 1; done docker-mysql-off: ## Stop and delete the MySQL Docker container. @@ -269,7 +280,7 @@ docker-mysql-off: ## Stop and delete the MySQL Docker container. docker rm mysql docker-postgres-on: ## Launch and initialize a PostgreSQL Docker container. - docker run -d --name postgres -p 5432:5432 postgres + docker run -d --name postgres -p 5432:5432 $(DOCKER_POSTGRES_IMAGE) while ! nc -z 127.0.0.1 5432; do sleep 1; done docker-postgres-off: ## Stop and delete the PostgreSQL Docker container. From 4659269349981533fe4024d4fd688e824f871cc9 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 8 Oct 2019 09:43:10 -0400 Subject: [PATCH 3/8] Invalidate the layer cache in tests Signed-off-by: Roberto Rosario --- mayan/apps/common/tests/base.py | 3 ++- mayan/apps/converter/tests/mixins.py | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mayan/apps/common/tests/base.py b/mayan/apps/common/tests/base.py index 3c352df9df..81802e63e7 100644 --- a/mayan/apps/common/tests/base.py +++ b/mayan/apps/common/tests/base.py @@ -5,6 +5,7 @@ from django.test import TestCase from django_downloadview import assert_download_response from mayan.apps.acls.tests.mixins import ACLTestCaseMixin +from mayan.apps.converter.tests.mixins import LayerTestCaseMixin from mayan.apps.permissions.classes import Permission from mayan.apps.smart_settings.classes import Namespace from mayan.apps.user_management.tests.mixins import UserTestMixin @@ -19,7 +20,7 @@ from .mixins import ( class BaseTestCase( - SilenceLoggerTestCaseMixin, ConnectionsCheckTestCaseMixin, + LayerTestCaseMixin, SilenceLoggerTestCaseMixin, ConnectionsCheckTestCaseMixin, RandomPrimaryKeyModelMonkeyPatchMixin, ACLTestCaseMixin, ModelTestCaseMixin, OpenFileCheckTestCaseMixin, TempfileCheckTestCasekMixin, UserTestMixin, TestCase diff --git a/mayan/apps/converter/tests/mixins.py b/mayan/apps/converter/tests/mixins.py index b5a914a232..7fffc10f4d 100644 --- a/mayan/apps/converter/tests/mixins.py +++ b/mayan/apps/converter/tests/mixins.py @@ -14,6 +14,12 @@ from .literals import ( ) +class LayerTestCaseMixin(object): + def setUp(self): + super(LayerTestCaseMixin, self).setUp() + Layer.invalidate_cache() + + class LayerTestMixin(PermissionTestMixin): test_layer = Layer( label='Test layer', name='test_layer', order=1000, @@ -38,8 +44,6 @@ class LayerTestMixin(PermissionTestMixin): 'select': self.test_layer_permission, 'view': self.test_layer_permission, } - Layer.invalidate_cache() - Layer.update() class TransformationTestMixin(LayerTestMixin): From 7b3a83ee39c700ca54ab505a2daed72faebe6f59 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 8 Oct 2019 09:48:54 -0400 Subject: [PATCH 4/8] Update GitLab CI to use Python 3 and virtualenv Signed-off-by: Roberto Rosario --- .gitlab-ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a5b56f4358..b620d70cb2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -152,7 +152,9 @@ job_push_python: - locale-gen en_US.UTF-8 - update-locale LANG=en_US.UTF-8 - export LC_ALL=en_US.UTF-8 - - apt-get install -qq curl exiftool gcc ghostscript gnupg1 graphviz libfuse2 libjpeg-dev libmagic1 libpng-dev libtiff-dev poppler-utils libreoffice poppler-utils python-dev python-pip tesseract-ocr tesseract-ocr-deu + - apt-get install -qq curl exiftool gcc ghostscript gnupg1 graphviz libfuse2 libjpeg-dev libmagic1 libpng-dev libtiff-dev poppler-utils libreoffice poppler-utils python-dev python-virtualenv python3-dev tesseract-ocr tesseract-ocr-deu + - virtualenv venv -p /usr/bin/python3 + - . venv/bin/activate - pip install -r requirements.txt -r requirements/testing-base.txt only: - releases/all @@ -170,6 +172,7 @@ test-mysql: - mysql:8.0.3 script: - apt-get install -qq libmysqlclient-dev mysql-client + - . venv/bin/activate - pip install mysqlclient - mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" -e "set global character_set_server=utf8mb4;" - python manage.py test --mayan-apps --settings=mayan.settings.testing.gitlab-ci.db_mysql --nomigrations @@ -185,6 +188,7 @@ test-postgres: - postgres script: - apt-get install -qq libpq-dev + - . venv/bin/activate - pip install psycopg2 - python manage.py test --mayan-apps --settings=mayan.settings.testing.gitlab-ci.db_postgres --nomigrations tags: @@ -193,6 +197,7 @@ test-postgres: test-sqlite: <<: *test_base script: + - . venv/bin/activate - python manage.py test --mayan-apps --settings=mayan.settings.testing.gitlab-ci --nomigrations deploy_demo: From 1b327b99f01814af6984e97f5f37ae68b1e29b93 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 8 Oct 2019 15:14:16 -0400 Subject: [PATCH 5/8] Update run_test Docker command name Signed-off-by: Roberto Rosario --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b620d70cb2..772bd315d3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ job_docker_build: - docker build --pull -t "$CI_REGISTRY_IMAGE" -f docker/Dockerfile . - VERSION=`cat docker/rootfs/version` - docker tag "$CI_REGISTRY_IMAGE" "$CI_REGISTRY_IMAGE:$VERSION" - - docker run --rm "$CI_REGISTRY_IMAGE:$VERSION" run-tests + - docker run --rm "$CI_REGISTRY_IMAGE:$VERSION" run_tests - docker push "$CI_REGISTRY_IMAGE:$VERSION" - docker push "$CI_REGISTRY_IMAGE:latest" - docker tag "$CI_REGISTRY_IMAGE:$VERSION" registry-1.docker.io/mayanedms/mayanedms:"$VERSION" @@ -58,7 +58,7 @@ job_docker_nightly: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" -f docker/Dockerfile . - - docker run --rm "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" run-tests + - docker run --rm "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" run_tests - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" only: - nightly From cc8147d002546bd2db06a20ddbd38f54172eb238 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Tue, 8 Oct 2019 15:15:50 -0400 Subject: [PATCH 6/8] Update requirements and setup Signed-off-by: Roberto Rosario --- mayan/__init__.py | 2 +- requirements/base.txt | 2 ++ setup.py | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mayan/__init__.py b/mayan/__init__.py index 9401b78d20..c1392d304f 100644 --- a/mayan/__init__.py +++ b/mayan/__init__.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals __title__ = 'Mayan EDMS' __version__ = '3.3beta1' __build__ = 0x030300 -__build_string__ = 'v3.3beta1_Sat Oct 5 15:08:53 2019 -0400' +__build_string__ = 'v3.3beta1-9-g1b327b99f0_Tue Oct 8 15:15:08 2019 -0400' __django_version__ = '1.11' __author__ = 'Roberto Rosario' __author_email__ = 'roberto.rosario@mayan-edms.com' diff --git a/requirements/base.txt b/requirements/base.txt index 87dd80811c..337001f564 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,7 +1,9 @@ Pillow==6.0.0 PyPDF2==1.26.0 PyYAML==5.1.1 +celery==4.3.0 django-activity-stream==0.7.0 +django-celery-beat==1.5.0 django-colorful==1.3 django-cors-headers==2.5.2 django-downloadview==1.9 diff --git a/setup.py b/setup.py index a8ab7ec567..5b4c273ef0 100644 --- a/setup.py +++ b/setup.py @@ -60,7 +60,9 @@ django==1.11.24 Pillow==6.0.0 PyPDF2==1.26.0 PyYAML==5.1.1 +celery==4.3.0 django-activity-stream==0.7.0 +django-celery-beat==1.5.0 django-colorful==1.3 django-cors-headers==2.5.2 django-downloadview==1.9 From bd0d298be3f8f4f6a56c8c093fb6823b1089319c Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 10 Oct 2019 14:34:50 -0400 Subject: [PATCH 7/8] New document version improvements from clients/bc - Comment field help text. - Remove create_document_form_form. - Use static NewVersionForm. - Update sources document upload and new version upload view names. Signed-off-by: Roberto Rosario --- .../apps/cabinets/tests/test_wizard_steps.py | 2 +- mayan/apps/checkouts/tests/test_views.py | 2 +- .../apps/metadata/tests/test_wizard_steps.py | 4 +-- mayan/apps/sources/apps.py | 5 ++-- mayan/apps/sources/forms.py | 13 ++++----- mayan/apps/sources/links.py | 2 +- mayan/apps/sources/tests/test_views.py | 10 +++---- mayan/apps/sources/urls.py | 14 ++++++---- mayan/apps/sources/views.py | 27 ++++++++----------- mayan/apps/sources/wizards.py | 2 +- mayan/apps/tags/tests/test_wizard_steps.py | 2 +- 11 files changed, 40 insertions(+), 43 deletions(-) diff --git a/mayan/apps/cabinets/tests/test_wizard_steps.py b/mayan/apps/cabinets/tests/test_wizard_steps.py index 84f7fabd82..3f93b768fa 100644 --- a/mayan/apps/cabinets/tests/test_wizard_steps.py +++ b/mayan/apps/cabinets/tests/test_wizard_steps.py @@ -33,7 +33,7 @@ class CabinetDocumentUploadTestCase(CabinetTestMixin, GenericDocumentViewTestCas def _request_upload_interactive_document_create_view(self): with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object: return self.post( - viewname='sources:upload_interactive', kwargs={ + viewname='sources:document_upload_interactive', kwargs={ 'source_id': self.test_source.pk }, data={ 'document_type_id': self.test_document_type.pk, diff --git a/mayan/apps/checkouts/tests/test_views.py b/mayan/apps/checkouts/tests/test_views.py index 128e1643e0..c701618511 100644 --- a/mayan/apps/checkouts/tests/test_views.py +++ b/mayan/apps/checkouts/tests/test_views.py @@ -376,7 +376,7 @@ class NewVersionBlockViewTestCase( self.login_superuser() response = self.post( - viewname='sources:upload_version', kwargs={ + viewname='sources:document_version_upload', kwargs={ 'document_pk': self.test_document.pk }, follow=True ) diff --git a/mayan/apps/metadata/tests/test_wizard_steps.py b/mayan/apps/metadata/tests/test_wizard_steps.py index a2384fdd83..853d735085 100644 --- a/mayan/apps/metadata/tests/test_wizard_steps.py +++ b/mayan/apps/metadata/tests/test_wizard_steps.py @@ -34,7 +34,7 @@ class DocumentUploadMetadataTestCase(MetadataTypeTestMixin, GenericDocumentViewT def test_upload_interactive_with_unicode_metadata(self): url = URL( - path=reverse(viewname='sources:upload_interactive') + path=reverse(viewname='sources:document_upload_interactive') ) url.args['metadata0_id'] = self.test_metadata_type.pk url.args['metadata0_value'] = TEST_METADATA_VALUE_UNICODE @@ -61,7 +61,7 @@ class DocumentUploadMetadataTestCase(MetadataTypeTestMixin, GenericDocumentViewT def test_upload_interactive_with_ampersand_metadata(self): url = URL( - path=reverse(viewname='sources:upload_interactive') + path=reverse(viewname='sources:document_upload_interactive') ) url.args['metadata0_id'] = self.test_metadata_type.pk url.args['metadata0_value'] = TEST_METADATA_VALUE_WITH_AMPERSAND diff --git a/mayan/apps/sources/apps.py b/mayan/apps/sources/apps.py index 7139e5a846..bd86e07bd6 100644 --- a/mayan/apps/sources/apps.py +++ b/mayan/apps/sources/apps.py @@ -145,8 +145,9 @@ class SourcesApp(MayanAppConfig): menu_secondary.bind_links( links=(link_document_version_upload,), sources=( - 'documents:document_version_list', 'documents:upload_version', - 'documents:document_version_revert' + 'documents:document_version_list', + 'documents:document_version_revert', + 'sources:document_version_upload' ) ) diff --git a/mayan/apps/sources/forms.py b/mayan/apps/sources/forms.py index a6431f71e5..e555967cd9 100644 --- a/mayan/apps/sources/forms.py +++ b/mayan/apps/sources/forms.py @@ -23,14 +23,11 @@ class NewDocumentForm(DocumentForm): class NewVersionForm(forms.Form): - def __init__(self, *args, **kwargs): - super(NewVersionForm, self).__init__(*args, **kwargs) - - self.fields['comment'] = forms.CharField( - label=_('Comment'), - required=False, - widget=forms.widgets.Textarea(attrs={'rows': 4}), - ) + comment = forms.CharField( + help_text=_('An optional comment to explain the upload.'), + label=_('Comment'), required=False, + widget=forms.widgets.Textarea(attrs={'rows': 4}), + ) class UploadBaseForm(forms.Form): diff --git a/mayan/apps/sources/links.py b/mayan/apps/sources/links.py index b1793547f5..35146f38a1 100644 --- a/mayan/apps/sources/links.py +++ b/mayan/apps/sources/links.py @@ -117,7 +117,7 @@ link_document_version_upload = Link( args='resolved_object.pk', condition=document_new_version_not_blocked, icon_class_path='mayan.apps.sources.icons.icon_document_version_upload', permissions=(permission_document_new_version,), - text=_('Upload new version'), view='sources:upload_version', + text=_('Upload new version'), view='sources:document_version_upload', ) link_setup_source_logs = Link( args=('resolved_object.pk',), diff --git a/mayan/apps/sources/tests/test_views.py b/mayan/apps/sources/tests/test_views.py index ee64dfdffd..a5484201f1 100644 --- a/mayan/apps/sources/tests/test_views.py +++ b/mayan/apps/sources/tests/test_views.py @@ -32,7 +32,7 @@ class DocumentUploadWizardViewTestMixin(object): def _request_upload_wizard_view(self, document_path=TEST_SMALL_DOCUMENT_PATH): with open(document_path, mode='rb') as file_object: return self.post( - viewname='sources:upload_interactive', kwargs={ + viewname='sources:document_upload_interactive', kwargs={ 'source_id': self.test_source.pk }, data={ 'source-file': file_object, @@ -42,7 +42,7 @@ class DocumentUploadWizardViewTestMixin(object): def _request_upload_interactive_view(self): return self.get( - viewname='sources:upload_interactive', data={ + viewname='sources:document_upload_interactive', data={ 'document_type_id': self.test_document_type.pk, } ) @@ -113,7 +113,7 @@ class DocumentUploadWizardViewTestCase( with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object: response = self.post( - viewname='sources:upload_interactive', kwargs={ + viewname='sources:document_upload_interactive', kwargs={ 'source_id': self.test_source.pk }, data={ 'source-file': file_object, @@ -157,7 +157,7 @@ class DocumentUploadIssueTestCase(GenericDocumentViewTestCase): # Upload the test document with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object: self.post( - viewname='sources:upload_interactive', data={ + viewname='sources:document_upload_interactive', data={ 'document-language': 'eng', 'source-file': file_object, 'document_type_id': self.test_document_type.pk @@ -207,7 +207,7 @@ class NewDocumentVersionViewTestCase(GenericDocumentViewTestCase): NewVersionBlock.objects.block(self.test_document) response = self.post( - viewname='sources:upload_version', kwargs={ + viewname='sources:document_version_upload', kwargs={ 'document_pk': self.test_document.pk }, follow=True ) diff --git a/mayan/apps/sources/urls.py b/mayan/apps/sources/urls.py index fdc7adc330..cffeb4bf29 100644 --- a/mayan/apps/sources/urls.py +++ b/mayan/apps/sources/urls.py @@ -9,7 +9,7 @@ from .api_views import ( from .views import ( SetupSourceCheckView, SetupSourceCreateView, SetupSourceDeleteView, SetupSourceEditView, SetupSourceListView, SourceLogListView, - StagingFileDeleteView, UploadInteractiveVersionView, UploadInteractiveView + StagingFileDeleteView, DocumentVersionUploadInteractiveView, UploadInteractiveView ) from .wizards import DocumentCreateWizard @@ -27,19 +27,23 @@ urlpatterns = [ ), url( regex=r'^documents/upload/new/interactive/(?P\d+)/$', - view=UploadInteractiveView.as_view(), name='upload_interactive' + view=UploadInteractiveView.as_view(), + name='document_upload_interactive' ), url( regex=r'^documents/upload/new/interactive/$', - view=UploadInteractiveView.as_view(), name='upload_interactive' + view=UploadInteractiveView.as_view(), + name='document_upload_interactive' ), url( regex=r'^documents/(?P\d+)/versions/upload/interactive/(?P\d+)/$', - view=UploadInteractiveVersionView.as_view(), name='upload_version' + view=DocumentVersionUploadInteractiveView.as_view(), + name='document_version_upload' ), url( regex=r'^documents/(?P\d+)/versions/upload/interactive/$', - view=UploadInteractiveVersionView.as_view(), name='upload_version' + view=DocumentVersionUploadInteractiveView.as_view(), + name='document_version_upload' ), # Setup views diff --git a/mayan/apps/sources/views.py b/mayan/apps/sources/views.py index be55047b7d..4e24c01be3 100644 --- a/mayan/apps/sources/views.py +++ b/mayan/apps/sources/views.py @@ -84,10 +84,10 @@ class UploadBaseView(MultiFormView): @staticmethod def get_tab_link_for_source(source, document=None): if document: - view = 'sources:upload_version' + view = 'sources:document_version_upload' args = ('"{}"'.format(document.pk), '"{}"'.format(source.pk),) else: - view = 'sources:upload_interactive' + view = 'sources:document_upload_interactive' args = ('"{}"'.format(source.pk),) return Link( @@ -180,8 +180,8 @@ class UploadBaseView(MultiFormView): }, }) - menu_facet.bound_links['sources:upload_interactive'] = self.tab_links - menu_facet.bound_links['sources:upload_version'] = self.tab_links + menu_facet.bound_links['sources:document_upload_interactive'] = self.tab_links + menu_facet.bound_links['sources:document_version_upload'] = self.tab_links context.update( { @@ -360,7 +360,7 @@ class UploadInteractiveView(UploadBaseView): return context -class UploadInteractiveVersionView(UploadBaseView): +class DocumentVersionUploadInteractiveView(UploadBaseView): def dispatch(self, request, *args, **kwargs): self.subtemplates_list = [] @@ -392,7 +392,7 @@ class UploadInteractiveVersionView(UploadBaseView): self.tab_links = UploadBaseView.get_active_tab_links(self.document) return super( - UploadInteractiveVersionView, self + DocumentVersionUploadInteractiveView, self ).dispatch(request, *args, **kwargs) def forms_valid(self, forms): @@ -448,13 +448,6 @@ class UploadInteractiveVersionView(UploadBaseView): files=kwargs.get('files', None), ) - def create_document_form_form(self, **kwargs): - return self.get_form_classes()['document_form']( - prefix=kwargs['prefix'], - data=kwargs.get('data', None), - files=kwargs.get('files', None), - ) - def get_form_classes(self): return { 'document_form': NewVersionForm, @@ -463,12 +456,14 @@ class UploadInteractiveVersionView(UploadBaseView): def get_context_data(self, **kwargs): context = super( - UploadInteractiveVersionView, self + DocumentVersionUploadInteractiveView, self ).get_context_data(**kwargs) context['object'] = self.document context['title'] = _( - 'Upload a new version from source: %s' - ) % self.source.label + 'Upload a new version for document "%(document)s" ' + 'from source: %(source)s' + ) % {'document': self.document, 'source': self.source.label} + context['submit_label'] = _('Submit') return context diff --git a/mayan/apps/sources/wizards.py b/mayan/apps/sources/wizards.py index c88c7c0822..0523442b15 100644 --- a/mayan/apps/sources/wizards.py +++ b/mayan/apps/sources/wizards.py @@ -201,7 +201,7 @@ class DocumentCreateWizard(SessionWizardView): for step in WizardStep.get_all(): query_dict.update(step.done(wizard=self) or {}) - url = furl(reverse(viewname='sources:upload_interactive')) + url = furl(reverse(viewname='sources:document_upload_interactive')) # Use equal and not .update() to get the same result as using # urlencode(doseq=True) url.args = query_dict diff --git a/mayan/apps/tags/tests/test_wizard_steps.py b/mayan/apps/tags/tests/test_wizard_steps.py index 46824a83b1..b93a8edf10 100644 --- a/mayan/apps/tags/tests/test_wizard_steps.py +++ b/mayan/apps/tags/tests/test_wizard_steps.py @@ -27,7 +27,7 @@ class TaggedDocumentUploadTestCase(TagTestMixin, GenericDocumentViewTestCase): def _request_upload_interactive_document_create_view(self): with open(TEST_SMALL_DOCUMENT_PATH, mode='rb') as file_object: return self.post( - viewname='sources:upload_interactive', kwargs={ + viewname='sources:document_upload_interactive', kwargs={ 'source_id': self.test_source.pk }, data={ 'document_type_id': self.test_document_type.pk, From c731ab70502cb58a440a24064d84dddb780db6ce Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 10 Oct 2019 14:50:26 -0400 Subject: [PATCH 8/8] Add kwargs and update string formatting Signed-off-by: Roberto Rosario --- mayan/apps/common/generics.py | 44 +++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/mayan/apps/common/generics.py b/mayan/apps/common/generics.py index 37f5c268ea..7de15ca51f 100644 --- a/mayan/apps/common/generics.py +++ b/mayan/apps/common/generics.py @@ -53,8 +53,8 @@ class MultiFormView(DjangoFormView): template_name = 'appearance/generic_form.html' def _create_form(self, form_name, klass): - form_kwargs = self.get_form_kwargs(form_name) - form_create_method = 'create_%s_form' % form_name + form_kwargs = self.get_form_kwargs(form_name=form_name) + form_create_method = 'create_{}_form'.format(form_name) if hasattr(self, form_create_method): form = getattr(self, form_create_method)(**form_kwargs) else: @@ -66,17 +66,17 @@ class MultiFormView(DjangoFormView): def dispatch(self, request, *args, **kwargs): form_classes = self.get_form_classes() - self.forms = self.get_forms(form_classes) + self.forms = self.get_forms(form_classes=form_classes) return super(MultiFormView, self).dispatch(request, *args, **kwargs) def forms_valid(self, forms): for form_name, form in forms.items(): - form_valid_method = '%s_form_valid' % form_name + form_valid_method = '{}_form_valid'.format(form_name) if hasattr(self, form_valid_method): - return getattr(self, form_valid_method)(form) + return getattr(self, form_valid_method)(form=form) - self.all_forms_valid(forms) + self.all_forms_valid(forms=forms) return HttpResponseRedirect(redirect_to=self.get_success_url()) @@ -98,14 +98,16 @@ class MultiFormView(DjangoFormView): def get_form_kwargs(self, form_name): kwargs = {} - kwargs.update({'initial': self.get_initial(form_name)}) - kwargs.update({'prefix': self.get_prefix(form_name)}) + kwargs.update({'initial': self.get_initial(form_name=form_name)}) + kwargs.update({'prefix': self.get_prefix(form_name=form_name)}) if self.request.method in ('POST', 'PUT'): - kwargs.update({ - 'data': self.request.POST, - 'files': self.request.FILES, - }) + kwargs.update( + { + 'data': self.request.POST, + 'files': self.request.FILES, + } + ) kwargs.update(self.get_form_extra_kwargs(form_name=form_name) or {}) @@ -118,13 +120,13 @@ class MultiFormView(DjangoFormView): return dict( [ ( - key, self._create_form(key, klass) + key, self._create_form(form_name=key, klass=klass) ) for key, klass in form_classes.items() ] ) def get_initial(self, form_name): - initial_method = 'get_%s_initial' % form_name + initial_method = 'get_{}_initial'.format(form_name) if hasattr(self, initial_method): return getattr(self, initial_method)() else: @@ -206,9 +208,9 @@ class AddRemoveView( getattr(self.main_object, self.related_field).add(*queryset) else: raise ImproperlyConfigured( - 'View %s must be called with a main_object_method_add, a ' + 'View {} must be called with a main_object_method_add, a ' 'related_field, or an action_add ' - 'method.' % self.__class__.__name__ + 'method.'.format(self.__class__.__name__) ) def _action_remove(self, queryset): @@ -225,9 +227,9 @@ class AddRemoveView( getattr(self.main_object, self.related_field).remove(*queryset) else: raise ImproperlyConfigured( - 'View %s must be called with a main_object_method_remove, a ' + 'View {} must be called with a main_object_method_remove, a ' 'related_field, or an action_remove ' - 'method.' % self.__class__.__name__ + 'method.'.format(self.__class__.__name__) ) def dispatch(self, request, *args, **kwargs): @@ -348,8 +350,10 @@ class AddRemoveView( def get_list_added_queryset(self): if not self.related_field: raise ImproperlyConfigured( - 'View %s must be called with either a related_field or ' - 'override .get_list_added_queryset().' % self.__class__.__name__ + 'View {} must be called with either a related_field or ' + 'override .get_list_added_queryset().'.format( + self.__class__.__name__ + ) ) return self.get_secondary_object_list().filter(