Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion anytask/issues/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _

Expand Down Expand Up @@ -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)
25 changes: 25 additions & 0 deletions anytask/issues/migrations/0008_eventchange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2021-05-14 23:05
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)),
('timestamp', models.DateTimeField(auto_now=True)),
('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='issues.Event')),
],
),
]
15 changes: 15 additions & 0 deletions anytask/issues/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -579,6 +583,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)
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)
return ret


@receiver(models.signals.post_save, sender=Issue)
def post_create_set_default_teacher(sender, instance, created, *args, **kwargs):
if created:
Expand Down
8 changes: 7 additions & 1 deletion anytask/issues/templates/file_uploader.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<input type="hidden" name="form_name" value="comment_form">
<textarea rows="4" name="comment" id="id_comment" cols="40" class="form-control col-md-12" style="margin-bottom: 10px;"></textarea>
<input type="hidden" name="issue_id" value="{{ issue.id }}">
<input type="hidden" id="edit_msg_event_id" name="event_id" value="">
{% block UPLOAD_FORM_BUTTON_BAR %}
<div class="fileupload-buttonbar">
{% comment %}
Expand Down Expand Up @@ -138,11 +139,16 @@
<button class="btn btn-info pull-xs-right" formaction="#" style="margin-top: 10px; margin-left: 10px;" type="submit">{% trans "zadat_vopros" %}</button>
{% else %}
<input type="hidden" name="update_issue" value="" />
<button style="margin-top: 10px;" type="submit" class="btn btn-primary pull-xs-right">
<button style="margin-top: 10px;" type="submit"
class="btn btn-primary pull-xs-right" id="submit-btn">
<span>{% trans "otpravit" %}</span>
</button>
{% endif %}
{% endblock %}
<input type="button" style="margin: 10px; display: none;"
class="btn btn-danger pull-xs-right" id="cancel-edit-msg-btn"
onClick="end_edit_msg()" value="{% trans "otmena" %}">
</input>
</div>
{% block UPLOAD_FORM_PROGRESS_BAR %}
{% comment %}
Expand Down
25 changes: 25 additions & 0 deletions anytask/issues/templates/issues/event_history.html
Original file line number Diff line number Diff line change
@@ -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 %}
<p>History</p>
<div class="row">
<div class="col-xs-11">
<div class="{% if event.author == user %}mine{% else %}not_mine{% endif %} history-body">
{% autoescape off %}
{{ event_change.old_value|sanitize }}
{% endautoescape %}
</div>
</div>
</div>
{% endfor %}
{% if not issue.get_history %}
{% trans "zdes_nichego_net" %}
{% endif %}

44 changes: 42 additions & 2 deletions anytask/issues/templates/issues/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,25 @@ <h5 class="card-title">{% trans "obsuzhdenie_zadachi" %}</h5>
<strong><a class="card-link" {% if event.author.username != "anytask" %}href="{{ event.author.get_absolute_url }}"{% endif %} style="color:#373a3c;">
{{ event.author.last_name }} {{ event.author.first_name }}</a>&nbsp;</strong>
<small class="text-muted">
<i class="fa fa-clock-o fa-flip-horizontal"></i>{% localtime on %} {{ event.timestamp|date:"d M H:i" }} {% endlocaltime %}
<i class="fa fa-clock-o fa-flip-horizontal"></i>{% localtime on %} {{ event.timestamp|date:"d M H:i:s" }} {% endlocaltime %}
</small>

{% if event.author == user %} {# start edit message elements #}
<small class="edit-message">
<a href="javascript:start_edit_msg({{ event.id }})">
<i class="fa fa-pencil"></i>
</a>
</small>
{% endif %} {# end edit message elements #}

{# start message history elements #}
<small class="edit-history">
<a href="javascript:show_edit_history({{ event.id }})">
<i class="fa fa-list"></i>
</a>
</small>
{# end message history elements #}

</div>
<div class="user_img col-xs-1 {% if event.author == user %}pull-xs-right{% else %}pull-xs-left{% endif %}">
<a class="card-link" {% if event.author.username != "anytask" %}href="{{ event.author.get_absolute_url }}"{% endif %}>
Expand All @@ -102,7 +119,7 @@ <h5 class="card-title">{% trans "obsuzhdenie_zadachi" %}</h5>
<div class="col-xs-11">
<div class="{% if event.author == user %}mine{% else %}not_mine{% endif %} history-body
{% if issue.task.deadline_time < event.timestamp and event.author.username == issue.student.username %}
after_deadline {% endif %}">
after_deadline {% endif %}" id="message_{{ event.id }}">
{% autoescape off %}
{{ event.get_message|sanitize }}
{% endautoescape %}
Expand All @@ -128,10 +145,33 @@ <h5 class="card-title">{% trans "obsuzhdenie_zadachi" %}</h5>
{% endfor %}
</div>
{% endif %}

</div>
</div>
</div>
</li>

{# message history #}
<div id="message_{{ event.id }}_history" style="display: none;">
<h6>Message history:</h6>
{% for event_change in event.get_history %}
<div class="row">
<div class="{% if event.author == user %}col-xs-12{% else %}col-xs-offset-1 col-xs-11{% endif %}">
<small class="text-muted">
<i class="fa fa-clock-o fa-flip-horizontal"></i>{% localtime on %} {{ event_change.timestamp|date:"d M H:i:s" }} {% endlocaltime %}
</small>
</div>

<div class="col-xs-11">
<div class="{% if event.author == user %}mine{% else %}not_mine{% endif %} history-body">
{% autoescape off %}
{{ event_change.old_value|sanitize }}
{% endautoescape %}
</div>
</div>
</div>
{% endfor %}
</div>
{% if event.is_omg %}
<li class="change">
{{ event.field.title }} changed to {{ event.value }} by {{ event.author.last_name }} {{ event.author.first_name }}
Expand Down
46 changes: 46 additions & 0 deletions anytask/issues/templates/issues/issue_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,51 @@
$("#file_field").append('<tr><td>' + files + '</td></tr>');
}

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();
}

function show_edit_history(event_id) {
elem = $('#message_' + event_id + '_history');
if (elem[0].style.display == "none") {
elem.show();
} else {
elem.hide();
}
}

</script>
23 changes: 22 additions & 1 deletion anytask/issues/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -267,8 +268,28 @@ 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

old_value = event.value
new_value = request.POST['comment']
history = EventChange.objects.create(
event=event,
old_value=old_value)
history.save()
event.value = new_value
event.save()
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:
Expand Down