print product pdf and view article frontend

This commit is contained in:
sanj 2010-03-25 20:31:51 +05:30
parent 4777a090d0
commit 7fc694a2a6
6 changed files with 89 additions and 7 deletions

View File

@ -79,9 +79,32 @@ class Product(models.Model):
abstract = models.TextField(blank=True, null=True)
videos = models.ManyToManyField("Video", blank=True)
audios = models.ManyToManyField("Audio", blank=True)
def __unicode__(self):
return "%s" % (self.title)
def get_print_multiplier(self, dpi):
# product = Product.objects.get(pk=self.product.id)
print_width_mm = self.typ.print_width
dpm = dpi // 25.4
pixel_width = print_width_mm * dpm
m = pixel_width // 800.0
return m
def get_page_list(self):
pages = []
articles = Article.objects.filter(page=self).order_by('order')
for a in articles:
a_pages = Page.objects.filter(article=a).order_by('page_no')
pages.extend(a_pages)
return pages
def get_view_size(self, width=800):
aspect_ratio = self.typ.aspect_ratio
width = width + .0
height = int(width // aspect_ratio)
return (int(width), height,)
class Video(models.Model):
fil = models.ForeignKey(File)
srt = models.ManyToManyField("Srt", blank=True, null=True)
@ -119,7 +142,7 @@ For delete box, prop = 'delete_box'
For image_crop, prop = 'crop',
For image_resize, prop = 'image_resize'
(of course this is ugly).
(of course, this is ugly).
'''
class Revision(models.Model):
@ -158,6 +181,7 @@ class Article(models.Model):
new_revisions_all = Revision.objects.filter(article=self).filter(id__gt=revision_no)
new_revisions_others = new_revisions_all.exclude(uuid=uuid)
for rev in new_revisions_others:
#If there are multiple changes on the same property of the same box, send back only the latest property value.
if new_revisions_all.filter(id__gt=rev.id, prop=rev.prop, box_type=rev.box_type, page=rev.page).count() > 0:
UGLY_HACK = True
else:

View File

@ -22,9 +22,11 @@ urlpatterns = patterns('',
(r'^article/(?P<id>\d+)/$', views.edit_article),
(r'^view_page/(?P<id>\d+)/$', views.view_page),
(r'^view_article/(?P<id>\d+)/$', views.view_article),
(r'^article_frontend/(?P<product_id>\d+)/(?P<article_order>\d+)/$', views.article_frontend),
(r'^issue/(?P<id>\d+)/$', views.edit_issue),
(r'^issue_list/', views.issue_list),
(r'^new_issue/', views.new_issue),
(r'^page_pdf/', views.page_pdf),
(r'^product_pdf/', views.product_pdf),
(r'^poll_changes/', views.poll_changes),
)

View File

@ -4,6 +4,8 @@ from files.models import *
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from oxdjango.decorators import login_required_json
from oxdjango.shortcuts import get_object_or_404_json
try:
import json
except:
@ -14,6 +16,7 @@ from os.path import join
from settings import MEDIA_ROOT
from PIL import Image
import os
from print_pdf import print_url_list
@login_required
def editor(request):
@ -72,7 +75,7 @@ def add_srt(request):
media.save()
return HttpResponse("1")
# @login_required
@login_required
def edit_article(request, id):
c = Category.objects.all()
a = Article.objects.get(pk=id)
@ -477,6 +480,26 @@ def view_article(request, id):
page_height = article.view_size()[1]
return render_to_response("view_article.html", {'pages': d, 'm': m, 'width': addPx(page_width), 'height': addPx(page_height)})
def article_frontend(request, product_id, article_order):
product = Product.objects.get(pk=product_id)
article = Article.objects.filter(product=product, order=article_order)[0]
width = product.get_view_size()[0]
height = product.get_view_size()[1]
pages = article.get_dict()
articles_before = Article.objects.filter(product=product, order__lt=article_order).order_by('order')
articles_after = Article.objects.filter(product=product, order__gt=article_order).order_by('order')
d = {
'pages': pages,
'height': height,
'width': width,
'm': 1,
'article': article,
'articles_before': articles_before,
'articles_after': articles_after
}
return render_to_response("article_frontend.html", {'pages': pages, 'width': width, 'height': height, 'm': 1})
def poll_changes(request):
a_id = request.GET['article_id']
article = Article.objects.get(pk=a_id)
@ -504,6 +527,36 @@ def page_pdf(request):
os.system(cmd)
return HttpResponseRedirect(output_path.replace(MEDIA_ROOT, "/static"))
'''
def article_pdf(request):
article_id = request.GET['a']
page_links = []
article = get_object_or_404_json(Article, pk=article_id)
pages = Page.objects.filter(article=article)
'''
def product_pdf(request):
p_id = request.GET['id']
product = get_object_or_404_json(Product, pk=p_id)
if request.GET.has_key('dpi'):
dpi = request.GET['dpi']
else:
dpi = 150
if request.GET.has_key('width'):
width_mm = request.GET['width']
else:
width_mm = product.typ.print_width
height_mm = int(width_mm // product.typ.aspect_ratio)
pages = product.get_page_list()
m = product.get_print_multiplier(dpi)
url_list = []
for p in pages:
url = "http://edgwareroad.org/edit/view_article/%d/?m=%f&p=%d'" % (p.article.id, m, p.id)
url_list.append(url)
output_path = MEDIA_ROOT + "/pdf/" + self.title + ".pdf"
pdf_path = print_url_list(url_list, width, height, output_path)
return HttpResponseRedirect(pdf_path.replace(MEDIA_ROOT, "/static"))
def article_json(request):
article_id = request.GET['id']
article = Article.objects.get(pk=article_id)

View File

@ -2,7 +2,7 @@
import os
from os.path import join
DEBUG = False
DEBUG = True
TEMPLATE_DEBUG = DEBUG
LOCAL_DEVELOPMENT = True
APPEND_SLASH = True

View File

@ -15,13 +15,13 @@ $(document).ready(function() {
$(this).next().slideUp();
return false;
});
/*
var playerPath = "/static/images/player.swf";
var so = new SWFObject(playerPath, 'mpl', '300', '30', '9');
so.addParam("allowfullscreen", "false");
so.addParam('flashvars', 'file=/static/images/GentlemanMiddleman.mp3');
so.write("audioPlayer");
*/
/*
var so2 = new SWFObject(playerPath, 'mpl2', '300', '30', '9');
so2.addParam("allowfullscreen", "false");

View File

@ -115,7 +115,10 @@ function handleRevision(json) {
}
$(document).ready(function() {
if (window.navigator.userAgent.indexOf("Firefox") == -1) {
alert("Sorry, this currently only works in Firefox.");
window.location.href = "/";
}
if (ARTICLE_ID != 0) {
loadArticle(ARTICLE_ID);
} else {
@ -390,7 +393,7 @@ function reSortBoxes (canvas) {
}
function compareZIndex(a, b) {
return $(b).css('z-index') - $(a).css('z-index');
return parseInt($(b).css('z-index')) - parseInt($(a).css('z-index'));
// console.log('gjugg');
// console.log($(b).css('z-index'));
// console.log('mugg');