Commit 5ea41de9 authored by Skia's avatar Skia
Browse files

WIP SAS

parent 585ba55e
...@@ -5,25 +5,27 @@ ...@@ -5,25 +5,27 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h3>{{ sithfile.get_display_name() }}</h3> <h3>{{ album.get_display_name() }}</h3>
<form action="" method="post" enctype="multipart/form-data"> <form action="" method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form.as_p() }} {{ form.as_p() }}
<p><input type="submit" value="{% trans %}Upload{% endtrans %}" /></p> <p><input type="submit" value="{% trans %}Upload{% endtrans %}" /></p>
</form> </form>
<div> <div>
{% for a in sithfile.children.filter(is_folder=True).all() %} {% for a in album.children.filter(is_folder=True).all() %}
<div style="display: inline-block; border: solid 1px black;"> <div style="display: inline-block; border: solid 1px black;">
<a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a> <a href="{{ url("sas:album", album_id=a.id) }}">{{ a.name }}</a>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
<div> <div>
{% for a in sithfile.children.filter(mime_type__in=['image/jpeg', 'image/png']).all() %} {# for a in album.children.filter(mime_type__in=['image/jpeg', 'image/png']).all() #}
{% if a.as_picture.can_be_viewed_by(user) %} {% for p in album.children.filter(is_folder=False).all() %}
<p>{{ p.name }}</p>
{% if p.as_picture.can_be_viewed_by(user) %}
<div style="display: inline-block; border: solid 1px black;"> <div style="display: inline-block; border: solid 1px black;">
<a href="{{ url("sas:picture", picture_id=a.id) }}"> <a href="{{ url("sas:picture", picture_id=p.id) }}">
<img src="{{ a.as_picture.get_download_url() }}" alt="{{ a.get_display_name() }}" style="width: 50px"/> <img src="{{ p.as_picture.get_download_url() }}" alt="{{ p.get_display_name() }}" style="width: 50px"/>
</a> </a>
</div> </div>
{% endif %} {% endif %}
......
from django.shortcuts import render from django.shortcuts import render
# from django.core.urlresolvers import reverse_lazy 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, FormView 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 _
...@@ -31,7 +31,8 @@ class SASForm(forms.Form): ...@@ -31,7 +31,8 @@ class SASForm(forms.Form):
self.add_error(None, _("Error creating album %(album)s: %(msg)s") % self.add_error(None, _("Error creating album %(album)s: %(msg)s") %
{'album': self.cleaned_data['album_name'], 'msg': str(e.message)}) {'album': self.cleaned_data['album_name'], 'msg': str(e.message)})
for f in files: for f in files:
new_file = Picture(parent=parent, name=f.name, file=f, owner=owner, mime_type=f.content_type, size=f._size) new_file = Picture(parent=parent, name=f.name, file=f, owner=owner, mime_type=f.content_type, size=f._size,
is_folder=False)
try: try:
new_file.clean() new_file.clean()
# TODO: generate thumbnail # TODO: generate thumbnail
...@@ -42,7 +43,7 @@ class SASForm(forms.Form): ...@@ -42,7 +43,7 @@ class SASForm(forms.Form):
class SASMainView(FormView): class SASMainView(FormView):
form_class = SASForm form_class = SASForm
template_name = "sas/main.jinja" template_name = "sas/main.jinja"
# success_url = reverse_lazy('sas:main') success_url = reverse_lazy('sas:main')
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
self.form = self.get_form() self.form = self.get_form()
...@@ -67,8 +68,9 @@ class PictureView(DetailView, CanViewMixin): ...@@ -67,8 +68,9 @@ 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): class AlbumView(CanViewMixin, DetailView, FormMixin):
model = Album model = Album
form_class = SASForm
pk_url_kwarg = "album_id" pk_url_kwarg = "album_id"
template_name = "sas/album.jinja" template_name = "sas/album.jinja"
...@@ -77,13 +79,25 @@ class AlbumView(CanViewMixin, FormMixin, DetailView): ...@@ -77,13 +79,25 @@ class AlbumView(CanViewMixin, FormMixin, DetailView):
return super(AlbumView, self).get(request, *args, **kwargs) return super(AlbumView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
print('GUY')
self.object = self.get_object() self.object = self.get_object()
self.form = self.get_form() self.form = self.get_form()
parent = SithFile.objects.filter(id=self.object.id).first()
files = request.FILES.getlist('images') files = request.FILES.getlist('images')
if request.user.is_authenticated() and request.user.is_in_group('ae-member') and self.form.is_valid(): if request.user.is_authenticated() and request.user.is_in_group('ae-membres'):
self.form.process(parent=self.object, owner=request.user, files=files)
if self.form.is_valid(): if self.form.is_valid():
return super(AlbumView, self).form_valid(self.form) self.form.process(parent=parent, owner=request.user, files=files)
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"))
return self.form_invalid(self.form) return self.form_invalid(self.form)
def get_success_url(self):
return reverse_lazy('sas:album', kwargs={'album_id': self.object.id})
def get_context_data(self, **kwargs):
kwargs = super(AlbumView, self).get_context_data(**kwargs)
kwargs['form'] = self.form
return kwargs
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