Skip to content

Commit

Permalink
Merge a16dbe2 into 4563479
Browse files Browse the repository at this point in the history
  • Loading branch information
deiferni committed Nov 13, 2013
2 parents 4563479 + a16dbe2 commit ee78024
Show file tree
Hide file tree
Showing 8 changed files with 641 additions and 494 deletions.
335 changes: 172 additions & 163 deletions seantis/reservation/locales/de/LC_MESSAGES/seantis.reservation.po

Large diffs are not rendered by default.

336 changes: 173 additions & 163 deletions seantis/reservation/locales/fr/LC_MESSAGES/seantis.reservation.po

Large diffs are not rendered by default.

333 changes: 171 additions & 162 deletions seantis/reservation/locales/seantis.reservation.pot

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions seantis/reservation/models/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def for_group(cls, group, **args):
reservation.target = group
return reservation

@property
def is_pending(self):
return self.status == 'pending'

@property
def is_recurrence(self):
return self.target_type == 'recurrence'
Expand Down
31 changes: 26 additions & 5 deletions seantis/reservation/templates/macros.pt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
<tal:block define="
first_reservation python: reservations[0];
last_reservation python: reservations[-1];
timespan_start view/timespan_start | nothing;
timespan_end view/timespan_end | nothing;
">
<div class="reservation">
<tal:block define="
Expand All @@ -79,7 +81,7 @@
<div tal:repeat="reservation reservations" class="reservation-list">
<tal:block define="
data python: reservation.data;
timespans python: reservation.timespans();
timespans python: reservation.timespan_entries(start=timespan_start, end=timespan_end);
">
<metal:use use-macro="context/@@seantis-reservation-macros/reservation-data" />
<metal:use use-macro="context/@@seantis-reservation-macros/reservation-timespans" />
Expand Down Expand Up @@ -183,7 +185,8 @@
<tal:comment replace="nothing">
Reservation timespans block. Needs the following variables:

timespans -> list of start/end tuples
timespans -> list of Timespan namedtuples
reservation -> the reservation
</tal:comment>

<metal:define define-macro="reservation-timespans" tal:define="macro python: context.unrestrictedTraverse('@@seantis-reservation-macros')">
Expand All @@ -193,11 +196,29 @@

<tal:block tal:repeat="timespan python: sorted(timespans)">
<tal:block tal:define="
start python: timespan[0];
end python: timespan[1];
start python: timespan.start;
end python: timespan.end;
allocation_id python: timespan.allocation_id;
display python: macro.utils.display_date(start, end);
show_actions show_actions | nothing;
">
<div tal:content="display"></div>
<div>
<tal:inline tal:content="display"></tal:inline>
<tal:removal_links tal:condition="python: show_actions and not reservation.is_pending">
<a tal:condition="python: reservation.is_recurrence and len(timespans) > 1"
class="link-overlay remove-reserved-slots"
tal:attributes="href python: macro.remove_reserved_slots_url(token, allocation_id)"
i18n:translate="">
Remove reservation
</a>
<a tal:condition="not: repeat/timespan/start"
class="link-overlay remove-all-reserved-slots"
tal:attributes="href python: macro.remove_all_reserved_slots_url(token, allocation_id)"
i18n:translate="">
Remove future reservations
</a>
</tal:removal_links>
</div>
</tal:block>
</tal:block>

Expand Down
2 changes: 1 addition & 1 deletion seantis/reservation/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def tearDown(self):
outlaw.execute('DELETE FROM blocked_periods')
outlaw.execute('DELETE FROM reservations')
outlaw.execute('DELETE FROM reserved_slots')
outlaw.execute('DELETE FROM recurrences')
outlaw.execute('DELETE FROM allocations')
outlaw.execute('DELETE FROM recurrences')
outlaw.dispose()

self.logout()
Expand Down
87 changes: 87 additions & 0 deletions seantis/reservation/tests/test_browser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from datetime import date
from datetime import time
from datetime import timedelta
import json
import transaction
from itertools import chain
Expand All @@ -10,6 +13,7 @@
from seantis.reservation import utils
from seantis.reservation import db
from seantis.reservation.tests import FunctionalTestCase
from seantis.reservation.db import Scheduler


class FormsetField(object):
Expand Down Expand Up @@ -596,6 +600,89 @@ def test_allocation_validation_whole_day(self):
'Please specify a valid time, for example 09:00', errors
)

def test_remove_reserved_slots_not_present_for_pending_reservations(self):
# setup resource and allocations
browser = self.new_browser()
browser.login_admin()

self.add_resource('removeslots')
resource = self.portal['testfolder']['removeslots']

db = Scheduler(resource.uuid())
start1 = datetime.combine(date.today(), time(resource.first_hour))
end1 = datetime.combine(date.today(), time(resource.last_hour))
start2 = start1 + timedelta(days=1)
end2 = end1 + timedelta(days=1)

rrule = 'RRULE:FREQ=DAILY;COUNT=2'
dates = (start1, end1, start2, end2)

db.allocate(
dates, raster=15, partly_available=True, rrule=rrule,
approve_manually=True, grouped=False
)
db.reserve(
u'foo@example.com', dates=dates, rrule=rrule
)
transaction.commit()

browser.open(self.infolder('/removeslots'))
menu = self.allocation_menu('removeslots', start1, end1)
browser.open(menu['manage'])

self.assertNotIn(
'Remove reservation',
str(browser.query('.remove-reserved-slots'))
)

def test_remove_reserved_slots(self):
# setup resource and allocations
browser = self.new_browser()
browser.login_admin()

self.add_resource('removeslots')
resource = self.portal['testfolder']['removeslots']

db = Scheduler(resource.uuid())
start1 = datetime.combine(date.today(), time(resource.first_hour))
end1 = datetime.combine(date.today(), time(resource.last_hour))
start2 = start1 + timedelta(days=1)
end2 = end1 + timedelta(days=1)

rrule = 'RRULE:FREQ=DAILY;COUNT=2'
dates = (start1, end1, start2, end2)

db.allocate(
dates, raster=15, partly_available=True, rrule=rrule,
approve_manually=False, grouped=False
)
token = db.reserve(
u'foo@example.com', dates=dates, rrule=rrule
)
db.approve_reservation(token)
transaction.commit()

browser.open(self.infolder('/removeslots'))
menu = self.allocation_menu('removeslots', start1, end1)
browser.open(menu['manage'])

self.assertTrue(db.has_reserved_slot_in_range(start1, end1))
self.assertTrue(db.has_reserved_slot_in_range(start2, end2))

# do stuff, go to reservation overwie and make sure links are present
self.assertIn(
'Remove reservation',
str(browser.query('.remove-reserved-slots'))
)
# click first link
link = browser.getLink('Remove reservation')
link.click()
# confirm removal
browser.getControl('Remove').click()

self.assertFalse(db.has_reserved_slot_in_range(start1, end1))
self.assertTrue(db.has_reserved_slot_in_range(start2, end2))

def test_reservation_approval(self):

browser = self.new_browser()
Expand Down
7 changes: 7 additions & 0 deletions seantis/reservation/tests/test_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ def test_target_dates_allocation(self):
self.assertSequenceEqual([(self.reservation.start,
self.reservation.end)],
self.reservation.target_dates())

def test_is_pending(self):
self.reservation.status = 'pending'
self.assertTrue(self.reservation.is_pending)

self.reservation.status = 'approved'
self.assertFalse(self.reservation.is_pending)

0 comments on commit ee78024

Please sign in to comment.