From 975befe299af3057e639f3c3bc98270d5cf29ea5 Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Fri, 23 Apr 2021 00:26:02 +0300 Subject: [PATCH 01/12] Added pencil icon --- anytask/issues/templates/issues/history.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/anytask/issues/templates/issues/history.html b/anytask/issues/templates/issues/history.html index 2d8dc1022..4a150e408 100644 --- a/anytask/issues/templates/issues/history.html +++ b/anytask/issues/templates/issues/history.html @@ -91,6 +91,9 @@
{% trans "obsuzhdenie_zadachi" %}
{% localtime on %} {{ event.timestamp|date:"d M H:i" }} {% endlocaltime %} + + +
From 22023454ab11930e3ad0695155f0ee27969695d3 Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Fri, 23 Apr 2021 18:37:16 +0300 Subject: [PATCH 02/12] CST-75 znick#379 add empty modal panel appearing on pencil click --- anytask/issues/templates/issues/history.html | 33 +++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/anytask/issues/templates/issues/history.html b/anytask/issues/templates/issues/history.html index 4a150e408..1e4a3d518 100644 --- a/anytask/issues/templates/issues/history.html +++ b/anytask/issues/templates/issues/history.html @@ -91,9 +91,40 @@
{% trans "obsuzhdenie_zadachi" %}
{% localtime on %} {{ event.timestamp|date:"d M H:i" }} {% endlocaltime %} + + {% if event.author == user %} {# start edit message elements #} - +
+ + + + + {% endif %} {# end edit message elements #} +
From 469bb6f422bc481d5aeea705a50ea1ac7332e9d3 Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Fri, 23 Apr 2021 22:37:19 +0300 Subject: [PATCH 03/12] CST-75 znick#379 remove modal panel, add js focus on id_comment element Edit will be performed in existing id_comment textarea. On submit the form will send information about message edited if any. --- anytask/issues/templates/file_uploader.html | 4 ++- anytask/issues/templates/issues/history.html | 27 +------------------ anytask/issues/templates/issues/issue_js.html | 6 +++++ 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/anytask/issues/templates/file_uploader.html b/anytask/issues/templates/file_uploader.html index 70f068b0e..0fe08a379 100644 --- a/anytask/issues/templates/file_uploader.html +++ b/anytask/issues/templates/file_uploader.html @@ -66,6 +66,7 @@ + {% block UPLOAD_FORM_BUTTON_BAR %} diff --git a/anytask/issues/templates/issues/issue_js.html b/anytask/issues/templates/issues/issue_js.html index 71761dc0e..ca266e8db 100644 --- a/anytask/issues/templates/issues/issue_js.html +++ b/anytask/issues/templates/issues/issue_js.html @@ -221,5 +221,11 @@ $("#file_field").append('' + files + ''); } + function start_edit_msg(event_id, event_msg) { + $('#id_comment').val(event_msg); + $('#submit_btn').focus(); + $('#submit_btn').blur(); + } + From 7bb72240ab2400fa2cf65de158adaf30e079c364 Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Sat, 24 Apr 2021 16:03:25 +0300 Subject: [PATCH 04/12] CST-75 znick#379 add message edit, check user permission on edit --- anytask/issues/templates/file_uploader.html | 8 ++++++-- anytask/issues/templates/issues/history.html | 4 ++-- anytask/issues/templates/issues/issue_js.html | 16 ++++++++++++---- anytask/issues/views.py | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/anytask/issues/templates/file_uploader.html b/anytask/issues/templates/file_uploader.html index 0fe08a379..fd0198f52 100644 --- a/anytask/issues/templates/file_uploader.html +++ b/anytask/issues/templates/file_uploader.html @@ -66,7 +66,7 @@ - + {% block UPLOAD_FORM_BUTTON_BAR %}
{% comment %} @@ -140,11 +140,15 @@ {% else %} {% endif %} {% endblock %} + +
{% block UPLOAD_FORM_PROGRESS_BAR %} {% comment %} diff --git a/anytask/issues/templates/issues/history.html b/anytask/issues/templates/issues/history.html index 54fc20985..fa8e5ea29 100644 --- a/anytask/issues/templates/issues/history.html +++ b/anytask/issues/templates/issues/history.html @@ -94,7 +94,7 @@
{% trans "obsuzhdenie_zadachi" %}
{% if event.author == user %} {# start edit message elements #} - + @@ -111,7 +111,7 @@
{% trans "obsuzhdenie_zadachi" %}
+ after_deadline {% endif %}" id="message_{{ event.id }}"> {% autoescape off %} {{ event.get_message|sanitize }} {% endautoescape %} diff --git a/anytask/issues/templates/issues/issue_js.html b/anytask/issues/templates/issues/issue_js.html index ca266e8db..38dec5434 100644 --- a/anytask/issues/templates/issues/issue_js.html +++ b/anytask/issues/templates/issues/issue_js.html @@ -221,10 +221,18 @@ $("#file_field").append('' + files + ''); } - function start_edit_msg(event_id, event_msg) { - $('#id_comment').val(event_msg); - $('#submit_btn').focus(); - $('#submit_btn').blur(); + function start_edit_msg(event_id) { + $('#id_comment').val($('#message_' + event_id).html()); + $('#edit_msg_event_id').val(event_id); + $('#cancel-edit-msg-btn').show(); + $('#submit-btn').focus(); + $('#submit-btn').blur(); + } + + function end_edit_msg() { + $('#id_comment').val(""); + $('#edit_msg_event_id').val(""); + $('#cancel-edit-msg-btn').hide(); } diff --git a/anytask/issues/views.py b/anytask/issues/views.py index 413a32504..d4c2a05c1 100644 --- a/anytask/issues/views.py +++ b/anytask/issues/views.py @@ -267,8 +267,23 @@ def upload(request): issue = get_object_or_404(Issue, id=int(request.POST['issue_id'])) if 'update_issue' in request.POST: + + # If event_id in POST, edit message and redirect back + if 'event_id' in request.POST and request.POST['event_id'].isdigit(): + user = request.user + event_id = int(request.POST['event_id']) + event = get_object_or_404(Event, id=event_id) + if event.author != user: + raise PermissionDenied + event.value = request.POST['comment'] + event.save() + print(event.value) + print(request.POST) + return HttpResponsePermanentRedirect("/issue/" + request.POST['issue_id']) + event_value = {'files': [], 'comment': '', 'compilers': []} event_value['comment'] = request.POST['comment'] + file_counter = 0 for field, value in dict(request.POST).iteritems(): if 'compiler' in field: From 4db81efb64ae52be9ffd72dac448463e78fb49e5 Mon Sep 17 00:00:00 2001 From: Dmitrii Kuptsov Date: Sat, 17 Apr 2021 10:09:27 +0300 Subject: [PATCH 05/12] CST-46 fix migrate --rewrite-only-existing --- anytask/common/s3_migrate.py | 9 +++++++-- anytask/issues/tests.py | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/anytask/common/s3_migrate.py b/anytask/common/s3_migrate.py index 05cd166e1..4ff1ecfc1 100644 --- a/anytask/common/s3_migrate.py +++ b/anytask/common/s3_migrate.py @@ -94,6 +94,7 @@ def __init__(self, stdout=None, stderr=None, no_color=False): self.dry_run = None self.ignored_extensions = None self.dest_storage = None + self.newly_uploaded = set() def add_arguments(self, parser): """Call super when overriding""" @@ -170,14 +171,18 @@ def s3_upload(self, field): try: new_path = upload_to_s3(field, self.dest_storage, self.dry_run) self.stdout.write(self.OK_UPLOADED.format(new_path)) + self.newly_uploaded.add(new_path) if self.rewrite_url_only_existing: result = None # don't update DB model for newly uploaded files else: result = new_path except KeyError as e: new_path = e.message - self.stdout.write(self.DEST_EXISTS_OK.format(new_path)) - result = new_path + if (new_path in self.newly_uploaded) and self.rewrite_url_only_existing: + result = None + else: + self.stdout.write(self.DEST_EXISTS_OK.format(new_path)) + result = new_path except Exception as e: self.stdout.write(self.ERR_UNHANDLED_EXCEPTION.format(field.name, e)) result = None diff --git a/anytask/issues/tests.py b/anytask/issues/tests.py index b73f799c9..035c583e3 100644 --- a/anytask/issues/tests.py +++ b/anytask/issues/tests.py @@ -1140,6 +1140,43 @@ def test_rewrite_url_only_existing(self): self.assertTrue(self.s3_storage.exists(file.file.name)) self.assertEqual(expected_stdout, out.getvalue().strip()) + def test_rewrite_url_only_existing_many_refs(self): + issue = Issue.objects.create(task_id=self.task.id, student_id=self.student.id) + event_create_file = Event.objects.create(issue=issue, field=IssueField.objects.get(name='file')) + file_first = File.objects.create( + file=SimpleUploadedFile('test_s3_issues.py', b'some text'), event=event_create_file) + file_second = File.objects.get(pk=file_first.pk) + file_second.pk = 0x1337 + file_second.save(force_insert=True) + + out = StringIO() + call_command('s3migrate_issue_attachments', '--execute', '--rewrite-only-existing', stdout=out) + + file_first = File.objects.get(pk=file_first.pk) + file_second = File.objects.get(pk=file_second.pk) + for file in [file_first, file_second]: + expected_s3_path = S3OverlayStorage.append_s3_prefix(file.file.name) + self.assertFalse(S3OverlayStorage.is_s3_stored(file.file.name)) + self.assertTrue(self.s3_storage.exists(expected_s3_path)) + self.assertEqual(('''Note: uploaded: {}'''.format(expected_s3_path)), + out.getvalue().strip()) + + out = StringIO() + call_command('s3migrate_issue_attachments', '--execute', '--rewrite-only-existing', stdout=out) + + for file in [file_first, file_second]: + expected_s3_path = S3OverlayStorage.append_s3_prefix(file.file.name) + expected_stdout = ('''Note: destination already exists: {}\n''' + '''Note: updating model: {}, {}\n''' + '''Note: updated model: {}, {}\n''' + ).format( + expected_s3_path, file, expected_s3_path, file, expected_s3_path) + expected_stdout = (expected_stdout * 2).strip() + file = File.objects.get(pk=file.pk) + self.assertTrue(S3OverlayStorage.is_s3_stored(file.file.name)) + self.assertTrue(self.s3_storage.exists(file.file.name)) + self.assertEqual(expected_stdout, out.getvalue().strip()) + def test_upload_archives(self): for ext in anyrb.unpacker.get_supported_extensions(): fail_msg = 'Failed for extension: {}'.format(ext) From ef1cc463a053b2f0334ae70f8f129543d0f11cfe Mon Sep 17 00:00:00 2001 From: Dmitrii Kuptsov Date: Sat, 17 Apr 2021 10:36:49 +0300 Subject: [PATCH 06/12] CST-46 Optional MinIO container in deploy_local_beta --- deploy_local_beta/deploy_local_beta.sh | 25 +++++++++++++++++++ .../deploy_local_beta_python2.sh | 4 --- deploy_local_beta/run.sh | 5 ++++ deploy_local_beta/settings.sh | 8 ++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/deploy_local_beta/deploy_local_beta.sh b/deploy_local_beta/deploy_local_beta.sh index 5dcf94145..0255cc1d1 100755 --- a/deploy_local_beta/deploy_local_beta.sh +++ b/deploy_local_beta/deploy_local_beta.sh @@ -31,3 +31,28 @@ then else . $ANYBETA_DEPLOY/deploy_local_beta_python3.sh fi + +# MINIO +################ + +if [ x"$ANYBETA_WITH_MINIO" = "x1" ] +then + ANYBETA_report + ANYBETA_report "Pull MinIO docker image" + docker pull "$ANYBETA_MINIO_IMAGE" + ANYBETA_crash_on_error + ANYBETA_report "Start MinIO container" + docker run --rm --detach -p 9000:9000 "$ANYBETA_MINIO_IMAGE" server /data + sleep 5 + ANYBETA_crash_on_error + ANYBETA_report "Create test bucket" + s3cmd --no-ssl $ANYBETA_MINIO_OPTIONS mb s3://"$ANYBETA_MINIO_BUCKET" + ANYBETA_crash_on_error +fi + +# FINISHED +################# + +ANYBETA_report +ANYBETA_report "Deploy completed!" +ANYBETA_report "You can now start django server using \`manage.py runserver\`" diff --git a/deploy_local_beta/deploy_local_beta_python2.sh b/deploy_local_beta/deploy_local_beta_python2.sh index 8a7bbdec1..d31814fdc 100755 --- a/deploy_local_beta/deploy_local_beta_python2.sh +++ b/deploy_local_beta/deploy_local_beta_python2.sh @@ -47,7 +47,3 @@ ANYBETA_report ANYBETA_report "Create test database" $ANYBETA_DEPLOY/generate_test_db.sh ANYBETA_crash_on_error - -ANYBETA_report -ANYBETA_report "Deploy completed!" -ANYBETA_report "You can now start django server using \`manage.py runserver\`" diff --git a/deploy_local_beta/run.sh b/deploy_local_beta/run.sh index e8f8e2067..e6d6a9436 100755 --- a/deploy_local_beta/run.sh +++ b/deploy_local_beta/run.sh @@ -39,6 +39,11 @@ while (( "$#" )); do exit 0 ;; + --with-minio) + export ANYBETA_WITH_MINIO=1 + shift + ;; + *) ANYBETA_error "Error: unknown parameter $ANYBETA_PARAM" exit 1 diff --git a/deploy_local_beta/settings.sh b/deploy_local_beta/settings.sh index a57a9e805..5f158dde5 100755 --- a/deploy_local_beta/settings.sh +++ b/deploy_local_beta/settings.sh @@ -16,6 +16,10 @@ export ANYBETA_VENV_NAME="anytask_venv" export ANYBETA_VENV_DIR="$ANYBETA_ROOT/$ANYBETA_VENV_NAME" export ANYBETA_VENV_ACTIVATE="$ANYBETA_VENV_DIR/bin/activate" +export ANYBETA_MINIO_BUCKET="anytask-test-s3" +export ANYBETA_MINIO_IMAGE="minio/minio:RELEASE.2021-03-17T02-33-02Z" +export ANYBETA_MINIO_OPTIONS="--access_key minioadmin --secret_key minioadmin --host localhost:9000 --host-bucket localhost:9000" + export ANYBETA_REPORT_PREFIX=">>>" export ANYBETA_ERROR_PREFIX="ERROR:" @@ -94,6 +98,10 @@ function ANYBETA_cleanup() { unset ANYBETA_ROOT unset ANYBETA_DEPLOY + unset ANYBETA_WITH_MINIO + unset ANYBETA_MINIO_BUCKET + unset ANYBETA_MINIO_IMAGE + unset ANYBETA_MINIO_OPTIONS unset ANYBETA_PYTHON_PATH unset ANYBETA_VENV_NAME unset ANYBETA_VENV_DIR From af4e3ccdaa2c8a5122969ddb0482e1ce1ea7abc6 Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Sat, 1 May 2021 01:16:55 +0300 Subject: [PATCH 07/12] CST-81 znick#379 copy message contents to textarea without files tag --- anytask/issues/templates/issues/issue_js.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/anytask/issues/templates/issues/issue_js.html b/anytask/issues/templates/issues/issue_js.html index 38dec5434..326f2e72b 100644 --- a/anytask/issues/templates/issues/issue_js.html +++ b/anytask/issues/templates/issues/issue_js.html @@ -222,7 +222,12 @@ } function start_edit_msg(event_id) { - $('#id_comment').val($('#message_' + event_id).html()); + tmp = $('#message_' + event_id).clone()[0]; + files_tag = Array.from(tmp.children) + .filter(el => el.className == "files")[0]; + if (files_tag) tmp.removeChild(files_tag); + $('#id_comment').val(tmp.innerHTML); + $('#edit_msg_event_id').val(event_id); $('#cancel-edit-msg-btn').show(); $('#submit-btn').focus(); From 867461dce1f9076192c8ff49d919dd05691a1427 Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Fri, 7 May 2021 21:24:52 +0300 Subject: [PATCH 08/12] CST-87 znick#379 hide file upload elements --- anytask/issues/templates/issues/issue_js.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/anytask/issues/templates/issues/issue_js.html b/anytask/issues/templates/issues/issue_js.html index 326f2e72b..aaedcd44a 100644 --- a/anytask/issues/templates/issues/issue_js.html +++ b/anytask/issues/templates/issues/issue_js.html @@ -222,21 +222,40 @@ } function start_edit_msg(event_id) { + // set value tmp = $('#message_' + event_id).clone()[0]; files_tag = Array.from(tmp.children) .filter(el => el.className == "files")[0]; if (files_tag) tmp.removeChild(files_tag); $('#id_comment').val(tmp.innerHTML); + // set message edit id $('#edit_msg_event_id').val(event_id); + + // hide file upload + $('table').last().hide(); + $('#drop-zone').hide(); + + // show cancel button $('#cancel-edit-msg-btn').show(); + + // scroll to edit field $('#submit-btn').focus(); $('#submit-btn').blur(); } function end_edit_msg() { + // clean edit field $('#id_comment').val(""); + + // clean edit message id $('#edit_msg_event_id').val(""); + + // show file upload + $('table').last().show(); + $('#drop-zone').show(); + + // hide cancel button $('#cancel-edit-msg-btn').hide(); } From 218326bf6c1af93b800e085ca6e0cc961bde1c95 Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Sat, 8 May 2021 00:44:56 +0300 Subject: [PATCH 09/12] CST-86 znick#379 save event change history --- anytask/issues/admin.py | 8 +++++- anytask/issues/migrations/0008_eventchange.py | 25 +++++++++++++++++++ anytask/issues/models.py | 11 ++++++++ anytask/issues/views.py | 17 ++++++++++--- 4 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 anytask/issues/migrations/0008_eventchange.py diff --git a/anytask/issues/admin.py b/anytask/issues/admin.py index 67969fe01..d221bbeb3 100644 --- a/anytask/issues/admin.py +++ b/anytask/issues/admin.py @@ -2,7 +2,7 @@ from issues.model_issue_field import IssueField from issues.model_issue_status import IssueStatus, IssueStatusSystem -from issues.models import Issue, Event +from issues.models import Issue, Event, EventChange from django.contrib import admin from django.utils.translation import ugettext as _ @@ -58,8 +58,14 @@ class EventAdmin(admin.ModelAdmin): readonly_fields = ('timestamp',) +class EventChangeAdmin(admin.ModelAdmin): + raw_id_fields = ['event'] + search_fields = ('event__id', ) + + admin.site.register(Issue) admin.site.register(Event, EventAdmin) +admin.site.register(EventChange, EventChangeAdmin) admin.site.register(IssueField) admin.site.register(IssueStatus, IssueStatusAdmin) admin.site.register(IssueStatusSystem, IssueStatusSystemAdmin) diff --git a/anytask/issues/migrations/0008_eventchange.py b/anytask/issues/migrations/0008_eventchange.py new file mode 100644 index 000000000..f5e10d8ea --- /dev/null +++ b/anytask/issues/migrations/0008_eventchange.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2021-05-07 21:42 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('issues', '0007_auto_20210228_1721'), + ] + + operations = [ + migrations.CreateModel( + name='EventChange', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('old_value', models.TextField(blank=True, max_length=2500)), + ('diff', models.TextField(blank=True, max_length=2500)), + ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='issues.Event')), + ], + ), + ] diff --git a/anytask/issues/models.py b/anytask/issues/models.py index f78800e3f..7deaaf519 100644 --- a/anytask/issues/models.py +++ b/anytask/issues/models.py @@ -579,6 +579,17 @@ def __unicode__(self): return ret +class EventChange(models.Model): + event = models.ForeignKey(Event, null=False, blank=False) + + old_value = models.TextField(max_length=2500, blank=True) + diff = models.TextField(max_length=2500, blank=True) + + def __unicode__(self): + ret = u'Change in event {0}, issue {1}'.format(self.event.id, self.event.issue.id) + return ret + + @receiver(models.signals.post_save, sender=Issue) def post_create_set_default_teacher(sender, instance, created, *args, **kwargs): if created: diff --git a/anytask/issues/views.py b/anytask/issues/views.py index d4c2a05c1..ed85e7728 100644 --- a/anytask/issues/views.py +++ b/anytask/issues/views.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import os from copy import deepcopy +from difflib import Differ from django.conf import settings from django.contrib.auth.decorators import login_required @@ -19,7 +20,7 @@ from anyrb.common import AnyRB from issues.model_issue_field import IssueField from issues.model_issue_status import IssueStatus -from issues.models import Issue, Event, File +from issues.models import Issue, Event, File, EventChange def user_is_teacher_or_staff(user, issue): @@ -275,10 +276,18 @@ def upload(request): event = get_object_or_404(Event, id=event_id) if event.author != user: raise PermissionDenied - event.value = request.POST['comment'] + + old_value = event.value + new_value = request.POST['comment'] + history = EventChange.objects.create( + event=event, + old_value=old_value, + diff=''.join(list(Differ().compare( + old_value.splitlines(True), + new_value.splitlines(True))))) + history.save() + event.value = new_value event.save() - print(event.value) - print(request.POST) return HttpResponsePermanentRedirect("/issue/" + request.POST['issue_id']) event_value = {'files': [], 'comment': '', 'compilers': []} From 918ff5321c4edfa74b85cbf0fddd714c3c238cc6 Mon Sep 17 00:00:00 2001 From: Nikolay Zhuravlev Date: Sun, 9 May 2021 11:54:51 +0300 Subject: [PATCH 10/12] Fix flake8 --- anytask/issues/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/anytask/issues/views.py b/anytask/issues/views.py index ed85e7728..b42f5b6eb 100644 --- a/anytask/issues/views.py +++ b/anytask/issues/views.py @@ -280,11 +280,11 @@ def upload(request): old_value = event.value new_value = request.POST['comment'] history = EventChange.objects.create( - event=event, - old_value=old_value, - diff=''.join(list(Differ().compare( - old_value.splitlines(True), - new_value.splitlines(True))))) + event=event, + old_value=old_value, + diff=''.join(list(Differ().compare( + old_value.splitlines(True), + new_value.splitlines(True))))) history.save() event.value = new_value event.save() From e752508159d5e95d52a4a200c74a7e0c6ef31810 Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Fri, 14 May 2021 21:34:27 +0300 Subject: [PATCH 11/12] CST-86 znick#379 remove diff, add timestamp --- anytask/issues/migrations/0008_eventchange.py | 4 ++-- anytask/issues/models.py | 2 +- anytask/issues/views.py | 5 +---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/anytask/issues/migrations/0008_eventchange.py b/anytask/issues/migrations/0008_eventchange.py index f5e10d8ea..0465d59ca 100644 --- a/anytask/issues/migrations/0008_eventchange.py +++ b/anytask/issues/migrations/0008_eventchange.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.29 on 2021-05-07 21:42 +# Generated by Django 1.11.29 on 2021-05-14 17:30 from __future__ import unicode_literals from django.db import migrations, models @@ -18,7 +18,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('old_value', models.TextField(blank=True, max_length=2500)), - ('diff', models.TextField(blank=True, max_length=2500)), + ('change_time', models.DateTimeField(auto_now=True)), ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='issues.Event')), ], ), diff --git a/anytask/issues/models.py b/anytask/issues/models.py index 7deaaf519..349778c12 100644 --- a/anytask/issues/models.py +++ b/anytask/issues/models.py @@ -583,7 +583,7 @@ class EventChange(models.Model): event = models.ForeignKey(Event, null=False, blank=False) old_value = models.TextField(max_length=2500, blank=True) - diff = models.TextField(max_length=2500, blank=True) + change_time = models.DateTimeField(auto_now=True) def __unicode__(self): ret = u'Change in event {0}, issue {1}'.format(self.event.id, self.event.issue.id) diff --git a/anytask/issues/views.py b/anytask/issues/views.py index b42f5b6eb..8d60a8a9d 100644 --- a/anytask/issues/views.py +++ b/anytask/issues/views.py @@ -281,10 +281,7 @@ def upload(request): new_value = request.POST['comment'] history = EventChange.objects.create( event=event, - old_value=old_value, - diff=''.join(list(Differ().compare( - old_value.splitlines(True), - new_value.splitlines(True))))) + old_value=old_value) history.save() event.value = new_value event.save() From 2577aae623e2cb5c1480295733211b617f9df05a Mon Sep 17 00:00:00 2001 From: Mikhail Yumanov Date: Mon, 17 May 2021 09:58:48 +0300 Subject: [PATCH 12/12] CST-86 znick#379 show message history --- anytask/issues/migrations/0008_eventchange.py | 4 +-- anytask/issues/models.py | 6 +++- .../templates/issues/event_history.html | 25 ++++++++++++++ anytask/issues/templates/issues/history.html | 33 ++++++++++++++++++- anytask/issues/templates/issues/issue_js.html | 8 +++++ 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 anytask/issues/templates/issues/event_history.html diff --git a/anytask/issues/migrations/0008_eventchange.py b/anytask/issues/migrations/0008_eventchange.py index 0465d59ca..451a20a10 100644 --- a/anytask/issues/migrations/0008_eventchange.py +++ b/anytask/issues/migrations/0008_eventchange.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.29 on 2021-05-14 17:30 +# Generated by Django 1.11.29 on 2021-05-14 23:05 from __future__ import unicode_literals from django.db import migrations, models @@ -18,7 +18,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('old_value', models.TextField(blank=True, max_length=2500)), - ('change_time', models.DateTimeField(auto_now=True)), + ('timestamp', models.DateTimeField(auto_now=True)), ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='issues.Event')), ], ), diff --git a/anytask/issues/models.py b/anytask/issues/models.py index 349778c12..8ff4c08d1 100644 --- a/anytask/issues/models.py +++ b/anytask/issues/models.py @@ -557,6 +557,10 @@ def get_notify_message(self): message.append(', '.join(file_list)) return u'\n'.join(message) + def get_history(self): + history = EventChange.objects.filter(event_id=self.id) + return history + def is_comment(self): return self.field.name == 'comment' @@ -583,7 +587,7 @@ class EventChange(models.Model): event = models.ForeignKey(Event, null=False, blank=False) old_value = models.TextField(max_length=2500, blank=True) - change_time = models.DateTimeField(auto_now=True) + timestamp = models.DateTimeField(auto_now=True) def __unicode__(self): ret = u'Change in event {0}, issue {1}'.format(self.event.id, self.event.issue.id) diff --git a/anytask/issues/templates/issues/event_history.html b/anytask/issues/templates/issues/event_history.html new file mode 100644 index 000000000..6bee013eb --- /dev/null +++ b/anytask/issues/templates/issues/event_history.html @@ -0,0 +1,25 @@ +{% load link_to_open %} +{% load i18n %} +{% load tz %} +{% load info %} +{% get_current_language as LANGUAGE_CODE %} + +{% load sanitize_html %} + + + {% for event_change in event_history %} +

History

+
+
+
+ {% autoescape off %} + {{ event_change.old_value|sanitize }} + {% endautoescape %} +
+
+
+ {% endfor %} + {% if not issue.get_history %} + {% trans "zdes_nichego_net" %} + {% endif %} + diff --git a/anytask/issues/templates/issues/history.html b/anytask/issues/templates/issues/history.html index fa8e5ea29..cefd2e137 100644 --- a/anytask/issues/templates/issues/history.html +++ b/anytask/issues/templates/issues/history.html @@ -89,7 +89,7 @@
{% trans "obsuzhdenie_zadachi" %}
{{ event.author.last_name }} {{ event.author.first_name }}  - {% localtime on %} {{ event.timestamp|date:"d M H:i" }} {% endlocaltime %} + {% localtime on %} {{ event.timestamp|date:"d M H:i:s" }} {% endlocaltime %} {% if event.author == user %} {# start edit message elements #} @@ -100,6 +100,14 @@
{% trans "obsuzhdenie_zadachi" %}
{% endif %} {# end edit message elements #} + {# start message history elements #} + + + + + + {# end message history elements #} +
{% endif %} +
+ + {# message history #} + {% if event.is_omg %}
  • {{ event.field.title }} changed to {{ event.value }} by {{ event.author.last_name }} {{ event.author.first_name }} diff --git a/anytask/issues/templates/issues/issue_js.html b/anytask/issues/templates/issues/issue_js.html index aaedcd44a..85910e031 100644 --- a/anytask/issues/templates/issues/issue_js.html +++ b/anytask/issues/templates/issues/issue_js.html @@ -259,5 +259,13 @@ $('#cancel-edit-msg-btn').hide(); } + function show_edit_history(event_id) { + elem = $('#message_' + event_id + '_history'); + if (elem[0].style.display == "none") { + elem.show(); + } else { + elem.hide(); + } + }