mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
Improve SAS moderation interface
This commit is contained in:
parent
39b7349034
commit
57d8926a3f
@ -7,41 +7,28 @@
|
||||
{% block content %}
|
||||
<h3>{% trans %}SAS moderation{% endtrans %}</h3>
|
||||
<div id="moderation">
|
||||
<form action="" method="POST" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
{% for p in pictures %}
|
||||
<div style="">
|
||||
{% if p.is_folder %}
|
||||
<strong>{% trans %}Album{% endtrans %}</strong>
|
||||
{% else %}
|
||||
<strong>{% trans %}Picture{% endtrans %}</strong>
|
||||
{% endif %}
|
||||
<p>
|
||||
<a href="{{ url("sas:picture", picture_id=p.id) }}">
|
||||
<img src="{{ p.get_download_compressed_url() }}" alt="{{ p.name }}">
|
||||
</a><br/>
|
||||
{% trans %}Full name: {% endtrans %}{{ p.get_parent_path()+'/'+p.name }}<br/>
|
||||
{% trans %}Owner: {% endtrans %}{{ p.owner.get_display_name() }}<br/>
|
||||
{% trans %}Date: {% endtrans %}{{ p.date|date(DATE_FORMAT) }} {{ p.date|time(TIME_FORMAT) }}<br/>
|
||||
</p>
|
||||
{% if p.asked_for_removal %}
|
||||
<p class="important">{% trans %}Asked for removal{% endtrans %}</p>
|
||||
{% endif %}
|
||||
<p>
|
||||
<input type="radio" name="a_{{ p.id }}" id="m_{{ p.id }}" value="moderate"/>
|
||||
<a href="{{ url('core:file_moderate', file_id=p.id) }}?next={{ url('sas:moderation') }}">{% trans %}Moderate{% endtrans %}</a>
|
||||
</p>
|
||||
<p>
|
||||
<input type="radio" name="a_{{ p.id }}" id="m_{{ p.id }}" value="delete"/>
|
||||
<a href="{{ url('core:file_delete', file_id=p.id) }}?next={{ url('sas:moderation') }}">{% trans %}Delete{% endtrans %}</a>
|
||||
</p>
|
||||
<p>
|
||||
<input type="radio" name="a_{{ p.id }}" id="m_{{ p.id }}" value="nothing" checked/>
|
||||
{% trans %}Do nothing{% endtrans %}
|
||||
</p>
|
||||
<h4>{% trans %}Albums{% endtrans %}</h4>
|
||||
<ul>
|
||||
{% for a in albums_to_moderate %}
|
||||
<li>{{ a }}:
|
||||
<form action="" method="POST">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="album_id" value="{{ a.id }}" />
|
||||
<input type="submit" name="moderate" value="{% trans %}Moderate{% endtrans %}" />
|
||||
<input type="submit" name="delete" value="{% trans %}Delete{% endtrans %}" />
|
||||
</form>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% for a in albums %}
|
||||
<h4>{{ a.get_display_name() }}</h4>
|
||||
{% for p in pictures.filter(parent=a).order_by('id') %}
|
||||
<div class="picture">
|
||||
<a href="{{ url("sas:picture", picture_id=p.id) }}">
|
||||
<img src="{{ p.get_download_thumb_url() }}" alt="{{ p.name }}">
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<p><input type="submit" value="{% trans %}Go{% endtrans %}" /></p>
|
||||
</form>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
@ -78,7 +78,9 @@
|
||||
<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>
|
||||
{% if picture.moderator %}
|
||||
<p>{% trans %}Moderator: {% endtrans %}<a href="{{ picture.moderator.get_absolute_url() }}">{{ picture.moderator.get_short_name() }}</a></p>
|
||||
{% endif %}
|
||||
<p>{{ picture.parent.children.filter(id__lte=picture.id).count() }} / {{ picture.parent.children.count() }}</p>
|
||||
</div>
|
||||
<div>
|
||||
@ -105,6 +107,9 @@
|
||||
{% set next = next.get_absolute_url() + "#pict" %}
|
||||
{% endif %}
|
||||
<div style="background: lightgrey; padding: 2px;">
|
||||
{% if picture.asked_for_removal %}
|
||||
<span class="important">{% trans %}Asked for removal{% endtrans %}</span>
|
||||
{% endif %}
|
||||
<a href="{{ url('core:file_moderate', file_id=picture.id) }}?next={{ next }}">
|
||||
{% trans %}Moderate{% endtrans %}</a> |
|
||||
<a href="{{ url('core:file_delete', file_id=picture.id) }}?next={{ next }}">
|
||||
|
33
sas/views.py
33
sas/views.py
@ -41,6 +41,8 @@ class SASForm(forms.Form):
|
||||
for f in files:
|
||||
new_file = Picture(parent=parent, name=f.name, file=f, owner=owner, mime_type=f.content_type, size=f._size,
|
||||
is_folder=False, is_moderated=automodere)
|
||||
if automodere:
|
||||
new_file.moderator = owner
|
||||
try:
|
||||
new_file.clean()
|
||||
new_file.generate_thumbnails()
|
||||
@ -193,26 +195,28 @@ class ModerationView(TemplateView):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
if request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID):
|
||||
for k,v in request.GET.items():
|
||||
if k[:2] == "a_":
|
||||
try:
|
||||
pict = Picture.objects.filter(id=int(k[2:])).first()
|
||||
if v == "delete":
|
||||
pict.delete()
|
||||
elif v == "moderate":
|
||||
pict.is_moderated = True
|
||||
pict.asked_for_removal = False
|
||||
pict.save()
|
||||
except: pass
|
||||
return super(ModerationView, self).get(request, *args, **kwargs)
|
||||
raise PermissionDenied
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
return self.get(request, *args, **kwargs)
|
||||
if request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID):
|
||||
try:
|
||||
a = Album.objects.filter(id=request.POST['album_id']).first()
|
||||
if 'moderate' in request.POST.keys():
|
||||
a.moderator = request.user
|
||||
a.is_moderated = True
|
||||
a.save()
|
||||
elif 'delete' in request.POST.keys():
|
||||
a.delete()
|
||||
except: pass
|
||||
return super(ModerationView, self).get(request, *args, **kwargs)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
kwargs = super(ModerationView, self).get_context_data(**kwargs)
|
||||
kwargs['pictures'] = Picture.objects.filter(is_moderated=False, is_in_sas=True).order_by('id')
|
||||
kwargs['albums_to_moderate'] = Album.objects.filter(is_moderated=False, is_in_sas=True,
|
||||
is_folder=True).order_by('id')
|
||||
kwargs['pictures'] = Picture.objects.filter(is_moderated=False, is_in_sas=True, is_folder=False)
|
||||
kwargs['albums'] = Album.objects.filter(id__in=kwargs['pictures'].values('parent').distinct('parent'))
|
||||
return kwargs
|
||||
|
||||
class PictureEditForm(forms.ModelForm):
|
||||
@ -224,8 +228,9 @@ class PictureEditForm(forms.ModelForm):
|
||||
class AlbumEditForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Album
|
||||
fields=['name', 'file', 'parent']
|
||||
fields=['name', 'file', 'parent', 'edit_groups']
|
||||
parent = make_ajax_field(Album, 'parent', 'files', help_text="")
|
||||
edit_groups = make_ajax_field(Album, 'edit_groups', 'groups', help_text="")
|
||||
|
||||
class PictureEditView(CanEditMixin, UpdateView):
|
||||
model=Picture
|
||||
|
Loading…
Reference in New Issue
Block a user