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):
page = Page.objects.get(pk=r['page_id'])
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()
return rev.id
@ -576,8 +581,11 @@ class ImageBox(models.Model):
self.height = height
self.save()
tpl = (self.crop_x1, self.crop_y1, self.crop_x2, self.crop_y2,)
original_cropped = Image.open(MEDIA_ROOT + "/" + self.original_print()).crop(tpl)
original_cropped.save(self.cropped_path())
image_full_path = join(MEDIA_ROOT, self.original_print())
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
def cropped_fname(self):

View File

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

View File

@ -8,7 +8,7 @@ from os.path import join
from convert import convertFile
from django.db.models.signals import post_save
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.
def baseFileName(filename):
@ -30,6 +30,13 @@ MIME_TYPES = (
('hid', 'Hidden'),
)
TYPE_CHOICES = (
('image', 'Image'),
('audio', 'Audio'),
('text', 'Text'),
('video', 'Video'),
)
class Folder(models.Model):
name = models.CharField(max_length=1024)
relative_path = models.CharField(max_length=2048)
@ -71,7 +78,8 @@ class File(models.Model):
file_date = models.DateField("Date", blank=True, null=True)
added = models.DateField("Date Added", auto_now_add=True)
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)
oshash = models.CharField(max_length=128, blank=True, db_index=True)
# folder = models.ForeignKey("Folder")
@ -88,13 +96,14 @@ class File(models.Model):
filename = os.path.basename(path)
title = kwargs.get("title", filename)
description = kwargs.get("description", "")
ext = os.path.splitext(filename)[1][1:]
django_file_path = UPLOAD_ROOT.replace(MEDIA_ROOT, "")[1:]
f = cls(file=django_file_path, full_path=path, title=title, description=description, ext=ext, oshash=oshash, info=info)
ext = os.path.splitext(filename)[1][1:].lower()
typ = getFileType(path, ext)
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.save()
f.categories.append(category)
f.save_m2m()
f.categories.add(category)
f.save()
return f
@classmethod

View File

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

View File

@ -262,7 +262,7 @@ Canvas.prototype.init = function() {
c = edgeArticle[$(this).attr('data-index')];
if ($(ui.draggable).attr('class') == 'resource ui-draggable') {
r = edgeBin.allResources[$(ui.draggable).attr("data-index")];
if (r.mime == 'jpg') {
if (r.mime == 'image') {
top = $(this).position().top;
left = $(this).position().left;
height = parseInt(r.height) / 2;
@ -273,7 +273,7 @@ Canvas.prototype.init = function() {
// 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)}});
}
else if (r.mime == 'mp3') {
else if (r.mime == 'audio') {
media_box = $(this).children('.audio_video');
$.getJSON('/edit/add_media/', {
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');
$.getJSON('/edit/add_media/', {
@ -798,7 +798,7 @@ var Bin = function() {
this.allResources = [];
};
Bin.prototype.loadCategory = function(catid) {
Bin.prototype.loadCategory = function(catid, type) {
var that = this;
this.jq.find('.resource').remove();
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) {
var that = this;
this.jq.find('.resource').remove();
this.resources = [];
}
*/
Bin.prototype.searchString = function(str) {
var that = this;
@ -948,7 +950,7 @@ var MyResource = function(json, index) {
this.file = json.file;
this.description = json.description;
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.added = json.added;
this.addToBin();
@ -1016,10 +1018,10 @@ Resource.prototype.addEventHandlers = function() {
var that = this;
this.jq.tooltip();
var mim2tmpl = {
'jpg': "tmpl_resource_image",
'ogv': "tmpl_resource_av",
'mp3': "tmpl_resource_av",
'txt': "tmpl_resource_doc"
'image': "tmpl_resource_image",
'video': "tmpl_resource_av",
'audio': "tmpl_resource_av",
'text': "tmpl_resource_doc"
}
this.jq.hover(function() {
var tmpl_id = mim2tmpl[that.mime];
@ -1615,7 +1617,7 @@ $(function() {
$('.upload_srts').live("click", function(e) {
var r = $(this).getResource();
var media_id = r.media_id;
var type = r.mime == 'ogv' ? 'video' : 'audio';
var type = r.mime == 'video' ? 'video' : 'audio';
if (media_id == 0) {
alert("sorry, there was some problem with converting this audio / video, ID: " + r.id);
} else {

View File

@ -5,6 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<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/fonts.css" />
<link rel="stylesheet" type="text/css" href="/static/css/jquery.tooltip.css" />
<link href="/static/css/articleDemo.css" rel="stylesheet" type="text/css" />
<style type="text/css">

View File

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