From 8b63fa9aeaa2f41a6674f5032bbc30bfd572af5a Mon Sep 17 00:00:00 2001 From: Skia Date: Mon, 12 Dec 2016 17:23:06 +0100 Subject: [PATCH] Store file moderator --- core/migrations/0015_sithfile_moderator.py | 21 +++++++++++++++++++ core/models.py | 6 +++++- core/views/files.py | 1 + migrate.py | 24 ++++++++++++++++++++-- sas/templates/sas/picture.jinja | 2 ++ 5 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 core/migrations/0015_sithfile_moderator.py diff --git a/core/migrations/0015_sithfile_moderator.py b/core/migrations/0015_sithfile_moderator.py new file mode 100644 index 00000000..753c82f7 --- /dev/null +++ b/core/migrations/0015_sithfile_moderator.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0014_auto_20161210_0009'), + ] + + operations = [ + migrations.AddField( + model_name='sithfile', + name='moderator', + field=models.ForeignKey(related_name='moderated_files', verbose_name='owner', default=0, to=settings.AUTH_USER_MODEL), + preserve_default=False, + ), + ] diff --git a/core/models.py b/core/models.py index 3d6b3c3b..af7d6222 100644 --- a/core/models.py +++ b/core/models.py @@ -439,6 +439,9 @@ class AnonymousUser(AuthAnonymousUser): def __init__(self, request): super(AnonymousUser, self).__init__() + def was_subscribed(self): + return False + @property def subscribed(self): return False @@ -526,8 +529,9 @@ class SithFile(models.Model): size = models.IntegerField(_("size"), default=0) date = models.DateTimeField(_('date'), default=timezone.now) is_moderated = models.BooleanField(_("is moderated"), default=False) + moderator = models.ForeignKey(User, related_name="moderated_files", verbose_name=_("owner")) asked_for_removal = models.BooleanField(_("asked for removal"), default=False) - is_in_sas = models.BooleanField(_("is in the SAS"), default=False) + is_in_sas = models.BooleanField(_("is in the SAS"), default=False) # Allows to query this flag, updated at each call to save() class Meta: verbose_name = _("file") diff --git a/core/views/files.py b/core/views/files.py index afeeceb3..6128d0f7 100644 --- a/core/views/files.py +++ b/core/views/files.py @@ -203,6 +203,7 @@ class FileModerateView(CanEditPropMixin, SingleObjectMixin): def get(self, request, *args, **kwargs): self.object = self.get_object() self.object.is_moderated = True + self.object.moderator = request.user self.object.save() if 'next' in self.request.GET.keys(): return redirect(self.request.GET['next']) diff --git a/migrate.py b/migrate.py index d5d28450..997e9261 100644 --- a/migrate.py +++ b/migrate.py @@ -1136,6 +1136,25 @@ def migrate_sas(): # except: # f = None +def reset_sas_moderators(): + cur = db.cursor(MySQLdb.cursors.SSDictCursor) + cur.execute(""" + SELECT * + FROM sas_photos + WHERE id_utilisateur_moderateur IS NOT NULL + """) + for r in cur: + try: + name = str(r['id_photo']) + '.jpg' + pict = SithFile.objects.filter(name__icontains=name, is_in_sas=True).first() + user = User.objects.filter(id=r['id_utilisateur_moderateur']).first() + if pict and user: + pict.moderator = user + pict.save() + else: + print("No pict %s (%s) or user %s (%s)" %(pict, name, user, r['id_utilisateur_moderateur'])) + except Exception as e: + print(repr(e)) def main(): print("Start at %s" % start) @@ -1153,8 +1172,9 @@ def main(): # migrate_godfathers() # migrate_etickets() # reset_index('core', 'club', 'subscription', 'accounting', 'eboutic', 'launderette', 'counter') - migrate_sas() - reset_index('core', 'sas') + # migrate_sas() + # reset_index('core', 'sas') + reset_sas_moderators() end = datetime.datetime.now() print("End at %s" % end) print("Running time: %s" % (end-start)) diff --git a/sas/templates/sas/picture.jinja b/sas/templates/sas/picture.jinja index ecbf9b9f..685d0383 100644 --- a/sas/templates/sas/picture.jinja +++ b/sas/templates/sas/picture.jinja @@ -77,6 +77,8 @@
{% trans %}Infos{% endtrans %}

{% trans %}Date: {% endtrans %}{{ picture.date|date(DATETIME_FORMAT) }}

+

{% trans %}Owner: {% endtrans %}{{ picture.owner.get_short_name() }}

+

{% trans %}Moderator: {% endtrans %}{{ picture.moderator.get_short_name() }}

{{ picture.parent.children.filter(id__lte=picture.id).count() }} / {{ picture.parent.children.count() }}