diff --git a/core/models.py b/core/models.py index 5d63a966..1e1c66e4 100644 --- a/core/models.py +++ b/core/models.py @@ -584,6 +584,11 @@ class SithFile(models.Model): else: return super(SithFile, self).__getattribute__(attr) + @property + def as_picture(self): + from sas.models import Picture + return Picture.objects.filter(id=self.id).first() + def __str__(self): if self.is_folder: return _("Folder: ") + self.name diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index e47262c6..6401679d 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -68,7 +68,7 @@ {% trans %}Main{% endtrans %} {% trans %}Matmatronch{% endtrans %} {% trans %}Wiki{% endtrans %} - {% trans %}SAS{% endtrans %} + {% trans %}SAS{% endtrans %} {% trans %}Forum{% endtrans %} {% trans %}Services{% endtrans %} {% trans %}Files{% endtrans %} diff --git a/sas/__init__.py b/sas/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sas/admin.py b/sas/admin.py new file mode 100644 index 00000000..aec06f37 --- /dev/null +++ b/sas/admin.py @@ -0,0 +1,8 @@ +from django.contrib import admin + +from sas.models import * + + +admin.site.register(Album) +admin.site.register(Picture) + diff --git a/sas/migrations/__init__.py b/sas/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/sas/models.py b/sas/models.py new file mode 100644 index 00000000..e40fb729 --- /dev/null +++ b/sas/models.py @@ -0,0 +1,44 @@ +from django.db import models +from django.conf import settings +from django.core.urlresolvers import reverse + +from core.models import SithFile, User + +class Picture(SithFile): + class Meta: + proxy = True + + @property + def is_in_sas(self): + sas = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first() + return sas in self.get_parent_list() + + def can_be_edited_by(self, user): + 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 + user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP)) + + def get_download_url(self): + return reverse('sas:download', kwargs={'picture_id': self.id}) + +class Album(SithFile): + class Meta: + proxy = True + + @property + def is_in_sas(self): + sas = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first() + return sas in self.get_parent_list() + + def can_be_edited_by(self, user): + 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 + user.is_in_group(settings.SITH_MAIN_MEMBERS_GROUP)) + + def get_absolute_url(self): + return reverse('sas:album', kwargs={'album_id': self.id}) + diff --git a/sas/templates/sas/album.jinja b/sas/templates/sas/album.jinja new file mode 100644 index 00000000..82429ae7 --- /dev/null +++ b/sas/templates/sas/album.jinja @@ -0,0 +1,28 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}SAS{% endtrans %} +{% endblock %} + +{% block content %} +

{{ sithfile.get_display_name() }}

+
+ {% for a in sithfile.children.filter(is_folder=True).all() %} +
+ {{ a.name }} +
+ {% endfor %} +
+
+ {% for a in sithfile.children.filter(mime_type__in=['image/jpeg', 'image/png']).all() %} + {% if a.as_picture.can_be_viewed_by(user) %} +
+ + {{ a.get_display_name() }} + +
+ {% endif %} + {% endfor %} +
+{% endblock %} + diff --git a/sas/templates/sas/main.jinja b/sas/templates/sas/main.jinja new file mode 100644 index 00000000..9a904f51 --- /dev/null +++ b/sas/templates/sas/main.jinja @@ -0,0 +1,16 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}SAS{% endtrans %} +{% endblock %} + +{% block content %} +

{% trans %}SAS{% endtrans %}

+
+ {% for a in root_file.children.filter(is_folder=True).all() %} +
+ {{ a.name }} +
+ {% endfor %} +
+{% endblock %} diff --git a/sas/templates/sas/picture.jinja b/sas/templates/sas/picture.jinja new file mode 100644 index 00000000..39feee7d --- /dev/null +++ b/sas/templates/sas/picture.jinja @@ -0,0 +1,16 @@ +{% extends "core/base.jinja" %} + +{% block title %} +{% trans %}SAS{% endtrans %} +{% endblock %} + +{% block content %} +

{{ picture.get_display_name() }}

+
+ PREV / NEXT +
+
+ {{ picture.get_display_name() }} +
+{% endblock %} + diff --git a/sas/tests.py b/sas/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/sas/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/sas/urls.py b/sas/urls.py new file mode 100644 index 00000000..ce53d1b7 --- /dev/null +++ b/sas/urls.py @@ -0,0 +1,13 @@ +from django.conf.urls import url, include + +from sas.views import * + +urlpatterns = [ + url(r'^$', SASMainView.as_view(), name='main'), + url(r'^album/(?P[0-9]+)$', AlbumView.as_view(), name='album'), + url(r'^picture/(?P[0-9]+)$', PictureView.as_view(), name='picture'), + url(r'^picture/(?P[0-9]+)/download$', send_pict, name='download'), + # url(r'^album/new$', AlbumCreateView.as_view(), name='album_new'), + # url(r'^(?P[0-9]+)/$', ClubView.as_view(), name='club_view'), +] + diff --git a/sas/views.py b/sas/views.py new file mode 100644 index 00000000..31e2aa48 --- /dev/null +++ b/sas/views.py @@ -0,0 +1,38 @@ +from django.shortcuts import render +from django.views.generic import ListView, DetailView, RedirectView, TemplateView +from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin +from django.utils.translation import ugettext as _ +from django.utils import timezone +from django.conf import settings +from django import forms + +from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultipleField + +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 sas.models import Picture, Album + +class SASMainView(TemplateView): + template_name = "sas/main.jinja" + + def get_context_data(self, **kwargs): + kwargs = super(SASMainView, self).get_context_data(**kwargs) + kwargs['root_file'] = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first() + return kwargs + +class AlbumView(DetailView, CanViewMixin): + model = Album + pk_url_kwarg = "album_id" + template_name = "sas/album.jinja" + +class PictureView(DetailView, CanViewMixin): + model = Picture + pk_url_kwarg = "picture_id" + template_name = "sas/picture.jinja" + +def send_pict(request, picture_id): + return send_file(request, picture_id, Picture) + diff --git a/sith/settings.py b/sith/settings.py index b65403b6..83e81dbf 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -55,6 +55,7 @@ INSTALLED_APPS = ( 'launderette', 'api', 'rootplace', + 'sas', ) MIDDLEWARE_CLASSES = ( @@ -445,6 +446,10 @@ SITH_LAUNDERETTE_PRICES = { 'DRYING': 0.75, } +# SAS variables +SITH_SAS_ROOT_DIR_ID = 63 +SITH_SAS_ADMIN_GROUP_ID = 74 + try: from .settings_custom import * print("Custom settings imported") diff --git a/sith/urls.py b/sith/urls.py index 97ac0af3..74370bab 100644 --- a/sith/urls.py +++ b/sith/urls.py @@ -36,6 +36,7 @@ urlpatterns = [ url(r'^accounting/', include('accounting.urls', namespace="accounting", app_name="accounting")), url(r'^eboutic/', include('eboutic.urls', namespace="eboutic", app_name="eboutic")), url(r'^launderette/', include('launderette.urls', namespace="launderette", app_name="launderette")), + url(r'^sas/', include('sas.urls', namespace="sas", app_name="sas")), url(r'^api/v1/', include('api.urls', namespace="api", app_name="api")), url(r'^admin/', include(admin.site.urls)), url(r'^ajax_select/', include(ajax_select_urls)),