stable with db changes (sqlDiff140111.sql)

This commit is contained in:
sanj 2011-01-15 20:32:59 +05:30
parent 0e6ca63a4a
commit d41107dd5a
4 changed files with 87 additions and 17 deletions

View File

@ -1,5 +1,5 @@
from django.db import models from django.db import models
from files.models import File from files.models import File, Category
from fields import HexColorField from fields import HexColorField
from django.contrib.comments.signals import comment_was_posted from django.contrib.comments.signals import comment_was_posted
import simplejson import simplejson
@ -10,7 +10,7 @@ from PIL import Image
from django.template import Template, Context from django.template import Template, Context
from django.template.loader import get_template from django.template.loader import get_template
from settings import MEDIA_ROOT from settings import MEDIA_ROOT
from django.contrib.auth.models import User from django.contrib.auth.models import User, Group
from tagging.fields import TagField from tagging.fields import TagField
from tagging.models import Tag from tagging.models import Tag
@ -170,15 +170,47 @@ def saveRevision(r):
return rev.id return rev.id
class Article(models.Model): class Article(models.Model):
"""
Each page references an article. A single page cannot reference more than one article. The article is what people comment on (and potentially what audio & video are attached to).
"""
name = models.CharField(max_length=255)
product = models.ForeignKey("Product")
order = models.IntegerField()
''' '''
Each page references an article. A single page cannot reference more than one article. The article is what people comment on (and potentially what audio & video are attached to).
'''
name = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
product = models.ForeignKey("Product", blank=True, null=True)
typ = models.ForeignKey("ProductType")
order = models.IntegerField() #Not needed, do not use
study = models.ForeignKey(Category, blank=True, null=True)
tags = TagField(blank=True, null=True)
owner = models.ForeignKey(User, null=True, related_name='article_owner')
created = models.DateTimeField(auto_now_add=True, null=True)
locked = models.BooleanField(default=False)
published = models.BooleanField(default=False)
users = models.ManyToManyField(User, related_name='article_user', blank=True)
groups = models.ManyToManyField(Group, blank=True)
'''
Return boolean for whether user can access article or not - must be passed a valid User object.
'''
def can_edit(self, user):
if user.is_anonymous():
return False
if user.is_superuser:
return True
if self.owner == user:
return True
if self.locked:
return False
for u in self.users.iterator():
if u == User:
return True
for g in self.groups.iterator():
for u in g.users.iterator():
if u == User:
return True
return False
'''
Return all changes since revision_no.
''' '''
def changes(self, revision_no, uuid): def changes(self, revision_no, uuid):
if int(revision_no) == self.current_revision(): if int(revision_no) == self.current_revision():
@ -217,8 +249,8 @@ class Article(models.Model):
return (self.editor_width, height,) return (self.editor_width, height,)
def view_size(self): def view_size(self):
product = Product.objects.get(pk=self.product.id) # product = Product.objects.get(pk=self.product.id)
aspect_ratio = product.typ.aspect_ratio aspect_ratio = self.typ.aspect_ratio
width = 800 width = 800
height = int(800.0 // aspect_ratio) height = int(800.0 // aspect_ratio)
return (width, height,) return (width, height,)
@ -229,8 +261,8 @@ class Article(models.Model):
return (self.print_width, height, multiplier,) return (self.print_width, height, multiplier,)
def get_print_multiplier(self, dpi): def get_print_multiplier(self, dpi):
product = Product.objects.get(pk=self.product.id) # product = Product.objects.get(pk=self.product.id)
print_width_mm = product.typ.print_width print_width_mm = self.typ.print_width
dpm = dpi / 25.4 dpm = dpi / 25.4
pixel_width = print_width_mm * dpm pixel_width = print_width_mm * dpm
m = pixel_width / 800.0 m = pixel_width / 800.0
@ -257,6 +289,41 @@ class Article(models.Model):
class Meta: class Meta:
unique_together = ('product', 'order',) unique_together = ('product', 'order',)
class PermissionRequest(models.Model):
article = models.ForeignKey(Article)
from_user = models.ForeignKey(User, related_name='permission_from')
message = models.TextField(blank=True, null=True)
# to_user = models.ForeignKey(User, related_name='permission_to')
accepted = models.BooleanField(default=None)
def accept(self):
self.accepted = True
self.article.users.add(self.from_user)
return True
def decline(self):
self.accepted = False
return True
@classmethod
def new(cls, article, from_user):
pr = cls(article=article, from_user=from_user)
pr.save()
return pr
@classmethod
def get_pending(cls, article):
ret = []
pending_qset = cls.objects.filter(accepted=None)
for p in pending_qset:
ret.append({
'user': p.from_user.username,
'message': p.message
})
return ret
class Page(models.Model): class Page(models.Model):
# Question: Does Page need some custom CSS definitions like bg_color, borders, etc. ? # Question: Does Page need some custom CSS definitions like bg_color, borders, etc. ?
page_no = models.IntegerField() page_no = models.IntegerField()

View File

@ -3,6 +3,7 @@ import views
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^editor/$', views.editor), (r'^editor/$', views.editor),
(r'^upload/$', views.upload),
(r'^new_page/', views.new_page), (r'^new_page/', views.new_page),
(r'^article/json/', views.article_json), (r'^article/json/', views.article_json),
(r'^textbox/new/', views.textbox_new), (r'^textbox/new/', views.textbox_new),

View File

@ -25,6 +25,8 @@ def editor(request):
c = Category.objects.all() c = Category.objects.all()
return render_to_response("editor.html", {'categories': c, 'user': user}) return render_to_response("editor.html", {'categories': c, 'user': user})
def upload(request):
return render_to_response("upload.html")
''' '''
def edit_page(request, id): def edit_page(request, id):
page = Page.objects.get(pk=id) page = Page.objects.get(pk=id)
@ -593,8 +595,8 @@ def article_pdf(request):
a_id = request.GET['id'] a_id = request.GET['id']
article = get_object_or_404_json(Article, pk=a_id) article = get_object_or_404_json(Article, pk=a_id)
dpi = request.GET.get('dpi', 300) dpi = request.GET.get('dpi', 300)
width_mm = request.GET.get('width', article.product.typ.print_width) width_mm = request.GET.get('width', article.typ.print_width)
height_mm = int(width_mm // article.product.typ.aspect_ratio) height_mm = int(width_mm // article.typ.aspect_ratio)
pages = Page.objects.filter(article=article) pages = Page.objects.filter(article=article)
m = article.get_print_multiplier(dpi) m = article.get_print_multiplier(dpi)
url = SITE_BASE + "/edit/view_article/%d/?m=%f" % (article.id, m) url = SITE_BASE + "/edit/view_article/%d/?m=%f" % (article.id, m)

View File

@ -103,7 +103,7 @@ class File(models.Model):
f.userID = user f.userID = user
f.save() f.save()
f.categories.add(category) f.categories.add(category)
f.save() # f.save()
return f return f
@classmethod @classmethod