Continue SAS

This commit is contained in:
Skia 2016-11-08 01:43:13 +01:00
parent d554a5ee8d
commit 585ba55e5e
5 changed files with 73 additions and 11 deletions

View File

@ -46,6 +46,7 @@ class Command(BaseCommand):
club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root) club_root = SithFile(parent=None, name="clubs", is_folder=True, owner=root)
club_root.save() club_root.save()
SithFile(parent=None, name="SAS", is_folder=True, owner=root).save() SithFile(parent=None, name="SAS", is_folder=True, owner=root).save()
Group(name="SAS admin").save()
main_club = Club(id=1, name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'], main_club = Club(id=1, name=settings.SITH_MAIN_CLUB['name'], unix_name=settings.SITH_MAIN_CLUB['unix_name'],
address=settings.SITH_MAIN_CLUB['address']) address=settings.SITH_MAIN_CLUB['address'])
main_club.save() main_club.save()
@ -275,9 +276,9 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
ca.save() ca.save()
gj = GeneralJournal(name="A16", start_date=date.today(), club_account=ca) gj = GeneralJournal(name="A16", start_date=date.today(), club_account=ca)
gj.save() gj.save()
credit = AccountingType(code=74, label="Someone gave us money", movement_type='credit') credit = AccountingType(code=74, label="Someone gave us money", movement_type='CREDIT')
credit.save() credit.save()
debit = AccountingType(code=607, label="Had to pay a beer", movement_type='debit') debit = AccountingType(code=607, label="Had to pay a beer", movement_type='DEBIT')
debit.save() debit.save()
Operation(journal=gj, date=date.today(), amount=666.42, Operation(journal=gj, date=date.today(), amount=666.42,
remark="An answer to life...", mode="CASH", done=True, accounting_type=credit, target_type="USER", remark="An answer to life...", mode="CASH", done=True, accounting_type=credit, target_type="USER",

View File

@ -6,6 +6,11 @@
{% block content %} {% block content %}
<h3>{{ sithfile.get_display_name() }}</h3> <h3>{{ sithfile.get_display_name() }}</h3>
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="{% trans %}Upload{% endtrans %}" /></p>
</form>
<div> <div>
{% for a in sithfile.children.filter(is_folder=True).all() %} {% for a in sithfile.children.filter(is_folder=True).all() %}
<div style="display: inline-block; border: solid 1px black;"> <div style="display: inline-block; border: solid 1px black;">

View File

@ -6,6 +6,11 @@
{% block content %} {% block content %}
<h3>{% trans %}SAS{% endtrans %}</h3> <h3>{% trans %}SAS{% endtrans %}</h3>
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="{% trans %}Create{% endtrans %}" /></p>
</form>
<div> <div>
{% for a in root_file.children.filter(is_folder=True).all() %} {% for a in root_file.children.filter(is_folder=True).all() %}
<div style="display: inline-block; border: solid 1px black;"> <div style="display: inline-block; border: solid 1px black;">

View File

@ -1,6 +1,7 @@
from django.shortcuts import render from django.shortcuts import render
# from django.core.urlresolvers import reverse_lazy
from django.views.generic import ListView, DetailView, RedirectView, TemplateView from django.views.generic import ListView, DetailView, RedirectView, TemplateView
from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin from django.views.generic.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin, FormView
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils import timezone from django.utils import timezone
from django.conf import settings from django.conf import settings
@ -15,19 +16,49 @@ from core.models import SithFile
from sas.models import Picture, Album from sas.models import Picture, Album
class SASMainView(TemplateView): class SASForm(forms.Form):
album_name = forms.CharField(label=_("Add a new album"), max_length=30, required=False)
images = forms.ImageField(widget=forms.ClearableFileInput(attrs={'multiple': True}), label=_("Upload images"),
required=False)
def process(self, parent, owner, files):
try:
if self.cleaned_data['album_name'] != "":
album = Album(parent=parent, name=self.cleaned_data['album_name'], owner=owner)
album.clean()
album.save()
except Exception as e:
self.add_error(None, _("Error creating album %(album)s: %(msg)s") %
{'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)
try:
new_file.clean()
# TODO: generate thumbnail
new_file.save()
except Exception as e:
self.add_error(None, _("Error uploading file %(file_name)s: %(msg)s") % {'file_name': f, 'msg': repr(e)})
class SASMainView(FormView):
form_class = SASForm
template_name = "sas/main.jinja" template_name = "sas/main.jinja"
# success_url = reverse_lazy('sas:main')
def post(self, request, *args, **kwargs):
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)
if self.form.is_valid():
return super(SASMainView, self).form_valid(self.form)
return self.form_invalid(self.form)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs = super(SASMainView, self).get_context_data(**kwargs) kwargs = super(SASMainView, self).get_context_data(**kwargs)
kwargs['root_file'] = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first() kwargs['root_file'] = SithFile.objects.filter(id=settings.SITH_SAS_ROOT_DIR_ID).first()
return kwargs return kwargs
class AlbumView(DetailView, CanViewMixin):
model = Album
pk_url_kwarg = "album_id"
template_name = "sas/album.jinja"
class PictureView(DetailView, CanViewMixin): class PictureView(DetailView, CanViewMixin):
model = Picture model = Picture
pk_url_kwarg = "picture_id" pk_url_kwarg = "picture_id"
@ -36,3 +67,23 @@ class PictureView(DetailView, CanViewMixin):
def send_pict(request, picture_id): def send_pict(request, picture_id):
return send_file(request, picture_id, Picture) return send_file(request, picture_id, Picture)
class AlbumView(CanViewMixin, FormMixin, DetailView):
model = Album
pk_url_kwarg = "album_id"
template_name = "sas/album.jinja"
def get(self, request, *args, **kwargs):
self.form = self.get_form()
return super(AlbumView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
self.form = self.get_form()
files = request.FILES.getlist('images')
if request.user.is_authenticated() and request.user.is_in_group('ae-member') and self.form.is_valid():
self.form.process(parent=self.object, owner=request.user, files=files)
if self.form.is_valid():
return super(AlbumView, self).form_valid(self.form)
return self.form_invalid(self.form)

View File

@ -447,8 +447,8 @@ SITH_LAUNDERETTE_PRICES = {
} }
# SAS variables # SAS variables
SITH_SAS_ROOT_DIR_ID = 63 SITH_SAS_ROOT_DIR_ID = 4
SITH_SAS_ADMIN_GROUP_ID = 74 SITH_SAS_ADMIN_GROUP_ID = 26
try: try:
from .settings_custom import * from .settings_custom import *