From 7ffa47e874c08339b17df01aca4a230c3fa3a9f9 Mon Sep 17 00:00:00 2001 From: Robert Barsch Date: Tue, 2 Apr 2013 14:54:10 +0200 Subject: [PATCH 1/3] adding readonly support for stores and files --- fileshack/models.py | 7 +++++++ fileshack/static/fileshack/js/models.js | 4 +++- fileshack/static/fileshack/js/views.js | 3 +++ fileshack/templates/fileshack/index.html | 2 ++ fileshack/views.py | 11 +++++++---- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/fileshack/models.py b/fileshack/models.py index 53ee21f..b503735 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): 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 %}