Skip to content

Commit

Permalink
Merge c811c5e into 4d5e47a
Browse files Browse the repository at this point in the history
  • Loading branch information
deiferni committed Oct 21, 2013
2 parents 4d5e47a + c811c5e commit ff3b033
Show file tree
Hide file tree
Showing 22 changed files with 411 additions and 226 deletions.
21 changes: 13 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
*.egg
*.egg-info
*.mo
*.pyc
*.pyo
.svn
.DS_Store
.installed.cfg
.mr.developer.cfg
.svn
bin
bootstrap.py
build
buildout.cfg
database.cfg
develop-eggs
develop.cfg
dist
downloads
eggs
parts
src
test_database.py
var
*.egg-info
*.mo
build
.mr.developer.cfg
*.egg
database.cfg
test_database.py
versions.cfg
110 changes: 60 additions & 50 deletions seantis/reservation/allocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from z3c.form import field
from z3c.form import button
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
from z3c.form.browser.checkbox import CheckBoxFieldWidget
from z3c.form.browser.radio import RadioFieldWidget

from seantis.reservation import _
from seantis.reservation import utils
Expand All @@ -20,6 +18,12 @@
AllocationGroupView,
extract_action_data,
)
from plone.formwidget.recurrence.z3cform.widget import RecurrenceFieldWidget
from plone.formwidget.datetime.z3cform.widget import DateFieldWidget
from z3c.form.interfaces import ActionExecutionError
from zope.interface import Invalid
from zope import schema
import itertools


class AllocationForm(ResourceBaseForm):
Expand All @@ -37,17 +41,23 @@ class AllocationAddForm(AllocationForm):

fields = field.Fields(IAllocation).select(
'id', 'group', 'timeframes', 'whole_day', 'start_time', 'end_time',
'recurring', 'day', 'recurrence_start', 'recurrence_end',
'days', 'separately'
'day', 'recurrence', 'separately',
)
fields['days'].widgetFactory = CheckBoxFieldWidget
fields['recurring'].widgetFactory = RadioFieldWidget

fields['day'].widgetFactory = DateFieldWidget
fields['recurrence'].widgetFactory = RecurrenceFieldWidget

label = _(u'Allocation')

enable_form_tabbing = True
default_fieldset_label = _(u'Date')

def updateWidgets(self):
super(AllocationAddForm, self).updateWidgets()
widget = self.widgets['recurrence']
widget.start_field = 'day'
widget.show_repeat_forever = False

@property
def additionalSchemata(self):
return [
Expand All @@ -74,23 +84,16 @@ def whole_day(self):
))

def defaults(self):

recurrence_start, recurrence_end = self.default_recurrence()
recurring = recurrence_start != recurrence_end

ctx = self.context
return {
'group': u'',
'recurrence_start': recurrence_start,
'recurrence_end': recurrence_end,
'timeframes': self.json_timeframes(),
'quota': ctx.quota,
'approve_manually': ctx.approve_manually,
'raster': ctx.raster,
'partly_available': ctx.partly_available,
'reservation_quota_limit': ctx.reservation_quota_limit,
'whole_day': self.whole_day,
'recurring': recurring
'whole_day': self.whole_day
}

def timeframes(self):
Expand All @@ -107,22 +110,6 @@ def json_timeframes(self):
obj.isoformat() if isinstance(obj, date) else None
return unicode(json.dumps(results, default=dthandler))

def default_recurrence(self):
start = self.start and self.start.date() or None
end = self.end and self.end.date() or None

if not all((start, end)):
return None, None

if self.whole_day:
start, end

for frame in sorted(self.timeframes(), key=lambda f: f.start):
if frame.start <= start and start <= frame.end:
return (frame.start, frame.end)

return start, end

def get_dates(self, data):
""" Return a list with date tuples depending on the data entered by the
user, using rrule if requested.
Expand All @@ -133,15 +120,11 @@ def get_dates(self, data):
data['day'], data['start_time'], data['end_time']
)

if not data['recurring']:
if not data['recurrence']:
return ((start, end))

rule = rrule.rrule(
rrule.DAILY,
byweekday=data['days'],
dtstart=data['recurrence_start'],
until=data['recurrence_end'],
)
rule = rrule.rrulestr(data['recurrence'],
dtstart=start)

event = lambda d: \
utils.get_date_range(d, data['start_time'], data['end_time'])
Expand All @@ -151,6 +134,7 @@ def get_dates(self, data):
@button.buttonAndHandler(_(u'Allocate'))
@extract_action_data
def allocate(self, data):
self._validate_recurrence_options(data)
dates = self.get_dates(data)

def allocate():
Expand All @@ -162,13 +146,29 @@ def allocate():
grouped=not data['separately'],
approve_manually=data['approve_manually'],
reservation_quota_limit=data['reservation_quota_limit'],
whole_day=data['whole_day']
whole_day=data['whole_day'],
rrule=data['recurrence'],

)
self.flash(_(u'Allocation added'))

utils.handle_action(action=allocate, success=self.redirect_to_context)

def _validate_recurrence_options(self, data):
"""Validate that when recurrence is configured and the resource is
partly available the separately option must be enabled as well.
This validation has been moved here from a form invariant since
invariants do not seem to work with groups.
"""
if 'recurrence' in data and data['recurrence']:
if data['partly_available'] and not data['separately']:
raise ActionExecutionError(Invalid(_(
u'Partly available allocations can only be reserved '
u'separately'
)))

@button.buttonAndHandler(_(u'Cancel'))
def cancel(self, action):
self.redirect_to_context()
Expand Down Expand Up @@ -286,25 +286,32 @@ class AllocationRemoveForm(AllocationForm, AllocationGroupView):

destructive_buttons = ('delete', )

fields = field.Fields(IAllocation).select('id', 'group')
fields = field.Fields(IAllocation).select('id', 'group') + \
field.Fields(schema.Int(__name__='recurrence_id',
required=False))
template = ViewPageTemplateFile('templates/remove_allocation.pt')

label = _(u'Remove allocations')

hidden_fields = ['id', 'group']
hidden_fields = ['id', 'group', 'recurrence_id']
ignore_requirements = True

@button.buttonAndHandler(_(u'Delete'))
@extract_action_data
def delete(self, data):

assert bool(data['id']) != bool(data['group']), \
"Either id or group, not both"
nof_params = len(list(itertools.ifilter(None, (
data['id'],
data['group'],
data['recurrence_id'],)
)))
assert nof_params == 1, "Exactly one of id, group or recurrence_id"

scheduler = self.scheduler

def delete():
scheduler.remove_allocation(id=data['id'], group=data['group'])
scheduler.remove_allocation(id=data['id'],
group=data['group'],
recurrence_id=data['recurrence_id'])
self.flash(_(u'Allocation removed'))

utils.handle_action(action=delete, success=self.redirect_to_context)
Expand All @@ -314,9 +321,12 @@ def cancel(self, action):
self.redirect_to_context()

def defaults(self):
id, group = self.id, self.group

if group:
return dict(group=self.group, id=None)
else:
return dict(id=self.id, group=None)
id, group, recurrence_id = self.id, self.group, self.recurrence_id
result = dict(id=None, recurrence_id=None, group=None)
if recurrence_id:
result['recurrence_id'] = recurrence_id
elif group:
result['group'] = group
elif id:
result['id'] = id
return result
23 changes: 17 additions & 6 deletions seantis/reservation/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
/* the approve field is now called approve_manually, since the old one has to linger around for migration
and there's no easy way to hide it, this hack helps: */
#formfield-form-widgets-approve {
display: none;
display: none;
}

/* without this the events in the month view are not clickable */
.fc-view-month .fc-day-content {
visibility: hidden;
visibility: hidden;
}


Expand Down Expand Up @@ -203,18 +203,28 @@ body .event-unavailable .fc-event-time {
/* hidden waitinglist in manage reservations */

.hide-waitinglist .splitleft {
width: 75%;
width: 75%;
}

.hide-waitinglist .splitright {
display: none;
display: none;
}

.overlay.overlay-ajax {
z-index: 9999 !important;
}

/* to overlap the overlay */
#calroot {
.riform {
z-index: 10000;
}

/* to overlap the overlay's overlay. please forgive me for !important.*/
#calroot {
z-index: 10001 !important;
}


/* ensures that the plone menu is displayed above the calendar */
.fc-view > div {
z-index: 0 !important;
Expand Down Expand Up @@ -282,4 +292,5 @@ body .event-unavailable .fc-event-time {
.multicalendar .legend .icon {
display: none !important;
}
}
}

0 comments on commit ff3b033

Please sign in to comment.