Motion CSV Import: Create new category if category is unkown.

This commit is contained in:
Emanuel Schuetze 2014-05-18 20:17:42 +02:00
parent f958dd2ab0
commit 6bdfc33182
3 changed files with 9 additions and 6 deletions

View File

@ -17,6 +17,7 @@ Agenda:
- Fixed organizational item structuring.
Motions:
- New slide for vote results.
- Created new categories during CSV import.
Assignment:
- Coupled assignment candidates with list of speakers.
- Created a poll description field for each assignment poll.

View File

@ -78,11 +78,14 @@ def import_motions(csvfile, default_submitter, override, importing_person=None):
motion.reason = reason
if category:
try:
motion.category = Category.objects.get(name=category)
category_object = Category.objects.get(name=category)
except Category.DoesNotExist:
warning.append(_('Category unknown. No category is used.'))
category_object = Category.objects.create(name=category, prefix=category[:1])
warning.append(_('Category unknown. New category created.'))
except Category.MultipleObjectsReturned:
category_object = None
warning.append(_('Several suitable categories found. No category is used.'))
motion.category = category_object
motion.save()
# Add submitter

View File

@ -24,9 +24,8 @@ class CSVImport(TestCase):
self.normal_client.login(username='User_CiuNgo4giqueeChie5oi', password='eihi1Eequaek4eagaiKu')
# Category
self.category1 = Category.objects.create(name='Satzungsanträge', prefix='SA')
self.category2 = Category.objects.create(name='Bildung', prefix='B1')
self.category3 = Category.objects.create(name='Bildung', prefix='B2')
self.category1 = Category.objects.create(name='Bildung', prefix='B1')
self.category2 = Category.objects.create(name='Bildung', prefix='B2')
def test_example_file_de(self):
special_user = User.objects.create_user(username='Harry_Holland',
@ -66,7 +65,7 @@ class CSVImport(TestCase):
self.assertEqual(motion2.reason, u'Die Änderung der Satzung ist aufgrund der letzten Erfahrungen eine sinnvolle Maßnahme, weil ...')
self.assertEqual(len(motion2.submitter.all()), 1)
self.assertEqual(motion2.submitter.all()[0].person, special_user)
self.assertEqual(motion2.category, self.category1)
self.assertEqual(motion2.category.name, u"Satzungsanträge") # category is created automatically
# check user 'John Doe'
self.assertTrue('Several suitable submitters found.' in warning_message)