general: add label/user_name/backoffice_url metadata on bookings (#20280)
This commit is contained in:
parent
969394c623
commit
a51fb45aa4
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('agendas', '0020_auto_20171102_1021'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='booking',
|
||||
name='backoffice_url',
|
||||
field=models.URLField(blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='booking',
|
||||
name='label',
|
||||
field=models.CharField(max_length=250, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='booking',
|
||||
name='user_name',
|
||||
field=models.CharField(max_length=250, blank=True),
|
||||
),
|
||||
]
|
|
@ -333,6 +333,10 @@ class Booking(models.Model):
|
|||
primary_booking = models.ForeignKey('self', null=True,
|
||||
on_delete=models.CASCADE, related_name='secondary_booking_set')
|
||||
|
||||
label = models.CharField(max_length=250, blank=True)
|
||||
user_name = models.CharField(max_length=250, blank=True)
|
||||
backoffice_url = models.URLField(blank=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
with transaction.atomic():
|
||||
super(Booking, self).save(*args, **kwargs)
|
||||
|
|
|
@ -350,6 +350,9 @@ class Fillslot(GenericAPIView):
|
|||
|
||||
event = Event.objects.filter(id=event_pk)[0]
|
||||
new_booking = Booking(event_id=event_pk, extra_data=request.data)
|
||||
for attr in ('label', 'user_name', 'backoffice_url'):
|
||||
if isinstance(request.data.get(attr), basestring):
|
||||
setattr(new_booking, attr, request.data.get(attr))
|
||||
|
||||
if event.waiting_list_places:
|
||||
if (event.booked_places + places_count) > event.places or event.waiting_list:
|
||||
|
|
|
@ -290,6 +290,18 @@ def test_booking_api(app, some_data, user):
|
|||
assert Booking.objects.count() == 2
|
||||
assert Booking.objects.filter(event__agenda=agenda).count() == 2
|
||||
|
||||
# test with additional data
|
||||
resp = app.post_json('/api/agenda/%s/fillslot/%s/' % (agenda.id, event.id),
|
||||
params={'label': 'foo', 'user_name': 'bar', 'backoffice_url': 'http://baz/'})
|
||||
assert Booking.objects.get(id=resp.json['booking_id']).label == 'foo'
|
||||
assert Booking.objects.get(id=resp.json['booking_id']).user_name == 'bar'
|
||||
assert Booking.objects.get(id=resp.json['booking_id']).backoffice_url == 'http://baz/'
|
||||
|
||||
# test invalid data are silently ignored
|
||||
resp = app.post_json('/api/agenda/%s/fillslot/%s/' % (agenda.id, event.id),
|
||||
params={'user_name': {'foo': 'bar'}})
|
||||
assert Booking.objects.get(id=resp.json['booking_id']).user_name == ''
|
||||
|
||||
resp = app.post('/api/agenda/foobar/fillslot/%s/' % event.id, status=404)
|
||||
|
||||
resp = app.post('/api/agenda/233/fillslot/%s/' % event.id, status=404)
|
||||
|
|
Loading…
Reference in New Issue