Add possibility to put services in different places of the homepage

This commit is contained in:
Frédéric Péters 2010-05-06 20:43:42 +00:00
parent 0bb23ca52e
commit aeda44901c
5 changed files with 276 additions and 19 deletions

View File

@ -173,3 +173,5 @@ class PanelDirectory(Directory):
AdminRootDirectory.register_page('panel', PanelDirectory())
import categories_admin

View File

@ -0,0 +1,183 @@
# w.c.s. - web application for online forms
# Copyright (C) 2005-2010 Entr'ouvert
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
from quixote import redirect
from quixote.directory import Directory
from qommon import misc
from wcs.categories import Category
from qommon.form import *
from qommon.admin.menu import html_top, command_icon, error_page
class CategoryUI:
def __init__(self, category):
self.category = category
if self.category is None:
self.category = Category()
def get_form(self):
form = Form(enctype='multipart/form-data')
form.add(StringWidget, 'name', title = _('Category Name'), required = True, size=30,
value = self.category.name)
form.add(TextWidget, 'description', title = _('Description'), cols = 80, rows = 10,
value = self.category.description)
form.add(SingleSelectWidget, 'position',
title=_('Position on homepage'),
value=self.category.get_position(),
options = [('1st', _('First Column')),
('2nd', _('Second Column')),
('side', _('Sidebar')),
('none', _('None'))])
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
return form
def submit_form(self, form):
if self.category.id:
self.category.name = form.get_widget('name').parse()
category = self.category
else:
category = Category(name = form.get_widget('name').parse())
name = form.get_widget('name').parse()
category_names = [x.name for x in Category.select() if x.id != category.id]
if name in category_names:
form.get_widget('name').set_error(_('This name is already used'))
raise ValueError()
category.description = form.get_widget('description').parse()
category.position = form.get_widget('position').parse()
category.store()
class CategoryPage(Directory):
_q_exports = ['edit', 'delete']
def __init__(self, component):
self.category = Category.get(component)
self.category_ui = CategoryUI(self.category)
get_response().breadcrumb.append((component + '/', self.category.name))
def edit [html] (self):
form = self.category_ui.get_form()
if form.get_widget('cancel').parse():
return redirect('..')
if form.is_submitted() and not form.has_errors():
try:
self.category_ui.submit_form(form)
except ValueError:
pass
else:
return redirect('..')
get_response().breadcrumb.append( ('edit', _('Edit')) )
html_top('categories', title = _('Edit Category'))
'<h2>%s</h2>' % _('Edit Category')
form.render()
def delete [html] (self):
form = Form(enctype='multipart/form-data')
form.widgets.append(HtmlWidget('<p>%s</p>' % _(
'You are about to irrevocably delete this category.')))
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('categories', title = _('Delete Category'))
'<h2>%s %s</h2>' % (_('Deleting Category:'), self.category.name)
form.render()
else:
self.category.remove_self()
return redirect('..')
class CategoriesDirectory(Directory):
_q_exports = ['', 'new', 'update_order']
label = N_('Categories')
def _q_index [html] (self):
get_response().breadcrumb.append( ('categories/', _('Categories')) )
html_top('categories', title = _('Categories'))
get_response().add_javascript(['jquery.js', 'interface.js', 'biglist.js'])
'<div class="explanation">'
'<p>%s</p>' % _('Categories are used to sort the different forms.')
'</div>'
"""<ul id="main-actions">
<li><a class="new-item" href="new">%s</a></li>
</ul>""" % _('New Category')
'<ul class="biglist sortable" id="category-list">'
categories = Category.select()
Category.sort_by_position(categories)
for category in categories:
'<li class="biglistitem" id="itemId_%s">' % category.id
'<strong class="label">%s</strong>' % category.name
'<p class="details">'
'</p>'
'<p class="commands">'
command_icon('%s/edit' % category.id, 'edit')
command_icon('%s/delete' % category.id, 'remove', popup = True)
'</p></li>'
'</ul>'
def update_order(self):
request = get_request()
new_order = request.form['order'].strip(';').split(';')
categories = Category.select()
dict = {}
for l in categories:
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):
get_response().breadcrumb.append( ('categories/', _('Categories')) )
get_response().breadcrumb.append( ('new', _('New')) )
category_ui = CategoryUI(None)
form = category_ui.get_form()
if form.get_widget('cancel').parse():
return redirect('.')
if form.is_submitted() and not form.has_errors():
try:
category_ui.submit_form(form)
except ValueError:
pass
else:
return redirect('.')
html_top('categories', title = _('New Category'))
'<h2>%s</h2>' % _('New Category')
form.render()
def _q_lookup(self, component):
get_response().breadcrumb.append( ('categories/', _('Categories')) )
return CategoryPage(component)
from admin import AdminRootDirectory
AdminRootDirectory.register_page('categories', CategoriesDirectory())

View File

@ -49,6 +49,13 @@ OldRootDirectory = wcs.root.RootDirectory
import qommon.ident.password
import qommon.ident.idp
def category_get_position(self):
if hasattr(self, 'position') and self.position:
return self.position
if self.url_name == 'consultations':
return '2nd'
return '1st'
Category.get_position = category_get_position
class FormsRootDirectory(wcs.forms.root.RootDirectory):
@ -826,9 +833,10 @@ class AlternateRootDirectory(OldRootDirectory):
'<div id="centre">'
self.box_services()
self.box_services(position='1st')
'</div>'
'<div id="droite">'
self.box_services(position='2nd')
self.consultations()
self.announces()
if get_request().user and not get_request().user.anonymous:
@ -840,26 +848,48 @@ class AlternateRootDirectory(OldRootDirectory):
get_response().filter['bigdiv'] = 'rub_service'
self.box_services(level = 2)
def box_services [html] (self, level = 3):
def box_services [html] (self, level=3, position=None):
## Services
'<div id="services">'
if level == 2:
'<h2>%s</h2>' % _('Services')
else:
'<h3>%s</h3>' % _('Services')
if get_request().user and get_request().user.roles:
accepted_roles = get_request().user.roles
else:
accepted_roles = []
self.consultations_category = None
'<ul>'
cats = Category.select(order_by = 'name')
cats = [x for x in cats if x.url_name != 'consultations']
Category.sort_by_position(cats)
all_formdefs = FormDef.select(lambda x: not x.disabled, order_by = 'name')
if position:
t = self.display_list_of_formdefs(
[x for x in cats if x.get_position() == position],
all_formdefs, accepted_roles)
else:
t = self.display_list_of_formdefs(cats, all_formdefs, accepted_roles)
if not t:
return
if position == '2nd':
'<div id="services-2nd">'
else:
'<div id="services">'
if level == 2:
'<h2>%s</h2>' % _('Services')
else:
if position == '1st':
'<h3>%s</h3>' % _('Services')
else:
'<h3></h3>'
'<ul>'
t
'</ul>'
'</div>'
def display_list_of_formdefs [html] (self, cats, all_formdefs, accepted_roles):
for category in cats:
if category.url_name == 'consultations':
self.consultations_category = category
@ -902,23 +932,29 @@ class AlternateRootDirectory(OldRootDirectory):
_('Access to all forms in this category'))
'</ul>'
'</li>\n'
'</ul>'
'</div>'
def consultations [html] (self):
if not self.consultations_category:
cats = [x for x in Category.select() if x.url_name == 'consultations']
if not cats:
return
consultations_category = cats[0]
formdefs = FormDef.select(lambda x: (
x.category_id == consultations_category.id and not x.disabled),
order_by = 'name')
if not formdefs:
return
## Consultations
'<div id="consultations">'
'<h3>%s</h3>' % _('Consultations')
formdefs = FormDef.select(lambda x: (
x.category_id == self.consultations_category.id and not x.disabled),
order_by = 'name')
if consultations_category.description:
'<p>'
consultations_category.description
'</p>'
'<ul>'
for formdef in formdefs:
'<li>'
'<a href="%s/%s/">%s</a>' % (
self.consultations_category.url_name, formdef.url_name, formdef.name)
consultations_category.url_name, formdef.url_name, formdef.name)
'</li>'
'</ul>'
'</div>'
@ -926,6 +962,20 @@ class AlternateRootDirectory(OldRootDirectory):
def box_side [html] (self, path):
'<div id="sidebox">'
self.links()
cats = Category.select(order_by = 'name')
cats = [x for x in cats if x.url_name != 'consultations' and x.get_position() == 'side']
Category.sort_by_position(cats)
if cats:
'<div id="side-services">'
'<h3>%s</h3>' % _('Services')
'<ul>'
for cat in cats:
'<li><a href="%s/">%s</a></li>' % (cat.url_name, cat.name)
'</ul>'
'</div>'
all_formdefs = FormDef.select(lambda x: not x.disabled, order_by = 'name')
if Event.keys(): # if there are events, add a link to the agenda
tags = get_cfg('misc', {}).get('event_tags')
if not tags:

BIN
theme/bg-services-240.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -234,6 +234,7 @@ div#centre {
padding:0 5px 0 0;
}
div#services-2nd h3,
div#services h3 {
background:url(bg-services.gif) left top no-repeat;
width:305px;
@ -241,41 +242,62 @@ div#services h3 {
padding:5px 0 5px 50px;
}
div#services ul li a{
div#services-2nd h3 {
background:url(bg-services-240.gif) left top no-repeat;
width:238px;
text-align: right;
padding:5px 5px 5px 0;
}
div#services-2nd ul li a,
div#services ul li a {
border-bottom:2px dotted #ff9623;
}
div#services ul ul li a{
div#services-2nd ul ul li a,
div#services ul ul li a {
background:url(puce-service.gif) left center no-repeat;
padding-left:10px;
border:none;
}
div#services-2nd ul li a:hover,
div#services ul li a:hover {
border-left: 10px solid #ff9623;
padding-left:10px;
color:#ff9623;
}
div#services-2nd ul ul li a:hover,
div#services ul ul li a:hover {
color:#ff9623;
text-decoration:underline;
border:none;
}
div#services-2nd li,
div#services li {
margin-top: 8px;
}
div#services-2nd li li,
div#services li li {
margin: 0;
font-size:90%
}
div#services-2nd ul ul,
div#services ul ul {
margin:8px 0 0 1em;
}
div#services-2nd li p,
div#services li p {
margin-top: 8px;
text-align: justify;
padding-right: 5px;
}
/* ///////////////////////// COLONNE DROITE : CONSULTATION + ANNONCES */
div#droite {