back-end work complete for publish page
This commit is contained in:
parent
9f6c7b16a8
commit
51a8c7cd58
|
@ -15,6 +15,7 @@ from tagging.fields import TagField
|
||||||
from tagging.models import Tag
|
from tagging.models import Tag
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from sorl.thumbnail import get_thumbnail
|
from sorl.thumbnail import get_thumbnail
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
def addPx(val):
|
def addPx(val):
|
||||||
'''
|
'''
|
||||||
|
@ -204,6 +205,11 @@ class Article(models.Model):
|
||||||
groups = models.ManyToManyField(Group, blank=True)
|
groups = models.ManyToManyField(Group, blank=True)
|
||||||
theme = models.ForeignKey(ArticleTheme, blank=True, null=True)
|
theme = models.ForeignKey(ArticleTheme, blank=True, null=True)
|
||||||
|
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('product', 'order',)
|
||||||
|
ordering = ['-created']
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Return boolean for whether user can edit article on tool or not - must be passed a valid User object.
|
Return boolean for whether user can edit article on tool or not - must be passed a valid User object.
|
||||||
'''
|
'''
|
||||||
|
@ -241,18 +247,27 @@ class Article(models.Model):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_can_edit_list(kls, user, qset=False):
|
||||||
|
if not qset:
|
||||||
|
qset = kls.objects.all()
|
||||||
|
return qset.filter(Q(owner=user) | Q(users=user))
|
||||||
|
|
||||||
|
# for q in qset:
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_published_list(kls, user, qset=False):
|
def get_published_list(kls, user, qset=False):
|
||||||
if not qset:
|
if not qset:
|
||||||
qset = kls.objects.all()
|
qset = kls.objects.all()
|
||||||
return qset.objects.filter(published=True)
|
return qset.filter(published=True).exclude(Q(owner=user) | Q(users=user))
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fts(kls, search, qset=False):
|
def fts(kls, search, qset=False):
|
||||||
if not qset:
|
if not qset:
|
||||||
qset = kls.objects.all()
|
qset = kls.objects.all()
|
||||||
return qset.objects.filter(name__icontains=search)
|
return qset.filter(name__icontains=search)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -345,8 +360,17 @@ class Article(models.Model):
|
||||||
rList.append(p.get_dict(m))
|
rList.append(p.get_dict(m))
|
||||||
return rList
|
return rList
|
||||||
|
|
||||||
class Meta:
|
def get_list_dict(self, user):
|
||||||
unique_together = ('product', 'order',)
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'title': self.name,
|
||||||
|
'can_edit': self.can_edit(user),
|
||||||
|
'edit_url': "/edit/article/%d/" % (self.id,),
|
||||||
|
'is_locked': self.locked,
|
||||||
|
'is_published': self.published,
|
||||||
|
'web_url': "/edit/web_frontend/%d/" % (self.id,)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PermissionRequest(models.Model):
|
class PermissionRequest(models.Model):
|
||||||
article = models.ForeignKey(Article)
|
article = models.ForeignKey(Article)
|
||||||
|
|
|
@ -4,6 +4,8 @@ import Image
|
||||||
import sys
|
import sys
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
|
from editor.models import Article
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
def home(request):
|
def home(request):
|
||||||
context = RequestContext(request, {})
|
context = RequestContext(request, {})
|
||||||
|
@ -17,8 +19,24 @@ def archive(request):
|
||||||
context = RequestContext(request, {})
|
context = RequestContext(request, {})
|
||||||
return render_to_response("main/archive.html", context)
|
return render_to_response("main/archive.html", context)
|
||||||
|
|
||||||
|
@login_required
|
||||||
def publish(request):
|
def publish(request):
|
||||||
context = RequestContext(request, {})
|
|
||||||
|
user = request.user
|
||||||
|
can_edit_list = Article.get_can_edit_list(user)
|
||||||
|
published_list = Article.get_published_list(user)
|
||||||
|
own_list = []
|
||||||
|
pub_list = []
|
||||||
|
for c in can_edit_list:
|
||||||
|
own_list.append(c.get_list_dict(user))
|
||||||
|
for p in published_list:
|
||||||
|
pub_list.append(p.get_list_dict(user))
|
||||||
|
|
||||||
|
context = RequestContext(request, {
|
||||||
|
'own_list': own_list,
|
||||||
|
'pub_list': pub_list
|
||||||
|
})
|
||||||
|
|
||||||
return render_to_response("main/publish.html", context)
|
return render_to_response("main/publish.html", context)
|
||||||
|
|
||||||
def browse(request):
|
def browse(request):
|
||||||
|
|
|
@ -33,10 +33,24 @@ If you are a participant looking to open a new account, please write to contact@
|
||||||
Tool link
|
Tool link
|
||||||
</p> <br/>
|
</p> <br/>
|
||||||
<p>
|
<p>
|
||||||
Search for an existing article you were working on <br/>
|
Search for an existing article you were working on</p> <br/>
|
||||||
|
<ul id="ownList">
|
||||||
|
{% for o in own_list %}
|
||||||
|
<li>
|
||||||
|
<span class="articleTitle">{{ o.title }}</span>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
Or <br/>
|
Or <br/>
|
||||||
Create a new one
|
Create a new one
|
||||||
</p>
|
<ul id="publishedList">
|
||||||
|
{% for p in pub_list %}
|
||||||
|
<li>
|
||||||
|
<span class="articleTitle">{{ p.title }}</span>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user