diff --git a/cfp/migrations/0022_auto_20171201_1800.py b/cfp/migrations/0022_auto_20171201_1800.py new file mode 100644 index 0000000..f3d84ea --- /dev/null +++ b/cfp/migrations/0022_auto_20171201_1800.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-12-01 18:00 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cfp', '0021_conference_video_publishing_date'), + ] + + operations = [ + migrations.RenameField( + model_name='activity', + old_name='volunteers', + new_name='old_volunteers', + ), + migrations.AlterField( + model_name='activity', + name='old_volunteers', + field=models.ManyToManyField(blank=True, related_name='old_activities', to='cfp.Volunteer', verbose_name='Volunteer'), + ), + migrations.AddField( + model_name='volunteer', + name='activities', + field=models.ManyToManyField(blank=True, related_name='volunteers', to='cfp.Activity', verbose_name='Activities'), + ), + ] diff --git a/cfp/migrations/0023_auto_20171201_1801.py b/cfp/migrations/0023_auto_20171201_1801.py new file mode 100644 index 0000000..97b2a3c --- /dev/null +++ b/cfp/migrations/0023_auto_20171201_1801.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-12-01 18:01 +from __future__ import unicode_literals + +from django.db import migrations + + +def forward(apps, schema_editor): + db_alias = schema_editor.connection.alias + Volunteer = apps.get_model("cfp", "Volunteer") + for volunteer in Volunteer.objects.using(db_alias).all(): + for activity in volunteer.old_activities.all(): + volunteer.activities.add(activity) + + +def backward(apps, schema_editor): + db_alias = schema_editor.connection.alias + Activity = apps.get_model("cfp", "Activity") + for activity in Activity.objects.using(db_alias).all(): + for volunteer in activity.volunteers.all(): + activity.old_volunteers.add(volunteer) + + +class Migration(migrations.Migration): + + dependencies = [ + ('cfp', '0022_auto_20171201_1800'), + ] + + operations = [ + migrations.RunPython(forward, backward), + ] diff --git a/cfp/migrations/0024_remove_activity_old_volunteers.py b/cfp/migrations/0024_remove_activity_old_volunteers.py new file mode 100644 index 0000000..c7681e6 --- /dev/null +++ b/cfp/migrations/0024_remove_activity_old_volunteers.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.1 on 2017-12-01 18:51 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('cfp', '0023_auto_20171201_1801'), + ] + + operations = [ + migrations.RemoveField( + model_name='activity', + name='old_volunteers', + ), + ] diff --git a/cfp/models.py b/cfp/models.py index 72c6284..e1a95d0 100644 --- a/cfp/models.py +++ b/cfp/models.py @@ -459,6 +459,27 @@ class Vote(PonyConfModel): return self.talk.get_absolute_url() +class Activity(models.Model): + site = models.ForeignKey(Site, on_delete=models.CASCADE) + name = models.CharField(max_length=256, verbose_name=_('Name')) + slug = AutoSlugField(populate_from='name') + description = models.TextField(blank=True, verbose_name=_('Description')) + + class Meta: + unique_together = ('site', 'name') + verbose_name = _('Activity') + verbose_name_plural = _('Activities') + + def get_absolute_url(self): + return reverse('activity-list') + + def get_filter_url(self): + return reverse('volunteer-list') + '?activity=' + self.slug + + def __str__(self): + return self.name + + class Volunteer(PonyConfModel): site = models.ForeignKey(Site, on_delete=models.CASCADE) name = models.CharField(max_length=128, verbose_name=_('Your Name')) @@ -469,6 +490,7 @@ class Volunteer(PonyConfModel): language = models.CharField(max_length=10, blank=True) notes = models.TextField(default='', blank=True, verbose_name=_('Notes'), help_text=_('If you have some constraints, you can indicate them here.')) + activities = models.ManyToManyField(Activity, blank=True, related_name='volunteers', verbose_name=_('Activities')) conversation = models.OneToOneField(MessageThread) def get_absolute_url(self): @@ -496,25 +518,3 @@ class Volunteer(PonyConfModel): def __str__(self): return str(self.name) - - -class Activity(models.Model): - site = models.ForeignKey(Site, on_delete=models.CASCADE) - name = models.CharField(max_length=256, verbose_name=_('Name')) - slug = AutoSlugField(populate_from='name') - description = models.TextField(blank=True, verbose_name=_('Description')) - volunteers = models.ManyToManyField(Volunteer, blank=True, related_name='activities', verbose_name=_('Volunteer')) - - class Meta: - unique_together = ('site', 'name') - verbose_name = _('Activity') - verbose_name_plural = _('Activities') - - def get_absolute_url(self): - return reverse('activity-list') - - def get_filter_url(self): - return reverse('volunteer-list') + '?activity=' + self.slug - - def __str__(self): - return self.name diff --git a/cfp/views.py b/cfp/views.py index 5f969b2..5645a0f 100644 --- a/cfp/views.py +++ b/cfp/views.py @@ -62,6 +62,7 @@ def volunteer_enrole(request): if request.user.is_authenticated(): volunteer.email = request.user.email volunteer.save() + form.save_m2m() body = _("""Hi {}, Thank your for your help in the organization of the conference {}! @@ -130,12 +131,10 @@ def volunteer_dashboard(request, volunteer): def volunteer_update_activity(request, volunteer, activity, join): activity = get_object_or_404(Activity, slug=activity, site=request.conference.site) if join: - activity.volunteers.add(volunteer) - activity.save() + volunteer.activities.add(activity) messages.success(request, _('Thank you for your participation!')) else: - activity.volunteers.remove(volunteer) - activity.save() + volunteer.activities.remove(activity) messages.success(request, _('Okay, no problem!')) return redirect(reverse('volunteer-dashboard', kwargs=dict(volunteer_token=volunteer.token)))