0001-general-add-label-user_name-backoffice_url-metadata-.patch
chrono/agendas/migrations/0021_auto_20171126_1330.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 |
from __future__ import unicode_literals |
|
3 | ||
4 |
from django.db import migrations, models |
|
5 | ||
6 | ||
7 |
class Migration(migrations.Migration): |
|
8 | ||
9 |
dependencies = [ |
|
10 |
('agendas', '0020_auto_20171102_1021'), |
|
11 |
] |
|
12 | ||
13 |
operations = [ |
|
14 |
migrations.AddField( |
|
15 |
model_name='booking', |
|
16 |
name='backoffice_url', |
|
17 |
field=models.URLField(blank=True), |
|
18 |
), |
|
19 |
migrations.AddField( |
|
20 |
model_name='booking', |
|
21 |
name='label', |
|
22 |
field=models.CharField(max_length=250, blank=True), |
|
23 |
), |
|
24 |
migrations.AddField( |
|
25 |
model_name='booking', |
|
26 |
name='user_name', |
|
27 |
field=models.CharField(max_length=250, blank=True), |
|
28 |
), |
|
29 |
] |
chrono/agendas/models.py | ||
---|---|---|
345 | 345 |
primary_booking = models.ForeignKey('self', null=True, |
346 | 346 |
on_delete=models.CASCADE, related_name='secondary_booking_set') |
347 | 347 | |
348 |
label = models.CharField(max_length=250, blank=True) |
|
349 |
user_name = models.CharField(max_length=250, blank=True) |
|
350 |
backoffice_url = models.URLField(blank=True) |
|
351 | ||
348 | 352 |
def save(self, *args, **kwargs): |
349 | 353 |
with transaction.atomic(): |
350 | 354 |
super(Booking, self).save(*args, **kwargs) |
chrono/api/views.py | ||
---|---|---|
350 | 350 | |
351 | 351 |
event = Event.objects.filter(id=event_pk)[0] |
352 | 352 |
new_booking = Booking(event_id=event_pk, extra_data=request.data) |
353 |
for attr in ('label', 'user_name', 'backoffice_url'): |
|
354 |
if isinstance(request.data.get(attr), basestring): |
|
355 |
setattr(new_booking, attr, request.data.get(attr)) |
|
353 | 356 | |
354 | 357 |
if event.waiting_list_places: |
355 | 358 |
if (event.booked_places + places_count) > event.places or event.waiting_list: |
tests/test_api.py | ||
---|---|---|
290 | 290 |
assert Booking.objects.count() == 2 |
291 | 291 |
assert Booking.objects.filter(event__agenda=agenda).count() == 2 |
292 | 292 | |
293 |
# test with additional data |
|
294 |
resp = app.post_json('/api/agenda/%s/fillslot/%s/' % (agenda.id, event.id), |
|
295 |
params={'label': 'foo', 'user': 'bar', 'url': 'http://baz/'}) |
|
296 |
assert Booking.objects.get(id=resp.json['booking_id']).label == 'foo' |
|
297 |
assert Booking.objects.get(id=resp.json['booking_id']).user == 'bar' |
|
298 |
assert Booking.objects.get(id=resp.json['booking_id']).url == 'http://baz/' |
|
299 | ||
300 |
# test invalid data are silently ignored |
|
301 |
resp = app.post_json('/api/agenda/%s/fillslot/%s/' % (agenda.id, event.id), |
|
302 |
params={'user': {'foo': 'bar'}}) |
|
303 |
assert Booking.objects.get(id=resp.json['booking_id']).user == '' |
|
304 | ||
293 | 305 |
resp = app.post('/api/agenda/foobar/fillslot/%s/' % event.id, status=404) |
294 | 306 | |
295 | 307 |
resp = app.post('/api/agenda/233/fillslot/%s/' % event.id, status=404) |
296 |
- |