From 00939566966641e40a6b16f875eb325a9011a5a6 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 21 Jul 2017 15:48:40 +0200 Subject: [PATCH] Add event-specific groups and signals --- event/signals.py | 19 +++++++++++++++++++ users/migrations/0001_initial.py | 25 +++++++++++++++++++++++++ users/migrations/__init__.py | 0 users/models.py | 9 ++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 event/signals.py create mode 100644 users/migrations/0001_initial.py create mode 100644 users/migrations/__init__.py diff --git a/event/signals.py b/event/signals.py new file mode 100644 index 0000000..f942e3c --- /dev/null +++ b/event/signals.py @@ -0,0 +1,19 @@ +from django.dispatch import receiver +from django.db.models.signals import post_save +from event.models import Event +from shared.models import GEGroup + + +@receiver(post_save, sender=Event) +def create_groups_for_event(sender, **kwargs): + event, created = kwargs["instance"], kwargs["created"] + if created: + GEGroup.objects.create( + name="orga", + event=event + ) + + GEGroup.objects.create( + name="participants", + event=event, + ) diff --git a/users/migrations/0001_initial.py b/users/migrations/0001_initial.py new file mode 100644 index 0000000..2b464b1 --- /dev/null +++ b/users/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2017-07-20 13:37 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0008_alter_user_username_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='GEGroup', + fields=[ + ('group_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='auth.Group')), + ], + bases=('auth.group',), + ), + ] diff --git a/users/migrations/__init__.py b/users/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/users/models.py b/users/models.py index 85206e0..615d1b0 100644 --- a/users/models.py +++ b/users/models.py @@ -1,2 +1,9 @@ from django.db import models -from django.contrib.auth.models import User +from django.contrib.auth import get_user_model +from django.contrib.auth.models import Group + +User = get_user_model() + + +class GEGroup(Group): + pass