0001-agendas-add-publication_date-on-event-40728.patch
chrono/agendas/migrations/0044_event_publication_date.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', '0043_booking_user_external_id'), |
|
11 |
] |
|
12 | ||
13 |
operations = [ |
|
14 |
migrations.AddField( |
|
15 |
model_name='event', |
|
16 |
name='publication_date', |
|
17 |
field=models.DateField(blank=True, null=True, verbose_name='Publication date'), |
|
18 |
), |
|
19 |
] |
chrono/agendas/models.py | ||
---|---|---|
525 | 525 |
class Event(models.Model): |
526 | 526 |
agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE) |
527 | 527 |
start_datetime = models.DateTimeField(_('Date/time')) |
528 |
publication_date = models.DateField(_('Publication date'), blank=True, null=True) |
|
528 | 529 |
places = models.PositiveIntegerField(_('Places')) |
529 | 530 |
waiting_list_places = models.PositiveIntegerField(_('Places in waiting list'), default=0) |
530 | 531 |
label = models.CharField( |
... | ... | |
652 | 653 |
def export_json(self): |
653 | 654 |
return { |
654 | 655 |
'start_datetime': make_naive(self.start_datetime).strftime('%Y-%m-%d %H:%M:%S'), |
656 |
'publication_date': self.publication_date.strftime('%Y-%m-%d') if self.publication_date else None, |
|
655 | 657 |
'places': self.places, |
656 | 658 |
'waiting_list_places': self.waiting_list_places, |
657 | 659 |
'label': self.label, |
chrono/manager/forms.py | ||
---|---|---|
73 | 73 |
widgets = { |
74 | 74 |
'agenda': forms.HiddenInput(), |
75 | 75 |
'start_datetime': DateTimeWidget(), |
76 |
'publication_date': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'), |
|
76 | 77 |
} |
77 | 78 |
exclude = ['full', 'meeting_type', 'desk', 'slug'] |
78 | 79 | |
... | ... | |
83 | 84 |
widgets = { |
84 | 85 |
'agenda': forms.HiddenInput(), |
85 | 86 |
'start_datetime': DateTimeWidget(), |
87 |
'publication_date': forms.DateInput(attrs={'type': 'date'}, format='%Y-%m-%d'), |
|
86 | 88 |
} |
87 | 89 |
exclude = ['full', 'meeting_type', 'desk'] |
88 | 90 |
chrono/manager/templates/chrono/manager_event_detail_fragment.html | ||
---|---|---|
4 | 4 |
<div> |
5 | 5 |
{% if object.description %}<p>{{ object.description }}</p>{% endif %} |
6 | 6 |
{% if object.pricing %}<p>{% trans "Pricing:" %} {{ object.pricing }}</p>{% endif %} |
7 |
{% if object.url %}<p><a href="{{ object.url }}">{{ object.url|truncatechars:100 }}</a>{% endif %} |
|
7 |
{% if object.url %}<p><a href="{{ object.url }}">{{ object.url|truncatechars:100 }}</a></p>{% endif %} |
|
8 |
{% if object.publication_date %}<p>{% trans "Publication date:" %} {{ object.publication_date }}</p>{% endif %} |
|
8 | 9 |
</div> |
9 | 10 |
</div> |
10 | 11 |
{% endif %} |
chrono/manager/templates/chrono/manager_events_agenda_settings.html | ||
---|---|---|
37 | 37 |
{% endblocktrans %} |
38 | 38 |
{% endif %} |
39 | 39 |
) |
40 |
{% if event.publication_date %} |
|
41 |
({% trans "publication date:" %} {{ event.publication_date }}) |
|
42 |
{% endif %} |
|
40 | 43 |
{% if not event.in_bookable_period %} |
41 | 44 |
({% trans "out of bookable period" %}) |
42 | 45 |
{% endif %} |
tests/test_import_export.py | ||
---|---|---|
131 | 131 |
first_event.description = 'description' |
132 | 132 |
first_event.pricing = '100' |
133 | 133 |
first_event.url = 'https://example.net/' |
134 |
first_event.publication_date = datetime.date(2020, 5, 11) |
|
134 | 135 |
first_event.save() |
135 | 136 | |
136 | 137 |
output = get_output_of_command('export_site') |
... | ... | |
147 | 148 |
assert first_imported_event.description == 'description' |
148 | 149 |
assert first_imported_event.pricing == '100' |
149 | 150 |
assert first_imported_event.url == 'https://example.net/' |
151 |
assert first_imported_event.publication_date == datetime.date(2020, 5, 11) |
|
150 | 152 | |
151 | 153 | |
152 | 154 |
def test_import_export_permissions(app, some_data, meetings_agenda): |
tests/test_manager.py | ||
---|---|---|
388 | 388 |
resp = resp.follow() |
389 | 389 |
event = Event.objects.get(places=10) |
390 | 390 |
assert event.slug is None |
391 |
assert not "This agenda doesn't have any event yet." in resp.text |
|
391 |
assert event.publication_date is None |
|
392 |
assert "This agenda doesn't have any event yet." not in resp.text |
|
392 | 393 |
assert '/manage/agendas/%s/events/%s/' % (agenda.id, event.id) in resp.text |
393 | 394 |
assert ('Feb. 15, %s, 5 p.m.' % year) in resp.text |
394 | 395 |
assert '10 places' in resp.text |
... | ... | |
402 | 403 |
resp = resp.click('New Event') |
403 | 404 |
resp.form['start_datetime$date'] = '%s-02-15' % year |
404 | 405 |
resp.form['start_datetime$time'] = '18:00' |
406 |
resp.form['publication_date'] = '2020-05-11' |
|
405 | 407 |
resp.form['places'] = 11 |
406 | 408 |
resp.form['description'] = 'A description' |
407 | 409 |
resp = resp.form.submit() |
408 | 410 |
resp = resp.follow() |
409 | 411 |
event = Event.objects.get(places=11) |
410 | 412 |
assert event.description == 'A description' |
413 |
assert event.publication_date == datetime.date(2020, 5, 11) |
|
411 | 414 | |
412 | 415 |
# add with errors in datetime parts |
413 | 416 |
for parts in ( |
... | ... | |
452 | 455 |
resp = resp.form.submit() |
453 | 456 |
resp = resp.follow() |
454 | 457 |
event = Event.objects.get(places=10) |
455 |
assert not "This agenda doesn't have any event yet." in resp.text
|
|
458 |
assert "This agenda doesn't have any event yet." not in resp.text
|
|
456 | 459 |
assert '/manage/agendas/%s/events/%s/edit' % (agenda.id, event.id) in resp.text |
457 | 460 |
assert 'Feb. 15, 2016, 5 p.m.' in resp.text |
458 | 461 |
assert '10 places' in resp.text |
... | ... | |
468 | 471 |
resp = resp.click('Feb. 15, 2016, 5 p.m.') |
469 | 472 |
assert resp.form['start_datetime$date'].value == '2016-02-15' |
470 | 473 |
assert resp.form['start_datetime$time'].value == '17:00' |
474 |
assert resp.form['publication_date'].value == '' |
|
471 | 475 |
resp.form['start_datetime$date'] = '2016-02-16' |
472 | 476 |
resp.form['start_datetime$time'] = '17:00' |
477 |
resp.form['publication_date'] = '2020-05-11' |
|
473 | 478 |
resp.form['places'] = 20 |
474 | 479 |
resp = resp.form.submit() |
475 | 480 |
resp = resp.follow() |
476 | 481 |
assert '/manage/agendas/%s/events/%s/edit' % (agenda.id, event.id) in resp.text |
477 | 482 |
assert 'Feb. 16, 2016, 5 p.m.' in resp.text |
478 | 483 |
assert '20 places' in resp.text |
484 |
event.refresh_from_db() |
|
485 |
assert event.publication_date == datetime.date(2020, 5, 11) |
|
479 | 486 | |
480 | 487 | |
481 | 488 |
def test_edit_missing_event(app, admin_user): |
... | ... | |
487 | 494 |
agenda = Agenda(label=u'Foo bar') |
488 | 495 |
agenda.view_role = manager_user.groups.all()[0] |
489 | 496 |
agenda.save() |
490 |
event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)), places=20, agenda=agenda) |
|
491 |
event.save() |
|
497 |
event = Event.objects.create( |
|
498 |
start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)), |
|
499 |
places=20, |
|
500 |
agenda=agenda, |
|
501 |
publication_date=datetime.date(2020, 5, 11), |
|
502 |
) |
|
492 | 503 |
app = login(app, username='manager', password='manager') |
493 | 504 |
resp = app.get('/manage/agendas/%s/events/%s/edit' % (agenda.id, event.id), status=403) |
494 | 505 | |
... | ... | |
498 | 509 |
resp = resp.click('Feb. 15, 2016, 5 p.m.') |
499 | 510 |
assert resp.form['start_datetime$date'].value == '2016-02-15' |
500 | 511 |
assert resp.form['start_datetime$time'].value == '17:00' |
512 |
assert resp.form['publication_date'].value == '2020-05-11' |
|
501 | 513 |
resp.form['start_datetime$date'] = '2016-02-16' |
502 | 514 |
resp.form['start_datetime$time'] = '17:00' |
515 |
resp.form['publication_date'] = '' |
|
503 | 516 |
resp.form['places'] = 20 |
504 | 517 |
resp = resp.form.submit() |
505 | 518 |
resp = resp.follow() |
506 | 519 |
assert '/manage/agendas/%s/events/%s/edit' % (agenda.id, event.id) in resp.text |
507 | 520 |
assert 'Feb. 16, 2016, 5 p.m.' in resp.text |
508 | 521 |
assert '20 places' in resp.text |
522 |
event.refresh_from_db() |
|
523 |
assert event.publication_date is None |
|
509 | 524 | |
510 | 525 | |
511 | 526 |
def test_booked_places(app, admin_user): |
512 |
- |