0001-manager-extend-CSV-import-support-to-new-attributes-.patch
chrono/manager/forms.py | ||
---|---|---|
167 | 167 |
required=True, |
168 | 168 |
help_text=_( |
169 | 169 |
'CSV file with date, time, number of places, ' |
170 |
'number of places in waiting list, and label ' |
|
171 |
'as columns.' |
|
170 |
'number of places in waiting list, label, and ' |
|
171 |
'optionally, identifier, description, pricing ' |
|
172 |
'and URL as columns.' |
|
172 | 173 |
), |
173 | 174 |
) |
174 | 175 |
events = None |
... | ... | |
236 | 237 |
event.label = force_text(csvline[4]) |
237 | 238 |
exclude = ['desk', 'meeting_type'] |
238 | 239 |
if len(csvline) >= 6: |
239 |
event.slug = ' '.join([force_text(x) for x in csvline[5:]])
|
|
240 |
event.slug = force_text(csvline[5])
|
|
240 | 241 |
else: |
241 | 242 |
exclude += ['slug'] |
243 |
column_index = 7 |
|
244 |
for more_attr in ('description', 'pricing', 'url'): |
|
245 |
if len(csvline) >= column_index: |
|
246 |
setattr(event, more_attr, csvline[column_index - 1]) |
|
247 |
column_index += 1 |
|
248 | ||
242 | 249 |
try: |
243 | 250 |
event.full_clean(exclude=exclude) |
244 | 251 |
except ValidationError as e: |
chrono/manager/templates/chrono/manager_sample_events.txt | ||
---|---|---|
1 |
{% load i18n %}{% trans 'date' %},{% trans 'time' %},{% trans 'number of places' %},{% trans 'number of places in waiting list' %},{% trans 'label' %},{% trans 'identifier' %} |
|
2 |
{{ some_future_date|date:"Y-m-d" }},{{ some_future_date|date:"H:i" }},15,0,{% trans "example event" as label %}{{ label }},{{ label|slugify }} |
|
1 |
{% load i18n %}{% trans 'date' %},{% trans 'time' %},{% trans 'number of places' %},{% trans 'number of places in waiting list' %},{% trans 'label' %},{% trans 'identifier' %},{% trans 'description' %},{% trans 'pricing' %},{% trans 'URL' %} |
|
2 |
{{ some_future_date|date:"Y-m-d" }},{{ some_future_date|date:"H:i" }},15,0,{% trans "example event" as label %}{{ label }},{{ label|slugify }},,,https://www.example.net |
tests/test_manager.py | ||
---|---|---|
716 | 716 |
resp = resp.form.submit(status=200) |
717 | 717 |
assert 'Invalid file format. (__all__: Event with this Agenda and Identifier already exists.' in resp.text |
718 | 718 | |
719 |
# additional optional attributes |
|
720 |
Event.objects.all().delete() |
|
721 |
resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200) |
|
722 |
resp.form['events_csv_file'] = Upload( |
|
723 |
't.csv', b'2016-09-16,18:00,10,5,label,slug,description,pricing,url', 'text/csv' |
|
724 |
) |
|
725 |
resp = resp.form.submit(status=302) |
|
726 |
assert Event.objects.count() == 1 |
|
727 |
assert Event.objects.all()[0].description == 'description' |
|
728 |
assert Event.objects.all()[0].pricing == 'pricing' |
|
729 |
assert Event.objects.all()[0].url == 'url' |
|
730 | ||
719 | 731 | |
720 | 732 |
def test_add_meetings_agenda(app, admin_user): |
721 | 733 |
app = login(app) |
722 |
- |