Store file moderator

This commit is contained in:
Skia 2016-12-12 17:23:06 +01:00
parent 2919f3a133
commit 8b63fa9aea
5 changed files with 51 additions and 3 deletions

View File

@ -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,
),
]

View File

@ -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")

View File

@ -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'])

View File

@ -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))

View File

@ -77,6 +77,8 @@
<div>
<h5>{% trans %}Infos{% endtrans %}</h5>
<p>{% trans %}Date: {% endtrans %}{{ picture.date|date(DATETIME_FORMAT) }}</p>
<p>{% trans %}Owner: {% endtrans %}<a href="{{ picture.owner.get_absolute_url() }}">{{ picture.owner.get_short_name() }}</a></p>
<p>{% trans %}Moderator: {% endtrans %}<a href="{{ picture.moderator.get_absolute_url() }}">{{ picture.moderator.get_short_name() }}</a></p>
<p>{{ picture.parent.children.filter(id__lte=picture.id).count() }} / {{ picture.parent.children.count() }}</p>
</div>
<div>