mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Store file moderator
This commit is contained in:
parent
2919f3a133
commit
8b63fa9aea
21
core/migrations/0015_sithfile_moderator.py
Normal file
21
core/migrations/0015_sithfile_moderator.py
Normal 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,
|
||||||
|
),
|
||||||
|
]
|
@ -439,6 +439,9 @@ class AnonymousUser(AuthAnonymousUser):
|
|||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
super(AnonymousUser, self).__init__()
|
super(AnonymousUser, self).__init__()
|
||||||
|
|
||||||
|
def was_subscribed(self):
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subscribed(self):
|
def subscribed(self):
|
||||||
return False
|
return False
|
||||||
@ -526,8 +529,9 @@ class SithFile(models.Model):
|
|||||||
size = models.IntegerField(_("size"), default=0)
|
size = models.IntegerField(_("size"), default=0)
|
||||||
date = models.DateTimeField(_('date'), default=timezone.now)
|
date = models.DateTimeField(_('date'), default=timezone.now)
|
||||||
is_moderated = models.BooleanField(_("is moderated"), default=False)
|
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)
|
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:
|
class Meta:
|
||||||
verbose_name = _("file")
|
verbose_name = _("file")
|
||||||
|
@ -203,6 +203,7 @@ class FileModerateView(CanEditPropMixin, SingleObjectMixin):
|
|||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
self.object.is_moderated = True
|
self.object.is_moderated = True
|
||||||
|
self.object.moderator = request.user
|
||||||
self.object.save()
|
self.object.save()
|
||||||
if 'next' in self.request.GET.keys():
|
if 'next' in self.request.GET.keys():
|
||||||
return redirect(self.request.GET['next'])
|
return redirect(self.request.GET['next'])
|
||||||
|
24
migrate.py
24
migrate.py
@ -1136,6 +1136,25 @@ def migrate_sas():
|
|||||||
# except:
|
# except:
|
||||||
# f = None
|
# 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():
|
def main():
|
||||||
print("Start at %s" % start)
|
print("Start at %s" % start)
|
||||||
@ -1153,8 +1172,9 @@ def main():
|
|||||||
# migrate_godfathers()
|
# migrate_godfathers()
|
||||||
# migrate_etickets()
|
# migrate_etickets()
|
||||||
# reset_index('core', 'club', 'subscription', 'accounting', 'eboutic', 'launderette', 'counter')
|
# reset_index('core', 'club', 'subscription', 'accounting', 'eboutic', 'launderette', 'counter')
|
||||||
migrate_sas()
|
# migrate_sas()
|
||||||
reset_index('core', 'sas')
|
# reset_index('core', 'sas')
|
||||||
|
reset_sas_moderators()
|
||||||
end = datetime.datetime.now()
|
end = datetime.datetime.now()
|
||||||
print("End at %s" % end)
|
print("End at %s" % end)
|
||||||
print("Running time: %s" % (end-start))
|
print("Running time: %s" % (end-start))
|
||||||
|
@ -77,6 +77,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<h5>{% trans %}Infos{% endtrans %}</h5>
|
<h5>{% trans %}Infos{% endtrans %}</h5>
|
||||||
<p>{% trans %}Date: {% endtrans %}{{ picture.date|date(DATETIME_FORMAT) }}</p>
|
<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>
|
<p>{{ picture.parent.children.filter(id__lte=picture.id).count() }} / {{ picture.parent.children.count() }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
Loading…
Reference in New Issue
Block a user