mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
Clean up, fix, and improve templates around clipboard
This commit is contained in:
parent
0859648bd4
commit
f594a99751
@ -649,6 +649,11 @@ class SithFile(models.Model):
|
||||
from sas.models import Picture
|
||||
return Picture.objects.filter(id=self.id).first()
|
||||
|
||||
@property
|
||||
def as_album(self):
|
||||
from sas.models import Album
|
||||
return Album.objects.filter(id=self.id).first()
|
||||
|
||||
def __str__(self):
|
||||
if self.is_folder:
|
||||
return _("Folder: ") + self.name
|
||||
|
@ -372,6 +372,10 @@ textarea {
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
.not_moderated {
|
||||
border: solid 1px red;
|
||||
box-shadow: red 2px 2px 10px;
|
||||
}
|
||||
|
||||
/*--------------------------------FOOTER-------------------------------*/
|
||||
footer{
|
||||
|
@ -27,6 +27,15 @@
|
||||
<input name="cut" type="submit" value="{% trans %}Cut{% endtrans %}"> |
|
||||
<input name="paste" type="submit" value="{% trans %}Paste{% endtrans %}">
|
||||
</p>
|
||||
{% if clipboard %}
|
||||
<p>{% trans %}Clipboard: {% endtrans %}
|
||||
<ul>
|
||||
{% for f in clipboard %}
|
||||
<li>{{ f.get_full_path() }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</p>
|
||||
{% endif %}
|
||||
<ul>
|
||||
{% for f in file.children.order_by('-is_folder', 'name').all() %}
|
||||
<li>
|
||||
|
@ -143,10 +143,14 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.form = self.get_form()
|
||||
if 'clipboard' not in request.session.keys():
|
||||
request.session['clipboard'] = []
|
||||
return super(FileView, self).get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
if 'clipboard' not in request.session.keys():
|
||||
request.session['clipboard'] = []
|
||||
if request.user.can_edit(self.object):
|
||||
if 'delete' in request.POST.keys():
|
||||
for f_id in request.POST.getlist('file_list'):
|
||||
@ -156,7 +160,6 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
||||
if 'clear' in request.POST.keys():
|
||||
request.session['clipboard'] = []
|
||||
if 'cut' in request.POST.keys():
|
||||
request.session['clipboard'] = request.session['clipboard'] or []
|
||||
for f_id in request.POST.getlist('file_list'):
|
||||
f_id = int(f_id)
|
||||
if f_id in [c.id for c in self.object.children.all()] and f_id not in request.session['clipboard']:
|
||||
@ -164,11 +167,10 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
||||
if 'paste' in request.POST.keys():
|
||||
for f_id in request.session['clipboard']:
|
||||
sf = SithFile.objects.filter(id=f_id).first()
|
||||
print(sf)
|
||||
if sf:
|
||||
sf.move_to(self.object)
|
||||
request.session['clipboard'] = []
|
||||
print(request.session['clipboard'])
|
||||
request.session.modified = True
|
||||
self.form = self.get_form() # The form handle only the file upload
|
||||
files = request.FILES.getlist('file_field')
|
||||
if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid():
|
||||
@ -186,6 +188,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
||||
kwargs['form'] = self.form
|
||||
if self.kwargs['popup']:
|
||||
kwargs['popup'] = 'popup'
|
||||
kwargs['clipboard'] = SithFile.objects.filter(id__in=self.request.session['clipboard'])
|
||||
return kwargs
|
||||
|
||||
class FileDeleteView(CanEditPropMixin, DeleteView):
|
||||
|
@ -18,9 +18,10 @@
|
||||
<a href="{{ url('sas:album_edit', album_id=album.id) }}">{% trans %}Edit{% endtrans %}</a><br>
|
||||
<hr>
|
||||
<div>
|
||||
{% for a in album.children.filter(is_folder=True, is_moderated=True).order_by('-id') %}
|
||||
{% for a in album.children.filter(is_folder=True).order_by('-id') %}
|
||||
{% if a.as_album.can_be_viewed_by(user) %}
|
||||
<a href="{{ url("sas:album", album_id=a.id) }}" style="display: inline-block">
|
||||
<div class="album">
|
||||
<div class="album{% if not a.is_moderated %} not_moderated{% endif %}">
|
||||
<div>
|
||||
{% if a.file %}
|
||||
<img src="{{ a.as_picture.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
|
||||
@ -33,12 +34,13 @@
|
||||
{{ a.name }}
|
||||
</div>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div>
|
||||
{% for p in album.children.filter(is_folder=False, is_moderated=True).order_by('id') %}
|
||||
{% for p in album.children.filter(is_folder=False).order_by('id') %}
|
||||
{% if p.as_picture.can_be_viewed_by(user) %}
|
||||
<div class="picture">
|
||||
<div class="picture{% if not p.is_moderated %} not_moderated{% endif %}">
|
||||
<a href="{{ url("sas:picture", picture_id=p.id) }}#pict">
|
||||
<img src="{{ p.as_picture.get_download_thumb_url() }}" alt="{{ p.get_display_name() }}" />
|
||||
</a>
|
||||
|
Loading…
Reference in New Issue
Block a user