mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Begin SAS
This commit is contained in:
parent
0b068d3e92
commit
d554a5ee8d
@ -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
|
||||
|
@ -68,7 +68,7 @@
|
||||
<a href="https://ae.utbm.fr/">{% trans %}Main{% endtrans %}</a>
|
||||
<a href="https://ae.utbm.fr/matmatronch/">{% trans %}Matmatronch{% endtrans %}</a>
|
||||
<a href="{{ url('core:page', page_name="Index") }}">{% trans %}Wiki{% endtrans %}</a>
|
||||
<a href="https://ae.utbm.fr/sas2/">{% trans %}SAS{% endtrans %}</a>
|
||||
<a href="{{ url('sas:main') }}">{% trans %}SAS{% endtrans %}</a>
|
||||
<a href="https://ae.utbm.fr/forum2/">{% trans %}Forum{% endtrans %}</a>
|
||||
<a href="{{ url('core:page', "services") }}">{% trans %}Services{% endtrans %}</a>
|
||||
<a href="{{ url('core:file_list') }}">{% trans %}Files{% endtrans %}</a>
|
||||
|
0
sas/__init__.py
Normal file
0
sas/__init__.py
Normal file
8
sas/admin.py
Normal file
8
sas/admin.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from sas.models import *
|
||||
|
||||
|
||||
admin.site.register(Album)
|
||||
admin.site.register(Picture)
|
||||
|
0
sas/migrations/__init__.py
Normal file
0
sas/migrations/__init__.py
Normal file
44
sas/models.py
Normal file
44
sas/models.py
Normal file
@ -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})
|
||||
|
28
sas/templates/sas/album.jinja
Normal file
28
sas/templates/sas/album.jinja
Normal file
@ -0,0 +1,28 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}SAS{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{{ sithfile.get_display_name() }}</h3>
|
||||
<div>
|
||||
{% for a in sithfile.children.filter(is_folder=True).all() %}
|
||||
<div style="display: inline-block; border: solid 1px black;">
|
||||
<a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div>
|
||||
{% for a in sithfile.children.filter(mime_type__in=['image/jpeg', 'image/png']).all() %}
|
||||
{% if a.as_picture.can_be_viewed_by(user) %}
|
||||
<div style="display: inline-block; border: solid 1px black;">
|
||||
<a href="{{ url("sas:picture", picture_id=a.id) }}">
|
||||
<img src="{{ a.as_picture.get_download_url() }}" alt="{{ a.get_display_name() }}" style="width: 50px"/>
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
16
sas/templates/sas/main.jinja
Normal file
16
sas/templates/sas/main.jinja
Normal file
@ -0,0 +1,16 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}SAS{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans %}SAS{% endtrans %}</h3>
|
||||
<div>
|
||||
{% for a in root_file.children.filter(is_folder=True).all() %}
|
||||
<div style="display: inline-block; border: solid 1px black;">
|
||||
<a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
16
sas/templates/sas/picture.jinja
Normal file
16
sas/templates/sas/picture.jinja
Normal file
@ -0,0 +1,16 @@
|
||||
{% extends "core/base.jinja" %}
|
||||
|
||||
{% block title %}
|
||||
{% trans %}SAS{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{{ picture.get_display_name() }}</h3>
|
||||
<div style="float: right">
|
||||
PREV / NEXT
|
||||
</div>
|
||||
<div>
|
||||
<img src="{{ picture.get_download_url() }}" alt="{{ picture.get_display_name() }}" style="width: 90%"/>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
3
sas/tests.py
Normal file
3
sas/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
13
sas/urls.py
Normal file
13
sas/urls.py
Normal file
@ -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<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'),
|
||||
# url(r'^album/new$', AlbumCreateView.as_view(), name='album_new'),
|
||||
# url(r'^(?P<club_id>[0-9]+)/$', ClubView.as_view(), name='club_view'),
|
||||
]
|
||||
|
38
sas/views.py
Normal file
38
sas/views.py
Normal file
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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)),
|
||||
|
Loading…
Reference in New Issue
Block a user