Commit bf9aa29a authored by Skia's avatar Skia 🤘
Browse files

Add clipboard to SAS

parent f594a997
Pipeline #499 passed with stage
in 2 minutes and 44 seconds
......@@ -141,6 +141,28 @@ class FileView(CanViewMixin, DetailView, FormMixin):
context_object_name = "file"
form_class = AddFilesForm
def handle_clipboard(request, object):
if 'delete' in request.POST.keys():
for f_id in request.POST.getlist('file_list'):
sf = SithFile.objects.filter(id=f_id).first()
if sf:
sf.delete()
if 'clear' in request.POST.keys():
request.session['clipboard'] = []
if 'cut' in request.POST.keys():
for f_id in request.POST.getlist('file_list'):
f_id = int(f_id)
if f_id in [c.id for c in object.children.all()] and f_id not in request.session['clipboard']:
print(f_id)
request.session['clipboard'].append(f_id)
if 'paste' in request.POST.keys():
for f_id in request.session['clipboard']:
sf = SithFile.objects.filter(id=f_id).first()
if sf:
sf.move_to(object)
request.session['clipboard'] = []
request.session.modified = True
def get(self, request, *args, **kwargs):
self.form = self.get_form()
if 'clipboard' not in request.session.keys():
......@@ -152,25 +174,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
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'):
sf = SithFile.objects.filter(id=f_id).first()
if sf:
sf.delete()
if 'clear' in request.POST.keys():
request.session['clipboard'] = []
if 'cut' in request.POST.keys():
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']:
request.session['clipboard'].append(f_id)
if 'paste' in request.POST.keys():
for f_id in request.session['clipboard']:
sf = SithFile.objects.filter(id=f_id).first()
if sf:
sf.move_to(self.object)
request.session['clipboard'] = []
request.session.modified = True
FileView.handle_clipboard(request, self.object)
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():
......
......@@ -24,7 +24,7 @@ class Picture(SithFile):
return False
def can_be_edited_by(self, user):
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) or super(Picture, self).can_be_edited_by(user)
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID)
def can_be_viewed_by(self, user):
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
......@@ -87,7 +87,7 @@ class Album(SithFile):
proxy = True
def can_be_edited_by(self, user):
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) or super(Album, self).can_be_edited_by(user)
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID)
def can_be_viewed_by(self, user):
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
......
......@@ -17,37 +17,69 @@
<h3>{{ album.get_display_name() }}</h3>
<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).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{% if not a.is_moderated %} not_moderated{% endif %}">
<div>
{% if a.file %}
<img src="{{ a.as_picture.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
{% elif a.children.filter(is_folder=False, is_moderated=True).exists() %}
<img src="{{ a.children.filter(is_folder=False).first().as_picture.get_download_thumb_url() }}" alt="{% trans %}preview{% endtrans %}">
{% else %}
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
{% if user.can_edit(album) %}
<form action="" method="post" enctype="multipart/form-data" style="width: 100%;">
{% csrf_token %}
<p>
<input name="delete" type="submit" value="{% trans %}Delete{% endtrans %}"> |
<input name="clear" type="submit" value="{% trans %}Clear clipboard{% endtrans %}"> |
<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 %}
{% endif %}
<div>
{% for a in album.children.filter(is_folder=True).order_by('-id') %}
<div style="display: inline-block;">
{% if user.can_edit(album) %}
<input type="checkbox" name="file_list" value="{{ a.id }}">
{% endif %}
{% 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{% if not a.is_moderated %} not_moderated{% endif %}">
<div>
{% if a.file %}
<img src="{{ a.as_picture.get_download_url() }}" alt="{% trans %}preview{% endtrans %}">
{% elif a.children.filter(is_folder=False, is_moderated=True).exists() %}
<img src="{{ a.children.filter(is_folder=False).first().as_picture.get_download_thumb_url() }}" alt="{% trans %}preview{% endtrans %}">
{% else %}
<img src="{{ static('core/img/sas.jpg') }}" alt="{% trans %}preview{% endtrans %}">
{% endif %}
</div>
{{ a.name }}
</div>
{{ a.name }}
</div>
</a>
{% endif %}
{% endfor %}
</div>
<div>
{% for p in album.children.filter(is_folder=False).order_by('id') %}
{% if p.as_picture.can_be_viewed_by(user) %}
<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>
{% endif %}
</div>
{% endfor %}
</div>
{% endif %}
{% endfor %}
</div>
<div>
{% for p in album.children.filter(is_folder=False).order_by('id') %}
<div style="display: inline-block;">
{% if user.can_edit(album) %}
<input type="checkbox" name="file_list" value="{{ p.id }}">
{% endif %}
{% if p.as_picture.can_be_viewed_by(user) %}
<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>
</div>
{% endif %}
</div>
{% endfor %}
</div>
{% if user.can_edit(album) %}
</form>
{% endif %}
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p() }}
......
......@@ -17,7 +17,7 @@ from PIL import Image
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime
from core.views.files import send_file
from core.views.files import send_file, FileView
from core.models import SithFile, User, Notification, RealGroup
from sas.models import Picture, Album, PeoplePictureRelation
......@@ -154,14 +154,20 @@ class AlbumView(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(AlbumView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
self.form = self.get_form()
if 'clipboard' not in request.session.keys():
request.session['clipboard'] = []
if request.user.can_edit(self.object): # Handle the copy-paste functions
FileView.handle_clipboard(request, self.object)
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-membres'):
if request.user.is_authenticated() and request.user.is_subscribed():
if self.form.is_valid():
self.form.process(parent=parent, owner=request.user, files=files,
automodere=request.user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID))
......@@ -177,6 +183,7 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
def get_context_data(self, **kwargs):
kwargs = super(AlbumView, self).get_context_data(**kwargs)
kwargs['form'] = self.form
kwargs['clipboard'] = SithFile.objects.filter(id__in=self.request.session['clipboard'])
return kwargs
# Admin views
......
Supports Markdown
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