## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """UI components for hostels and related components. """ import grok from time import time from datetime import date, datetime from zope.component import createObject from waeup.sirp.browser import ( WAeUPPage, WAeUPEditFormPage, WAeUPAddFormPage, WAeUPDisplayFormPage) from waeup.sirp.browser.breadcrumbs import Breadcrumb from waeup.sirp.browser.resources import datepicker, datatable, tabs from waeup.sirp.browser.viewlets import ( ManageActionButton, PrimaryNavTab, AddActionButton) from waeup.sirp.interfaces import IWAeUPObject, IUserAccount from waeup.sirp.widgets.datewidget import ( FriendlyDateWidget, FriendlyDateDisplayWidget, FriendlyDatetimeDisplayWidget) from waeup.sirp.browser.resources import toggleall from waeup.sirp.authentication import get_principal_role_manager from waeup.sirp.students.browser import msave from waeup.sirp.hostels.container import HostelsContainer from waeup.sirp.hostels.hostel import Hostel from waeup.sirp.hostels.interfaces import IHostelsContainer, IHostel class HostelsTab(PrimaryNavTab): """Hostels tab in primary navigation. """ grok.context(IWAeUPObject) grok.order(5) grok.require('waeup.viewHostels') grok.template('primarynavtab') pnav = 5 tab_title = u'Hostels' @property def link_target(self): return self.view.application_url('hostels') class HostelsBreadcrumb(Breadcrumb): """A breadcrumb for the hostels container. """ grok.context(IHostelsContainer) title = u'Hostels' class HostelBreadcrumb(Breadcrumb): """A breadcrumb for the hostel container. """ grok.context(IHostel) class HostelsContainerPage(WAeUPDisplayFormPage): """The standard view for hostels containers. """ grok.context(IHostelsContainer) grok.name('index') grok.require('waeup.viewHostels') #grok.template('containerpage') label = 'Accommodation Section' title = 'Accommodation' pnav = 5 class HostelsContainerManageActionButton(ManageActionButton): grok.order(1) grok.context(IHostelsContainer) grok.view(HostelsContainerPage) grok.require('waeup.manageHostels') text = 'Manage accommodation section' class HostelsContainerManagePage(WAeUPDisplayFormPage): """The manage page for hostel containers. """ grok.context(IHostelsContainer) grok.name('manage') grok.require('waeup.manageHostels') #grok.template('containermanagepage') pnav = 5 title = 'Accommodation' label = 'Manage accommodation section' class HostelsContainerAddActionButton(AddActionButton): grok.order(1) grok.context(IHostelsContainer) grok.view(HostelsContainerManagePage) grok.require('waeup.manageHostels') text = 'Add hostel' target = 'addhostel' class HostelAddFormPage(WAeUPAddFormPage): """Add-form to add a hostel. """ grok.context(IHostelsContainer) grok.require('waeup.manageHostels') grok.name('addhostel') grok.template('hosteladdpage') form_fields = grok.AutoFields(IHostel) title = 'Accommodation' label = 'Add hostel' pnav = 5 @grok.action('Create hostel') def addHostel(self, **data): hostel = Hostel() self.applyData(hostel, **data) self.context.addHostel(hostel) self.flash('Hostel created.') self.redirect(self.url(self.context[hostel.hostel_id], 'index')) return class HostelDisplayFormPage(WAeUPDisplayFormPage): """ Page to display hostel data """ grok.context(IHostel) grok.name('index') grok.require('waeup.viewHostels') #grok.template('hostelpage') pnav = 5 #@property #def label(self): # return self.context.name #@property #def title(self): # return self.title class HostelManageActionButton(ManageActionButton): grok.order(1) grok.context(IHostel) grok.view(HostelDisplayFormPage) grok.require('waeup.manageHostels') text = 'Manage' target = 'edit' class HostelManageFormPage(WAeUPEditFormPage): """ View to edit hostel data """ grok.context(IHostel) grok.name('edit') grok.require('waeup.manageHostels') form_fields = grok.AutoFields(IHostel).omit('hostel_id') #grok.template('hostelmanagepage') label = 'Manage hostel data' pnav = 5 #@property #def title(self): # return self.context.name def update(self): datepicker.need() # Enable jQuery datepicker in date fields. super(HostelManageFormPage, self).update() return @grok.action('Save') def save(self, **data): msave(self, **data) return