-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from ProjetSigma/feature/110-group-creation
Feature/110 group creation
- Loading branch information
Showing
15 changed files
with
482 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-01-26 13:41 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0009_auto_20160111_0057'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='School', | ||
fields=[ | ||
('group_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='sigma_core.Group')), | ||
('design', models.CharField(max_length=255)), | ||
], | ||
bases=('sigma_core.group',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-01-27 14:24 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0010_school'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SchoolGroup', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('validated', models.BooleanField(default=False)), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('updated', models.DateTimeField(auto_now=True)), | ||
('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='group_schools', to='sigma_core.Group')), | ||
('school', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='school_groups', to='sigma_core.School')), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9 on 2016-01-27 17:48 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('sigma_core', '0011_schoolgroup'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GroupAcknowledgment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('validated', models.BooleanField(default=False)), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('updated', models.DateTimeField(auto_now=True)), | ||
], | ||
), | ||
migrations.RemoveField( | ||
model_name='schoolgroup', | ||
name='group', | ||
), | ||
migrations.RemoveField( | ||
model_name='schoolgroup', | ||
name='school', | ||
), | ||
migrations.AddField( | ||
model_name='group', | ||
name='resp_school', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='sigma_core.School'), | ||
), | ||
migrations.DeleteModel( | ||
name='SchoolGroup', | ||
), | ||
migrations.AddField( | ||
model_name='groupacknowledgment', | ||
name='asking_group', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='group_recognizers', to='sigma_core.Group'), | ||
), | ||
migrations.AddField( | ||
model_name='groupacknowledgment', | ||
name='validator_group', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='group_acknowledgments', to='sigma_core.Group'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from django.db import models | ||
|
||
from dry_rest_permissions.generics import allow_staff_or_superuser | ||
|
||
from sigma_core.models.group import Group | ||
|
||
|
||
class School(Group): | ||
design = models.CharField(max_length=255) | ||
|
||
def save(self, *args, **kwargs): | ||
""" | ||
Schools are special groups: some params cannot be specified by user. | ||
""" | ||
self.visibility = Group.VIS_PUBLIC | ||
self.type = Group.TYPE_SCHOOL | ||
self.default_member_rank = -1 | ||
self.req_rank_invite = Group.ADMINISTRATOR_RANK | ||
self.req_rank_kick = Group.ADMINISTRATOR_RANK | ||
self.req_rank_accept_join_requests = Group.ADMINISTRATOR_RANK | ||
self.req_rank_promote = Group.ADMINISTRATOR_RANK | ||
self.req_rank_demote = Group.ADMINISTRATOR_RANK | ||
self.req_rank_modify_group_infos = Group.ADMINISTRATOR_RANK | ||
self.resp_school = None | ||
|
||
return super(School, self).save(*args, **kwargs) | ||
|
||
# Permissions | ||
@staticmethod | ||
def has_read_permission(request): | ||
""" | ||
Schools list is visible by everybody. | ||
""" | ||
return True | ||
|
||
def has_object_read_permission(self, request): | ||
""" | ||
Schools are only visible by members. | ||
""" | ||
return request.user.is_group_member(self) | ||
|
||
@staticmethod | ||
@allow_staff_or_superuser | ||
def has_create_permission(request): | ||
""" | ||
Schools can be created by Sigma admin only. | ||
""" | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from rest_framework import serializers | ||
|
||
from sigma_core.models.school import School | ||
|
||
|
||
class BasicSchoolSerializer(serializers.ModelSerializer): | ||
""" | ||
Serialize School model without memberships. | ||
""" | ||
class Meta: | ||
model = School | ||
|
||
|
||
class SchoolSerializer(BasicSchoolSerializer): | ||
""" | ||
Serialize School model with memberships. | ||
""" | ||
class Meta: | ||
model = School | ||
|
||
acknowledged_groups = serializers.PrimaryKeyRelatedField(read_only=True, many=True) | ||
memberships = serializers.PrimaryKeyRelatedField(read_only=True, many=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.