uglyish code
This commit is contained in:
parent
d5bc4156e1
commit
b7ad384456
|
@ -1,7 +1,8 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from tagging.fields import TagField
|
from tagging.fields import TagField
|
||||||
|
from oxdjango.fields import DictField
|
||||||
from tagging.models import Tag
|
from tagging.models import Tag
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User, Group, Permission
|
||||||
import os
|
import os
|
||||||
from convert import convertFile
|
from convert import convertFile
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
|
@ -24,6 +25,37 @@ MIME_TYPES = (
|
||||||
('hid', 'Hidden'),
|
('hid', 'Hidden'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class Folder(models.Model):
|
||||||
|
name = models.CharField(max_length=1024)
|
||||||
|
relative_path = models.CharField(max_length=2048)
|
||||||
|
parent = models.ForeignKey("Folder")
|
||||||
|
category = models.ForeignKey("Category")
|
||||||
|
|
||||||
|
def get_full_path(self):
|
||||||
|
return join(UPLOAD_ROOT, category.folder_name, parent.
|
||||||
|
|
||||||
|
def get_children(self):
|
||||||
|
return Folder.objects.filter(parent=self)
|
||||||
|
|
||||||
|
def has_parent(self):
|
||||||
|
if self.name == self.category.folder_name:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_files(self):
|
||||||
|
return File.objects.filter(folder=self)
|
||||||
|
|
||||||
|
def get_dict(self):
|
||||||
|
return {
|
||||||
|
'files': self.get_files(),
|
||||||
|
'folders': self.get_children(),
|
||||||
|
'parent': self.parent,
|
||||||
|
'name': self.name,
|
||||||
|
'fullPath': self.fullPath
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class File(models.Model):
|
class File(models.Model):
|
||||||
file = models.FileField('File', upload_to='files')
|
file = models.FileField('File', upload_to='files')
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
|
@ -34,6 +66,8 @@ class File(models.Model):
|
||||||
added = models.DateField("Date Added", auto_now_add=True)
|
added = models.DateField("Date Added", auto_now_add=True)
|
||||||
categories = models.ManyToManyField('Category', verbose_name='Studies')
|
categories = models.ManyToManyField('Category', verbose_name='Studies')
|
||||||
type = models.ForeignKey('Type', verbose_name='File Type')
|
type = models.ForeignKey('Type', verbose_name='File Type')
|
||||||
|
folder = models.ForeignKey("Folder")
|
||||||
|
info = DictField(blank=True, null=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
@ -49,6 +83,8 @@ class File(models.Model):
|
||||||
|
|
||||||
class Category(models.Model):
|
class Category(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
|
groups = models.ManyToManyField(Group, null=True)
|
||||||
|
folder_name = models.CharField(max_length=512)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
|
@ -48,6 +48,7 @@ USE_I18N = True
|
||||||
# Absolute path to the directory that holds media.
|
# Absolute path to the directory that holds media.
|
||||||
# Example: "/home/media/media.lawrence.com/"
|
# Example: "/home/media/media.lawrence.com/"
|
||||||
MEDIA_ROOT = join(PROJECT_PATH, 'static')
|
MEDIA_ROOT = join(PROJECT_PATH, 'static')
|
||||||
|
UPLOAD_ROOT = join(MEDIA_ROOT, 'media', 'studies')
|
||||||
|
|
||||||
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
|
||||||
# trailing slash if there is a path component (optional in other cases).
|
# trailing slash if there is a path component (optional in other cases).
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
from add_file import addFile
|
||||||
|
|
||||||
def isVideo(path):
|
def isVideo(path):
|
||||||
basename, ext = os.path.splitext(path)
|
basename, ext = os.path.splitext(path)
|
||||||
|
@ -15,7 +16,7 @@ def isAudio(path):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def spider(path, fn):
|
def spider(path, fn, **kwargs):
|
||||||
# path = self.archives()[archive]
|
# path = self.archives()[archive]
|
||||||
path = os.path.normpath(path)
|
path = os.path.normpath(path)
|
||||||
for dirpath, dirnames, filenames in os.walk(path):
|
for dirpath, dirnames, filenames in os.walk(path):
|
||||||
|
@ -24,7 +25,7 @@ def spider(path, fn):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if not filename.startswith('._') and not filename in ('.DS_Store', ):
|
if not filename.startswith('._') and not filename in ('.DS_Store', ):
|
||||||
# print dirpath + " + " + filename
|
# print dirpath + " + " + filename
|
||||||
fn(dirpath, filename)
|
fn(dirpath, filename, kwargs)
|
||||||
|
|
||||||
def mvFile(dirpath, filename):
|
def mvFile(dirpath, filename):
|
||||||
path = os.path.join(dirpath, filename)
|
path = os.path.join(dirpath, filename)
|
||||||
|
@ -62,3 +63,4 @@ def encodeAudio(path):
|
||||||
os.system(cmd)
|
os.system(cmd)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user