mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 02:24:26 +00:00
Add cut/paste function in files
This commit is contained in:
parent
8b63fa9aea
commit
0859648bd4
20
core/migrations/0016_auto_20161212_1922.py
Normal file
20
core/migrations/0016_auto_20161212_1922.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0015_sithfile_moderator'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='sithfile',
|
||||||
|
name='moderator',
|
||||||
|
field=models.ForeignKey(related_name='moderated_files', blank=True, null=True, to=settings.AUTH_USER_MODEL, verbose_name='owner'),
|
||||||
|
),
|
||||||
|
]
|
@ -529,7 +529,7 @@ class SithFile(models.Model):
|
|||||||
size = models.IntegerField(_("size"), default=0)
|
size = models.IntegerField(_("size"), default=0)
|
||||||
date = models.DateTimeField(_('date'), default=timezone.now)
|
date = models.DateTimeField(_('date'), default=timezone.now)
|
||||||
is_moderated = models.BooleanField(_("is moderated"), default=False)
|
is_moderated = models.BooleanField(_("is moderated"), default=False)
|
||||||
moderator = models.ForeignKey(User, related_name="moderated_files", verbose_name=_("owner"))
|
moderator = models.ForeignKey(User, related_name="moderated_files", verbose_name=_("owner"), null=True, blank=True)
|
||||||
asked_for_removal = models.BooleanField(_("asked for removal"), default=False)
|
asked_for_removal = models.BooleanField(_("asked for removal"), default=False)
|
||||||
is_in_sas = models.BooleanField(_("is in the SAS"), default=False) # Allows to query this flag, updated at each call to save()
|
is_in_sas = models.BooleanField(_("is in the SAS"), default=False) # Allows to query this flag, updated at each call to save()
|
||||||
|
|
||||||
@ -617,6 +617,27 @@ class SithFile(models.Model):
|
|||||||
self.view_groups = self.parent.view_groups.all()
|
self.view_groups = self.parent.view_groups.all()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
def move_to(self, parent):
|
||||||
|
"""Move a file to somewhere else"""
|
||||||
|
if not parent.is_folder:
|
||||||
|
return
|
||||||
|
import shutil
|
||||||
|
import os
|
||||||
|
with transaction.atomic():
|
||||||
|
if self.is_folder:
|
||||||
|
old_file_name = self.get_full_path()
|
||||||
|
else:
|
||||||
|
old_file_name = self.file.name
|
||||||
|
self.parent = parent
|
||||||
|
self.save()
|
||||||
|
if self.is_folder:
|
||||||
|
for c in self.children.all():
|
||||||
|
c.move_to(self)
|
||||||
|
shutil.rmtree(settings.MEDIA_ROOT + old_file_name)
|
||||||
|
else:
|
||||||
|
self.file.save(name=self.name, content=self.file)
|
||||||
|
os.remove(settings.MEDIA_ROOT + old_file_name)
|
||||||
|
|
||||||
def __getattribute__(self, attr):
|
def __getattribute__(self, attr):
|
||||||
if attr == "is_file":
|
if attr == "is_file":
|
||||||
return not self.is_folder
|
return not self.is_folder
|
||||||
@ -645,6 +666,9 @@ class SithFile(models.Model):
|
|||||||
def get_parent_path(self):
|
def get_parent_path(self):
|
||||||
return '/' + '/'.join([p.name for p in self.get_parent_list()[::-1]])
|
return '/' + '/'.join([p.name for p in self.get_parent_list()[::-1]])
|
||||||
|
|
||||||
|
def get_full_path(self):
|
||||||
|
return self.get_parent_path() + '/' + self.name
|
||||||
|
|
||||||
def get_display_name(self):
|
def get_display_name(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -19,9 +19,18 @@
|
|||||||
<p><input type="submit" value="{% trans %}Add{% endtrans %}"></p>
|
<p><input type="submit" value="{% trans %}Add{% endtrans %}"></p>
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<ul>
|
<form action="" method="post" enctype="multipart/form-data">
|
||||||
|
{% 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>
|
||||||
|
<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>
|
||||||
|
<input type="checkbox" name="file_list" value="{{ f.id }}">
|
||||||
{% if f.is_folder %}
|
{% if f.is_folder %}
|
||||||
📁
|
📁
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -29,7 +38,8 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="{{ url('core:file_detail', file_id=f.id, popup=popup) }}">{{ f.get_display_name() }}</a></li>
|
<a href="{{ url('core:file_detail', file_id=f.id, popup=popup) }}">{{ f.get_display_name() }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>{% trans %}Real name: {% endtrans %}{{ file.file.name.split('/')[-1] }}</p>
|
<p>{% trans %}Real name: {% endtrans %}{{ file.file.name.split('/')[-1] }}</p>
|
||||||
<p>{% trans %}Date: {% endtrans %}{{ file.date|localtime|date(DATETIME_FORMAT) }} -
|
<p>{% trans %}Date: {% endtrans %}{{ file.date|localtime|date(DATETIME_FORMAT) }} -
|
||||||
|
@ -58,7 +58,7 @@ class AddFilesForm(forms.Form):
|
|||||||
notif = True
|
notif = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.add_error(None, _("Error creating folder %(folder_name)s: %(msg)s") %
|
self.add_error(None, _("Error creating folder %(folder_name)s: %(msg)s") %
|
||||||
{'folder_name': self.cleaned_data['folder_name'], 'msg': str(e.message)})
|
{'folder_name': self.cleaned_data['folder_name'], 'msg': repr(e)})
|
||||||
for f in files:
|
for f in files:
|
||||||
new_file = SithFile(parent=parent, name=f.name, file=f, owner=owner, is_folder=False,
|
new_file = SithFile(parent=parent, name=f.name, file=f, owner=owner, is_folder=False,
|
||||||
mime_type=f.content_type, size=f._size)
|
mime_type=f.content_type, size=f._size)
|
||||||
@ -69,11 +69,10 @@ class AddFilesForm(forms.Form):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.add_error(None, _("Error uploading file %(file_name)s: %(msg)s") % {'file_name': f, 'msg': repr(e)})
|
self.add_error(None, _("Error uploading file %(file_name)s: %(msg)s") % {'file_name': f, 'msg': repr(e)})
|
||||||
if notif:
|
if notif:
|
||||||
for u in RealGroup.objects.filter(id=settings.SITH_GROUP_SAS_ADMIN_ID).first().users.all():
|
for u in RealGroup.objects.filter(id=settings.SITH_GROUP_COM_ADMIN_ID).first().users.all():
|
||||||
if not u.notifications.filter(type="FILE_MODERATION").exists():
|
if not u.notifications.filter(type="FILE_MODERATION").exists():
|
||||||
Notification(user=u, url=reverse("core:file_moderation"), type="FILE_MODERATION").save()
|
Notification(user=u, url=reverse("core:file_moderation"), type="FILE_MODERATION").save()
|
||||||
|
|
||||||
|
|
||||||
class FileListView(ListView):
|
class FileListView(ListView):
|
||||||
template_name = 'core/file_list.jinja'
|
template_name = 'core/file_list.jinja'
|
||||||
context_object_name = "file_list"
|
context_object_name = "file_list"
|
||||||
@ -148,7 +147,29 @@ class FileView(CanViewMixin, DetailView, FormMixin):
|
|||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
self.form = self.get_form()
|
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():
|
||||||
|
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']:
|
||||||
|
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()
|
||||||
|
print(sf)
|
||||||
|
if sf:
|
||||||
|
sf.move_to(self.object)
|
||||||
|
request.session['clipboard'] = []
|
||||||
|
print(request.session['clipboard'])
|
||||||
|
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():
|
||||||
self.form.process(parent=self.object, owner=request.user, files=files)
|
self.form.process(parent=self.object, owner=request.user, files=files)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -24,7 +24,7 @@ class Picture(SithFile):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def can_be_edited_by(self, user):
|
def can_be_edited_by(self, user):
|
||||||
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID)
|
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) or super(Picture, self).can_be_edited_by(user)
|
||||||
|
|
||||||
def can_be_viewed_by(self, user):
|
def can_be_viewed_by(self, user):
|
||||||
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
|
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
|
proxy = True
|
||||||
|
|
||||||
def can_be_edited_by(self, user):
|
def can_be_edited_by(self, user):
|
||||||
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID)
|
return user.is_in_group(settings.SITH_GROUP_SAS_ADMIN_ID) or super(Album, self).can_be_edited_by(user)
|
||||||
|
|
||||||
def can_be_viewed_by(self, user):
|
def can_be_viewed_by(self, user):
|
||||||
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
|
return self.can_be_edited_by(user) or (self.is_in_sas and self.is_moderated and
|
||||||
|
Loading…
Reference in New Issue
Block a user