[6953] | 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 | """ |
---|
| 18 | import grok |
---|
| 19 | from time import time |
---|
| 20 | from datetime import date, datetime |
---|
| 21 | from zope.component import createObject |
---|
| 22 | from waeup.sirp.browser import ( |
---|
| 23 | WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage) |
---|
| 24 | from waeup.sirp.browser.breadcrumbs import Breadcrumb |
---|
| 25 | from waeup.sirp.browser.resources import datepicker, datatable, tabs |
---|
| 26 | from waeup.sirp.browser.viewlets import ( |
---|
| 27 | ManageActionButton, PrimaryNavTab, AddActionButton) |
---|
| 28 | from waeup.sirp.interfaces import IWAeUPObject, IUserAccount |
---|
| 29 | from waeup.sirp.widgets.datewidget import ( |
---|
| 30 | FriendlyDateWidget, FriendlyDateDisplayWidget, |
---|
| 31 | FriendlyDatetimeDisplayWidget) |
---|
| 32 | from waeup.sirp.browser.resources import toggleall |
---|
| 33 | from waeup.sirp.authentication import get_principal_role_manager |
---|
| 34 | from waeup.sirp.students.browser import msave |
---|
| 35 | from waeup.sirp.hostels.container import HostelsContainer |
---|
| 36 | from waeup.sirp.hostels.hostel import Hostel |
---|
| 37 | from waeup.sirp.hostels.interfaces import IHostelsContainer, IHostel |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | class 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 | |
---|
| 56 | class HostelsBreadcrumb(Breadcrumb): |
---|
| 57 | """A breadcrumb for the hostels container. |
---|
| 58 | """ |
---|
| 59 | grok.context(IHostelsContainer) |
---|
| 60 | title = u'Hostels' |
---|
| 61 | |
---|
| 62 | class HostelBreadcrumb(Breadcrumb): |
---|
| 63 | """A breadcrumb for the hostel container. |
---|
| 64 | """ |
---|
| 65 | grok.context(IHostel) |
---|
| 66 | |
---|
| 67 | class 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 | |
---|
| 78 | class 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 | |
---|
| 85 | class 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 | |
---|
| 96 | class 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 | |
---|
| 104 | class 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): |
---|
[6954] | 118 | hostel = Hostel() |
---|
| 119 | self.applyData(hostel, **data) |
---|
[6953] | 120 | self.context.addHostel(hostel) |
---|
| 121 | self.flash('Hostel created.') |
---|
| 122 | self.redirect(self.url(self.context[hostel.hostel_id], 'index')) |
---|
| 123 | return |
---|
| 124 | |
---|
| 125 | class HostelDisplayFormPage(WAeUPDisplayFormPage): |
---|
| 126 | """ Page to display hostel data |
---|
| 127 | """ |
---|
| 128 | grok.context(IHostel) |
---|
| 129 | grok.name('index') |
---|
| 130 | grok.require('waeup.viewHostels') |
---|
| 131 | #grok.template('hostelpage') |
---|
| 132 | pnav = 5 |
---|
| 133 | |
---|
| 134 | #@property |
---|
| 135 | #def label(self): |
---|
| 136 | # return self.context.name |
---|
| 137 | |
---|
| 138 | #@property |
---|
| 139 | #def title(self): |
---|
| 140 | # return self.title |
---|
| 141 | |
---|
| 142 | class HostelManageActionButton(ManageActionButton): |
---|
| 143 | grok.order(1) |
---|
| 144 | grok.context(IHostel) |
---|
| 145 | grok.view(HostelDisplayFormPage) |
---|
| 146 | grok.require('waeup.manageHostels') |
---|
| 147 | text = 'Manage' |
---|
| 148 | target = 'edit' |
---|
| 149 | |
---|
| 150 | class HostelManageFormPage(WAeUPEditFormPage): |
---|
| 151 | """ View to edit hostel data |
---|
| 152 | """ |
---|
| 153 | grok.context(IHostel) |
---|
| 154 | grok.name('edit') |
---|
| 155 | grok.require('waeup.manageHostels') |
---|
| 156 | form_fields = grok.AutoFields(IHostel).omit('hostel_id') |
---|
| 157 | #grok.template('hostelmanagepage') |
---|
| 158 | label = 'Manage hostel data' |
---|
| 159 | pnav = 5 |
---|
| 160 | |
---|
| 161 | #@property |
---|
| 162 | #def title(self): |
---|
| 163 | # return self.context.name |
---|
| 164 | |
---|
| 165 | def update(self): |
---|
| 166 | datepicker.need() # Enable jQuery datepicker in date fields. |
---|
| 167 | super(HostelManageFormPage, self).update() |
---|
| 168 | return |
---|
| 169 | |
---|
| 170 | @grok.action('Save') |
---|
| 171 | def save(self, **data): |
---|
| 172 | msave(self, **data) |
---|
| 173 | return |
---|