Commit 19a9d5da authored by Joren Vrancken's avatar Joren Vrancken Committed by Sébastiaan Versteeg
Browse files

Feedback gebruikt

parent ae183d91
import re
import json
import requests
import pytz
from django.contrib.auth.models import User
from datetime import datetime
from django.core.management.base import BaseCommand
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import timezone
import events.models as events_models
import members.models as members_models
FIELD_DATA_TYPES = {
'0': 'charfield',
'1': 'intfield',
'2': 'checkbox',
'0': events_models.RegistrationInformationField.TEXT_FIELD,
'1': events_models.RegistrationInformationField.INTEGER_FIELD,
'2': events_models.RegistrationInformationField.BOOLEAN_FIELD,
}
......@@ -22,18 +24,19 @@ def naive_to_aware(date_string):
to timezone aware datetime object"""
naive_datetime = datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S')
# TODO: I'm 50% sure this is not the right way
return pytz.timezone('Europe/Amsterdam').localize(naive_datetime)
return timezone.get_current_timezone().localize(naive_datetime)
class Command(BaseCommand):
help = 'Make the events database great.'
help = 'Migrate the events from the old website.'
def handle(self, *args, **options):
api_key = 'fcd7ad95a6ae9d70bc844e0f3dcd9b6518c7dd78'
if not settings.EVENTS_MIGRATION_KEY:
raise ImproperlyConfigured('EVENTS_MIGRATION_KEY not specified')
events_api_url = 'https://thalia.nu/events/api/?apikey={}'.format(
api_key)
settings.EVENTS_MIGRATION_KEY)
print('[*]Getting events json data')
try:
......@@ -91,15 +94,15 @@ class Command(BaseCommand):
'title', 'description', 'location',
'no_registration_message'):
for language_code in ('en', 'nl'):
django_multilangiualfield = '{}_{}'.format(
django_multilingualfield = '{}_{}'.format(
django_field, language_code)
if not hasattr(new_event, django_multilangiualfield):
if not hasattr(new_event, django_multilingualfield):
print('[!]Could neither find {} nor {}'.format(
django_field, django_multilangiualfield))
django_field, django_multilingualfield))
return
setattr(new_event, django_multilangiualfield,
setattr(new_event, django_multilingualfield,
concrete_data)
# DateTimeField
......@@ -192,14 +195,17 @@ class Command(BaseCommand):
'field': registration_field,
}
if registration_field.type == 'charfield':
if registration_field.type == events_models.\
RegistrationInformationField.TEXT_FIELD:
new_registration_information = events_models. \
TextRegistrationInformation(
value=field_info_data['value'],
**parameters
)
elif registration_field.type == 'checkbox':
elif registration_field.type == events_models.\
RegistrationInformationField.BOOLEAN_FIELD:
value = False
......@@ -210,6 +216,8 @@ class Command(BaseCommand):
events_models.BooleanRegistrationInformation(
value=value,
**parameters)
# registration_field.type == INTEGER_FIELD:
else:
new_registration_information = \
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-13 13:33
# Generated by Django 1.10.2 on 2016-10-21 10:15
from __future__ import unicode_literals
import django.core.validators
......@@ -9,6 +9,8 @@ import django.db.models.deletion
class Migration(migrations.Migration):
replaces = [('events', '0001_initial'), ('events', '0002_auto_20160813_1620'), ('events', '0003_remove_event_registration_required'), ('events', '0004_event_cancel_deadline'), ('events', '0005_auto_20160914_2154'), ('events', '0006_auto_20160928_1919'), ('events', '0006_auto_20160921_2201'), ('events', '0007_merge_20161016_1322'), ('events', '0008_auto_20161016_1704'), ('events', '0007_auto_20161009_2352'), ('events', '0009_merge_20161019_2025'), ('events', '0010_auto_20161019_2221'), ('events', '0011_auto_20161019_2235')]
initial = True
dependencies = [
......@@ -122,12 +124,144 @@ class Migration(migrations.Migration):
name='registration',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Registration'),
),
migrations.AddField(
model_name='registrationinformationfield',
name='required',
field=models.BooleanField(default=True, verbose_name='required'),
preserve_default=False,
),
migrations.AlterField(
model_name='registrationinformationfield',
name='type',
field=models.CharField(choices=[('boolean', 'Checkbox'), ('text', 'Text'), ('integer', 'Integer')], max_length=10, verbose_name='field type'),
),
migrations.RemoveField(
model_name='registrationinformationfield',
name='description',
),
migrations.RemoveField(
model_name='registrationinformationfield',
name='name',
),
migrations.AddField(
model_name='registrationinformationfield',
name='description_en',
field=models.TextField(blank=True, null=True, verbose_name='description (EN)'),
),
migrations.AddField(
model_name='registrationinformationfield',
name='description_nl',
field=models.TextField(blank=True, null=True, verbose_name='description (NL)'),
),
migrations.AddField(
model_name='registrationinformationfield',
name='name_en',
field=models.CharField(default='foo', max_length=100, verbose_name='field name (EN)'),
preserve_default=False,
),
migrations.AddField(
model_name='registrationinformationfield',
name='name_nl',
field=models.CharField(default='bar', max_length=100, verbose_name='field name (NL)'),
preserve_default=False,
),
migrations.AlterOrderWithRespectTo(
name='registrationinformationfield',
order_with_respect_to='event',
),
migrations.AlterField(
model_name='registration',
name='paid',
field=models.BooleanField(default=False, verbose_name='paid'),
),
migrations.AlterField(
model_name='registration',
name='present',
field=models.BooleanField(default=False, verbose_name='present'),
),
migrations.AlterUniqueTogether(
name='registration',
unique_together=set([('member', 'event', 'name', 'date_cancelled')]),
),
migrations.AlterField(
model_name='event',
name='organiser',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='activemembers.Committee'),
),
migrations.RemoveField(
model_name='event',
name='registration_required',
),
migrations.AddField(
model_name='event',
name='cancel_deadline',
field=models.DateTimeField(blank=True, null=True, verbose_name='cancel deadline'),
),
migrations.RemoveField(
model_name='event',
name='location',
),
migrations.RemoveField(
model_name='event',
name='no_registration_message',
),
migrations.RemoveField(
model_name='event',
name='title',
),
migrations.AddField(
model_name='event',
name='location_en',
field=models.CharField(default='', max_length=255, verbose_name='location (EN)'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='location_nl',
field=models.CharField(default='', max_length=255, verbose_name='location (NL)'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='no_registration_message_en',
field=models.CharField(blank=True, help_text='Default: No registration required', max_length=200, null=True, verbose_name='message when there is no registration (EN)'),
),
migrations.AddField(
model_name='event',
name='no_registration_message_nl',
field=models.CharField(blank=True, help_text='Default: No registration required', max_length=200, null=True, verbose_name='message when there is no registration (NL)'),
),
migrations.AddField(
model_name='event',
name='title_en',
field=models.CharField(default='', max_length=100, verbose_name='title (EN)'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='title_nl',
field=models.CharField(default='', max_length=100, verbose_name='title (NL)'),
preserve_default=False,
),
migrations.AlterField(
model_name='event',
name='organiser',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='activemembers.Committee', verbose_name='organiser'),
),
migrations.RemoveField(
model_name='event',
name='description',
),
migrations.AddField(
model_name='event',
name='description_en',
field=models.TextField(default='', verbose_name='description (EN)'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='description_nl',
field=models.TextField(default='', verbose_name='description (NL)'),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-13 14:20
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='event',
name='organiser',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='activemembers.Committee'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-13 14:21
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0002_auto_20160813_1620'),
]
operations = [
migrations.RemoveField(
model_name='event',
name='registration_required',
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-31 19:39
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0003_remove_event_registration_required'),
]
operations = [
migrations.AddField(
model_name='event',
name='cancel_deadline',
field=models.DateTimeField(blank=True, null=True, verbose_name='cancel deadline'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-09-14 19:54
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('events', '0004_event_cancel_deadline'),
]
operations = [
migrations.RemoveField(
model_name='event',
name='location',
),
migrations.RemoveField(
model_name='event',
name='no_registration_message',
),
migrations.RemoveField(
model_name='event',
name='title',
),
migrations.AddField(
model_name='event',
name='location_en',
field=models.CharField(default='', max_length=255, verbose_name='location (EN)'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='location_nl',
field=models.CharField(default='', max_length=255, verbose_name='location (NL)'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='no_registration_message_en',
field=models.CharField(blank=True, help_text='Default: No registration required', max_length=200, null=True, verbose_name='message when there is no registration (EN)'),
),
migrations.AddField(
model_name='event',
name='no_registration_message_nl',
field=models.CharField(blank=True, help_text='Default: No registration required', max_length=200, null=True, verbose_name='message when there is no registration (NL)'),
),
migrations.AddField(
model_name='event',
name='title_en',
field=models.CharField(default='', max_length=100, verbose_name='title (EN)'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='title_nl',
field=models.CharField(default='', max_length=100, verbose_name='title (NL)'),
preserve_default=False,
),
migrations.AlterField(
model_name='event',
name='organiser',
field=models.ForeignKey(null=True,
on_delete=django.db.models.deletion.SET_NULL, to='activemembers.Committee', verbose_name='organiser'),
),
migrations.AlterField(
model_name='registration',
name='paid',
field=models.BooleanField(default=False, verbose_name='paid'),
),
migrations.AlterField(
model_name='registration',
name='present',
field=models.BooleanField(default=False, verbose_name='present'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-09-21 20:01
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0005_auto_20160914_2154'),
]
operations = [
migrations.RemoveField(
model_name='event',
name='description',
),
migrations.AddField(
model_name='event',
name='description_en',
field=models.TextField(default='', verbose_name='description (EN)'),
preserve_default=False,
),
migrations.AddField(
model_name='event',
name='description_nl',
field=models.TextField(default='', verbose_name='description (NL)'),
preserve_default=False,
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-09-28 17:19
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0005_auto_20160914_2154'),
]
operations = [
migrations.AddField(
model_name='booleanregistrationinformation',
name='explanation_field',
field=models.TextField(blank=True, null=True, verbose_name='explanation_field'),
),
migrations.AddField(
model_name='integerregistrationinformation',
name='explanation_field',
field=models.TextField(blank=True, null=True, verbose_name='explanation_field'),
),
migrations.AddField(
model_name='textregistrationinformation',
name='explanation_field',
field=models.TextField(blank=True, null=True, verbose_name='explanation_field'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-10-09 21:52
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0006_auto_20160921_2201'),
]
operations = [
migrations.AddField(
model_name='registrationinformationfield',
name='required',
field=models.BooleanField(default=True, verbose_name='required'),
preserve_default=False,
),
migrations.AlterField(
model_name='registrationinformationfield',
name='type',
field=models.CharField(choices=[('boolean', 'Checkbox'), ('text', 'Text'), ('integer', 'Integer')], max_length=10, verbose_name='field type'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-10-16 11:22
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0006_auto_20160921_2201'),
('events', '0006_auto_20160928_1919'),
]
operations = [
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-10-16 15:04
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0007_merge_20161016_1322'),
]
operations = [
migrations.RemoveField(
model_name='booleanregistrationinformation',
name='explanation_field',
),
migrations.RemoveField(
model_name='integerregistrationinformation',
name='explanation_field',
),
migrations.RemoveField(
model_name='textregistrationinformation',
name='explanation_field',
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-10-19 18:25
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0008_auto_20161016_1704'),
('events', '0007_auto_20161009_2352'),
]
operations = [
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-10-19 20:21
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0009_merge_20161019_2025'),
]
operations = [
migrations.RemoveField(
model_name='registrationinformationfield',
name='description',
),
migrations.RemoveField(
model_name='registrationinformationfield',
name='name',
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2016-10-19 20:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [