diff --git a/fileshack/__init__.py b/fileshack/__init__.py index e69de29..df1dec8 100644 --- a/fileshack/__init__.py +++ b/fileshack/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +import signals \ No newline at end of file diff --git a/fileshack/admin.py b/fileshack/admin.py index 7ccbc33..cbc1256 100644 --- a/fileshack/admin.py +++ b/fileshack/admin.py @@ -5,7 +5,7 @@ class StoreAdmin(admin.ModelAdmin): list_display = ("__unicode__",) class ItemAdmin(admin.ModelAdmin): - pass + readonly_fields = ('created', 'size_total', 'size') admin.site.register(Store, StoreAdmin) admin.site.register(Item, ItemAdmin) diff --git a/fileshack/models.py b/fileshack/models.py index 53ee21f..b806961 100644 --- a/fileshack/models.py +++ b/fileshack/models.py @@ -41,6 +41,7 @@ class Store(Model): protect_files = BooleanField(_("protect files"), help_text=_("Protect files by a random string, so that they cannot be downloaded by guessing their name."), default=True) allow_watch = BooleanField(_("allow watch"), help_text=_('Allow users to subscribe to receive e-mail updates. Requires cron (see documentation).'), default=False) watch_delay = PositiveIntegerField(_("watch delay"), help_text=_("Minimum delay between two notifications in minutes. Only applies when Allow watch is enabled."), default=360) + readonly = BooleanField(_("read only"), help_text=_("Set all files to read only. Uploading or deleting files is disabled."), default=False) def __unicode__(self): url = self.get_absolute_url() @@ -72,6 +73,11 @@ class Item(Model): modified = DateTimeField(_("modified"), auto_now=True) size_total = IntegerField(_("size total"), default=0) size = IntegerField(_("size"), default=0) + readonly = BooleanField(_("read only"), default=False) + + @property + def is_readonly(self): + return self.store.readonly or self.readonly def delete(self): dir = os.path.dirname(os.path.join(settings.MEDIA_ROOT, self.fileobject.name)) @@ -132,6 +138,7 @@ def simple(self): "modified": self.modified, "created": self.created, "uploaded": self.uploaded, + "readonly": self.is_readonly, } def __unicode__(self): @@ -139,6 +146,8 @@ def __unicode__(self): class Meta: ordering = [('created')] + verbose_name = _("file") + verbose_name_plural = ("files") class User(Model): email = EmailField(_("e-mail"), max_length=254, unique=True) diff --git a/fileshack/signals.py b/fileshack/signals.py new file mode 100644 index 0000000..3535af1 --- /dev/null +++ b/fileshack/signals.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +from django.db.models.signals import pre_save +from models import Item + + +def set_file_size(sender, instance, **kwargs): # @UnusedVariable + """ + Automatic set file sizes after uploading. + """ + if instance.fileobject._file is None: + # skip front-end uploads + return + # set sizes + instance.size = instance.fileobject._file.size + instance.size_total = instance.fileobject._file.size + +pre_save.connect(set_file_size, Item) diff --git a/fileshack/static/fileshack/js/models.js b/fileshack/static/fileshack/js/models.js index 6ee9567..80e32f5 100644 --- a/fileshack/static/fileshack/js/models.js +++ b/fileshack/static/fileshack/js/models.js @@ -72,7 +72,8 @@ var Item = new Class({ status: 'READY', // 'READY', 'UPLOADING', 'STALE'. created: new Date(), uploaded: new Date(), - modified: new Date() + modified: new Date(), + readonly: false, }, initialize: function(attributes) { @@ -98,6 +99,7 @@ var Item = new Class({ this.modified = new Date().parse(json.modified); this.uploaded = new Date().parse(json.uploaded); this.created = new Date().parse(json.created); + this.readonly = json.readonly; this.fireEvent('change'); }, diff --git a/fileshack/static/fileshack/js/views.js b/fileshack/static/fileshack/js/views.js index a048e36..a0d77c1 100644 --- a/fileshack/static/fileshack/js/views.js +++ b/fileshack/static/fileshack/js/views.js @@ -101,6 +101,9 @@ var ItemView = new Class({ this.progressbar.value = 1; updateProgress(this.progressbar); } + if (this.model.readonly) + this.deletebtn.hide(); + var percentage = 0; if (this.model.size > 0 && this.model.size_total > 0) percentage = Math.round((this.model.size * 100)/this.model.size_total); diff --git a/fileshack/templates/fileshack/index.html b/fileshack/templates/fileshack/index.html index 2dafbfa..1f47e62 100644 --- a/fileshack/templates/fileshack/index.html +++ b/fileshack/templates/fileshack/index.html @@ -59,6 +59,7 @@ {% block content %}
+ {% if not store.readonly %}
{% trans "Drop your item in here or click" %} @@ -68,6 +69,7 @@
+ {% endif %}