Commit e681cc65 authored by Skia's avatar Skia

Add SAS moderation tool

parent 157b1e4c
This diff is collapsed.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0007_auto_20161108_1703'),
]
operations = [
migrations.CreateModel(
name='Album',
fields=[
],
options={
'proxy': True,
},
bases=('core.sithfile',),
),
migrations.CreateModel(
name='Picture',
fields=[
],
options={
'proxy': True,
},
bases=('core.sithfile',),
),
]
......@@ -17,7 +17,7 @@ class Picture(SithFile):
return user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID)
def can_be_viewed_by(self, user):
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_authorized and
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP))
def get_download_url(self):
......@@ -36,7 +36,7 @@ class Album(SithFile):
return user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID)
def can_be_viewed_by(self, user):
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_authorized and
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP))
def get_absolute_url(self):
......
......@@ -12,7 +12,7 @@
<p><input type="submit" value="{% trans %}Upload{% endtrans %}" /></p>
</form>
<div>
{% for a in album.children.filter(is_folder=True).all() %}
{% for a in album.children.filter(is_folder=True, is_moderated=True).all() %}
<div style="display: inline-block; border: solid 1px black;">
<a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a>
</div>
......@@ -20,8 +20,7 @@
</div>
<div>
{# for a in album.children.filter(mime_type__in=['image/jpeg', 'image/png']).all() #}
{% for p in album.children.filter(is_folder=False).all() %}
<p>{{ p.name }}</p>
{% for p in album.children.filter(is_folder=False, is_moderated=True).all() %}
{% if p.as_picture.can_be_viewed_by(user) %}
<div style="display: inline-block; border: solid 1px black;">
<a href="{{ url("sas:picture", picture_id=p.id) }}">
......
......@@ -6,16 +6,27 @@
{% block content %}
<h3>{% trans %}SAS{% endtrans %}</h3>
{% if user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID) %}
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p() }}
{{ form.non_field_errors() }}
<p>{{ form.album_name.errors }}<label for="{{ form.album_name.name }}">{{ form.album_name.label }}</label>
{{ form.album_name }}</p>
<p><input type="submit" value="{% trans %}Create{% endtrans %}" /></p>
</form>
{% endif %}
<div>
{% for a in root_file.children.filter(is_folder=True).all() %}
<div style="display: inline-block; border: solid 1px black;">
{% if a.is_moderated %}
<div style="display: inline-block; border: solid 1px black; text-align: center">
<a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a>
</div>
{% elif user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID) %}
<div style="display: inline-block; border: solid 1px red; text-align: center">
<p><a href="{{ url('core:file_moderate', file_id=a.id) }}?next={{ url('sas:moderation') }}">Moderate</a> or <a href="">Delete</a></p>
<a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a>
</div>
{% endif %}
{% endfor %}
</div>
{% endblock %}
{% extends "core/base.jinja" %}
{% block title %}
{% trans %}SAS moderation{% endtrans %}
{% endblock %}
{% block content %}
<h3>{% trans %}SAS moderation{% endtrans %}</h3>
<div>
{% for p in pictures %}
<div style="margin: 2px; padding: 2px; border: solid 1px red; text-align: center">
{% if p.is_folder %}
<strong>Album</strong>
{% else %}
<strong>Picture</strong>
{% endif %}
<p>
<a href="{{ url("sas:picture", picture_id=p.id) }}">
<img src="{{ url('sas:download', picture_id=p.id) }}" alt="{{ p.name }}" style="width: 100px">
</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>
<p><a href="{{ url('core:file_moderate', file_id=p.id) }}?next={{ url('sas:moderation') }}">{% trans %}Moderate{% endtrans %}</a> -
<a href="{{ url('core:file_delete', file_id=p.id) }}?next={{ url('sas:moderation') }}">{% trans %}Delete{% endtrans %}</a></p>
</div>
{% endfor %}
</div>
{% endblock %}
......@@ -4,6 +4,7 @@ from sas.views import *
urlpatterns = [
url(r'^$', SASMainView.as_view(), name='main'),
url(r'^moderation$', ModerationView.as_view(), name='moderation'),
url(r'^album/(?P<album_id>[0-9]+)$', AlbumView.as_view(), name='album'),
url(r'^picture/(?P<picture_id>[0-9]+)$', PictureView.as_view(), name='picture'),
url(r'^picture/(?P<picture_id>[0-9]+)/download$', send_pict, name='download'),
......
......@@ -12,7 +12,7 @@ from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultip
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime
from core.views.files import send_file
from core.models import SithFile
from core.models import SithFile, User
from sas.models import Picture, Album
......@@ -21,10 +21,10 @@ class SASForm(forms.Form):
images = forms.ImageField(widget=forms.ClearableFileInput(attrs={'multiple': True}), label=_("Upload images"),
required=False)
def process(self, parent, owner, files):
def process(self, parent, owner, files, automodere=False):
try:
if self.cleaned_data['album_name'] != "":
album = Album(parent=parent, name=self.cleaned_data['album_name'], owner=owner)
album = Album(parent=parent, name=self.cleaned_data['album_name'], owner=owner, is_moderated=automodere)
album.clean()
album.save()
except Exception as e:
......@@ -32,7 +32,7 @@ class SASForm(forms.Form):
{'album': self.cleaned_data['album_name'], 'msg': str(e.message)})
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_folder=False, is_moderated=automodere)
try:
new_file.clean()
# TODO: generate thumbnail
......@@ -49,10 +49,14 @@ class SASMainView(FormView):
self.form = self.get_form()
parent = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first()
files = request.FILES.getlist('images')
if request.user.is_authenticated() and request.user.is_in_group('ae-membres') and self.form.is_valid():
self.form.process(parent=parent, owner=request.user, files=files)
root = User.objects.filter(username="root").first()
if request.user.is_authenticated() and request.user.is_in_group(settings.SITH_SAS_ADMIN_GROUP_ID):
if self.form.is_valid():
return super(SASMainView, self).form_valid(self.form)
self.form.process(parent=parent, owner=root, files=files, automodere=True)
if self.form.is_valid():
return super(SASMainView, self).form_valid(self.form)
else:
self.form.add_error(None, _("You do not have the permission to do that"))
return self.form_invalid(self.form)
def get_context_data(self, **kwargs):
......@@ -79,7 +83,6 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
return super(AlbumView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
print('GUY')
self.object = self.get_object()
self.form = self.get_form()
parent = SithFile.objects.filter(id=self.object.id).first()
......@@ -90,7 +93,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
if self.form.is_valid():
return super(AlbumView, self).form_valid(self.form)
else:
self.form.add_error(None, _("You have do not have permission to do that"))
self.form.add_error(None, _("You do not have the permission to do that"))
return self.form_invalid(self.form)
def get_success_url(self):
......@@ -101,3 +104,14 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
kwargs['form'] = self.form
return kwargs
# Admin views
class ModerationView(TemplateView):
template_name = "sas/moderation.jinja"
def get_context_data(self, **kwargs):
kwargs = super(ModerationView, self).get_context_data(**kwargs)
kwargs['pictures'] = [p for p in Picture.objects.filter(is_moderated=False).all() if p.is_in_sas]
return kwargs
......@@ -448,7 +448,7 @@ SITH_LAUNDERETTE_PRICES = {
# SAS variables
SITH_SAS_ROOT_DIR_ID = 4
SITH_SAS_ADMIN_GROUP_ID = 26
SITH_SAS_ADMIN_GROUP_ID = 9
try:
from .settings_custom import *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment