This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'group' into features/kulogin
- Loading branch information
Showing
21 changed files
with
265 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ db.sqlite3 | |
*.pyo | ||
.idea/ | ||
docs/_build | ||
.DS_Store |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
from django.contrib import admin | ||
|
||
from models import UserProfile | ||
# Register your models here. | ||
class UserProfileAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
'user', 'birthday', 'gender', | ||
'faculty', 'major', 'types') | ||
|
||
admin.site.register(UserProfile, UserProfileAdmin) |
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,30 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
from django.conf import settings | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserProfile', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('birthday', models.DateField(null=True, blank=True)), | ||
('gender', models.CharField(max_length=5, choices=[(b'M', b'Male'), (b'F', b'Female')])), | ||
('faculty', models.CharField(max_length=30)), | ||
('major', models.CharField(max_length=30)), | ||
('types', models.CharField(max_length=30)), | ||
('user', models.OneToOneField(related_name='profile', to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'db_table': 'youniversity_profile', | ||
}, | ||
), | ||
] |
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
Empty file.
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,16 @@ | ||
from django.contrib import admin | ||
from models import * | ||
|
||
|
||
class GroupAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
'name', 'type', 'description', 'long_description', | ||
'logo', 'header', 'permisssion') | ||
|
||
class GroupMemberAdmin(admin.ModelAdmin): | ||
list_display = ( | ||
'group_id','user_id', 'role') | ||
|
||
|
||
admin.site.register(Group, GroupAdmin) | ||
admin.site.register(GroupMember, GroupMemberAdmin) |
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,41 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Group', | ||
fields=[ | ||
('id', models.IntegerField(serialize=False, primary_key=True)), | ||
('name', models.CharField(max_length=25)), | ||
('type', models.IntegerField(default=0)), | ||
('description', models.CharField(max_length=50)), | ||
('long_description', models.CharField(max_length=200)), | ||
('logo', models.CharField(max_length=25)), | ||
('header', models.CharField(max_length=25)), | ||
('permisssion', models.IntegerField(default=0)), | ||
], | ||
options={ | ||
}, | ||
bases=(models.Model,), | ||
), | ||
migrations.CreateModel( | ||
name='Group_Member', | ||
fields=[ | ||
('id', models.IntegerField(serialize=False, primary_key=True)), | ||
('group_id', models.IntegerField(default=0)), | ||
('user_id', models.IntegerField(default=0)), | ||
('role', models.CharField(max_length=50)), | ||
], | ||
options={ | ||
}, | ||
bases=(models.Model,), | ||
), | ||
] |
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,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('group', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='group', | ||
name='id', | ||
field=models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), | ||
preserve_default=True, | ||
), | ||
migrations.AlterField( | ||
model_name='group_member', | ||
name='id', | ||
field=models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True), | ||
preserve_default=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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import models, migrations | ||
from django.conf import settings | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('group', '0002_auto_20150920_1117'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='GroupMember', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('role', models.CharField(max_length=50)), | ||
('group_id', models.ForeignKey(default=0, to='group.Group')), | ||
('user_id', models.ForeignKey(default=0, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.DeleteModel( | ||
name='Group_Member', | ||
), | ||
] |
Empty file.
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,21 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
|
||
|
||
# Create your models here. | ||
|
||
class Group(models.Model): | ||
name = models.CharField(max_length=25) | ||
type = models.IntegerField(default=0) | ||
description = models.CharField(max_length=50) | ||
long_description = models.CharField(max_length=200) | ||
logo = models.CharField(max_length=25) | ||
#logo_image = ImageField(upload_to=get_image_path, blank=True, null=True) | ||
header = models.CharField(max_length=25) | ||
#header_image = ImageField(upload_to=get_image_path, blank=True, null=True) | ||
permisssion = models.IntegerField(default=0) | ||
|
||
class GroupMember(models.Model): | ||
group_id = models.ForeignKey(Group, default=0) | ||
user_id = models.ForeignKey(User, default=0) | ||
role = models.CharField(max_length=50) |
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,7 @@ | ||
from rest_framework import serializers | ||
from models import * | ||
|
||
class GroupMemberSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = GroupMember | ||
fields = ('user_id', 'role') |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,6 @@ | ||
from django.conf.urls import include, url | ||
from . import views | ||
|
||
urlpatterns = [ | ||
url(r'^(?P<group_id>[0-9]+)/member', views.MemberViewSet.as_view(), name='GroupMember'), | ||
] |
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,40 @@ | ||
from rest_framework.response import Response | ||
from rest_framework.generics import ListCreateAPIView | ||
from rest_framework.exceptions import ValidationError, NotAuthenticated, NotFound | ||
|
||
from models import * | ||
from serializers import * | ||
|
||
class MemberViewSet(ListCreateAPIView): | ||
serializer_class = GroupMemberSerializer | ||
|
||
def get_group_id(self): | ||
try: | ||
return int(self.kwargs['group_id']) | ||
except ValueError: | ||
return ValidationError('group id cannot be parsed') | ||
|
||
def get_queryset(self): | ||
return GroupMember.objects.filter(group_id=self.get_group_id()) | ||
|
||
def create(self, *args, **kwargs): | ||
if not self.request.user.is_authenticated(): | ||
raise NotAuthenticated | ||
|
||
try: | ||
group = Group.objects.get(id=self.get_group_id()) | ||
except Group.DoesNotExist: | ||
raise NotFound('no such group') | ||
|
||
member, created = GroupMember.objects.get_or_create( | ||
group_id = Group.objects.get(id = self.get_group_id), | ||
user_id = User.objects.get( id = self.request.user.id), | ||
defaults = { | ||
'role': 0 | ||
} | ||
) | ||
|
||
if not created: | ||
raise ValidationError('request already exists') | ||
|
||
return Response(GroupMemberSerializer(member).data) |
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,6 @@ | ||
from rest_framework.authentication import SessionAuthentication | ||
|
||
class SessionCsrfExemptAuthentication(SessionAuthentication): | ||
|
||
def enforce_csrf(self, request): | ||
return # To not perform the csrf check previously happening |
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
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