changed ftp stuff

This commit is contained in:
Sanj 2011-02-08 23:47:17 +05:30
parent 46f32e8e4d
commit 4eccf28b83
2 changed files with 8 additions and 6 deletions

View File

@ -4,9 +4,10 @@ from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django import forms from django import forms
from models import Category, File from models import Category, File
from settings import UPLOAD_ROOT from settings import FTP_ROOT, UPLOAD_ROOT
import os import os
from os.path import join, isdir, getmtime, basename from os.path import join, isdir, getmtime, basename
import shutil
''' '''
class folder_names(object): class folder_names(object):
@ -15,9 +16,9 @@ class folder_names(object):
''' '''
def getFolderList(): def getFolderList():
os.chdir(UPLOAD_ROOT) os.chdir(FTP_ROOT)
dirs = filter(isdir, os.listdir(UPLOAD_ROOT)) dirs = filter(isdir, os.listdir(FTP_ROOT))
full_dirs = [join(UPLOAD_ROOT, d) for d in dirs] full_dirs = [join(FTP_ROOT, d) for d in dirs]
full_dirs.sort(key=lambda x: getmtime(x), reverse=True) full_dirs.sort(key=lambda x: getmtime(x), reverse=True)
return map(lambda x: (basename(x), basename(x)), full_dirs) return map(lambda x: (basename(x), basename(x)), full_dirs)
@ -42,7 +43,7 @@ class FolderField(forms.ChoiceField):
class AddFolderForm(forms.Form): class AddFolderForm(forms.Form):
folder_name = FolderField(label="Name of Folder") folder_name = FolderField(label="Name of Folder", choices=getFolderList())
category = forms.ModelChoiceField(Category.objects, required=False, label="Study") category = forms.ModelChoiceField(Category.objects, required=False, label="Study")
category_name = forms.CharField(required=False, label="Create New Study") category_name = forms.CharField(required=False, label="Create New Study")
@ -59,6 +60,7 @@ def add_folder(request):
category.save() category.save()
user = request.user user = request.user
# import pdb;pdb.set_trace() # import pdb;pdb.set_trace()
shutil.move(join(FTP_ROOT, folder_name), join(UPLOAD_ROOT, folder_name))
File.addFiles(category, user, folder_name) File.addFiles(category, user, folder_name)
return render_to_response("files/added_folder.html", { return render_to_response("files/added_folder.html", {
'folder_name': folder_name, 'folder_name': folder_name,

View File

@ -28,7 +28,7 @@ DATABASE_USER = 'root' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3. DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
FTP_ROOT = '/srv/edgware/ftp'
# Local time zone for this installation. Choices can be found here: # Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems. # although not all choices may be available on all operating systems.