tested basics, updating server

This commit is contained in:
sanj 2010-07-28 02:34:24 +05:30
parent 9c90da92b4
commit 49bccbc5e6
8 changed files with 218 additions and 197 deletions

View File

@ -160,7 +160,12 @@ class Revision(models.Model):
def saveRevision(r): def saveRevision(r):
page = Page.objects.get(pk=r['page_id']) page = Page.objects.get(pk=r['page_id'])
article = page.article article = page.article
rev = Revision(article=article, page=page, user=r.user, box_type=r['box_type'], box_id=r['box_id'], prop=r['prop'], old_val=r['old_val'], new_val=r['new_val'], uuid=r['uuid']) #FIXME: all calls to saveRevision should always send user, so this should not be required.
if r.has_key('user'):
user = r['user']
else:
user = User.objects.get(pk=1)
rev = Revision(article=article, page=page, user=user, box_type=r['box_type'], box_id=r['box_id'], prop=r['prop'], old_val=r['old_val'], new_val=r['new_val'], uuid=r['uuid'])
rev.save() rev.save()
return rev.id return rev.id
@ -576,8 +581,11 @@ class ImageBox(models.Model):
self.height = height self.height = height
self.save() self.save()
tpl = (self.crop_x1, self.crop_y1, self.crop_x2, self.crop_y2,) tpl = (self.crop_x1, self.crop_y1, self.crop_x2, self.crop_y2,)
original_cropped = Image.open(MEDIA_ROOT + "/" + self.original_print()).crop(tpl) image_full_path = join(MEDIA_ROOT, self.original_print())
original_cropped.save(self.cropped_path()) print
original_cropped = Image.open(image_full_path).crop(tpl)
save_path = join(MEDIA_ROOT, self.cropped_path(), self.cropped_fname())
original_cropped.save(save_path)
return self return self
def cropped_fname(self): def cropped_fname(self):

View File

@ -44,14 +44,15 @@ def add_media(request):
file_id = request.GET['resource_id'] file_id = request.GET['resource_id']
page = Page.objects.get(pk=page_id) page = Page.objects.get(pk=page_id)
fil = File.objects.get(pk=file_id) fil = File.objects.get(pk=file_id)
typ = Type.objects.get(pk=fil.type_id) typ = fil.type
if typ.mime == 'ogv': # typ = Type.objects.get(pk=fil.type_id)
if typ == 'video':
try: try:
video = Video.objects.get(fil__id=file_id) video = Video.objects.get(fil__id=file_id)
page.videos.append(video) page.videos.append(video)
except: except:
pass pass
elif typ.mime == 'mp3': elif typ == 'audio':
try: try:
audio = Audio.objects.get(fil__id=file_id) audio = Audio.objects.get(fil__id=file_id)
page.audios.append(audio) page.audios.append(audio)
@ -68,9 +69,9 @@ def add_srt(request):
mime = request.POST['mime'] mime = request.POST['mime']
srt_file = request.FILES['srt'] srt_file = request.FILES['srt']
## REMEMBER TO SAVE SRT FILE!!!## ## REMEMBER TO SAVE SRT FILE!!!##
if mime == 'ogv': if mime == 'video':
media = Video.objects.get(fil_id=file_id) media = Video.objects.get(fil_id=file_id)
elif mime == 'mp3': elif mime == 'audio':
media = Audio.objects.get(fil_id=file_id) media = Audio.objects.get(fil_id=file_id)
media.srt.append(srt) media.srt.append(srt)
media.save() media.save()
@ -378,7 +379,7 @@ def category_json(request):
# these should not be here # these should not be here
width = 0 width = 0
height = 0 height = 0
if r.type.mime == 'jpg': if r.type == 'image':
filePath = r.original_print() filePath = r.original_print()
try: try:
fil = Image.open(join(MEDIA_ROOT, filePath)) fil = Image.open(join(MEDIA_ROOT, filePath))
@ -399,13 +400,13 @@ def category_json(request):
filePath = r.file.url filePath = r.file.url
iconPath = "/static/images/binimages/%s.jpg" % (r.type.mime) iconPath = "/static/images/binimages/%s.jpg" % (r.type.mime)
resizedPath = filePath resizedPath = filePath
if r.type.mime == 'ogv': if r.type == 'video':
try: try:
v = Video.objects.filter(fil=r)[0] v = Video.objects.filter(fil=r)[0]
media_id = v.id media_id = v.id
except: except:
media_id = 0 media_id = 0
elif r.type.mime == 'mp3': elif r.type == 'audio':
try: try:
a = Audio.objects.filter(fil=r)[0] a = Audio.objects.filter(fil=r)[0]
media_id = a.id media_id = a.id
@ -417,7 +418,7 @@ def category_json(request):
d = { d = {
'id': r.id, 'id': r.id,
'type': r.type.name, 'type': r.type,
'title': r.title, 'title': r.title,
'file': filePath, 'file': filePath,
'description': r.description, 'description': r.description,
@ -427,7 +428,7 @@ def category_json(request):
'height': int(height), 'height': int(height),
'resized': resizedPath, 'resized': resizedPath,
'added': str(r.added), 'added': str(r.added),
'mime': r.type.mime, 'mime': r.type,
'media_id': media_id 'media_id': media_id
} }
rList.append(d) rList.append(d)

View File

@ -48,15 +48,15 @@ def ignoreFile(f):
#This function is called from the post_save signal, receives kwargs['instance'] as a File instance #This function is called from the post_save signal, receives kwargs['instance'] as a File instance
def convertFile(**kwargs): def convertFile(**kwargs):
fn = { fn = {
'jpg': ignoreFile, 'image': ignoreFile,
'mp3': toOgg, 'audio': toOgg,
'txt': ignoreFile, 'text': ignoreFile,
'ogv': toOgv, 'video': toOgv,
'oth': ignoreFile, 'other': ignoreFile,
'hid': ignoreFile # 'other': ignoreFile
} }
f = kwargs['instance'] f = kwargs['instance']
fn[f.type.mime](f) fn[f.type](f)
return return

View File

@ -8,7 +8,7 @@ from os.path import join
from convert import convertFile from convert import convertFile
from django.db.models.signals import post_save from django.db.models.signals import post_save
from settings import UPLOAD_ROOT, MEDIA_ROOT from settings import UPLOAD_ROOT, MEDIA_ROOT
from utils.add_file import hashFile, fileInfo from utils.add_file import hashFile, fileInfo, getFileType
#FIXME: The following two functions are ridiculous. please remove and clean up all references to them. #FIXME: The following two functions are ridiculous. please remove and clean up all references to them.
def baseFileName(filename): def baseFileName(filename):
@ -30,6 +30,13 @@ MIME_TYPES = (
('hid', 'Hidden'), ('hid', 'Hidden'),
) )
TYPE_CHOICES = (
('image', 'Image'),
('audio', 'Audio'),
('text', 'Text'),
('video', 'Video'),
)
class Folder(models.Model): class Folder(models.Model):
name = models.CharField(max_length=1024) name = models.CharField(max_length=1024)
relative_path = models.CharField(max_length=2048) relative_path = models.CharField(max_length=2048)
@ -71,7 +78,8 @@ class File(models.Model):
file_date = models.DateField("Date", blank=True, null=True) file_date = models.DateField("Date", blank=True, null=True)
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')
type = models.CharField(max_length=255, choices=TYPE_CHOICES)
ext = models.CharField(max_length=100, blank=True) ext = models.CharField(max_length=100, blank=True)
oshash = models.CharField(max_length=128, blank=True, db_index=True) oshash = models.CharField(max_length=128, blank=True, db_index=True)
# folder = models.ForeignKey("Folder") # folder = models.ForeignKey("Folder")
@ -88,13 +96,14 @@ class File(models.Model):
filename = os.path.basename(path) filename = os.path.basename(path)
title = kwargs.get("title", filename) title = kwargs.get("title", filename)
description = kwargs.get("description", "") description = kwargs.get("description", "")
ext = os.path.splitext(filename)[1][1:] ext = os.path.splitext(filename)[1][1:].lower()
django_file_path = UPLOAD_ROOT.replace(MEDIA_ROOT, "")[1:] typ = getFileType(path, ext)
f = cls(file=django_file_path, full_path=path, title=title, description=description, ext=ext, oshash=oshash, info=info) django_file_path = join(path.replace(MEDIA_ROOT, "")[1:])
f = cls(file=django_file_path, full_path=path, title=title, description=description, ext=ext, type=typ, oshash=oshash, info=info)
f.userID = user f.userID = user
f.save() f.save()
f.categories.append(category) f.categories.add(category)
f.save_m2m() f.save()
return f return f
@classmethod @classmethod

View File

@ -232,9 +232,9 @@ p {
} }
.binSelect { .binSelect {
width: 208px; width: 45%;
font-size: 12px; font-size: 12px;
margin-left: 7px; margin-left: 2px;
} }
#addElements { #addElements {

View File

@ -262,7 +262,7 @@ Canvas.prototype.init = function() {
c = edgeArticle[$(this).attr('data-index')]; c = edgeArticle[$(this).attr('data-index')];
if ($(ui.draggable).attr('class') == 'resource ui-draggable') { if ($(ui.draggable).attr('class') == 'resource ui-draggable') {
r = edgeBin.allResources[$(ui.draggable).attr("data-index")]; r = edgeBin.allResources[$(ui.draggable).attr("data-index")];
if (r.mime == 'jpg') { if (r.mime == 'image') {
top = $(this).position().top; top = $(this).position().top;
left = $(this).position().left; left = $(this).position().left;
height = parseInt(r.height) / 2; height = parseInt(r.height) / 2;
@ -273,7 +273,7 @@ Canvas.prototype.init = function() {
// console.log('index: ' + new_index); // console.log('index: ' + new_index);
i = new ImageBox(c, r, {css: {'z-index': "" + new_index, 'top':toPx((ev.pageY - top) - height), 'left': toPx((ev.pageX - left) - width)}}); i = new ImageBox(c, r, {css: {'z-index': "" + new_index, 'top':toPx((ev.pageY - top) - height), 'left': toPx((ev.pageX - left) - width)}});
} }
else if (r.mime == 'mp3') { else if (r.mime == 'audio') {
media_box = $(this).children('.audio_video'); media_box = $(this).children('.audio_video');
$.getJSON('/edit/add_media/', { $.getJSON('/edit/add_media/', {
resource_id: r.id, resource_id: r.id,
@ -283,7 +283,7 @@ Canvas.prototype.init = function() {
}); });
} }
else if (r.mime == 'ogv') { else if (r.mime == 'video') {
media_box = $(this).children('.audio_video'); media_box = $(this).children('.audio_video');
$.getJSON('/edit/add_media/', { $.getJSON('/edit/add_media/', {
@ -798,7 +798,7 @@ var Bin = function() {
this.allResources = []; this.allResources = [];
}; };
Bin.prototype.loadCategory = function(catid) { Bin.prototype.loadCategory = function(catid, type) {
var that = this; var that = this;
this.jq.find('.resource').remove(); this.jq.find('.resource').remove();
this.resources = []; this.resources = [];
@ -815,13 +815,15 @@ Bin.prototype.loadCategory = function(catid) {
}); });
}; };
/*
This function is a very good idea. You would send a json object with parameters to the back-end to filter results by, allowing search to get a lot better.
Bin.prototype.loadResources = function(url, params) { Bin.prototype.loadResources = function(url, params) {
var that = this; var that = this;
this.jq.find('.resource').remove(); this.jq.find('.resource').remove();
this.resources = []; this.resources = [];
} }
*/
Bin.prototype.searchString = function(str) { Bin.prototype.searchString = function(str) {
var that = this; var that = this;
@ -948,7 +950,7 @@ var MyResource = function(json, index) {
this.file = json.file; this.file = json.file;
this.description = json.description; this.description = json.description;
this.tags = json.tags; this.tags = json.tags;
this.mime = json.mime; this.mime = json.mime; //inaccurately called 'mime' - this is either image, text, audio or video, as a string.
this.icon = json.icon; this.icon = json.icon;
this.added = json.added; this.added = json.added;
this.addToBin(); this.addToBin();
@ -1016,10 +1018,10 @@ Resource.prototype.addEventHandlers = function() {
var that = this; var that = this;
this.jq.tooltip(); this.jq.tooltip();
var mim2tmpl = { var mim2tmpl = {
'jpg': "tmpl_resource_image", 'image': "tmpl_resource_image",
'ogv': "tmpl_resource_av", 'video': "tmpl_resource_av",
'mp3': "tmpl_resource_av", 'audio': "tmpl_resource_av",
'txt': "tmpl_resource_doc" 'text': "tmpl_resource_doc"
} }
this.jq.hover(function() { this.jq.hover(function() {
var tmpl_id = mim2tmpl[that.mime]; var tmpl_id = mim2tmpl[that.mime];
@ -1615,7 +1617,7 @@ $(function() {
$('.upload_srts').live("click", function(e) { $('.upload_srts').live("click", function(e) {
var r = $(this).getResource(); var r = $(this).getResource();
var media_id = r.media_id; var media_id = r.media_id;
var type = r.mime == 'ogv' ? 'video' : 'audio'; var type = r.mime == 'video' ? 'video' : 'audio';
if (media_id == 0) { if (media_id == 0) {
alert("sorry, there was some problem with converting this audio / video, ID: " + r.id); alert("sorry, there was some problem with converting this audio / video, ID: " + r.id);
} else { } else {

View File

@ -5,6 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Edgwareroad.org {{article.title}}</title> <title>Edgwareroad.org {{article.title}}</title>
<link rel="stylesheet" type="text/css" href="/static/css/colorbox.css" /> <link rel="stylesheet" type="text/css" href="/static/css/colorbox.css" />
<link rel="stylesheet" type="text/css" href="/static/css/fonts.css" />
<link rel="stylesheet" type="text/css" href="/static/css/jquery.tooltip.css" /> <link rel="stylesheet" type="text/css" href="/static/css/jquery.tooltip.css" />
<link href="/static/css/articleDemo.css" rel="stylesheet" type="text/css" /> <link href="/static/css/articleDemo.css" rel="stylesheet" type="text/css" />
<style type="text/css"> <style type="text/css">

View File

@ -59,7 +59,7 @@
}); });
</script> </script>
<title> <title>
Edgware Editor - {{ user.username }} Edgware Editor - Hi {{ user.username }}
</title> </title>
</head> </head>
<body> <body>
@ -206,13 +206,13 @@
</div> </div>
<div id="addElements"> <div id="addElements">
<select id="searchSelect" class="binSelect" name="searchSelect"> <select id="searchSelect" class="binSelect" name="searchSelect">
<option value="0">Choose a Study</option> <option value="0">Study</option>
{% for c in categories %} {% for c in categories %}
<option value="{{c.id}}">{{c.name}}</option> <option value="{{c.id}}">{{c.name}}</option>
{% endfor %} {% endfor %}
</select><br /> </select>
<select id="typeSelect" class="binSelect" name="typeSelect"> <select id="typeSelect" class="binSelect" name="typeSelect">
<option value="0">Chose a Type</option> <option value="0">Type</option>
<option value="images">Images</option> <option value="images">Images</option>
<option value="audio">Audio</option> <option value="audio">Audio</option>
<option value="video">Video</option> <option value="video">Video</option>