1 |
|
# w.c.s. - web application for online forms
|
2 |
|
# Copyright (C) 2005-2010 Entr'ouvert
|
3 |
|
#
|
4 |
|
# This program is free software; you can redistribute it and/or modify
|
5 |
|
# it under the terms of the GNU General Public License as published by
|
6 |
|
# the Free Software Foundation; either version 2 of the License, or
|
7 |
|
# (at your option) any later version.
|
8 |
|
#
|
9 |
|
# This program is distributed in the hope that it will be useful,
|
10 |
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
# GNU General Public License for more details.
|
13 |
|
#
|
14 |
|
# You should have received a copy of the GNU General Public License
|
15 |
|
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
16 |
|
|
17 |
|
from quixote import redirect
|
18 |
|
from quixote.directory import Directory
|
19 |
|
from quixote.html import TemplateIO, htmltext
|
20 |
|
|
21 |
|
from wcs.qommon import _, N_
|
22 |
|
from wcs.qommon import misc
|
23 |
|
from wcs.categories import Category
|
24 |
|
from wcs.qommon.form import *
|
25 |
|
from wcs.qommon.backoffice.menu import html_top
|
26 |
|
from wcs.qommon.admin.menu import command_icon, error_page
|
27 |
|
import wcs.admin.categories
|
28 |
|
|
29 |
|
|
30 |
|
class CategoryUI(wcs.admin.categories.CategoryUI):
|
31 |
|
def get_form(self, **kwargs):
|
32 |
|
form = super().get_form(**kwargs)
|
33 |
|
homepage_redirect_url = get_cfg('misc', {}).get('homepage-redirect-url')
|
34 |
|
if not homepage_redirect_url:
|
35 |
|
form.add(
|
36 |
|
SingleSelectWidget,
|
37 |
|
'homepage_position',
|
38 |
|
title=_('Position on homepage'),
|
39 |
|
value=self.category.get_homepage_position(),
|
40 |
|
options=[
|
41 |
|
('1st', _('First Column')),
|
42 |
|
('2nd', _('Second Column')),
|
43 |
|
('side', _('Sidebar')),
|
44 |
|
('none', _('None')),
|
45 |
|
],
|
46 |
|
)
|
47 |
|
form.add(
|
48 |
|
IntWidget,
|
49 |
|
'limit',
|
50 |
|
title=_('Limit number of items displayed on homepage'),
|
51 |
|
value=self.category.get_limit(),
|
52 |
|
)
|
53 |
|
return form
|
54 |
|
|
55 |
|
def submit_form(self, form):
|
56 |
|
super().submit_form(form)
|
57 |
|
|
58 |
|
homepage_redirect_url = get_cfg('misc', {}).get('homepage-redirect-url')
|
59 |
|
if not homepage_redirect_url:
|
60 |
|
self.category.homepage_position = form.get_widget('homepage_position').parse()
|
61 |
|
self.category.limit = form.get_widget('limit').parse()
|
62 |
|
|
63 |
|
self.category.store()
|
64 |
|
|
65 |
|
|
66 |
|
class CategoryPage(wcs.admin.categories.CategoryPage):
|
67 |
|
category_ui_class = CategoryUI
|
68 |
|
|
69 |
|
|
70 |
|
class CategoriesDirectory(wcs.admin.categories.CategoriesDirectory):
|
71 |
|
label = N_('Categories')
|
72 |
|
category_ui_class = CategoryUI
|
73 |
|
category_page_class = CategoryPage
|
misc: remove custom category attributes (#72817)