moved announces and links to 1st class objects; so they no longer appear in
forms related pages (in admin and backoffice)
This commit is contained in:
parent
772d32876d
commit
3be7cfa9c9
|
@ -1,8 +1,8 @@
|
|||
import gettext
|
||||
|
||||
import modules.root
|
||||
import modules.announces
|
||||
import modules.links
|
||||
import modules.links_ui
|
||||
import modules.announces_ui
|
||||
|
||||
import modules.admin
|
||||
|
||||
|
|
|
@ -180,6 +180,4 @@ class PanelDirectory(Directory):
|
|||
'</ul>'
|
||||
|
||||
|
||||
|
||||
|
||||
wcs.admin.root.register_admin_page('panel', PanelDirectory())
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
from quixote import get_request, get_response, get_session, redirect
|
||||
from quixote.directory import Directory
|
||||
|
||||
import wcs
|
||||
from wcs.formdef import FormDef
|
||||
import wcs.admin.root
|
||||
from wcs.admin.menu import *
|
||||
from wcs.form import *
|
||||
|
||||
from wcs.forms.root import FormPage, PublicFormStatusPage
|
||||
from wcs.forms.common import FormStatusPage
|
||||
|
||||
from wcs import errors
|
||||
|
||||
class AnnouncesFormStatusPage(PublicFormStatusPage):
|
||||
def __init__(self, component):
|
||||
html_top('announces', title = 'XX')
|
||||
formdef = FormDef.get_by_urlname('annonce')
|
||||
try:
|
||||
filled = formdef.data_class().get(component)
|
||||
except KeyError:
|
||||
raise errors.TraversalError()
|
||||
|
||||
PublicFormStatusPage.__init__(self, formdef, filled)
|
||||
if not 'delete' in self._q_exports:
|
||||
self._q_exports.append('delete')
|
||||
|
||||
def check_receiver(self):
|
||||
return # FIXME: must not stay like this
|
||||
|
||||
def html_top(self, title = None):
|
||||
return html_top('announces', title)
|
||||
|
||||
def _q_index [html] (self):
|
||||
return self.status()
|
||||
|
||||
def status(self):
|
||||
return FormStatusPage.status(self)
|
||||
|
||||
def submit(self, form, comment_only = False):
|
||||
t = PublicFormStatusPage.submit(self, form, comment_only = comment_only)
|
||||
if t:
|
||||
t = t.replace('/annonce/', '/admin/announces/')
|
||||
return t
|
||||
|
||||
def delete [html] (self):
|
||||
get_response().breadcrumb.append((str(self.filled.id), self.filled.get_field_value('Titre')))
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
|
||||
'You are about to irrevocably delete this link.')))
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
if form.get_widget('cancel').parse():
|
||||
return redirect('..')
|
||||
if not form.is_submitted() or form.has_errors():
|
||||
get_response().breadcrumb.append(('delete', _('Delete')))
|
||||
html_top('announces', title = _('Delete Link'))
|
||||
'<h2>%s %s</h2>' % (_('Deleting Link:'), self.filled.get_field_value('Titre'))
|
||||
form.render()
|
||||
else:
|
||||
self.filled.remove_self()
|
||||
return redirect('..')
|
||||
|
||||
edit = PublicFormStatusPage.wfedit
|
||||
|
||||
|
||||
class AnnouncesFormPage(FormPage):
|
||||
def __init__(self):
|
||||
FormPage.__init__(self, 'annonce')
|
||||
|
||||
def _q_lookup(self, component):
|
||||
filled = self.formdef.data_class().get(component)
|
||||
return AnnouncesFormStatusPage(self.formdef, filled)
|
||||
|
||||
class AnnouncesDirectory(Directory):
|
||||
_q_exports = ['', 'new', 'listing']
|
||||
label = N_('Announces')
|
||||
|
||||
def _q_index [html] (self):
|
||||
html_top('announces', _('Announces'))
|
||||
get_response().breadcrumb.append(('announces', _('Announces')))
|
||||
'<p><a href="new">%s</a></p>' % _('New')
|
||||
try:
|
||||
announces = FormDef.get_by_urlname('annonce').data_class().select()
|
||||
except:
|
||||
announces = []
|
||||
|
||||
'<ul class="biglist">'
|
||||
for l in announces:
|
||||
link_id = l.id
|
||||
'<li>'
|
||||
'<strong class="label">%s</strong>' % l.get_field_value('Titre')
|
||||
'<p class="commands">'
|
||||
command_icon('%s/' % link_id, 'view')
|
||||
command_icon('%s/edit' % link_id, 'edit')
|
||||
command_icon('%s/delete' % link_id, 'remove')
|
||||
'</p></li>'
|
||||
'</ul>'
|
||||
|
||||
def new(self):
|
||||
html_top('announces', title = 'XX')
|
||||
s = AnnouncesFormPage()._q_index()
|
||||
# fixing up breadcrumb
|
||||
for i, data in enumerate(get_response().breadcrumb):
|
||||
if data[0] == 'annonce/':
|
||||
get_response().breadcrumb[i] = ('announces', _('Announces'))
|
||||
break
|
||||
return s
|
||||
|
||||
def _q_lookup(self, component):
|
||||
html_top('announces', title = 'XX')
|
||||
get_response().breadcrumb.append(('announces', _('Announces')))
|
||||
return AnnouncesFormStatusPage(component)
|
||||
|
||||
def listing(self):
|
||||
return redirect('.')
|
||||
|
||||
wcs.admin.root.register_admin_page('announces', AnnouncesDirectory())
|
|
@ -0,0 +1,8 @@
|
|||
from wcs.storage import StorableObject
|
||||
|
||||
class Announce(StorableObject):
|
||||
_names = 'announces'
|
||||
|
||||
title = None
|
||||
text = None
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
from quixote import get_request, get_response, get_session, redirect
|
||||
from quixote.directory import Directory
|
||||
|
||||
import wcs
|
||||
import wcs.admin.root
|
||||
from wcs.admin.menu import *
|
||||
|
||||
from wcs import errors
|
||||
from wcs.form import *
|
||||
|
||||
from announces import Announce
|
||||
|
||||
|
||||
class AnnounceDirectory(Directory):
|
||||
_q_exports = ['', 'edit', 'delete']
|
||||
|
||||
def __init__(self, announce):
|
||||
self.announce = announce
|
||||
|
||||
def _q_index [html] (self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.add_submit('edit', _('Edit'))
|
||||
form.add_submit('delete', _('Delete'))
|
||||
|
||||
if form.get_submit() == 'edit':
|
||||
return redirect('edit')
|
||||
if form.get_submit() == 'delete':
|
||||
return redirect('delete')
|
||||
|
||||
html_top('announces', title = _('Announce: %s') % self.announce.title)
|
||||
'<h2>%s</h2>' % _('Announce: %s') % self.announce.title
|
||||
'<p>'
|
||||
self.announce.text
|
||||
'</p>'
|
||||
|
||||
form.render()
|
||||
|
||||
def edit [html] (self):
|
||||
form = self.form()
|
||||
if form.get_submit() == 'cancel':
|
||||
return redirect('.')
|
||||
|
||||
if form.is_submitted() and not form.has_errors():
|
||||
self.submit(form)
|
||||
return redirect('.')
|
||||
|
||||
html_top('announces', title = _('Edit Announce: %s') % self.announce.title)
|
||||
'<h2>%s</h2>' % _('Edit Announce: %s') % self.announce.title
|
||||
form.render()
|
||||
|
||||
|
||||
def form(self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.add(StringWidget, 'title', title = _('Title'), required = True,
|
||||
value = self.announce.title)
|
||||
form.add(TextWidget, 'text', title = _('Text'), required = True,
|
||||
value = self.announce.text, rows = 10, cols = 70)
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
return form
|
||||
|
||||
def submit(self, form):
|
||||
for k in ('title', 'text'):
|
||||
widget = form.get_widget(k)
|
||||
if widget:
|
||||
setattr(self.announce, k, widget.parse())
|
||||
self.announce.store()
|
||||
|
||||
def delete [html] (self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
|
||||
'You are about to irrevocably delete this announce.')))
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
if form.get_submit() == 'cancel':
|
||||
return redirect('..')
|
||||
if not form.is_submitted() or form.has_errors():
|
||||
get_response().breadcrumb.append(('delete', _('Delete')))
|
||||
html_top('announces', title = _('Delete Announce'))
|
||||
'<h2>%s</h2>' % _('Deleting Announce: %s') % self.announce.title
|
||||
form.render()
|
||||
else:
|
||||
self.announce.remove_self()
|
||||
return redirect('..')
|
||||
|
||||
|
||||
class AnnouncesDirectory(Directory):
|
||||
_q_exports = ['', 'new', 'listing']
|
||||
label = N_('Announces')
|
||||
|
||||
def _q_traverse(self, path):
|
||||
get_response().breadcrumb.append(('announces', _('Announces')))
|
||||
return Directory._q_traverse(self, path)
|
||||
|
||||
|
||||
def _q_index [html] (self):
|
||||
html_top('announces', _('Announces'),
|
||||
scripts = ['/js/prototype.js', '/js/scriptaculous/scriptaculous.js'] )
|
||||
'<p><a href="new">%s</a></p>' % _('New')
|
||||
|
||||
announces = Announce.select()
|
||||
|
||||
'<ul class="biglist" id="announces-list">'
|
||||
for l in announces:
|
||||
announce_id = l.id
|
||||
'<li id="fieldlistitem_%s">' % announce_id
|
||||
'<strong class="label">%s</strong>' % l.title
|
||||
'<p class="commands">'
|
||||
command_icon('%s/' % announce_id, 'view')
|
||||
command_icon('%s/edit' % announce_id, 'edit')
|
||||
command_icon('%s/delete' % announce_id, 'remove')
|
||||
'</p></li>'
|
||||
'</ul>'
|
||||
|
||||
def new [html] (self):
|
||||
announce_ui = AnnounceDirectory(Announce())
|
||||
|
||||
form = announce_ui.form()
|
||||
if form.get_submit() == 'cancel':
|
||||
return redirect('.')
|
||||
|
||||
if form.is_submitted() and not form.has_errors():
|
||||
announce_ui.submit(form)
|
||||
return redirect('%s/' % announce_ui.announce.id)
|
||||
|
||||
get_response().breadcrumb.append(('new', _('New Announce')))
|
||||
html_top('announces', title = _('New Announce'))
|
||||
'<h2>%s</h2>' % _('New Announce')
|
||||
form.render()
|
||||
|
||||
def _q_lookup(self, component):
|
||||
try:
|
||||
announce = Announce.get(component)
|
||||
except KeyError:
|
||||
raise errors.TraversalError()
|
||||
get_response().breadcrumb.append((str(announce.id), announce.title))
|
||||
return AnnounceDirectory(announce)
|
||||
|
||||
def listing(self):
|
||||
return redirect('.')
|
||||
|
||||
wcs.admin.root.register_admin_page('announces', AnnouncesDirectory())
|
|
@ -1,163 +0,0 @@
|
|||
from quixote import get_request, get_response, get_session, redirect
|
||||
from quixote.directory import Directory
|
||||
|
||||
import wcs
|
||||
from wcs.formdef import FormDef
|
||||
import wcs.admin.root
|
||||
from wcs.admin.menu import *
|
||||
from wcs.form import *
|
||||
|
||||
from wcs.forms.root import FormPage, PublicFormStatusPage
|
||||
from wcs.forms.common import FormStatusPage
|
||||
|
||||
from wcs import errors
|
||||
|
||||
class LinksFormStatusPage(PublicFormStatusPage):
|
||||
def __init__(self, component):
|
||||
html_top('links', title = 'XX')
|
||||
formdef = FormDef.get_by_urlname('liens')
|
||||
try:
|
||||
filled = formdef.data_class().get(component)
|
||||
except KeyError:
|
||||
raise errors.TraversalError()
|
||||
|
||||
PublicFormStatusPage.__init__(self, formdef, filled)
|
||||
if not 'delete' in self._q_exports:
|
||||
self._q_exports.append('delete')
|
||||
|
||||
def check_receiver(self):
|
||||
return # FIXME: must not stay like this
|
||||
|
||||
def html_top(self, title = None):
|
||||
return html_top('links', title)
|
||||
|
||||
def _q_index [html] (self):
|
||||
return self.status()
|
||||
|
||||
def status(self):
|
||||
return FormStatusPage.status(self)
|
||||
|
||||
def submit(self, form, comment_only = False):
|
||||
t = PublicFormStatusPage.submit(self, form, comment_only = comment_only)
|
||||
if t:
|
||||
t = t.replace('/liens/', '/admin/links/')
|
||||
return t
|
||||
|
||||
def delete [html] (self):
|
||||
get_response().breadcrumb.append((str(self.filled.id), self.filled.get_field_value('Titre')))
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
|
||||
'You are about to irrevocably delete this link.')))
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
if form.get_widget('cancel').parse():
|
||||
return redirect('..')
|
||||
if not form.is_submitted() or form.has_errors():
|
||||
get_response().breadcrumb.append(('delete', _('Delete')))
|
||||
html_top('links', title = _('Delete Link'))
|
||||
'<h2>%s %s</h2>' % (_('Deleting Link:'), self.filled.get_field_value('Titre'))
|
||||
form.render()
|
||||
else:
|
||||
self.filled.remove_self()
|
||||
return redirect('..')
|
||||
|
||||
edit = PublicFormStatusPage.wfedit
|
||||
|
||||
|
||||
class LinksFormPage(FormPage):
|
||||
def __init__(self):
|
||||
FormPage.__init__(self, 'liens')
|
||||
|
||||
def _q_lookup(self, component):
|
||||
filled = self.formdef.data_class().get(component)
|
||||
return LinksFormStatusPage(self.formdef, filled)
|
||||
|
||||
class LinksDirectory(Directory):
|
||||
_q_exports = ['', 'new', 'listing', 'update_order']
|
||||
label = N_('Links')
|
||||
|
||||
def _q_index [html] (self):
|
||||
html_top('links', _('Links'),
|
||||
scripts = ['/js/prototype.js', '/js/scriptaculous/scriptaculous.js'] )
|
||||
get_response().breadcrumb.append(('links', _('Links')))
|
||||
'<p><a href="new">%s</a></p>' % _('New')
|
||||
try:
|
||||
links = FormDef.get_by_urlname('liens').data_class().select()
|
||||
except:
|
||||
links = []
|
||||
|
||||
for l in links:
|
||||
if not hasattr(l, str('position')):
|
||||
l.position = None
|
||||
|
||||
def cmp_position(x, y):
|
||||
if x.position == y.position:
|
||||
return 0
|
||||
if x.position is None:
|
||||
return 1
|
||||
if y.position is None:
|
||||
return -1
|
||||
return cmp(x.position, y.position)
|
||||
links.sort(cmp_position)
|
||||
|
||||
|
||||
'<ul class="biglist" id="links-list">'
|
||||
for l in links:
|
||||
link_id = l.id
|
||||
'<li id="fieldlistitem_%s">' % link_id
|
||||
'<strong class="label">%s</strong>' % l.get_field_value('Titre')
|
||||
'<p class="details">'
|
||||
l.get_field_value('URL')
|
||||
'</p>'
|
||||
'<p class="commands">'
|
||||
command_icon('%s/' % link_id, 'view')
|
||||
command_icon('%s/edit' % link_id, 'edit')
|
||||
command_icon('%s/delete' % link_id, 'remove')
|
||||
'</p></li>'
|
||||
'</ul>'
|
||||
'''<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
Sortable.create('links-list', {dropOnEmpty:true,constraint:false,
|
||||
containement:["links-list"],
|
||||
onUpdate:function(){
|
||||
new Ajax.Request('update_order', {
|
||||
method:'post',
|
||||
parameters:Sortable.serialize('links-list'),
|
||||
onComplete:function(request){new Effect.Highlight('links-list',{});},
|
||||
evalScripts:true,
|
||||
asynchronous:true})}});\n
|
||||
// ]]>
|
||||
</script>'''
|
||||
|
||||
def update_order(self):
|
||||
request = get_request()
|
||||
new_order = request.form['links-list[]']
|
||||
links = FormDef.get_by_urlname('liens').data_class().select()
|
||||
dict = {}
|
||||
for l in links:
|
||||
dict[str(l.id)] = l
|
||||
for i, o in enumerate(new_order):
|
||||
dict[o].position = i + 1
|
||||
dict[o].store()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def new(self):
|
||||
html_top('links', title = 'XX')
|
||||
s = LinksFormPage()._q_index()
|
||||
# fixing up breadcrumb
|
||||
for i, data in enumerate(get_response().breadcrumb):
|
||||
if data[0] == 'liens/':
|
||||
get_response().breadcrumb[i] = ('links', _('Links'))
|
||||
break
|
||||
return s
|
||||
|
||||
def _q_lookup(self, component):
|
||||
html_top('links', title = 'XX')
|
||||
get_response().breadcrumb.append(('links', _('Links')))
|
||||
return LinksFormStatusPage(component)
|
||||
|
||||
def listing(self):
|
||||
return redirect('.')
|
||||
|
||||
wcs.admin.root.register_admin_page('links', LinksDirectory())
|
|
@ -0,0 +1,21 @@
|
|||
from wcs.storage import StorableObject
|
||||
|
||||
class Link(StorableObject):
|
||||
_names = 'links'
|
||||
|
||||
title = None
|
||||
url = None
|
||||
position = None
|
||||
|
||||
def sort_by_position(cls, links):
|
||||
def cmp_position(x, y):
|
||||
if x.position == y.position:
|
||||
return 0
|
||||
if x.position is None:
|
||||
return 1
|
||||
if y.position is None:
|
||||
return -1
|
||||
return cmp(x.position, y.position)
|
||||
links.sort(cmp_position)
|
||||
sort_by_position = classmethod(sort_by_position)
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
from quixote import get_request, get_response, get_session, redirect
|
||||
from quixote.directory import Directory
|
||||
|
||||
import wcs
|
||||
import wcs.admin.root
|
||||
from wcs.admin.menu import *
|
||||
|
||||
from wcs import errors
|
||||
from wcs.form import *
|
||||
|
||||
from links import Link
|
||||
|
||||
|
||||
class LinkDirectory(Directory):
|
||||
_q_exports = ['', 'edit', 'delete']
|
||||
|
||||
def __init__(self, link):
|
||||
self.link = link
|
||||
|
||||
def _q_index [html] (self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.add_submit('edit', _('Edit'))
|
||||
form.add_submit('delete', _('Delete'))
|
||||
|
||||
if form.get_submit() == 'edit':
|
||||
return redirect('edit')
|
||||
if form.get_submit() == 'delete':
|
||||
return redirect('delete')
|
||||
|
||||
html_top('links', title = _('Link: %s') % self.link.title)
|
||||
'<h2>%s</h2>' % _('Link: %s') % self.link.title
|
||||
'<p>'
|
||||
self.link.url
|
||||
'</p>'
|
||||
|
||||
form.render()
|
||||
|
||||
def edit [html] (self):
|
||||
form = self.form()
|
||||
if form.get_submit() == 'cancel':
|
||||
return redirect('.')
|
||||
|
||||
if form.is_submitted() and not form.has_errors():
|
||||
self.submit(form)
|
||||
return redirect('.')
|
||||
|
||||
html_top('links', title = _('Edit Link: %s') % self.link.title)
|
||||
'<h2>%s</h2>' % _('Edit Link: %s') % self.link.title
|
||||
form.render()
|
||||
|
||||
|
||||
def form(self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.add(StringWidget, 'title', title = _('Title'), required = True,
|
||||
value = self.link.title)
|
||||
form.add(StringWidget, 'url', title = _('URL'), required = True,
|
||||
value = self.link.url)
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
return form
|
||||
|
||||
def submit(self, form):
|
||||
for k in ('title', 'url'):
|
||||
widget = form.get_widget(k)
|
||||
if widget:
|
||||
setattr(self.link, k, widget.parse())
|
||||
self.link.store()
|
||||
|
||||
def delete [html] (self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
|
||||
'You are about to irrevocably delete this link.')))
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
if form.get_submit() == 'cancel':
|
||||
return redirect('..')
|
||||
if not form.is_submitted() or form.has_errors():
|
||||
get_response().breadcrumb.append(('delete', _('Delete')))
|
||||
html_top('links', title = _('Delete Link'))
|
||||
'<h2>%s</h2>' % _('Deleting Link: %s') % self.link.title
|
||||
form.render()
|
||||
else:
|
||||
self.link.remove_self()
|
||||
return redirect('..')
|
||||
|
||||
|
||||
class LinksDirectory(Directory):
|
||||
_q_exports = ['', 'new', 'listing', 'update_order']
|
||||
label = N_('Links')
|
||||
|
||||
def _q_traverse(self, path):
|
||||
get_response().breadcrumb.append(('links', _('Links')))
|
||||
return Directory._q_traverse(self, path)
|
||||
|
||||
|
||||
def _q_index [html] (self):
|
||||
html_top('links', _('Links'),
|
||||
scripts = ['/js/prototype.js', '/js/scriptaculous/scriptaculous.js'] )
|
||||
'<p><a href="new">%s</a></p>' % _('New')
|
||||
|
||||
links = Link.select()
|
||||
Link.sort_by_position(links)
|
||||
|
||||
'<ul class="biglist" id="links-list">'
|
||||
for l in links:
|
||||
link_id = l.id
|
||||
'<li id="fieldlistitem_%s">' % link_id
|
||||
'<strong class="label">%s</strong>' % l.title
|
||||
'<p class="details">'
|
||||
l.url
|
||||
'</p>'
|
||||
'<p class="commands">'
|
||||
command_icon('%s/' % link_id, 'view')
|
||||
command_icon('%s/edit' % link_id, 'edit')
|
||||
command_icon('%s/delete' % link_id, 'remove')
|
||||
'</p></li>'
|
||||
'</ul>'
|
||||
'''<script type="text/javascript">
|
||||
// <![CDATA[
|
||||
Sortable.create('links-list', {dropOnEmpty:true,constraint:false,
|
||||
containement:["links-list"],
|
||||
onUpdate:function(){
|
||||
new Ajax.Request('update_order', {
|
||||
method:'post',
|
||||
parameters:Sortable.serialize('links-list'),
|
||||
onComplete:function(request){new Effect.Highlight('links-list',{});},
|
||||
evalScripts:true,
|
||||
asynchronous:true})}});\n
|
||||
// ]]>
|
||||
</script>'''
|
||||
|
||||
def update_order(self):
|
||||
request = get_request()
|
||||
new_order = request.form['links-list[]']
|
||||
links = Link.select()
|
||||
dict = {}
|
||||
for l in links:
|
||||
dict[str(l.id)] = l
|
||||
for i, o in enumerate(new_order):
|
||||
dict[o].position = i + 1
|
||||
dict[o].store()
|
||||
return 'ok'
|
||||
|
||||
|
||||
def new [html] (self):
|
||||
link_ui = LinkDirectory(Link())
|
||||
|
||||
form = link_ui.form()
|
||||
if form.get_submit() == 'cancel':
|
||||
return redirect('.')
|
||||
|
||||
if form.is_submitted() and not form.has_errors():
|
||||
link_ui.submit(form)
|
||||
return redirect('%s/' % link_ui.link.id)
|
||||
|
||||
get_response().breadcrumb.append(('new', _('New Link')))
|
||||
html_top('links', title = _('New Link'))
|
||||
'<h2>%s</h2>' % _('New Link')
|
||||
form.render()
|
||||
|
||||
def _q_lookup(self, component):
|
||||
try:
|
||||
link = Link.get(component)
|
||||
except KeyError:
|
||||
raise errors.TraversalError()
|
||||
get_response().breadcrumb.append((str(link.id), link.title))
|
||||
return LinkDirectory(link)
|
||||
|
||||
def listing(self):
|
||||
return redirect('.')
|
||||
|
||||
wcs.admin.root.register_admin_page('links', LinksDirectory())
|
|
@ -14,6 +14,9 @@ from wcs.roles import logged_users_role
|
|||
from wcs.categories import Category
|
||||
from wcs.formdef import FormDef
|
||||
|
||||
from links import Link
|
||||
from announces import Announce
|
||||
|
||||
OldRootDirectory = wcs.root.RootDirectory
|
||||
|
||||
class AnnouncesDirectory(Directory):
|
||||
|
@ -98,42 +101,6 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
self.announces()
|
||||
'</div>'
|
||||
|
||||
def index2 [html] (self):
|
||||
template.html_top(default_org = _('Ma ville au quotidien'))
|
||||
|
||||
'<div id="gauche">'
|
||||
self.services2()
|
||||
self.consultations()
|
||||
'</div>'
|
||||
'<div id="droite">'
|
||||
self.links()
|
||||
self.announces()
|
||||
'</div>'
|
||||
|
||||
def services2 [html] (self):
|
||||
## Services
|
||||
self.consultations_category = None
|
||||
for category in Category.select(order_by = 'name'):
|
||||
if category.url_name == 'consultations':
|
||||
self.consultations_category = category
|
||||
continue
|
||||
'<div id="services">'
|
||||
'<h3>%s</h3>' % category.name
|
||||
|
||||
'<ul>'
|
||||
formdefs = FormDef.select(lambda x: (
|
||||
x.category_id == category.id and not x.disabled),
|
||||
order_by = 'name')
|
||||
for formdef in formdefs:
|
||||
'<li>'
|
||||
'<a href="%s/">%s</a>' % (formdef.url_name, formdef.name)
|
||||
'</li>'
|
||||
'</ul>'
|
||||
'</div>'
|
||||
|
||||
|
||||
|
||||
|
||||
def services [html] (self):
|
||||
## Services
|
||||
'<div id="services">'
|
||||
|
@ -206,42 +173,24 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
|
||||
def links [html] (self):
|
||||
## Links
|
||||
try:
|
||||
links = FormDef.get_by_urlname('liens').data_class().select()
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
for l in links:
|
||||
if not hasattr(l, str('position')):
|
||||
l.position = None
|
||||
|
||||
def cmp_position(x, y):
|
||||
if x.position == y.position:
|
||||
return 0
|
||||
if x.position is None:
|
||||
return 1
|
||||
if y.position is None:
|
||||
return -1
|
||||
return cmp(x.position, y.position)
|
||||
links.sort(cmp_position)
|
||||
links = Link.select()
|
||||
Link.sort_by_position(links)
|
||||
|
||||
'<div id="links">'
|
||||
'<h3>%s</h3>' % _('Useful links')
|
||||
'<ul>'
|
||||
for link in links:
|
||||
url = link.get_field_value('URL')
|
||||
name = link.get_field_value('Titre')
|
||||
'<li><a href="%s">%s</a></li>' % (url, name)
|
||||
'<li><a href="%s">%s</a></li>' % (link.url, link.title)
|
||||
'</ul>'
|
||||
'</div>'
|
||||
|
||||
|
||||
def announces [html] (self):
|
||||
## Announces
|
||||
try:
|
||||
announces = FormDef.get_by_urlname('annonce').data_class().select()
|
||||
except KeyError:
|
||||
announces = None
|
||||
announces = Announce.select()
|
||||
announces.sort(lambda x,y: cmp(x.id, y.id))
|
||||
announces.reverse()
|
||||
# XXX: sort by date
|
||||
|
||||
if announces:
|
||||
'<div id="announces">'
|
||||
|
@ -249,10 +198,10 @@ class AlternateRootDirectory(OldRootDirectory):
|
|||
for item in announces:
|
||||
'<div class="announce-item">'
|
||||
'<h4>'
|
||||
item.get_field_value('Titre')
|
||||
item.title
|
||||
'</h4>'
|
||||
'<p>'
|
||||
item.get_field_value('Texte')
|
||||
item.text
|
||||
'</p>'
|
||||
'</div>'
|
||||
|
||||
|
|
Reference in New Issue