This commit is contained in:
Skia 2016-11-08 15:12:37 +01:00
parent 585ba55e5e
commit 5ea41de91d
2 changed files with 29 additions and 13 deletions

View File

@ -5,25 +5,27 @@
{% endblock %}
{% block content %}
<h3>{{ sithfile.get_display_name() }}</h3>
<h3>{{ album.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>
{% 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;">
<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) %}
{# 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>
{% 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=a.id) }}">
<img src="{{ a.as_picture.get_download_url() }}" alt="{{ a.get_display_name() }}" style="width: 50px"/>
<a href="{{ url("sas:picture", picture_id=p.id) }}">
<img src="{{ p.as_picture.get_download_url() }}" alt="{{ p.get_display_name() }}" style="width: 50px"/>
</a>
</div>
{% endif %}

View File

@ -1,5 +1,5 @@
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.edit import UpdateView, CreateView, DeleteView, ProcessFormView, FormMixin, FormView
from django.utils.translation import ugettext as _
@ -31,7 +31,8 @@ class SASForm(forms.Form):
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)
new_file = Picture(parent=parent, name=f.name, file=f, owner=owner, mime_type=f.content_type, size=f._size,
is_folder=False)
try:
new_file.clean()
# TODO: generate thumbnail
@ -42,7 +43,7 @@ class SASForm(forms.Form):
class SASMainView(FormView):
form_class = SASForm
template_name = "sas/main.jinja"
# success_url = reverse_lazy('sas:main')
success_url = reverse_lazy('sas:main')
def post(self, request, *args, **kwargs):
self.form = self.get_form()
@ -67,8 +68,9 @@ class PictureView(DetailView, CanViewMixin):
def send_pict(request, picture_id):
return send_file(request, picture_id, Picture)
class AlbumView(CanViewMixin, FormMixin, DetailView):
class AlbumView(CanViewMixin, DetailView, FormMixin):
model = Album
form_class = SASForm
pk_url_kwarg = "album_id"
template_name = "sas/album.jinja"
@ -77,13 +79,25 @@ class AlbumView(CanViewMixin, FormMixin, DetailView):
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()
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 request.user.is_authenticated() and request.user.is_in_group('ae-membres'):
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)
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