add folder form
This commit is contained in:
parent
d41107dd5a
commit
07264983c6
|
@ -9,7 +9,7 @@ from os.path import join
|
|||
from PIL import Image
|
||||
from django.template import Template, Context
|
||||
from django.template.loader import get_template
|
||||
from settings import MEDIA_ROOT
|
||||
from settings import MEDIA_ROOT, PROJECT_PATH
|
||||
from django.contrib.auth.models import User, Group
|
||||
from tagging.fields import TagField
|
||||
from tagging.models import Tag
|
||||
|
@ -383,7 +383,7 @@ class Page(models.Model):
|
|||
'id': v.id,
|
||||
'title': v.fil.title,
|
||||
'description': v.fil.description,
|
||||
'file': v.fil.file.url,
|
||||
'file': v.fil.file.url.replace(PROJECT_PATH, ""),
|
||||
'mime': 'video'
|
||||
}
|
||||
videos.append(r)
|
||||
|
@ -394,7 +394,7 @@ class Page(models.Model):
|
|||
'id': a.id,
|
||||
'title': a.fil.title,
|
||||
'description': a.fil.description,
|
||||
'file': a.fil.file.url,
|
||||
'file': a.fil.file.url.replace(PROJECT_PATH, ""),
|
||||
'mime': 'audio'
|
||||
}
|
||||
audios.append(r)
|
||||
|
|
|
@ -13,7 +13,7 @@ except:
|
|||
from django.template import Template, Context
|
||||
from django.template.loader import get_template
|
||||
from os.path import join
|
||||
from settings import MEDIA_ROOT, SITE_BASE, UPLOAD_ROOT
|
||||
from settings import MEDIA_ROOT, SITE_BASE, UPLOAD_ROOT, PROJECT_PATH
|
||||
from PIL import Image
|
||||
import os
|
||||
from print_pdf import print_url_list
|
||||
|
@ -413,7 +413,7 @@ def category_json(request):
|
|||
iconPath = "/static/images/binimages/jpg.jpg"
|
||||
resizedPath = filePath
|
||||
else:
|
||||
filePath = r.file.url
|
||||
filePath = r.file.url.replace(PROJECT_PATH, "") #FIXME: Why does file.url return system path and not relative URL??
|
||||
iconPath = "/static/images/binimages/%s.jpg" % (r.type)
|
||||
resizedPath = filePath
|
||||
if r.type == 'video':
|
||||
|
|
|
@ -1,6 +1,75 @@
|
|||
# Create your views here.
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django import forms
|
||||
from models import Category, File
|
||||
from settings import UPLOAD_ROOT
|
||||
import os
|
||||
from os.path import join, isdir, getmtime, basename
|
||||
|
||||
'''
|
||||
class folder_names(object):
|
||||
def __iter__(self):
|
||||
return iter(map(lambda x: (x,x), os.listdir(UPLOAD_ROOT)))
|
||||
'''
|
||||
|
||||
def getFolderList():
|
||||
os.chdir(UPLOAD_ROOT)
|
||||
dirs = filter(isdir, os.listdir(UPLOAD_ROOT))
|
||||
full_dirs = [join(UPLOAD_ROOT, d) for d in dirs]
|
||||
full_dirs.sort(key=lambda x: getmtime(x), reverse=True)
|
||||
return map(lambda x: (basename(x), basename(x)), full_dirs)
|
||||
|
||||
class FolderSelect(forms.widgets.Select):
|
||||
def _get_choices(self):
|
||||
return getFolderList()
|
||||
# return map(lambda x: (x,x), os.listdir(UPLOAD_ROOT))
|
||||
|
||||
def _set_choices(self, value):
|
||||
self._choices = value
|
||||
|
||||
choices = property(_get_choices, _set_choices)
|
||||
|
||||
|
||||
|
||||
class FolderField(forms.ChoiceField):
|
||||
widget = FolderSelect
|
||||
|
||||
def _get_choices(self):
|
||||
return getFolderList()
|
||||
# return map(lambda x: (x,x), os.listdir(UPLOAD_ROOT))
|
||||
|
||||
|
||||
class AddFolderForm(forms.Form):
|
||||
folder_name = FolderField(label="Name of Folder")
|
||||
category = forms.ModelChoiceField(Category.objects, required=False, label="Study")
|
||||
category_name = forms.CharField(required=False, label="Create New Study")
|
||||
|
||||
@login_required
|
||||
def add_folder(request):
|
||||
if request.POST:
|
||||
form = AddFolderForm(request.POST)
|
||||
if form.is_valid():
|
||||
folder_name = form.cleaned_data['folder_name']
|
||||
category = form.cleaned_data['category']
|
||||
if not category:
|
||||
category_name = form.cleaned_data['category_name']
|
||||
category = Category(name=category_name)
|
||||
category.save()
|
||||
user = request.user
|
||||
# import pdb;pdb.set_trace()
|
||||
File.addFiles(category, user, folder_name)
|
||||
return render_to_response("files/added_folder.html", {
|
||||
'folder_name': folder_name,
|
||||
'category_name': category.name,
|
||||
'username': user.username
|
||||
})
|
||||
else:
|
||||
return render_to_response("files/add_folder.html", {'form': form})
|
||||
else:
|
||||
form = AddFolderForm()
|
||||
return render_to_response("files/add_folder.html", {'form': form})
|
||||
|
||||
def editor(request):
|
||||
return render_to_response("editor.html")
|
||||
|
|
|
@ -17,6 +17,7 @@ urlpatterns = patterns('',
|
|||
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
|
||||
(r'^comments/', include('django.contrib.comments.urls')),
|
||||
(r'^edit/', include('editor.urls')),
|
||||
(r'files/', include('files.urls')),
|
||||
(r'^gallery/', 'files.views.gallery'),
|
||||
# Uncomment the next line to enable the admin:
|
||||
(r'^admin/', include(admin.site.urls)),
|
||||
|
|
Loading…
Reference in New Issue
Block a user