Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Migrate InternGroup to Group #104

Merged
merged 4 commits into from
Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as _UserAdmin
from core.models import User, Semester, Card, NfcCard
from core.models import User, Semester, Card, NfcCard, Group

from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -46,3 +46,4 @@ class UserAdmin(_UserAdmin):
admin.site.register(Semester)
admin.site.register(Card)
admin.site.register(NfcCard)
admin.site.register(Group)
1 change: 1 addition & 0 deletions core/fixtures/group.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"model": "core.group", "pk": 1, "fields": {"name": "Hovedstyret", "leader": 1, "description": "HS sitt ansvar er \u00e5 drive foreningen"}}, {"model": "core.group", "pk": 2, "fields": {"name": "Kjellerstyret", "leader": 2, "description": "Kjellerstyret styrer Escape"}}, {"model": "core.group", "pk": 3, "fields": {"name": "\u00d8konomi", "leader": 1, "description": ""}}, {"model": "core.group", "pk": 4, "fields": {"name": "Arrangementsgruppen", "leader": 1, "description": ""}}, {"model": "core.group", "pk": 5, "fields": {"name": "Promotering", "leader": 1, "description": ""}}, {"model": "core.group", "pk": 6, "fields": {"name": "Bar", "leader": 1, "description": ""}}, {"model": "core.group", "pk": 7, "fields": {"name": "Kaf\u00e9", "leader": 1, "description": ""}}, {"model": "core.group", "pk": 8, "fields": {"name": "DJ", "leader": 1, "description": ""}}, {"model": "core.group", "pk": 9, "fields": {"name": "Arkivgruppen", "leader": 1, "description": ""}}, {"model": "core.group", "pk": 10, "fields": {"name": "Webgruppa", "leader": 1, "description": ""}}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kunne du pretty-formatert dette? Også mangler det en newline :p

31 changes: 31 additions & 0 deletions core/migrations/0008_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-12-18 21:41
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('core', '0007_auto_20160713_1508'),
('intern', '0002_auto_20161218_2243')
]

state_operations = [
migrations.CreateModel(
name='Group',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, unique=True)),
('description', models.CharField(blank=True, max_length=300, null=True)),
('leader', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

operations = [
migrations.SeparateDatabaseAndState(state_operations=state_operations)
]
8 changes: 8 additions & 0 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,11 @@ def __str__(self):
if not self.user:
return self.card_uid
return "%s (%s)" % (self.card_uid, self.user)

class Group(models.Model):
name = models.CharField(max_length=50, unique=True)
leader = models.ForeignKey(User)
description = models.CharField(max_length=300, null=True, blank=True)

def __str__(self):
return self.name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline?

9 changes: 7 additions & 2 deletions core/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


from core.serializers import CardCreateSerializer, CardSerializer, UserExtendedSerializer, NfcCardCreateSerializer, \
NfcCardSerializer
from core.models import Card, User, NfcCard
NfcCardSerializer, GroupSerializer
from core.models import Card, User, NfcCard, Group
from core.filters import CardFilter, UserFilter, NfcCardFilter
from core.permissions import CardPermission

Expand Down Expand Up @@ -85,3 +85,8 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet):

def get_serializer_class(self):
return UserExtendedSerializer

class GroupViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
serializer_class = GroupSerializer
queryset = Group.objects.all()
12 changes: 11 additions & 1 deletion core/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from core.models import User, Semester, Card, NfcCard
from core.models import Group, User, Semester, Card, NfcCard


class UserSimpleGuestSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -60,3 +60,13 @@ class Meta:
model = NfcCard
fields = ('card_uid', 'user', 'intern', 'comment')
extra_kwargs = {'user': {'default': None}, 'intern': {'default': False}, 'comment': {'default': None}}


class GroupSerializer(serializers.ModelSerializer):
leader = UserSerializer()

class Meta:
model = Group
fields = (
'id', 'name', 'leader', 'description'
)
3 changes: 2 additions & 1 deletion core/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from django.conf.urls import url
from core.views import me

from core.rest import CardViewSet, UserViewSet, NfcCardViewSet
from core.rest import CardViewSet, UserViewSet, NfcCardViewSet, GroupViewSet
from core.utils import SharedAPIRootRouter

# SharedAPIRootRouter is automatically imported in global urls config
router = SharedAPIRootRouter()
router.register(r'core/users', UserViewSet, base_name='users')
router.register(r'core/cards', CardViewSet, base_name='voucher_cards')
router.register(r'core/nfc', NfcCardViewSet)
router.register(r'core/groups', GroupViewSet)

urlpatterns = [
url(r'^api/me$', me, name='me'),
Expand Down
6 changes: 1 addition & 5 deletions intern/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from intern.models import Intern, InternCard, InternGroup, Role, AccessLevel, InternRole, InternLogEntry
from intern.models import Intern, InternCard, Role, AccessLevel, InternRole, InternLogEntry


class InternAdmin(admin.ModelAdmin):
Expand All @@ -10,9 +10,6 @@ class RoleAdmin(admin.ModelAdmin):
list_display = ('name', 'description')


class InternGroupAdmin(admin.ModelAdmin):
list_display = ('name', 'leader', 'description')


class AccessLevelAdmin(admin.ModelAdmin):
list_display = ('name', 'uio_name', 'description')
Expand All @@ -33,7 +30,6 @@ class InternLogEntryAdmin(admin.ModelAdmin):
# Register your models here.
admin.site.register(Intern, InternAdmin)
admin.site.register(Role, RoleAdmin)
admin.site.register(InternGroup, InternGroupAdmin)
admin.site.register(AccessLevel, AccessLevelAdmin)
admin.site.register(InternRole)
admin.site.register(InternCard, InternCardAdmin)
Expand Down
92 changes: 0 additions & 92 deletions intern/fixtures/groups.json

This file was deleted.

27 changes: 27 additions & 0 deletions intern/migrations/0002_auto_20161218_2243.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-12-18 21:43
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('intern', '0001_initial'),
]

database_operations = [
migrations.AlterModelTable('interngroup', 'core_group')
]

state_operations = [

]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=database_operations,
state_operations=state_operations
)
]
20 changes: 20 additions & 0 deletions intern/migrations/0003_auto_20161218_2255.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-12-18 21:55
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('intern', '0002_auto_20161218_2243'),
]

operations = [
migrations.AlterField(
model_name='role',
name='groups',
field=models.ManyToManyField(related_name='roles', to='core.Group'),
),
]
22 changes: 22 additions & 0 deletions intern/migrations/0004_auto_20161218_2309.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-12-18 22:09
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('intern', '0003_auto_20161218_2255'),
]

state_operations = [
migrations.DeleteModel(
name='InternGroup',
),
]

operations = [
migrations.SeparateDatabaseAndState(state_operations=state_operations)
]
14 changes: 2 additions & 12 deletions intern/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django.utils import timezone

from core.models import User, Semester, Card
from core.models import User, Semester, Card, Group
from core.utils import get_semester
from members.models import Member

Expand All @@ -15,20 +15,10 @@ class AccessLevel(models.Model):
def __str__(self):
return self.name


class InternGroup(models.Model):
name = models.CharField(max_length=50, unique=True)
leader = models.ForeignKey(User)
description = models.CharField(max_length=300, null=True, blank=True)

def __str__(self):
return self.name


class Role(models.Model):
name = models.CharField(max_length=50, unique=True)
description = models.CharField(max_length=300, null=True, blank=True)
groups = models.ManyToManyField(InternGroup, related_name='roles')
groups = models.ManyToManyField(Group, related_name='roles')
access_levels = models.ManyToManyField(AccessLevel)

def __str__(self):
Expand Down
9 changes: 6 additions & 3 deletions intern/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
from rest_framework.response import Response

from core.utils import get_semester
from core.models import Group
from core.serializers import GroupSerializer

from intern.models import *
from intern.serializers import InternRoleFullSerializer, InternSerializer, AccessLevelSerializer, InternGroupSerializer, \
from intern.serializers import InternRoleFullSerializer, InternSerializer, AccessLevelSerializer, \
RoleSerializer, AddInternRoleSerializer, InternCardSerializer, AddInternCardSerializer


Expand All @@ -24,9 +26,10 @@ class InternViewSet(viewsets.ModelViewSet):


class InternGroupViewSet(viewsets.ModelViewSet):
"""Deprecated. You should use api/core/groups instead"""
permission_classes = (DjangoModelPermissions,)
serializer_class = InternGroupSerializer
queryset = InternGroup.objects.all()
serializer_class = GroupSerializer
queryset = Group.objects.all()


class AccessLevelViewSet(viewsets.ReadOnlyModelViewSet):
Expand Down
16 changes: 3 additions & 13 deletions intern/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from rest_framework import serializers

from core.serializers import UserSerializer, CardSerializer, SemesterSerializer
from intern.models import AccessLevel, Intern, InternCard, InternGroup, InternRole, Role, InternLogEntry
from core.serializers import UserSerializer, CardSerializer, SemesterSerializer, GroupSerializer
from intern.models import AccessLevel, Intern, InternCard, InternRole, Role, Intern, InternLogEntry


class AccessLevelSerializer(serializers.ModelSerializer):
Expand All @@ -12,18 +12,8 @@ class Meta:
)


class InternGroupSerializer(serializers.ModelSerializer):
leader = UserSerializer()

class Meta:
model = InternGroup
fields = (
'id', 'name', 'leader', 'description'
)


class RoleSerializer(serializers.ModelSerializer):
groups = InternGroupSerializer(many=True)
groups = GroupSerializer(many=True)
access_levels = AccessLevelSerializer(many=True)

class Meta:
Expand Down
Loading