Commit f594a997 authored by Skia's avatar Skia
Browse files

Clean up, fix, and improve templates around clipboard

parent 0859648b
Pipeline #498 passed with stage
in 2 minutes and 34 seconds
...@@ -649,6 +649,11 @@ class SithFile(models.Model): ...@@ -649,6 +649,11 @@ class SithFile(models.Model):
from sas.models import Picture from sas.models import Picture
return Picture.objects.filter(id=self.id).first() 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): def __str__(self):
if self.is_folder: if self.is_folder:
return _("Folder: ") + self.name return _("Folder: ") + self.name
......
...@@ -372,6 +372,10 @@ textarea { ...@@ -372,6 +372,10 @@ textarea {
display: block; display: block;
margin: auto; margin: auto;
} }
.not_moderated {
border: solid 1px red;
box-shadow: red 2px 2px 10px;
}
/*--------------------------------FOOTER-------------------------------*/ /*--------------------------------FOOTER-------------------------------*/
footer{ footer{
......
...@@ -27,6 +27,15 @@ ...@@ -27,6 +27,15 @@
<input name="cut" type="submit" value="{% trans %}Cut{% endtrans %}"> | <input name="cut" type="submit" value="{% trans %}Cut{% endtrans %}"> |
<input name="paste" type="submit" value="{% trans %}Paste{% endtrans %}"> <input name="paste" type="submit" value="{% trans %}Paste{% endtrans %}">
</p> </p>
{% if clipboard %}
<p>{% trans %}Clipboard: {% endtrans %}
<ul>
{% for f in clipboard %}
<li>{{ f.get_full_path() }}</li>
{% endfor %}
</ul>
</p>
{% endif %}
<ul> <ul>
{% for f in file.children.order_by('-is_folder', 'name').all() %} {% for f in file.children.order_by('-is_folder', 'name').all() %}
<li> <li>
......
...@@ -143,10 +143,14 @@ class FileView(CanViewMixin, DetailView, FormMixin): ...@@ -143,10 +143,14 @@ class FileView(CanViewMixin, DetailView, FormMixin):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.form = self.get_form() self.form = self.get_form()
if 'clipboard' not in request.session.keys():
request.session['clipboard'] = []
return super(FileView, self).get(request, *args, **kwargs) return super(FileView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
if 'clipboard' not in request.session.keys():
request.session['clipboard'] = []
if request.user.can_edit(self.object): if request.user.can_edit(self.object):
if 'delete' in request.POST.keys(): if 'delete' in request.POST.keys():
for f_id in request.POST.getlist('file_list'): for f_id in request.POST.getlist('file_list'):
...@@ -156,7 +160,6 @@ class FileView(CanViewMixin, DetailView, FormMixin): ...@@ -156,7 +160,6 @@ class FileView(CanViewMixin, DetailView, FormMixin):
if 'clear' in request.POST.keys(): if 'clear' in request.POST.keys():
request.session['clipboard'] = [] request.session['clipboard'] = []
if 'cut' in request.POST.keys(): if 'cut' in request.POST.keys():
request.session['clipboard'] = request.session['clipboard'] or []
for f_id in request.POST.getlist('file_list'): for f_id in request.POST.getlist('file_list'):
f_id = int(f_id) 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']: 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): ...@@ -164,11 +167,10 @@ class FileView(CanViewMixin, DetailView, FormMixin):
if 'paste' in request.POST.keys(): if 'paste' in request.POST.keys():
for f_id in request.session['clipboard']: for f_id in request.session['clipboard']:
sf = SithFile.objects.filter(id=f_id).first() sf = SithFile.objects.filter(id=f_id).first()
print(sf)
if sf: if sf:
sf.move_to(self.object) sf.move_to(self.object)
request.session['clipboard'] = [] request.session['clipboard'] = []
print(request.session['clipboard']) request.session.modified = True
self.form = self.get_form() # The form handle only the file upload self.form = self.get_form() # The form handle only the file upload
files = request.FILES.getlist('file_field') files = request.FILES.getlist('file_field')
if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid(): 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): ...@@ -186,6 +188,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
kwargs['form'] = self.form kwargs['form'] = self.form
if self.kwargs['popup']: if self.kwargs['popup']:
kwargs['popup'] = 'popup' kwargs['popup'] = 'popup'
kwargs['clipboard'] = SithFile.objects.filter(id__in=self.request.session['clipboard'])
return kwargs return kwargs
class FileDeleteView(CanEditPropMixin, DeleteView): class FileDeleteView(CanEditPropMixin, DeleteView):
......
...@@ -18,9 +18,10 @@ ...@@ -18,9 +18,10 @@
<a href="{{ url('sas:album_edit', album_id=album.id) }}">{% trans %}Edit{% endtrans %}</a><br> <a href="{{ url('sas:album_edit', album_id=album.id) }}">{% trans %}Edit{% endtrans %}</a><br>
<hr> <hr>
<div> <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"> <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> <div>
{% if a.file %} {% if a.file %}
<img src="{{ a.as_picture.get_download_url() }}" alt="{% trans %}preview{% endtrans %}"> <img src="{{ a.as_picture.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
...@@ -33,12 +34,13 @@ ...@@ -33,12 +34,13 @@
{{ a.name }} {{ a.name }}
</div> </div>
</a> </a>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
<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) %} {% 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"> <a href="{{ url("sas:picture", picture_id=p.id) }}#pict">
<img src="{{ p.as_picture.get_download_thumb_url() }}" alt="{{ p.get_display_name() }}" /> <img src="{{ p.as_picture.get_download_thumb_url() }}" alt="{{ p.get_display_name() }}" />
</a> </a>
......
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