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

@ -1,26 +1,27 @@
{% load alter_size %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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/jquery.tooltip.css" />
<link href="/static/css/articleDemo.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.style1 {font-size: 16px}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<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">
.style1 {font-size: 16px}
body, html {
font-size: {{ "14px"|make_really_big:m }};
margin: 0px;
padding: 0px;
padding: 0px;
}
p {
padding: 0px;
margin: 0px;
}
}
.canvas {
position: relative;
@ -30,23 +31,23 @@ p {
.box {
position: absolute;
}
.page {
clear:left;
font-family: Helvetica, sans-serif;
font-size: 14px;
width: {{width}}px;
height: {{height}}px;
}
.page {
clear:left;
font-family: Helvetica, sans-serif;
font-size: 14px;
width: {{width}}px;
height: {{height}}px;
/*
border-left:1px #CC6600 dotted;
border-bottom: #CC6600 1px dotted;
border-left:1px #CC6600 dotted;
border-bottom: #CC6600 1px dotted;
*/
margin-left: 25px;
margin-top: 10px;
margin-left: 25px;
margin-top: 10px;
margin-bottom: 20px;
padding: 0px;
position: relative;
/* background-color: #FFFFFF; */
padding: 0px;
position: relative;
/* background-color: #FFFFFF; */
}
{% for p in pages %}
@ -78,101 +79,101 @@ p {
{% endfor %}
</style>
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/jquery.colorbox.js"></script>
<script type="text/javascript" src="/static/js/jquery.srt.js"></script>
<script type="text/javascript" src="/static/js/jquery.tooltip.js"></script>
<!-- <script type="text/javascript" src="/static/js/swfobject.js"></script> -->
<script type="text/javascript" src="/static/js/articleMockup.js"></script>
</head>
<body>
<div class="hiddenDivs">
<div id="videoWrap">
<video id="padmaVideo" data-base="/static/mockup/video/" src="" controls>Sorry, you currently need Firefox 3.5 to view this.</video>
<div id="srtWrap">
<div class="srtContainer">
<div class="srtTitle">Transcript:</div>
<div class="srt Transcript" data-srt="" data-video="padmaVideo">
</div>
<div class="toggleButton icon" title="Switch to Description">-></div>
</div>
<div class="srtContainer" style="display: none;">
<div class="srtTitle">Description:</div>
<div class="srt Description" data-video="padmaVideo" data-srt="">
</div>
<div class="toggleButton icon" title="Switch to Transcript">&lt;-</div>
</div>
</div>
</div>
</div>
<div class="hiddenDivs">
<div id="audioWrap">
<audio id="padmaAudio" data-base="/static/mockup/audio/" src="" controls>Sorry, you currently need Firefox 3.5 to view this.</audio>
<div id="srtWrap2">
<div class="audioSrt">
<div class="srtTitle"><span style="font-family:Verdana, Arial, Helvetica, sans-serif">Transcript:</span></div>
<div class="srt Transcript" data-srt="" data-video="padmaAudio">
</div>
<!-- <div class="toggleButton icon" title="Switch to Description">-></div> -->
</div>
<!--
<div class="srtContainer" style="display: none;">
<div class="srtTitle">Description:</div>
<div class="srt Description" data-video="padmaAudio" data-srt="">
</div>
<div class="toggleButton icon" title="Switch to Transcript">&lt;-</div>
</div>
-->
</div>
</div>
</div>
<div class="big" id="1">
<div id="lefttitle"><img src="/static/images/titlecard1.png" width="332" height="108" />
</div>
<div id="navcontaineren" class="english">
<ul id="navlisten">
<li id="active"><a href="http://edgwareroad.org/mockup/home" id="current">home</a></li>
<li><a href=""> contact </a></li>
<li><a href="">about</a> </li>
<li><a href="" target="_blank"> events</a>
</ul>
</div>
<div id="navcontainerar" class="arabic">
<ul id="navlistar">
<li id="active"><a href="http://edgwareroad.org/mockup/home" id="current">بيت</a></li>
<li><a href=""> احتكاك</a></li>
<li><a href="">حوالي</a> </li>
<li><a href="" target="_blank">أحداث</a>
</ul>
</div>
<div id="righttitle" class="english">Edgware Road, Vol 1, January 2010</div>
<div id="righttitle1" class="arabic">ادجوار رود ، المجلد 1 يناير 2010</div>
<div id="languageBtn"><span class="arabicBtn">االقائمة العربية</span> <span class="englishBtn">English Menu</span></div>
</div>
<script type="text/javascript" src="/static/js/jquery.js"></script>
<script type="text/javascript" src="/static/js/jquery.colorbox.js"></script>
<script type="text/javascript" src="/static/js/jquery.srt.js"></script>
<script type="text/javascript" src="/static/js/jquery.tooltip.js"></script>
<!-- <script type="text/javascript" src="/static/js/swfobject.js"></script> -->
<script type="text/javascript" src="/static/js/articleMockup.js"></script>
</head>
<body>
<div class="hiddenDivs">
<div id="videoWrap">
<video id="padmaVideo" data-base="/static/mockup/video/" src="" controls>Sorry, you currently need Firefox 3.5 to view this.</video>
<div id="srtWrap">
<div class="srtContainer">
<div class="srtTitle">Transcript:</div>
<div class="srt Transcript" data-srt="" data-video="padmaVideo">
</div>
<div class="toggleButton icon" title="Switch to Description">-></div>
</div>
<div class="srtContainer" style="display: none;">
<div class="srtTitle">Description:</div>
<div class="srt Description" data-video="padmaVideo" data-srt="">
</div>
<div class="toggleButton icon" title="Switch to Transcript">&lt;-</div>
</div>
</div>
</div>
</div>
<div class="hiddenDivs">
<div id="audioWrap">
<audio id="padmaAudio" data-base="/static/mockup/audio/" src="" controls>Sorry, you currently need Firefox 3.5 to view this.</audio>
<div id="srtWrap2">
<div class="audioSrt">
<div class="srtTitle"><span style="font-family:Verdana, Arial, Helvetica, sans-serif">Transcript:</span></div>
<div class="srt Transcript" data-srt="" data-video="padmaAudio">
</div>
<!-- <div class="toggleButton icon" title="Switch to Description">-></div> -->
</div>
<!--
<div class="srtContainer" style="display: none;">
<div class="srtTitle">Description:</div>
<div class="srt Description" data-video="padmaAudio" data-srt="">
</div>
<div class="toggleButton icon" title="Switch to Transcript">&lt;-</div>
</div>
-->
</div>
</div>
</div>
<div class="big" id="1">
<div id="lefttitle"><img src="/static/images/titlecard1.png" width="332" height="108" />
</div>
<div id="navcontaineren" class="english">
<ul id="navlisten">
<li id="active"><a href="http://edgwareroad.org/mockup/home" id="current">home</a></li>
<li><a href=""> contact </a></li>
<li><a href="">about</a> </li>
<li><a href="" target="_blank"> events</a>
</ul>
</div>
<div id="navcontainerar" class="arabic">
<ul id="navlistar">
<li id="active"><a href="http://edgwareroad.org/mockup/home" id="current">بيت</a></li>
<li><a href=""> احتكاك</a></li>
<li><a href="">حوالي</a> </li>
<li><a href="" target="_blank">أحداث</a>
</ul>
</div>
<div id="righttitle" class="english">Edgware Road, Vol 1, January 2010</div>
<div id="righttitle1" class="arabic">ادجوار رود ، المجلد 1 يناير 2010</div>
<div id="languageBtn"><span class="arabicBtn">االقائمة العربية</span> <span class="englishBtn">English Menu</span></div>
</div>
{% autoescape off %}
{% for p in pages %}
<div class="page" id="page{{p.id}}">
{% for p in pages %}
<div class="page" id="page{{p.id}}">
{% for t in p.textBoxes %}
<div id="textbox{{p.id}}{{t.id}}" class="box textBox">
{{t.html|parse_html:m}}
@ -182,41 +183,41 @@ p {
<div id="imagebox{{p.id}}{{i.id}}" class="box imageBox">
<img src="{{i.resource.resized}}" />
</div>
{% endfor %}
</div>
{% endfor %}
{% endautoescape %}
<p>&nbsp;</p>
<div id="contents">
<div class="english">
{% endfor %}
</div>
{% endfor %}
{% endautoescape %}
<p>&nbsp;</p>
<div id="contents">
<div class="english">
<p>Contents:<br />
{% for a_b in articles_before %}
{% for a_b in articles_before %}
<a href="../../{{a_b.product.id}}/{{a_b.order}}/">{{a_b.order}}</a>. {{a_b.title}}<br />
{% endfor %}
{{article.order}}. {{article.title}}
</div>
<div class="arabic">
<p>متلامس:<br />
<br />
</div>
<div id="scrollDots">
</div>
<div class="english">
<p>
{% for a_a in articles_after %}
{{article.order}}. {{article.title}}
</div>
<div class="arabic">
<p>متلامس:<br />
<br />
</div>
<div id="scrollDots">
</div>
<div class="english">
<p>
{% for a_a in articles_after %}
<a href="../../{{a_a.product.id}}/{{a_a.order}}/">{{a_a.order}}</a>. {{a_a.title}}<br />
{% endfor %}
</p>
</div>
<div class="arabic">
</div>
</p>
</div>
</body>
</html>
{% endfor %}
</p>
</div>
<div class="arabic">
</div>
</p>
</div>
</body>
</html>

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>