From 0144bd37fc183bf2208bc7d57a141bba848c255b Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Wed, 18 Mar 2020 17:36:09 +0000 Subject: [PATCH] Start to seperate versioning into its own app --- PyRIGS/settings.py | 1 + RIGS/importer_tests.py | 28 ------------------- RIGS/urls.py | 3 +- assets/urls.py | 2 +- assets/views.py | 18 ++++++------ gulpfile.js | 2 +- .../templates/activity_feed.html | 17 +---------- .../templates/activity_feed_data.html | 0 .../templates/activity_table.html | 19 +------------ .../templates/asset_activity_table.html | 0 .../templates/asset_version_history.html | 0 .../templates/version_changes.html | 6 ++-- .../templates/version_changes_change.html | 0 .../templates/version_history.html | 13 +-------- versioning/templates/version_scripts.html | 20 +++++++++++++ {RIGS => versioning}/versioning.py | 20 ++++++------- 16 files changed, 47 insertions(+), 102 deletions(-) delete mode 100644 RIGS/importer_tests.py rename {RIGS => versioning}/templates/activity_feed.html (69%) rename {RIGS => versioning}/templates/activity_feed_data.html (100%) rename {RIGS => versioning}/templates/activity_table.html (75%) rename {assets => versioning}/templates/asset_activity_table.html (100%) rename {assets => versioning}/templates/asset_version_history.html (100%) rename {RIGS => versioning}/templates/version_changes.html (56%) rename {RIGS => versioning}/templates/version_changes_change.html (100%) rename {RIGS => versioning}/templates/version_history.html (80%) create mode 100644 versioning/templates/version_scripts.html rename {RIGS => versioning}/versioning.py (99%) diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index e7598583..d8f00cec 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -58,6 +58,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', + 'versioning', 'RIGS', 'assets', diff --git a/RIGS/importer_tests.py b/RIGS/importer_tests.py deleted file mode 100644 index 36485f25..00000000 --- a/RIGS/importer_tests.py +++ /dev/null @@ -1,28 +0,0 @@ -__author__ = 'ghost' - -import unittest -from importer import fix_email - - -class EmailFixerTest(unittest.TestCase): - def test_correct(self): - e = fix_email("tom@ghost.uk.net") - self.assertEqual(e, "tom@ghost.uk.net") - - def test_partial(self): - e = fix_email("psytp") - self.assertEqual(e, "psytp@nottingham.ac.uk") - - def test_none(self): - old = None - new = fix_email(old) - self.assertEqual(old, new) - - def test_empty(self): - old = "" - new = fix_email(old) - self.assertEqual(old, new) - - -if __name__ == '__main__': - unittest.main() diff --git a/RIGS/urls.py b/RIGS/urls.py index 9f299fd8..d4df5b44 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -5,7 +5,8 @@ from django.views.decorators.clickjacking import xframe_options_exempt from django.views.generic import RedirectView from PyRIGS.decorators import (api_key_required, has_oembed, permission_required_with_403) -from RIGS import finance, ical, models, rigboard, versioning, views +from RIGS import finance, ical, models, rigboard, views +from versioning import versioning urlpatterns = [ path('', login_required(views.Index.as_view()), name='index'), diff --git a/assets/urls.py b/assets/urls.py index dc8e021c..5022b05b 100644 --- a/assets/urls.py +++ b/assets/urls.py @@ -1,7 +1,7 @@ from django.conf.urls import url from django.urls import path from assets import views, models -from RIGS import versioning +from versioning import versioning from django.contrib.auth.decorators import login_required from django.views.decorators.clickjacking import xframe_options_exempt diff --git a/assets/views.py b/assets/views.py index b113a901..9faeb468 100644 --- a/assets/views.py +++ b/assets/views.py @@ -1,16 +1,14 @@ +import simplejson +from assets import forms, models from django.contrib.auth.mixins import LoginRequiredMixin -from django.http import JsonResponse -from django.http import HttpResponse, Http404 +from django.db.models import Q +from django.http import Http404, HttpResponse, JsonResponse +from django.shortcuts import get_object_or_404 +from django.urls import reverse +from django.utils.decorators import method_decorator from django.views import generic from django.views.decorators.csrf import csrf_exempt -from django.utils.decorators import method_decorator -from django.urls import reverse -from django.db.models import Q -from django.shortcuts import get_object_or_404 -from assets import models, forms -from RIGS import versioning - -import simplejson +from versioning import versioning @method_decorator(csrf_exempt, name='dispatch') diff --git a/gulpfile.js b/gulpfile.js index 0650f823..f0b60268 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -77,7 +77,7 @@ function browserSyncReload(done) { function watchFiles() { gulp.watch("RIGS/static/scss/**/*", styles); gulp.watch("RIGS/static/js/**/*", scripts); - gulp.watch(['templates/**/*.html', 'RIGS/templates/**/*.html', 'assets/templates/**/*.html'], browserSyncReload); + gulp.watch(['templates/**/*.html', 'RIGS/templates/**/*.html', 'assets/templates/**/*.html', 'versioning/templates/**/*.html'], browserSyncReload); //gulp.watch("gulpfile.js", gulp.parallel(styles, scripts)); TODO This causes a reload loop } diff --git a/RIGS/templates/activity_feed.html b/versioning/templates/activity_feed.html similarity index 69% rename from RIGS/templates/activity_feed.html rename to versioning/templates/activity_feed.html index 0603b8e3..c61f9065 100644 --- a/RIGS/templates/activity_feed.html +++ b/versioning/templates/activity_feed.html @@ -1,21 +1,6 @@ -{% load static %} - {% block js %} - - +{% include 'version_scripts.html' %} - - - - +{% include 'version_scripts.html' %} {% endblock %} {% block content %} diff --git a/assets/templates/asset_activity_table.html b/versioning/templates/asset_activity_table.html similarity index 100% rename from assets/templates/asset_activity_table.html rename to versioning/templates/asset_activity_table.html diff --git a/assets/templates/asset_version_history.html b/versioning/templates/asset_version_history.html similarity index 100% rename from assets/templates/asset_version_history.html rename to versioning/templates/asset_version_history.html diff --git a/RIGS/templates/version_changes.html b/versioning/templates/version_changes.html similarity index 56% rename from RIGS/templates/version_changes.html rename to versioning/templates/version_changes.html index c40af3ef..541b33c0 100644 --- a/RIGS/templates/version_changes.html +++ b/versioning/templates/version_changes.html @@ -1,9 +1,9 @@ {% if version.changes.item_changes or version.changes.field_changes or version.changes.old == None %} {% for change in version.changes.field_changes %} - {{ change.field.verbose_name }} + {{ change.field.verbose_name }} {% endfor %} {% for itemChange in version.changes.item_changes %} - item '{% if itemChange.new %}{{ itemChange.new.name }}{% else %}{{ itemChange.old.name }}{% endif %}' + {% endspaceless %}'>item '{% if itemChange.new %}{{ itemChange.new.name }}{% else %}{{ itemChange.old.name }}{% endif %}' {% endfor %} {% else %} nothing useful diff --git a/RIGS/templates/version_changes_change.html b/versioning/templates/version_changes_change.html similarity index 100% rename from RIGS/templates/version_changes_change.html rename to versioning/templates/version_changes_change.html diff --git a/RIGS/templates/version_history.html b/versioning/templates/version_history.html similarity index 80% rename from RIGS/templates/version_history.html rename to versioning/templates/version_history.html index f61df5d3..0625e309 100644 --- a/RIGS/templates/version_history.html +++ b/versioning/templates/version_history.html @@ -1,22 +1,11 @@ {% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %} {% load to_class_name from filters %} {% load paginator from filters %} -{% load static %} {% block title %}{{object|to_class_name}} {{ object.pk|stringformat:"05d" }} - Revision History{% endblock %} {% block js %} - - - +{% include 'version_scripts.html' %} {% endblock %} {% block content %} diff --git a/versioning/templates/version_scripts.html b/versioning/templates/version_scripts.html new file mode 100644 index 00000000..c5602e20 --- /dev/null +++ b/versioning/templates/version_scripts.html @@ -0,0 +1,20 @@ +{% load static %} + + + + + \ No newline at end of file diff --git a/RIGS/versioning.py b/versioning/versioning.py similarity index 99% rename from RIGS/versioning.py rename to versioning/versioning.py index c652a9fa..0c861b10 100644 --- a/RIGS/versioning.py +++ b/versioning/versioning.py @@ -1,18 +1,14 @@ - - -import logging import datetime +import logging -from django.core.exceptions import ObjectDoesNotExist -from django.shortcuts import get_object_or_404 -from django.views import generic -from django.utils.functional import cached_property -from django.db.models import IntegerField, EmailField, TextField -from django.contrib.contenttypes.models import ContentType - -from reversion.models import Version, VersionQuerySet from diff_match_patch import diff_match_patch - +from django.contrib.contenttypes.models import ContentType +from django.core.exceptions import ObjectDoesNotExist +from django.db.models import EmailField, IntegerField, TextField +from django.shortcuts import get_object_or_404 +from django.utils.functional import cached_property +from django.views import generic +from reversion.models import Version, VersionQuerySet from RIGS import models logger = logging.getLogger('tec.pyrigs')