uglyish code

This commit is contained in:
sanj 2010-07-23 16:10:21 +05:30
parent d5bc4156e1
commit b7ad384456
3 changed files with 42 additions and 3 deletions

View File

@ -1,7 +1,8 @@
from django.db import models
from tagging.fields import TagField
from oxdjango.fields import DictField
from tagging.models import Tag
from django.contrib.auth.models import User
from django.contrib.auth.models import User, Group, Permission
import os
from convert import convertFile
from django.db.models.signals import post_save
@ -24,6 +25,37 @@ MIME_TYPES = (
('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):
file = models.FileField('File', upload_to='files')
title = models.CharField(max_length=255)
@ -34,6 +66,8 @@ class File(models.Model):
added = models.DateField("Date Added", auto_now_add=True)
categories = models.ManyToManyField('Category', verbose_name='Studies')
type = models.ForeignKey('Type', verbose_name='File Type')
folder = models.ForeignKey("Folder")
info = DictField(blank=True, null=True)
def __unicode__(self):
return self.title
@ -49,6 +83,8 @@ class File(models.Model):
class Category(models.Model):
name = models.CharField(max_length=255)
groups = models.ManyToManyField(Group, null=True)
folder_name = models.CharField(max_length=512)
def __unicode__(self):
return self.name

View File

@ -48,6 +48,7 @@ USE_I18N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
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
# trailing slash if there is a path component (optional in other cases).

View File

@ -1,5 +1,6 @@
import os
import shutil
from add_file import addFile
def isVideo(path):
basename, ext = os.path.splitext(path)
@ -15,7 +16,7 @@ def isAudio(path):
else:
return False
def spider(path, fn):
def spider(path, fn, **kwargs):
# path = self.archives()[archive]
path = os.path.normpath(path)
for dirpath, dirnames, filenames in os.walk(path):
@ -24,7 +25,7 @@ def spider(path, fn):
for filename in filenames:
if not filename.startswith('._') and not filename in ('.DS_Store', ):
# print dirpath + " + " + filename
fn(dirpath, filename)
fn(dirpath, filename, kwargs)
def mvFile(dirpath, filename):
path = os.path.join(dirpath, filename)
@ -62,3 +63,4 @@ def encodeAudio(path):
os.system(cmd)
return True