rename files to documents and use media for media files

This commit is contained in:
j 2013-05-27 10:13:59 +00:00
commit 8da6badf4c
27 changed files with 1010 additions and 856 deletions

View file

@ -33,13 +33,13 @@
"canEditFeaturedEdits": {"staff": true, "admin": true},
"canEditFeaturedLists": {"staff": true, "admin": true},
"canEditFeaturedTexts": {"staff": true, "admin": true},
"canEditFiles": {"staff": true, "admin": true},
"canEditMedia": {"staff": true, "admin": true},
"canEditMetadata": {"staff": true, "admin": true},
"canEditPlaces": {"staff": true, "admin": true},
"canEditSitePages": {"staff": true, "admin": true},
"canEditUsers": {"admin": true},
"canImportAnnotations": {},
"canManageFiles": {"staff": true, "admin": true},
"canManageDocuments": {"staff": true, "admin": true},
"canManagePlacesAndEvents": {"staff": true, "admin": true},
"canManageTitlesAndNames": {"staff": true, "admin": true},
"canManageUsers": {"staff": true, "admin": true},
@ -50,7 +50,7 @@
"canSeeAccessed": {"staff": true, "admin": true},
"canSeeDebugMenu": {"staff": true, "admin": true},
"canSeeExtraItemViews": {"staff": true, "admin": true},
"canSeeFiles": {"staff": true, "admin": true},
"canSeeMedia": {"staff": true, "admin": true},
"canSeeItem": {"guest": 3, "member": 3, "friend": 4, "staff": 4, "admin": 4},
"canSeeSize": {"friend": true, "staff": true, "admin": true},
"canSeeSoftwareVersion": {"staff": true, "admin": true},
@ -392,7 +392,7 @@
"id": "resolution",
"title": "Resolution",
"type": ["integer"],
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 90,
"format": {"type": "resolution", "args": ["px"]},
"sort": true
@ -409,7 +409,7 @@
"id": "pixels",
"title": "Pixels",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 90,
"format": {"type": "value", "args": ["px"]},
"sort": true
@ -496,7 +496,7 @@
"id": "bitrate",
"title": "Bitrate",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"format": {"type": "value", "args": ["bps"]},
"sort": true
@ -505,7 +505,7 @@
"id": "parts",
"title": "Number of Parts",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true
},
@ -513,7 +513,7 @@
"id": "numberoffiles",
"title": "Number of Files",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true,
"value": {"key": "files", "type": "length"}
@ -522,7 +522,7 @@
"id": "filename",
"title": "Filename",
"type": ["string"],
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"find": true
},
{
@ -607,7 +607,7 @@
{"id": "map", "title": "Map"},
{"id": "calendar", "title": "Calendar"},
{"id": "data", "title": "Data"},
{"id": "files", "title": "Files"}
{"id": "media", "title": "Media"}
],
// fixme: should be renamed to annotationLayers
"layers": [

View file

@ -34,13 +34,13 @@
"canEditFeaturedEdits": {"student": true, "staff": true, "admin": true},
"canEditFeaturedLists": {"student": true, "staff": true, "admin": true},
"canEditFeaturedTexts": {"student": true, "staff": true, "admin": true},
"canEditFiles": {"student": true, "staff": true, "admin": true},
"canEditMedia": {"student": true, "staff": true, "admin": true},
"canEditMetadata": {"student": true, "staff": true, "admin": true},
"canEditPlaces": {"student": true, "staff": true, "admin": true},
"canEditSitePages": {"staff": true, "admin": true},
"canEditUsers": {"staff": true, "admin": true},
"canImportAnnotations": {"student": true, "staff": true, "admin": true},
"canManageFiles": {"member": true, "student": true, "staff": true, "admin": true},
"canManageDocuments": {"member": true, "student": true, "staff": true, "admin": true},
"canManagePlacesAndEvents": {"member": true, "student": true, "staff": true, "admin": true},
"canManageTitlesAndNames": {"member": true, "student": true, "staff": true, "admin": true},
"canManageUsers": {"staff": true, "admin": true},
@ -51,7 +51,7 @@
"canSeeAccessed": {"student": true, "staff": true, "admin": true},
"canSeeDebugMenu": {"student": true, "staff": true, "admin": true},
"canSeeExtraItemViews": {"student": true, "staff": true, "admin": true},
"canSeeFiles": {"student": true, "staff": true, "admin": true},
"canSeeMedia": {"student": true, "staff": true, "admin": true},
"canSeeItem": {"guest": 3, "member": 3, "student": 3, "staff": 3, "admin": 3},
"canSeeSize": {"student": true, "staff": true, "admin": true},
"canSeeSoftwareVersion": {"student": true, "staff": true, "admin": true},
@ -434,7 +434,7 @@
"id": "resolution",
"title": "Resolution",
"type": ["integer"],
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 90,
"format": {"type": "resolution", "args": ["px"]},
"sort": true
@ -451,7 +451,7 @@
"id": "pixels",
"title": "Pixels",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 90,
"format": {"type": "value", "args": ["px"]},
"sort": true
@ -538,7 +538,7 @@
"id": "bitrate",
"title": "Bitrate",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"format": {"type": "value", "args": ["bps"]},
"sort": true
@ -547,7 +547,7 @@
"id": "parts",
"title": "Number of Parts",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true
},
@ -555,7 +555,7 @@
"id": "numberoffiles",
"title": "Number of Files",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true,
"value": {"key": "files", "type": "length"}
@ -564,7 +564,7 @@
"id": "filename",
"title": "Filename",
"type": ["string"],
"capability": "canSeeFiles"
"capability": "canSeeMedia"
},
{
"id": "created",
@ -648,7 +648,7 @@
{"id": "map", "title": "Map"},
{"id": "calendar", "title": "Calendar"},
{"id": "data", "title": "Data"},
{"id": "files", "title": "Files"}
{"id": "media", "title": "Media"}
],
// fixme: should be renamed to annotationLayers
"layers": [

View file

@ -31,13 +31,13 @@
"canEditFeaturedEdits": {"staff": true, "admin": true},
"canEditFeaturedLists": {"staff": true, "admin": true},
"canEditFeaturedTexts": {"staff": true, "admin": true},
"canEditFiles": {"staff": true, "admin": true},
"canEditMedia": {"staff": true, "admin": true},
"canEditMetadata": {"staff": true, "admin": true},
"canEditPlaces": {"staff": true, "admin": true},
"canEditSitePages": {"staff": true, "admin": true},
"canEditUsers": {"admin": true},
"canImportAnnotations": {"member": true, "staff": true, "admin": true},
"canManageFiles": {"member": true, "staff": true, "admin": true},
"canManageDocuments": {"member": true, "staff": true, "admin": true},
"canManagePlacesAndEvents": {"member": true, "staff": true, "admin": true},
"canManageTitlesAndNames": {"member": true, "staff": true, "admin": true},
"canManageUsers": {"staff": true, "admin": true},
@ -48,7 +48,7 @@
"canSeeAccessed": {"staff": true, "admin": true},
"canSeeDebugMenu": {"staff": true, "admin": true},
"canSeeExtraItemViews": {"staff": true, "admin": true},
"canSeeFiles": {"staff": true, "admin": true},
"canSeeMedia": {"staff": true, "admin": true},
"canSeeItem": {"guest": 1, "member": 1, "staff": 4, "admin": 4},
"canSeeSize": {"staff": true, "admin": true},
"canSeeSoftwareVersion": {"staff": true, "admin": true},
@ -410,7 +410,7 @@
"id": "size",
"title": "Size",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"format": {"type": "value", "args": ["B"]},
"sort": true
@ -427,7 +427,7 @@
"id": "numberoffiles",
"title": "Number of Files",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true,
"value": {"key": "files", "type": "length"}
@ -436,14 +436,14 @@
"id": "user",
"title": "User",
"type": "string",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"find": true
},
{
"id": "filename",
"title": "Filename",
"type": ["string"],
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"find": true
},
{
@ -524,7 +524,7 @@
{"id": "map", "title": "Map"},
{"id": "calendar", "title": "Calendar"},
{"id": "data", "title": "Data"},
{"id": "files", "title": "Files"}
{"id": "media", "title": "Media"}
],
"layers": [
{

View file

@ -31,13 +31,13 @@
"canEditFeaturedEdits": {"staff": true, "admin": true},
"canEditFeaturedLists": {"staff": true, "admin": true},
"canEditFeaturedTexts": {"staff": true, "admin": true},
"canEditFiles": {"staff": true, "admin": true},
"canEditMedia": {"staff": true, "admin": true},
"canEditMetadata": {"staff": true, "admin": true},
"canEditPlaces": {"staff": true, "admin": true},
"canEditSitePages": {"staff": true, "admin": true},
"canEditUsers": {"admin": true},
"canImportAnnotations": {"member": true, "staff": true, "admin": true},
"canManageFiles": {"member": true, "staff": true, "admin": true},
"canManageDocuments": {"member": true, "staff": true, "admin": true},
"canManagePlacesAndEvents": {"member": true, "staff": true, "admin": true},
"canManageTitlesAndNames": {"member": true, "staff": true, "admin": true},
"canManageUsers": {"staff": true, "admin": true},
@ -48,7 +48,7 @@
"canSeeAccessed": {"staff": true, "admin": true},
"canSeeDebugMenu": {"staff": true, "admin": true},
"canSeeExtraItemViews": {"staff": true, "admin": true},
"canSeeFiles": {"staff": true, "admin": true},
"canSeeMedia": {"staff": true, "admin": true},
"canSeeItem": {"guest": 1, "member": 1, "staff": 4, "admin": 4},
"canSeeSize": {"staff": true, "admin": true},
"canSeeSoftwareVersion": {"staff": true, "admin": true},
@ -351,7 +351,7 @@
"id": "size",
"title": "Size",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"format": {"type": "value", "args": ["B"]},
"sort": true
@ -368,7 +368,7 @@
"id": "numberoffiles",
"title": "Number of Files",
"type": "integer",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"columnWidth": 60,
"sort": true,
"value": {"key": "files", "type": "length"}
@ -377,7 +377,7 @@
"id": "user",
"title": "User",
"type": "string",
"capability": "canSeeFiles",
"capability": "canSeeMedia",
"find": true
},
{
@ -447,7 +447,7 @@
{"id": "map", "title": "Map"},
{"id": "calendar", "title": "Calendar"},
{"id": "data", "title": "Data"},
{"id": "files", "title": "Files"}
{"id": "media", "title": "Media"}
],
"layers": [
{

View file

@ -88,10 +88,10 @@ def parseConditions(conditions, operator, user):
return None
class FileManager(Manager):
class DocumentManager(Manager):
def get_query_set(self):
return super(FileManager, self).get_query_set()
return super(DocumentManager, self).get_query_set()
def find(self, data, user):
'''

View file

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
import os
from south.models import MigrationHistory
def was_applied(migration_file_path, app_name):
"""true if migration with a given file name ``migration_file``
was applied to app with name ``app_name``"""
try:
migration_file = os.path.basename(migration_file_path)
migration_name = migration_file.split('.')[0]
MigrationHistory.objects.get(
app_name = app_name,
migration = migration_name
)
return True
except MigrationHistory.DoesNotExist:
return False

View file

@ -4,10 +4,14 @@ from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from ..migration_utils import was_applied
class Migration(SchemaMigration):
def forwards(self, orm):
if was_applied(__file__, 'file'):
return
# Adding model 'File'
db.create_table('file_file', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
@ -97,4 +101,4 @@ class Migration(SchemaMigration):
}
}
complete_apps = ['file']
complete_apps = ['file']

View file

@ -4,9 +4,14 @@ from south.db import db
from south.v2 import DataMigration
from django.db import models
from ..migration_utils import was_applied
class Migration(DataMigration):
def forwards(self, orm):
if was_applied(__file__, 'file'):
return
"Write your forwards methods here."
# Note: Remember to use orm['appname.ModelName'] rather than "from appname.models..."
import os

View file

@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
import os
from os.path import exists, join
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
from django.conf import settings
class Migration(SchemaMigration):
def forwards(self, orm):
files_path = join(settings.MEDIA_ROOT, 'files')
documents_path = join(settings.MEDIA_ROOT, 'documents')
if not exists(documents_path) and exists(files_path):
os.rename(files_path, documents_path)
db.rename_table('file_file', 'document_document')
for f in orm['document.Document'].objects.all():
f.file.name = f.file.name.replace('files/', 'documents/')
f.save()
def backwards(self, orm):
files_path = join(settings.MEDIA_ROOT, 'files')
documents_path = join(settings.MEDIA_ROOT, 'documents')
if not exists(files_path) and exists(documents_path):
os.rename(documents_path, files_path)
for f in orm['document.Document'].objects.all():
f.file.name = f.file.name.replace('documents/', 'files/')
f.save()
db.rename_table('document_document', 'file_file')
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '255', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'document.document': {
'Meta': {'unique_together': "(('user', 'name', 'extension'),)", 'object_name': 'Document'},
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'default': "''"}),
'description_sort': ('django.db.models.fields.CharField', [], {'max_length': '512'}),
'extension': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'file': ('django.db.models.fields.files.FileField', [], {'default': 'None', 'max_length': '100', 'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'matches': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'name_sort': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'oshash': ('django.db.models.fields.CharField', [], {'max_length': '16', 'unique': 'True', 'null': 'True'}),
'ratio': ('django.db.models.fields.FloatField', [], {'default': '1'}),
'size': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'uploading': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'files'", 'to': "orm['auth.User']"})
}
}
complete_apps = ['document']

View file

@ -16,7 +16,7 @@ import ox
import managers
class File(models.Model):
class Document(models.Model):
class Meta:
unique_together = ("user", "name", "extension")
@ -35,7 +35,7 @@ class File(models.Model):
file = models.FileField(default=None, blank=True,null=True, upload_to=lambda f, x: f.path(x))
objects = managers.FileManager()
objects = managers.DocumentManager()
uploading = models.BooleanField(default = False)
name_sort = models.CharField(max_length=255)
@ -51,7 +51,7 @@ class File(models.Model):
self.name_sort = ox.sort_string(self.name or u'')[:255].lower()
self.description_sort = ox.sort_string(self.description or u'')[:512].lower()
super(File, self).save(*args, **kwargs)
super(Document, self).save(*args, **kwargs)
def __unicode__(self):
return self.get_id()
@ -82,7 +82,7 @@ class File(models.Model):
return False
if self.user == user or \
user.is_staff or \
user.get_profile().capability('canEditFiles') == True:
user.get_profile().capability('canEditDocuments') == True:
return True
return False
@ -94,7 +94,7 @@ class File(models.Model):
data['name'] = "Untitled"
name = data['name']
num = 1
while File.objects.filter(name=name, user=self.user, extension=self.extension).exclude(id=self.id).count()>0:
while Document.objects.filter(name=name, user=self.user, extension=self.extension).exclude(id=self.id).count()>0:
num += 1
name = data['name'] + ' [%d]' % num
self.name = name
@ -130,7 +130,7 @@ class File(models.Model):
def path(self, name=''):
h = "%07d" % self.id
return os.path.join('files', h[:2], h[2:4], h[4:6], h[6:], name)
return os.path.join('documents', h[:2], h[2:4], h[4:6], h[6:], name)
def save_chunk(self, chunk, chunk_id=-1, done=False):
if self.uploading:
@ -189,10 +189,10 @@ class File(models.Model):
matches += item.models.Item.objects.filter(data__contains=url).count()
matches += text.models.Text.objects.filter(text__contains=url).count()
if matches != self.matches:
File.objects.filter(id=self.id).update(matches=matches)
Document.objects.filter(id=self.id).update(matches=matches)
self.matches = matches
def delete_file(sender, **kwargs):
def delete_document(sender, **kwargs):
t = kwargs['instance']
if t.file:
if t.extension == 'pdf':
@ -200,5 +200,5 @@ def delete_file(sender, **kwargs):
if os.path.exists(thumb):
os.unlink(thumb)
t.file.delete()
pre_delete.connect(delete_file, sender=File)
pre_delete.connect(delete_document, sender=Document)

View file

@ -10,14 +10,44 @@ from ox.django.shortcuts import render_to_json_response, get_object_or_404_json,
from django import forms
from item import utils
from item.models import Item
import models
def get_file_or_404_json(id):
username, name, extension = models.File.parse_id(id)
return get_object_or_404_json(models.File, user__username=username, name=name, extension=extension)
def get_document_or_404_json(id):
username, name, extension = models.Document.parse_id(id)
return get_object_or_404_json(models.Document, user__username=username, name=name, extension=extension)
@login_required_json
def editFile(request):
def addDocument(request):
'''
add document(s) to item
takes {
item: string
id: string
or
ids: [string]
}
returns {
}
'''
response = json_response()
data = json.loads(request.POST['data'])
if 'ids' in data:
ids = data['ids']
else:
ids = [data['id']]
item = Item.objects.get(itemId=data['item'])
if item.editable(request.user):
for id in ids:
file = models.Document.get(id)
item.documents.add(file)
else:
response = json_response(status=403, file='permission denied')
return render_to_json_response(response)
actions.register(addDocument, cache=False)
@login_required_json
def editDocument(request):
'''
takes {
id: string
@ -32,7 +62,7 @@ def editFile(request):
response = json_response()
data = json.loads(request.POST['data'])
if data['id']:
file = models.File.get(data['id'])
file = models.Document.get(data['id'])
if file.editable(request.user):
file.edit(data, request.user)
file.save()
@ -42,7 +72,7 @@ def editFile(request):
else:
response = json_response(status=500, file='invalid request')
return render_to_json_response(response)
actions.register(editFile, cache=False)
actions.register(editDocument, cache=False)
def _order_query(qs, sort):
@ -69,11 +99,11 @@ def parse_query(data, user):
for key in ('keys', 'group', 'file', 'range', 'position', 'positions', 'sort'):
if key in data:
query[key] = data[key]
query['qs'] = models.File.objects.find(data, user).exclude(name='')
query['qs'] = models.Document.objects.find(data, user).exclude(name='')
return query
def findFiles(request):
def findDocuments(request):
'''
takes {
query: {
@ -121,35 +151,43 @@ def findFiles(request):
else:
response['data']['items'] = qs.count()
return render_to_json_response(response)
actions.register(findFiles)
actions.register(findDocuments)
@login_required_json
def removeFile(request):
def removeDocument(request):
'''
takes {
id: string,
or
ids: [string]
}
returns {
}
'''
data = json.loads(request.POST['data'])
response = json_response()
file = models.File.get(data['id'])
if file.editable(request.user):
file.delete()
else:
response = json_response(status=403, file='not allowed')
return render_to_json_response(response)
actions.register(removeFile, cache=False)
if 'ids' in data:
ids = data['ids']
else:
ids = [data['id']]
for id in ids:
file = models.Document.get(id)
if file.editable(request.user):
file.delete()
else:
response = json_response(status=403, file='not allowed')
break
return render_to_json_response(response)
actions.register(removeDocument, cache=False)
def file(request, id):
file = models.File.get(id)
return HttpFileResponse(file.file.path)
document = models.Document.get(id)
return HttpFileResponse(document.file.path)
def thumbnail(request, id):
file = models.File.get(id)
return HttpFileResponse(file.thumbnail())
document = models.Document.get(id)
return HttpFileResponse(document.thumbnail())
class ChunkForm(forms.Form):
chunk = forms.FileField()
@ -159,7 +197,7 @@ class ChunkForm(forms.Form):
@login_required_json
def upload(request):
if 'id' in request.GET:
file = models.File.get(request.GET['id'])
file = models.Document.get(request.GET['id'])
else:
extension = request.POST['filename'].split('.')
name = '.'.join(extension[:-1])
@ -185,7 +223,7 @@ def upload(request):
num = 1
_name = name
while not created:
file, created = models.File.objects.get_or_create(
file, created = models.Document.objects.get_or_create(
user=request.user, name=name, extension=extension)
if not created:
num += 1

View file

@ -128,7 +128,7 @@ INSTALLED_APPS = (
'user',
'urlalias',
'tv',
'file',
'document',
)
# Log errors into db

View file

@ -23,15 +23,15 @@ urlpatterns = patterns('',
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^api/upload/text/?$', 'text.views.upload'),
(r'^api/upload/file/?$', 'file.views.upload'),
(r'^api/upload/document/?$', 'document.views.upload'),
(r'^api/upload/direct/?$', 'archive.views.direct_upload'),
(r'^api/upload/?$', 'archive.views.firefogg_upload'),
(r'^url=(?P<url>.*)$', 'app.views.redirect_url'),
(r'^file/(?P<oshash>.*)$', 'archive.views.lookup_file'),
(r'^api/?$', include(ox.django.api.urls)),
(r'^resetUI$', 'user.views.reset_ui'),
(r'^files/(?P<id>.*?.pdf).jpg$', 'file.views.thumbnail'),
(r'^files/(?P<id>.*?.)$', 'file.views.file'),
(r'^documents/(?P<id>.*?.pdf).jpg$', 'document.views.thumbnail'),
(r'^documents/(?P<id>.*?.)$', 'document.views.file'),
(r'^list/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'itemlist.views.icon'),
(r'^text/(?P<id>.*?)/icon(?P<size>\d*).jpg$', 'text.views.icon'),
(r'^texts/(?P<id>.*?)/text.pdf$', 'text.views.pdf'),