Permalink
Browse files

First commit.

  • Loading branch information...
peterkuma committed Mar 6, 2012
0 parents commit efff25b66f22e6478be6d56703765ce8415713bd
Showing with 3,362 additions and 0 deletions.
  1. +5 −0 .gitignore
  2. 0 __init__.py
  3. BIN db/fileshack.sqlite
  4. 0 fileshack/__init__.py
  5. +12 −0 fileshack/admin.py
  6. +115 −0 fileshack/models.py
  7. +69 −0 fileshack/static/fileshack/css/accesscode.css
  8. +25 −0 fileshack/static/fileshack/css/error.css
  9. +294 −0 fileshack/static/fileshack/css/fileshack.css
  10. BIN fileshack/static/fileshack/img/box-selected.png
  11. +212 −0 fileshack/static/fileshack/img/box-selected.svg
  12. BIN fileshack/static/fileshack/img/box.png
  13. +191 −0 fileshack/static/fileshack/img/box.svg
  14. BIN fileshack/static/fileshack/img/button-blue-tall.png
  15. BIN fileshack/static/fileshack/img/button-blue.png
  16. BIN fileshack/static/fileshack/img/button-red.png
  17. BIN fileshack/static/fileshack/img/error-close.png
  18. +149 −0 fileshack/static/fileshack/img/error-close.svg
  19. BIN fileshack/static/fileshack/img/error-wide.png
  20. +148 −0 fileshack/static/fileshack/img/error-wide.svg
  21. BIN fileshack/static/fileshack/img/error.png
  22. +127 −0 fileshack/static/fileshack/img/error.svg
  23. BIN fileshack/static/fileshack/img/input-blue-tall.png
  24. +24 −0 fileshack/static/fileshack/js/accesscode.js
  25. +42 −0 fileshack/static/fileshack/js/collections.js
  26. +199 −0 fileshack/static/fileshack/js/fileshack.js
  27. +18 −0 fileshack/static/fileshack/js/misc.js
  28. +264 −0 fileshack/static/fileshack/js/models.js
  29. +75 −0 fileshack/static/fileshack/js/mootools-more.js
  30. +476 −0 fileshack/static/fileshack/js/mootools.js
  31. +111 −0 fileshack/static/fileshack/js/views.js
  32. +37 −0 fileshack/templates/fileshack/404.html
  33. +21 −0 fileshack/templates/fileshack/500.html
  34. +27 −0 fileshack/templates/fileshack/accesscode.html
  35. +12 −0 fileshack/templates/fileshack/iframe.html
  36. +79 −0 fileshack/templates/fileshack/index.html
  37. +13 −0 fileshack/urls.py
  38. +371 −0 fileshack/views.py
  39. 0 fileshackproject/__init__.py
  40. +159 −0 fileshackproject/settings.py
  41. +27 −0 fileshackproject/settings_local.py
  42. +21 −0 fileshackproject/urls.py
  43. +30 −0 fileshackproject/wsgi.py
  44. +9 −0 manage.py
@@ -0,0 +1,5 @@
+*.pyc
+*.komodoproject
+.komodotools
+*~
+
No changes.
Binary file not shown.
No changes.
@@ -0,0 +1,12 @@
+from models import *
+from django.contrib import admin
+
+class StoreAdmin(admin.ModelAdmin):
+ list_display = ("__unicode__",)
+
+class ItemAdmin(admin.ModelAdmin):
+ pass
+
+admin.site.register(Store, StoreAdmin)
+admin.site.register(Item, ItemAdmin)
+
@@ -0,0 +1,115 @@
+from django.db.models import *
+from django.utils.translation import ugettext_lazy as _
+from django.core.files.storage import default_storage
+from django.conf import settings
+from django.core.urlresolvers import reverse
+
+import os
+from random import choice
+from datetime import datetime as dt
+from datetime import timedelta
+
+class Store(Model):
+ path = CharField(_("path"), help_text=_("Path relative to the base URL under which the store is accessible. Leave empty if not sure."), unique=True, blank=True, max_length=200)
+ media = CharField(_("media"), help_text=_("Directiory under MEDIA_PATH into which files will be uploaded. Leave empty if not sure."), blank=True, max_length=200)
+ accesscode = CharField(_("access code"), help_text=_("Protect access to the store by an access code."), max_length=200)
+ item_limit = IntegerField(_("item size limit"), help_text=_("Limit the size of a single file."), default=0)
+ store_limit = IntegerField(_("store size limit"), help_text=_("Limit the size of the entire store."), default=0)
+ 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)
+
+ def __unicode__(self):
+ url = self.get_absolute_url()
+ if url.startswith("/"):
+ url = url[1:]
+ return "default" if url == "" else url
+
+ def get_absolute_url(self):
+ url = reverse("fileshack:index", kwargs=dict(store_path=self.path))
+ if url == "//": url = "/" # Ugly hack.
+ return url
+
+ def total(self):
+ total = 0
+ for dirpath, dirnames, filenames in os.walk(os.path.join(settings.MEDIA_ROOT, "fileshack", self.media)):
+ for f in filenames:
+ fp = os.path.join(dirpath, f)
+ total += os.path.getsize(fp)
+ return total
+
+def item_upload_to(instance, filename):
+ key = ""
+ if(instance.store.protect_files):
+ chars = "abcdefghijklmnopqrstuvwxyz0123456789"
+ key = "".join([choice(chars) for i in range(10)])
+ return os.path.join(instance.store.media, key, filename)
+
+class Item(Model):
+ store = ForeignKey(Store, verbose_name=_("store"))
+ fileobject = FileField(_("file"), upload_to=item_upload_to)
+ created = DateTimeField(_("created"), auto_now_add=True)
+ uploaded = DateTimeField(_("uploaded"), auto_now_add=True)
+ modified = DateTimeField(_("modified"), auto_now=True)
+ size_total = IntegerField(_("size total"), default=0)
+ size = IntegerField(_("size"), default=0)
+
+ def delete(self):
+ dir = os.path.dirname(os.path.join(settings.MEDIA_ROOT, self.fileobject.name))
+ self.fileobject.delete()
+ try: os.rmdir(dir)
+ except OSError: pass
+ return Model.delete(self)
+
+ def status(self):
+ if self.size < self.size_total and dt.now(self.modified.tzinfo) - self.modified > timedelta(seconds=10):
+ return 'STALE'
+ elif self.size < self.size_total:
+ return 'UPLOADING'
+ else:
+ return 'READY'
+
+ def exists(self):
+ return self.fileobject and default_storage.exists(self.fileobject.path)
+
+ def get_absolute_url(self):
+ if self.fileobject:
+ return self.fileobject.url
+ else:
+ return None
+
+ def name(self):
+ try:
+ return os.path.basename(self.fileobject.name)
+ except (OSError,ValueError):
+ return None
+
+ def size_human(self):
+ size = self.size()
+ for u in ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"):
+ unit = u
+ if size < 1024:
+ break
+ size = size/1024.0
+ if unit == "B" or unit == "KB":
+ return u"%.0f %s" % (size, unit)
+ else:
+ return u"%.1f %s" % (size, unit)
+
+ def simple(self):
+ return {
+ "id": self.id,
+ "status": self.status(),
+ "name": self.name(),
+ "url": self.get_absolute_url(),
+ "size": self.size,
+ "size_total": self.size_total,
+ "modified": self.modified,
+ "created": self.created,
+ "uploaded": self.uploaded,
+ }
+
+ def __unicode__(self):
+ return self.name()
+
+ class Meta:
+ ordering = ('created'),
+
@@ -0,0 +1,69 @@
+#preload-1 { width: 0; height: 0; background: url(../img/input-blue-tall.png); }
+#preload-2 { width: 0; height: 0; background: url(../img/button-blue-tall.png); }
+
+h1 {
+ margin-top: 150px;
+}
+
+#container {
+ text-align: center;
+}
+
+form {
+ width: 550px;
+ margin: 0 auto;
+}
+
+input {
+ width: 400px;
+ font-size: 20pt;
+ height: 40px;
+ border: 3px solid black;
+ border-radius: 5px;
+ margin: 5px;
+ padding: 6px;
+ float: left;
+ border: 3px solid #dddddd;
+}
+
+input:hover,input:focus,input.nonempty {
+ border: 3px solid #2dacf8;
+ background: url(../img/input-blue-tall.png);
+}
+
+button {
+ font-size: 20pt;
+ float: left;
+ width: 80px;
+ height: 58px;
+ margin: 5px;
+ border: 3px solid #dddddd;
+}
+
+button:hover,button:focus,button.nonempty {
+ color: black;
+ border: 3px solid #0088cb;
+ background: url(../img/button-blue-tall.png);
+}
+
+#error {
+ text-align: left;
+ width: 600px;
+ height: 162px;
+ position: relative;
+ top: 10px;
+ left: 100px;
+ clear: both;
+ background: url(../img/error.png) no-repeat;
+}
+
+#error .label {
+ font-size: 23pt;
+ padding: 52px 0 2px 30px;
+}
+
+#error .message {
+ font-size: 19pt;
+ color: #fdeeee;
+ padding: 0 0 15px 30px;
+}
@@ -0,0 +1,25 @@
+#error {
+ text-align: left;
+ width: 600px;
+ height: 162px;
+ position: relative;
+ top: -40px;
+ left: 20px;
+ clear: both;
+ background: url(../img/error.png) no-repeat;
+}
+
+#error .label {
+ font-size: 23pt;
+ padding: 52px 0 2px 30px;
+}
+
+#error .message {
+ font-size: 19pt;
+ color: #fdeeee;
+ padding: 0 0 15px 30px;
+}
+
+#error a {
+ color: inherit;
+}
Oops, something went wrong.

0 comments on commit efff25b

Please sign in to comment.