source: main/waeup.sirp/trunk/src/waeup/sirp/hostels/browser.py @ 6953

Last change on this file since 6953 was 6953, checked in by Henrik Bettermann, 13 years ago

Add some basic hostel UI stuff.

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
2## This program is free software; you can redistribute it and/or modify
3## it under the terms of the GNU General Public License as published by
4## the Free Software Foundation; either version 2 of the License, or
5## (at your option) any later version.
6##
7## This program is distributed in the hope that it will be useful,
8## but WITHOUT ANY WARRANTY; without even the implied warranty of
9## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10## GNU General Public License for more details.
11##
12## You should have received a copy of the GNU General Public License
13## along with this program; if not, write to the Free Software
14## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15##
16"""UI components for hostels and related components.
17"""
18import grok
19from time import time
20from datetime import date, datetime
21from zope.component import createObject
22from waeup.sirp.browser import (
23    WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage)
24from waeup.sirp.browser.breadcrumbs import Breadcrumb
25from waeup.sirp.browser.resources import datepicker, datatable, tabs
26from waeup.sirp.browser.viewlets import (
27    ManageActionButton, PrimaryNavTab, AddActionButton)
28from waeup.sirp.interfaces import IWAeUPObject, IUserAccount
29from waeup.sirp.widgets.datewidget import (
30    FriendlyDateWidget, FriendlyDateDisplayWidget,
31    FriendlyDatetimeDisplayWidget)
32from waeup.sirp.browser.resources import toggleall
33from waeup.sirp.authentication import get_principal_role_manager
34from waeup.sirp.students.browser import msave
35from waeup.sirp.hostels.container import HostelsContainer
36from waeup.sirp.hostels.hostel import Hostel
37from waeup.sirp.hostels.interfaces import IHostelsContainer, IHostel
38
39
40class HostelsTab(PrimaryNavTab):
41    """Hostels tab in primary navigation.
42    """
43
44    grok.context(IWAeUPObject)
45    grok.order(5)
46    grok.require('waeup.viewHostels')
47    grok.template('primarynavtab')
48
49    pnav = 5
50    tab_title = u'Hostels'
51
52    @property
53    def link_target(self):
54        return self.view.application_url('hostels')
55
56class HostelsBreadcrumb(Breadcrumb):
57    """A breadcrumb for the hostels container.
58    """
59    grok.context(IHostelsContainer)
60    title = u'Hostels'
61
62class HostelBreadcrumb(Breadcrumb):
63    """A breadcrumb for the hostel container.
64    """
65    grok.context(IHostel)
66
67class HostelsContainerPage(WAeUPDisplayFormPage):
68    """The standard view for hostels containers.
69    """
70    grok.context(IHostelsContainer)
71    grok.name('index')
72    grok.require('waeup.viewHostels')
73    #grok.template('containerpage')
74    label = 'Accommodation Section'
75    title = 'Accommodation'
76    pnav = 5
77
78class HostelsContainerManageActionButton(ManageActionButton):
79    grok.order(1)
80    grok.context(IHostelsContainer)
81    grok.view(HostelsContainerPage)
82    grok.require('waeup.manageHostels')
83    text = 'Manage accommodation section'
84
85class HostelsContainerManagePage(WAeUPDisplayFormPage):
86    """The manage page for hostel containers.
87    """
88    grok.context(IHostelsContainer)
89    grok.name('manage')
90    grok.require('waeup.manageHostels')
91    #grok.template('containermanagepage')
92    pnav = 5
93    title = 'Accommodation'
94    label = 'Manage accommodation section'
95
96class HostelsContainerAddActionButton(AddActionButton):
97    grok.order(1)
98    grok.context(IHostelsContainer)
99    grok.view(HostelsContainerManagePage)
100    grok.require('waeup.manageHostels')
101    text = 'Add hostel'
102    target = 'addhostel'
103
104class HostelAddFormPage(WAeUPAddFormPage):
105    """Add-form to add a hostel.
106    """
107    grok.context(IHostelsContainer)
108    grok.require('waeup.manageHostels')
109    grok.name('addhostel')
110    grok.template('hosteladdpage')
111    form_fields = grok.AutoFields(IHostel)
112    title = 'Accommodation'
113    label = 'Add hostel'
114    pnav = 5
115
116    @grok.action('Create hostel')
117    def addHostel(self, **data):
118        #hostel = createObject(u'waeup.Hostel')
119        #self.applyData(hostel, **data)
120        hostel = Hostel(**data)
121        self.context.addHostel(hostel)
122        self.flash('Hostel created.')
123        self.redirect(self.url(self.context[hostel.hostel_id], 'index'))
124        return
125
126class HostelDisplayFormPage(WAeUPDisplayFormPage):
127    """ Page to display hostel data
128    """
129    grok.context(IHostel)
130    grok.name('index')
131    grok.require('waeup.viewHostels')
132    #grok.template('hostelpage')
133    pnav = 5
134
135    #@property
136    #def label(self):
137    #    return self.context.name
138
139    #@property
140    #def title(self):
141    #    return self.title
142
143class HostelManageActionButton(ManageActionButton):
144    grok.order(1)
145    grok.context(IHostel)
146    grok.view(HostelDisplayFormPage)
147    grok.require('waeup.manageHostels')
148    text = 'Manage'
149    target = 'edit'
150
151class HostelManageFormPage(WAeUPEditFormPage):
152    """ View to edit hostel data
153    """
154    grok.context(IHostel)
155    grok.name('edit')
156    grok.require('waeup.manageHostels')
157    form_fields = grok.AutoFields(IHostel).omit('hostel_id')
158    #grok.template('hostelmanagepage')
159    label = 'Manage hostel data'
160    pnav = 5
161
162    #@property
163    #def title(self):
164    #    return self.context.name
165
166    def update(self):
167        datepicker.need() # Enable jQuery datepicker in date fields.
168        super(HostelManageFormPage, self).update()
169        return
170
171    @grok.action('Save')
172    def save(self, **data):
173        msave(self, **data)
174        return
Note: See TracBrowser for help on using the repository browser.