mirror of https://github.com/tLDP/LDP
Bugfixes and caching improvements, generating HTML from objects.
This commit is contained in:
parent
debb56e08e
commit
d78ad376d8
|
@ -74,6 +74,9 @@ class PageFactory:
|
|||
template = page.template
|
||||
html = template.template
|
||||
|
||||
dms.block.synch()
|
||||
self.blocks = dms.block.get_all()
|
||||
|
||||
html = self.replace_tokens(page, uri, html)
|
||||
|
||||
end_time = time.time()
|
||||
|
@ -119,18 +122,18 @@ class PageFactory:
|
|||
if state.session:
|
||||
newstring = tables.userdocs(uri, username=state.session.username)
|
||||
else:
|
||||
newstring = '|nopermission|'
|
||||
newstring = self.blocks['blknopermission'].block
|
||||
|
||||
# Page Meta-data
|
||||
elif token=='title':
|
||||
newstring = page.title[uri.lang]
|
||||
elif token=='body':
|
||||
if page.only_registered==1 and state.session==None:
|
||||
newstring = '|blknopermission|'
|
||||
newstring = self.blocks['blknopermission'].block
|
||||
elif page.only_admin==1 and (state.session==None or state.user.admin==0):
|
||||
newstring = '|blknopermission|'
|
||||
newstring = self.blocks['blknopermission'].block
|
||||
elif page.only_sysadmin==1 and (state.session==None or state.user.sysadmin==0):
|
||||
newstring = '|blknopermission|'
|
||||
newstring = self.blocks['blknopermission'].block
|
||||
else:
|
||||
newstring = page.page[uri.lang]
|
||||
elif token=='base':
|
||||
|
@ -186,7 +189,7 @@ class PageFactory:
|
|||
elif token=='type.name':
|
||||
type = dms.type.get_by_id(uri.code)
|
||||
if not type:
|
||||
newstring = '|blknotfound|'
|
||||
newstring = self.blocks['blknotfound'].block
|
||||
else:
|
||||
newstring = type.name[uri.lang]
|
||||
|
||||
|
@ -194,13 +197,13 @@ class PageFactory:
|
|||
elif token=='topic.name':
|
||||
topic = dms.topic.get_by_id(uri.code)
|
||||
if not topic:
|
||||
newstring = '|blknotfound|'
|
||||
newstring = self.blocks['blknotfound'].block
|
||||
else:
|
||||
newstring = topic.name[uri.lang]
|
||||
elif token=='topic.description':
|
||||
topic = dms.topic.get_by_id(uri.code)
|
||||
if not topic:
|
||||
newstring = '|blknotfound|'
|
||||
newstring = self.blocks['blknotfound'].block
|
||||
else:
|
||||
newstring = topic.description[uri.lang]
|
||||
|
||||
|
@ -208,13 +211,13 @@ class PageFactory:
|
|||
elif token=='collection.name':
|
||||
collection = dms.collection.get_by_id(uri.code)
|
||||
if not collection:
|
||||
newstring = '|blknotfound|'
|
||||
newstring = self.blocks['blknotfound'].block
|
||||
else:
|
||||
newstring = collection.name[uri.lang]
|
||||
elif token=='collection.description':
|
||||
collection = dms.collection.get_by_id(uri.code)
|
||||
if not collection:
|
||||
newstring = '|blknotfound|'
|
||||
newstring = self.blocks['blknotfound'].block
|
||||
else:
|
||||
newstring = collection.description[uri.lang]
|
||||
|
||||
|
@ -222,7 +225,7 @@ class PageFactory:
|
|||
elif token=='doc.title':
|
||||
doc = dms.document.get_by_id(uri.id)
|
||||
if doc==None:
|
||||
newstring = '|blknotfound|'
|
||||
newstring = self.blocks['blknotfound'].block
|
||||
else:
|
||||
newstring = doc.title
|
||||
if newstring=='':
|
||||
|
@ -232,7 +235,7 @@ class PageFactory:
|
|||
elif token=='doc.abstract':
|
||||
doc = dms.document.get_by_id(uri.id)
|
||||
if doc==None:
|
||||
newstring = '|blknotfound|'
|
||||
newstring = self.blocks['blknotfound'].block
|
||||
else:
|
||||
newstring = doc.abstract
|
||||
if newstring=='':
|
||||
|
|
|
@ -24,7 +24,7 @@ from Log import log
|
|||
from BaseClasses import *
|
||||
from Widgets import widgets
|
||||
from Sessions import sessions
|
||||
from Lintadas import lintadas
|
||||
#from Lintadas import lintadas
|
||||
from Stats import stats, Stat
|
||||
from OMF import OMF
|
||||
import os
|
||||
|
@ -78,18 +78,20 @@ VIEW_ICON_SM = 'View'
|
|||
VIEW_ICON = 'View'
|
||||
VIEW_ICON_BIG = 'View'
|
||||
|
||||
from persistence.document_html import DocumentView, DocumentEdit
|
||||
|
||||
class Tables(LampadasCollection):
|
||||
|
||||
def bar_graph(self, value, max, lang):
|
||||
return str(value) + '/' + str(max)
|
||||
|
||||
def viewdoc(self, uri):
|
||||
doc = dms.document.get_by_id(uri.id)
|
||||
docview = DocumentView(doc)
|
||||
return docview.get_html(uri)
|
||||
|
||||
# OLD CODE
|
||||
if doc==None:
|
||||
return '|blknotfound|'
|
||||
|
||||
lintadas.check_doc(uri.id)
|
||||
#lintadas.check_doc(uri.id)
|
||||
|
||||
box = WOStringIO('<table class="box" width="100%%">'
|
||||
'<tr><th colspan="6">|strdocdetails|</th></tr>'
|
||||
|
@ -150,6 +152,17 @@ class Tables(LampadasCollection):
|
|||
return box.get_value()
|
||||
|
||||
def editdoc(self, uri):
|
||||
if uri.id > 0:
|
||||
#lintadas.check_doc(uri.id)
|
||||
doc = dms.document.get_by_id(uri.id)
|
||||
else:
|
||||
# Create a new document
|
||||
doc = dms.document.new()
|
||||
docedit = DocumentEdit(doc)
|
||||
return docedit.get_html(uri)
|
||||
|
||||
|
||||
# OLD CODE
|
||||
if (state.session==None or state.user.can_edit(doc_id=uri.id)==0):
|
||||
return '|blknopermission|'
|
||||
|
||||
|
@ -157,7 +170,7 @@ class Tables(LampadasCollection):
|
|||
'<tr><th colspan="6">|strdocdetails|</th></tr>')
|
||||
|
||||
if uri.id > 0:
|
||||
lintadas.check_doc(uri.id)
|
||||
#lintadas.check_doc(uri.id)
|
||||
doc = dms.document.get_by_id(uri.id)
|
||||
delete_widget = widgets.delete() + '|strdelete| '
|
||||
box.write('<form method="GET" action="|uri.base|data/save/document" '
|
||||
|
@ -313,7 +326,7 @@ class Tables(LampadasCollection):
|
|||
% ('|strdocfiles|'))
|
||||
for key in doc.files.sort_by('filename'):
|
||||
docfile = doc.files[key]
|
||||
lintadas.check_file(docfile.filename)
|
||||
#lintadas.check_file(docfile.filename)
|
||||
sourcefile = docfile.sourcefile
|
||||
if sourcefile.errors.count() > 0:
|
||||
css_class = ' error'
|
||||
|
@ -351,7 +364,7 @@ class Tables(LampadasCollection):
|
|||
doc = dms.document.get_by_id(uri.id)
|
||||
for key in doc.files.sort_by('filename'):
|
||||
docfile = doc.files[key]
|
||||
lintadas.check_file(docfile.filename)
|
||||
#lintadas.check_file(docfile.filename)
|
||||
sourcefile = docfile.sourcefile
|
||||
if sourcefile.errors.count() > 0:
|
||||
css_class = ' error'
|
||||
|
@ -1153,13 +1166,94 @@ class Tables(LampadasCollection):
|
|||
if state.user.can_edit(username=username)==0:
|
||||
return '|nopermission|'
|
||||
if username > '':
|
||||
return self.doctable(uri, username=username, show_search=0)
|
||||
user = dms.username.get_by_id(username)
|
||||
else:
|
||||
return self.doctable(uri, username=state.user.username, show_search=0)
|
||||
user = state.user
|
||||
userdocs = user.documents
|
||||
|
||||
return self.doctable2(user.documents)
|
||||
|
||||
def doctable2(self, docs, layout='compact', columns={}):
|
||||
if layout=='compact':
|
||||
colspan = ICON_CELLS_COUNT + len(columns) + 1
|
||||
box = WOStringIO('<table class="box" width="100%%"><tr><th colspan="%s">|strdoctable|</th></tr>\n'
|
||||
'<tr><th class="collabel" colspan="%s" align="center">|strtitle|</th>'
|
||||
% (colspan, ICON_CELLS_COUNT + 1))
|
||||
for column in columns.keys():
|
||||
box.write('<th class="collabel">%s</td>' % column)
|
||||
box.write('</tr>\n')
|
||||
elif layout=='expanded':
|
||||
box = WOStringIO('')
|
||||
|
||||
odd_even = OddEven()
|
||||
for key in docs.sort_by('title'):
|
||||
doc = docs[key]
|
||||
if layout=='compact':
|
||||
box.write('<tr class="%s">\n' % odd_even.get_next())
|
||||
box.write(self.document_icon_cells(doc.id, 'td'))
|
||||
|
||||
# Format the title differently to flag its status
|
||||
display_title = html_encode(widgets.title_compressed(doc.title))
|
||||
|
||||
if doc.pub_time > '':
|
||||
box.write('<td style="width:100%%"><a href="|uri.base|doc/%s/index.html">%s</a></td>\n'
|
||||
% (str(doc.id), display_title))
|
||||
elif doc.errors.count() > 0 or doc.file_error_count > 0:
|
||||
box.write('<td style="width:100%%" class="error">%s</td>\n' % display_title)
|
||||
else:
|
||||
box.write('<td style="width:100%%">%s</td>\n' % display_title)
|
||||
|
||||
# Now any custom columns.
|
||||
for column in columns.keys():
|
||||
box.write('<td>%s</td>\n' % getattr(doc, columns[column]))
|
||||
box.write('</tr>\n')
|
||||
|
||||
# This is a blocky extended listing, complete with abstracts.
|
||||
elif layout=='expanded':
|
||||
|
||||
# Link to the online output.
|
||||
if doc.pub_time > '':
|
||||
block_indexlink = '<td width=32><a href="|uri.base|doc/' + str(doc.id) + '/index.html">' + HTML_ICON + '</a></td>'
|
||||
else:
|
||||
block_indexlink = '<td width=32></td>'
|
||||
|
||||
# Folder icon
|
||||
if doc.pub_time > '':
|
||||
block_dllink = '<td width=32><a href="|uri.base|docdownloads/' + str(doc.id) + '/">' + FOLDER_ICON + '</a></td>'
|
||||
else:
|
||||
block_dllink = ('<td width=32></td>')
|
||||
|
||||
# Edit icon
|
||||
block_editlink = '<td width=32><a href="|uri.base|document_main/' + str(doc.id) + '|uri.lang_ext|">' + EDIT_ICON + '</a></td>'
|
||||
|
||||
# Format the title based on the presence of errors.
|
||||
if doc.errors.count() > 0 or doc.file_error_count > 0:
|
||||
block_title = '<th colspan="4" class="error">' + html_encode(widgets.title_compressed(doc.title)) + '</th>'
|
||||
else:
|
||||
block_title = '<th colspan="4">' + html_encode(widgets.title_compressed(doc.title)) + '</th>'
|
||||
|
||||
# Finally, pull in the abstract.
|
||||
block_abstract = '<td>' + html_encode(doc.abstract) + '</td>'
|
||||
|
||||
box.write('<table class="box nontabular" width="100%%">\n'
|
||||
' <tr>%s</tr>\n'
|
||||
' <tr>%s\n'
|
||||
' %s\n'
|
||||
' %s\n'
|
||||
' %s\n'
|
||||
' </tr>'
|
||||
'</table>\n'
|
||||
% (block_title, block_indexlink, block_dllink, block_editlink, block_abstract))
|
||||
|
||||
if layout=='compact':
|
||||
box.write('</table>\n')
|
||||
|
||||
return box.get_value()
|
||||
|
||||
def section_menus(self, uri):
|
||||
log(3, "Creating all section menus")
|
||||
box = WOStringIO('')
|
||||
dms.section.synch()
|
||||
sections = dms.section.get_all()
|
||||
menu_separator = ''
|
||||
for key in sections.sort_by('sort_order'):
|
||||
|
|
|
@ -38,6 +38,9 @@ class Widgets:
|
|||
standard formats for some text items.
|
||||
"""
|
||||
|
||||
def bar_graph(self, value, max, lang):
|
||||
return str(value) + '/' + str(max)
|
||||
|
||||
def format_code(self, value, lang, view=0):
|
||||
if view==1:
|
||||
format = dms.format.get_by_id(value)
|
||||
|
|
|
@ -288,7 +288,6 @@ class DataManager(DataTable):
|
|||
if self.cache.filled==0:
|
||||
self.all_cached = 1
|
||||
return set
|
||||
self.synch()
|
||||
return self.get_cached()
|
||||
|
||||
def synch(self):
|
||||
|
|
|
@ -15,6 +15,7 @@ class Collection(DataManager):
|
|||
super(Collection, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.collection_i18n.synch()
|
||||
i18ns = self.dms.collection_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -16,9 +16,9 @@ class Document(DataManager):
|
|||
'version': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': ''},
|
||||
'last_update': {'key_field': NO, 'data_type': 'date', 'nullable': YES, 'i18n': NO, 'foreign_key': ''},
|
||||
'isbn': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': ''},
|
||||
'pub_status_code': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': 'pub_status.pub_status_code'},
|
||||
'review_status_code': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': 'review_status.review_status_code'},
|
||||
'tech_review_status_code': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': 'review_status.review_status_code'},
|
||||
'pub_status_code': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': 'pub_status.pub_status_code', 'default': 'P'},
|
||||
'review_status_code': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': 'review_status.review_status_code', 'default': 'U'},
|
||||
'tech_review_status_code': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': 'review_status.review_status_code', 'default': 'U'},
|
||||
'maintained': {'key_field': NO, 'data_type': 'bool', 'nullable': NO, 'i18n': NO, 'foreign_key': ''},
|
||||
'maintainer_wanted': {'key_field': NO, 'data_type': 'bool', 'nullable': NO, 'i18n': NO, 'foreign_key': ''},
|
||||
'license_code': {'key_field': NO, 'data_type': 'string', 'nullable': YES, 'i18n': NO, 'foreign_key': ''},
|
||||
|
|
|
@ -14,6 +14,7 @@ class DTD(DataManager):
|
|||
super(DTD, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.dtd_i18n.synch()
|
||||
i18ns = self.dms.dtd_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -15,6 +15,7 @@ class Error(DataManager):
|
|||
super(Error, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.error_i18n.synch()
|
||||
i18ns = self.dms.error_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -14,6 +14,7 @@ class ErrorType(DataManager):
|
|||
super(ErrorType, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.error_type_i18n.synch()
|
||||
i18ns = self.dms.error_type_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -16,6 +16,7 @@ class FileReport(DataManager):
|
|||
super(FileReport, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.file_report_i18n.synch()
|
||||
i18ns = self.dms.file_report_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -14,6 +14,7 @@ class Format(DataManager):
|
|||
super(Format, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.format_i18n.synch()
|
||||
i18ns = self.dms.format_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -16,6 +16,7 @@ class Language(DataManager):
|
|||
super(Language, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.language_i18n.synch()
|
||||
i18ns = self.dms.language_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -19,6 +19,7 @@ class License(DataManager):
|
|||
super(License, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.license_i18n.synch()
|
||||
i18ns = self.dms.license_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -15,6 +15,7 @@ class News(DataManager):
|
|||
super(News, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.news_i18n.synch()
|
||||
i18ns = self.dms.news_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -22,6 +22,7 @@ class Page(DataManager):
|
|||
super(Page, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.page_i18n.synch()
|
||||
i18ns = self.dms.page_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -15,6 +15,7 @@ class PubStatus(DataManager):
|
|||
super(PubStatus, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.pub_status_i18n.synch()
|
||||
i18ns = self.dms.pub_status_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -15,6 +15,7 @@ class ReviewStatus(DataManager):
|
|||
super(ReviewStatus, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.review_status_i18n.synch()
|
||||
i18ns = self.dms.review_status_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -14,6 +14,7 @@ class Role(DataManager):
|
|||
super(Role, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.role_i18n.synch()
|
||||
i18ns = self.dms.role_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -16,6 +16,7 @@ class Section(DataManager):
|
|||
super(Section, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.section_i18n.synch()
|
||||
i18ns = self.dms.section_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -16,6 +16,7 @@ class Topic(DataManager):
|
|||
super(Topic, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.topic_i18n.synch()
|
||||
i18ns = self.dms.topic_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -15,6 +15,7 @@ class Type(DataManager):
|
|||
super(Type, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.type_i18n.synch()
|
||||
i18ns = self.dms.type_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -14,6 +14,7 @@ class WebString(DataManager):
|
|||
super(WebString, self).synch()
|
||||
|
||||
# Synchronize with i18n cache.
|
||||
self.dms.string_i18n.synch()
|
||||
i18ns = self.dms.string_i18n.get_by_keys([['updated', '>=', last_synched]])
|
||||
for key in i18ns.keys():
|
||||
i18n = i18ns[key]
|
||||
|
|
|
@ -28,6 +28,18 @@ class Document(Persistence):
|
|||
return self.dms.language.get_by_id(self.lang)
|
||||
elif attribute=='license':
|
||||
return self.dms.license.get_by_id(self.license_code)
|
||||
elif attribute=='type':
|
||||
return self.dms.type.get_by_id(self.type_code)
|
||||
elif attribute=='format':
|
||||
return self.dms.format.get_by_id(self.format_code)
|
||||
elif attribute=='dtd':
|
||||
return self.dms.dtd.get_by_id(self.dtd_code)
|
||||
elif attribute=='pub_status':
|
||||
return self.dms.pub_status.get_by_id(self.pub_status_code)
|
||||
elif attribute=='review_status':
|
||||
return self.dms.review_status.get_by_id(self.review_status_code)
|
||||
elif attribute=='tech_review_status':
|
||||
return self.dms.review_status.get_by_id(self.tech_review_status_code)
|
||||
elif attribute=='top_file':
|
||||
top_file = self.dms.document_file.get_by_keys([['doc_id', '=', self.id], ['top', '=', 1]])
|
||||
if top_file.count()==1:
|
||||
|
@ -67,3 +79,4 @@ class Document(Persistence):
|
|||
if self.pub_date=='': self.pub_date = topfile.pub_date
|
||||
if self.isbn=='': self.isbn = topfile.isbn
|
||||
if self.encoding=='': self.encoding = topfile.encoding
|
||||
|
||||
|
|
|
@ -6,8 +6,14 @@ class DocumentUser(Persistence):
|
|||
|
||||
def __getattr__(self, attribute):
|
||||
if attribute=='document':
|
||||
return self.dms.document.get_by_id(self.doc_id)
|
||||
self.document = self.dms.document.get_by_id(self.doc_id)
|
||||
return self.document
|
||||
elif attribute=='user':
|
||||
return self.dms.username.get_by_id(self.username)
|
||||
self.user = self.dms.username.get_by_id(self.username)
|
||||
return self.user
|
||||
elif hasattr(self.document, attribute):
|
||||
return getattr(self.document, attribute)
|
||||
elif hasattr(self.user, attribute):
|
||||
return getattr(self.user, attribute)
|
||||
else:
|
||||
raise AttributeError('No such attribute %s' % attribute)
|
||||
|
|
Loading…
Reference in New Issue