Commit e8079030e46eb506b6f03157dcdfdb69cf3fde3e
Exists in
master
Test
Merge branch 'master' of https://git.ucsd.edu/110swag/flashy-backend
Showing 6 changed files Inline Diff
flashcards/admin.py
View file @
e807903
from django.contrib import admin | 1 | 1 | from django.contrib import admin | |
from flashcards.models import Flashcard, UserFlashcard, Section, FlashcardMask, \ | 2 | 2 | from flashcards.models import Flashcard, UserFlashcard, Section, FlashcardMask, \ | |
UserFlashcardReview | 3 | 3 | UserFlashcardReview, LecturePeriod, User | |
4 | from simple_email_confirmation import EmailAddress | |||
4 | 5 | |||
admin.site.register([ | 5 | 6 | admin.site.register([ | |
7 | User, | |||
Flashcard, | 6 | 8 | Flashcard, | |
FlashcardMask, | 7 | 9 | FlashcardMask, | |
UserFlashcard, | 8 | 10 | UserFlashcard, | |
UserFlashcardReview, | 9 | 11 | UserFlashcardReview, | |
Section | 10 | 12 | Section, | |
13 | LecturePeriod | |||
]) | 11 | 14 | ]) | |
flashcards/api.py
View file @
e807903
from django.core.mail import send_mail | 1 | 1 | from django.core.mail import send_mail | |
2 | from django.contrib.auth import authenticate, login | |||
3 | from django.contrib.auth.tokens import default_token_generator | |||
from rest_framework.views import APIView | 2 | 4 | from rest_framework.views import APIView | |
from rest_framework.response import Response | 3 | 5 | from rest_framework.response import Response | |
from rest_framework import status | 4 | 6 | from rest_framework import status | |
from rest_framework.exceptions import ValidationError | 5 | 7 | from rest_framework.exceptions import ValidationError, NotFound | |
from flashcards.serializers import * | 6 | 8 | from flashcards.serializers import * | |
7 | 9 | |||
8 | 10 | |||
class UserDetail(APIView): | 9 | 11 | class UserDetail(APIView): | |
def patch(self, request, format=None): | 10 | 12 | def patch(self, request, format=None): | |
""" | 11 | 13 | """ | |
Updates a user's password after they enter a valid old password. | 12 | 14 | Updates a user's password after they enter a valid old password. | |
TODO: email verification | 13 | 15 | TODO: email verification | |
""" | 14 | 16 | """ | |
15 | 17 | |||
if 'old_password' not in request.data: | 16 | 18 | if 'old_password' not in request.data: | |
raise ValidationError('Old password is required') | 17 | 19 | raise ValidationError('Old password is required') | |
if 'new_password' not in request.data: | 18 | 20 | if 'new_password' not in request.data: | |
raise ValidationError('New password is required') | 19 | 21 | raise ValidationError('New password is required') | |
if not request.data['new_password']: | 20 | 22 | if not request.data['new_password']: | |
raise ValidationError('Password cannot be blank') | 21 | 23 | raise ValidationError('Password cannot be blank') | |
22 | 24 | |||
currentuser = request.user | 23 | 25 | currentuser = request.user | |
24 | 26 | |||
if not currentuser.check_password(request.data['old_password']): | 25 | 27 | if not currentuser.check_password(request.data['old_password']): | |
raise ValidationError('Invalid old password') | 26 | 28 | raise ValidationError('Invalid old password') | |
27 | 29 | |||
send_mail("Please verify your Flashy account", | 28 | 30 | send_mail("Please verify your Flashy account", | |
body % currentuser.confirmation_key, | 29 | 31 | body % currentuser.confirmation_key, | |
"noreply@flashy.cards", | 30 | 32 | "noreply@flashy.cards", | |
[currentuser.email]) | 31 | 33 | [currentuser.email]) | |
32 | 34 | |||
currentuser.confirm_email( currentuser.confirmation_key ) | 33 | 35 | currentuser.confirm_email( currentuser.confirmation_key ) | |
34 | 36 | |||
if currentuser.isconfirmed | 35 | 37 | if currentuser.isconfirmed | |
currentuser.set_password(request.data['new_password']) | 36 | 38 | currentuser.set_password(request.data['new_password']) | |
currentuser.save() | 37 | 39 | currentuser.save() | |
38 | 40 | |||
return Response(status=status.HTTP_204_NO_CONTENT) | 39 | 41 | return Response(status=status.HTTP_204_NO_CONTENT) | |
40 | 42 | |||
def get(self, request, format=None): | 41 | 43 | def get(self, request, format=None): | |
serializer = UserSerializer(request.user) | 42 | 44 | serializer = UserSerializer(request.user) | |
return Response(serializer.data) | 43 | 45 | return Response(serializer.data) | |
44 | 46 | |||
def post(self, request, format=None): | 45 | 47 | def post(self, request, format=None): | |
if 'email' not in request.data: | 46 | 48 | if 'email' not in request.data: | |
raise ValidationError('Email is required') | 47 | 49 | raise ValidationError('Email is required') | |
if 'password' not in request.data: | 48 | 50 | if 'password' not in request.data: | |
raise ValidationError('Password is required') | 49 | 51 | raise ValidationError('Password is required') | |
50 | 52 | |||
email = request.data['email'] | 51 | 53 | email = request.data['email'] | |
user = User.objects.create_user(email) | 52 | 54 | user = User.objects.create_user(email, email=email, password=request.data['password']) | |
53 | 55 | |||
body = ''' | 54 | 56 | body = ''' | |
Visit the following link to confirm your email address: | 55 | 57 | Visit the following link to confirm your email address: | |
http://flashy.cards/app/verify_email/%s | 56 | 58 | http://flashy.cards/app/verify_email/%s | |
57 | 59 | |||
If you did not register for Flashy, no action is required. | 58 | 60 | If you did not register for Flashy, no action is required. | |
''' | 59 | 61 | ''' | |
60 | 62 | |||
send_mail("Please verify your Flashy account", | 61 | 63 | send_mail("Please verify your Flashy account", | |
body % user.confirmation_key, | 62 | 64 | body % user.confirmation_key, | |
"noreply@flashy.cards", | 63 | 65 | "noreply@flashy.cards", | |
[user.email]) | 64 | 66 | [user.email]) | |
65 | 67 | |||
68 | user = authenticate(email=email, password=request.data['password']) | |||
69 | login(request, user) | |||
70 | return Response(UserSerializer(user).data) | |||
71 | ||||
72 | def delete(self, request, format=None): | |||
73 | request.user.delete() | |||
74 | return Response(status=status.HTTP_204_NO_CONTENT) | |||
75 | ||||
76 | ||||
77 | class UserLogin(APIView): | |||
78 | """ | |||
79 | Authenticates user and returns user data if valid. Handles invalid | |||
80 | users. | |||
81 | """ | |||
82 | ||||
83 | def post(self, request, format=None): | |||
84 | """ | |||
85 | Returns user data if valid. | |||
86 | """ | |||
87 | if 'email' not in request.data: | |||
88 | raise ValidationError('Email is required') | |||
89 | if 'password' not in request.data: | |||
90 | raise ValidationError('Password is required') | |||
91 | ||||
92 | email = request.data['email'] | |||
93 | password = request.data['password'] | |||
94 | user = authenticate(username=email, password=password) | |||
95 | ||||
96 | if user is None: | |||
97 | raise ValidationError('Invalid email or password') | |||
98 | if not user.is_active: | |||
99 | raise ValidationError('Account is disabled') | |||
100 | login(request, user) | |||
return Response(UserSerializer(User).data) | 66 | 101 | return Response(UserSerializer(User).data) | |
102 | ||||
103 | ||||
104 | class PasswordReset(APIView): | |||
105 | """ | |||
106 | Allows user to reset their password. | |||
107 | """ | |||
108 | ||||
109 | def post(self, request, format=None): | |||
110 | """ | |||
111 | Send a password reset token/link to the provided email. | |||
112 | """ | |||
113 | if 'email' not in request.data: | |||
114 | raise ValidationError('Email is required') | |||
115 | ||||
116 | email = request.data['email'] | |||
117 | ||||
118 | # Find the user since they are not logged in. | |||
119 | try: | |||
120 | user = User.objects.get(email=email) | |||
121 | except User.DoesNotExist: | |||
122 | raise NotFound('Email does not exist') | |||
123 | ||||
124 | token = default_token_generator.make_token(user) | |||
125 | ||||
126 | body = ''' | |||
127 | Visit the following link to reset your password: | |||
128 | http://flashy.cards/app/reset_password/%d/%s | |||
129 | ||||
130 | If you did not request a password reset, no action is required. | |||
131 | ''' | |||
132 | ||||
133 | send_mail("Flashy password reset", | |||
134 | body % (user.pk, token), | |||
135 | "noreply@flashy.cards", | |||
136 | [user.email]) | |||
137 | ||||
138 | return Response(status=status.HTTP_204_NO_CONTENT) | |||
139 | ||||
140 | def patch(self, request, format=None): |
flashcards/models.py
View file @
e807903
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin | 1 | 1 | from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin, AbstractUser | |
from django.contrib.auth.tests.custom_user import CustomUser | 2 | 2 | from django.contrib.auth.tests.custom_user import CustomUser | |
from django.db.models import * | 3 | 3 | from django.db.models import * | |
from simple_email_confirmation import SimpleEmailConfirmationUserMixin | 4 | 4 | from simple_email_confirmation import SimpleEmailConfirmationUserMixin | |
5 | 5 | |||
6 | # Hack to fix AbstractUser before subclassing it | |||
7 | AbstractUser._meta.get_field('email')._unique = True | |||
6 | 8 | |||
class UserManager(BaseUserManager): | 7 | 9 | class User(AbstractUser, SimpleEmailConfirmationUserMixin, ): | |
def create_user(self, email, password=None): | 8 | |||
""" | 9 | |||
Creates and saves a User with the given email, date of | 10 | |||
birth and password. | 11 | |||
""" | 12 | |||
if not email: | 13 | |||
raise ValueError('Users must have an email address') | 14 | |||
15 | ||||
user = self.model(email=self.normalize_email(email)) | 16 | |||
17 | ||||
user.set_password(password) | 18 | |||
user.save(using=self._db) | 19 | |||
return user | 20 | |||
21 | ||||
def create_superuser(self, email, password): | 22 | |||
""" | 23 | |||
Creates and saves a superuser with the given email and password. | 24 | |||
""" | 25 | |||
user = self.create_user(email, password=password) | 26 | |||
user.is_staff = True | 27 | |||
user.save(using=self._db) | 28 | |||
return user | 29 | |||
30 | ||||
31 | ||||
class User(AbstractBaseUser, SimpleEmailConfirmationUserMixin, ): | 32 | |||
USERNAME_FIELD = 'email' | 33 | 10 | USERNAME_FIELD = 'email' | |
REQUIRED_FIELDS = [] | 34 | 11 | REQUIRED_FIELDS = [] | |
35 | ||||
objects = UserManager() | 36 | |||
is_staff = BooleanField(default=False) | 37 | |||
38 | ||||
email = EmailField( | 39 | |||
verbose_name='email address', | 40 | |||
max_length=255, | 41 | |||
unique=True, | 42 | |||
) | 43 | |||
date_joined = DateTimeField(auto_now_add=True) | 44 | |||
sections = ManyToManyField('Section') | 45 | 12 | sections = ManyToManyField('Section') | |
46 | 13 | |||
47 | 14 | |||
class UserFlashcard(Model): | 48 | 15 | class UserFlashcard(Model): | |
""" | 49 | 16 | """ | |
Represents the relationship between a user and a flashcard by: | 50 | 17 | Represents the relationship between a user and a flashcard by: | |
1. A user has a flashcard in their deck | 51 | 18 | 1. A user has a flashcard in their deck | |
2. A user used to have a flashcard in their deck | 52 | 19 | 2. A user used to have a flashcard in their deck | |
3. A user has a flashcard hidden from them | 53 | 20 | 3. A user has a flashcard hidden from them | |
""" | 54 | 21 | """ | |
user = ForeignKey(User) | 55 | 22 | user = ForeignKey('User') | |
mask = ForeignKey('FlashcardMask', help_text="A mask which overrides the card's mask") | 56 | 23 | mask = ForeignKey('FlashcardMask', help_text="A mask which overrides the card's mask") | |
pulled = DateTimeField(blank=True, null=True, help_text="When the user pulled the card") | 57 | 24 | pulled = DateTimeField(blank=True, null=True, help_text="When the user pulled the card") | |
flashcard = ForeignKey('Flashcard') | 58 | 25 | flashcard = ForeignKey('Flashcard') | |
unpulled = DateTimeField(blank=True, null=True, help_text="When the user unpulled this card") | 59 | 26 | unpulled = DateTimeField(blank=True, null=True, help_text="When the user unpulled this card") | |
60 | 27 | |||
class Meta: | 61 | 28 | class Meta: | |
# There can be at most one UserFlashcard for each User and Flashcard | 62 | 29 | # There can be at most one UserFlashcard for each User and Flashcard | |
unique_together = (('user', 'flashcard'),) | 63 | 30 | unique_together = (('user', 'flashcard'),) | |
index_together = ["user", "flashcard"] | 64 | 31 | index_together = ["user", "flashcard"] | |
# By default, order by most recently pulled | 65 | 32 | # By default, order by most recently pulled | |
ordering = ['-pulled'] | 66 | 33 | ordering = ['-pulled'] | |
67 | 34 | |||
def is_hidden(self): | 68 | 35 | def is_hidden(self): | |
""" | 69 | 36 | """ | |
A card is hidden only if a user has not ever added it to their deck. | 70 | 37 | A card is hidden only if a user has not ever added it to their deck. | |
:return: Whether the flashcard is hidden from the user | 71 | 38 | :return: Whether the flashcard is hidden from the user | |
""" | 72 | 39 | """ | |
return not self.pulled | 73 | 40 | return not self.pulled | |
74 | 41 | |||
def is_in_deck(self): | 75 | 42 | def is_in_deck(self): | |
""" | 76 | 43 | """ | |
:return:Whether the flashcard is in the user's deck | 77 | 44 | :return:Whether the flashcard is in the user's deck | |
""" | 78 | 45 | """ | |
return self.pulled and not self.unpulled | 79 | 46 | return self.pulled and not self.unpulled | |
80 | 47 | |||
81 | 48 | |||
class FlashcardMask(Model): | 82 | 49 | class FlashcardMask(Model): | |
""" | 83 | 50 | """ | |
A serialized list of character ranges that can be blanked out during review. | 84 | 51 | A serialized list of character ranges that can be blanked out during review. | |
This is encoded as '13-145,150-195' | 85 | 52 | This is encoded as '13-145,150-195' | |
""" | 86 | 53 | """ | |
ranges = CharField(max_length=255) | 87 | 54 | ranges = CharField(max_length=255) | |
88 | 55 | |||
89 | 56 | |||
class Flashcard(Model): | 90 | 57 | class Flashcard(Model): | |
text = CharField(max_length=255, help_text='The text on the card') | 91 | 58 | text = CharField(max_length=255, help_text='The text on the card') | |
section = ForeignKey('Section', help_text='The section with which the card is associated') | 92 | 59 | section = ForeignKey('Section', help_text='The section with which the card is associated') | |
pushed = DateTimeField(auto_now_add=True, help_text="When the card was first pushed") | 93 | 60 | pushed = DateTimeField(auto_now_add=True, help_text="When the card was first pushed") | |
material_date = DateTimeField(help_text="The date with which the card is associated") | 94 | 61 | material_date = DateTimeField(help_text="The date with which the card is associated") | |
previous = ForeignKey('Flashcard', null=True, blank=True, | 95 | 62 | previous = ForeignKey('Flashcard', null=True, blank=True, | |
help_text="The previous version of this card, if one exists") | 96 | 63 | help_text="The previous version of this card, if one exists") | |
author = ForeignKey(User) | 97 | 64 | author = ForeignKey(User) | |
is_hidden = BooleanField(default=False) | 98 | 65 | is_hidden = BooleanField(default=False) | |
hide_reason = CharField(blank=True, max_length=255, help_text="Reason for hiding this card") | 99 | 66 | hide_reason = CharField(blank=True, max_length=255, help_text="Reason for hiding this card") | |
mask = ForeignKey(FlashcardMask, blank=True, null=True, help_text="The default mask for this card") | 100 | 67 | mask = ForeignKey(FlashcardMask, blank=True, null=True, help_text="The default mask for this card") | |
101 | 68 | |||
class Meta: | 102 | 69 | class Meta: | |
# By default, order by most recently pushed | 103 | 70 | # By default, order by most recently pushed | |
ordering = ['-pushed'] | 104 | 71 | ordering = ['-pushed'] | |
105 | 72 | |||
def is_hidden_from(self, user): | 106 | 73 | def is_hidden_from(self, user): | |
""" | 107 | 74 | """ | |
A card can be hidden globally, but if a user has the card in their deck, | 108 | 75 | A card can be hidden globally, but if a user has the card in their deck, | |
this visibility overrides a global hide. | 109 | 76 | this visibility overrides a global hide. | |
:param user: | 110 | 77 | :param user: | |
:return: Whether the card is hidden from the user. | 111 | 78 | :return: Whether the card is hidden from the user. | |
""" | 112 | 79 | """ | |
result = user.userflashcard_set.filter(flashcard=self) | 113 | 80 | result = user.userflashcard_set.filter(flashcard=self) | |
if not result.exists(): return self.is_hidden | 114 | 81 | if not result.exists(): return self.is_hidden | |
return result[0].is_hidden() | 115 | 82 | return result[0].is_hidden() | |
116 | 83 | |||
117 | 84 | |||
@classmethod | 118 | 85 | @classmethod | |
def cards_visible_to(cls, user): | 119 | 86 | def cards_visible_to(cls, user): | |
""" | 120 | 87 | """ | |
:param user: | 121 | 88 | :param user: | |
:return: A queryset with all cards that should be visible to a user. | 122 | 89 | :return: A queryset with all cards that should be visible to a user. | |
""" | 123 | 90 | """ | |
return cls.objects.filter(hidden=False).exclude(userflashcard=user, userflashcard__pulled=None) | 124 | 91 | return cls.objects.filter(hidden=False).exclude(userflashcard=user, userflashcard__pulled=None) | |
125 | 92 | |||
126 | 93 | |||
class UserFlashcardReview(Model): | 127 | 94 | class UserFlashcardReview(Model): | |
""" | 128 | 95 | """ | |
An event of a user reviewing a flashcard. | 129 | 96 | An event of a user reviewing a flashcard. | |
""" | 130 | 97 | """ | |
user_flashcard = ForeignKey(UserFlashcard) | 131 | 98 | user_flashcard = ForeignKey(UserFlashcard) | |
when = DateTimeField() | 132 | 99 | when = DateTimeField() | |
blanked_word = CharField(max_length=8, blank=True, help_text="The character range which was blanked") | 133 | 100 | blanked_word = CharField(max_length=8, blank=True, help_text="The character range which was blanked") | |
response = CharField(max_length=255, blank=True, null=True, help_text="The user's response") | 134 | 101 | response = CharField(max_length=255, blank=True, null=True, help_text="The user's response") | |
correct = NullBooleanField(help_text="The user's self-evaluation of their response") | 135 | 102 | correct = NullBooleanField(help_text="The user's self-evaluation of their response") | |
136 | 103 | |||
def status(self): | 137 | 104 | def status(self): | |
""" | 138 | 105 | """ | |
There are three stages of a review object: | 139 | 106 | There are three stages of a review object: | |
1. the user has been shown the card | 140 | 107 | 1. the user has been shown the card | |
2. the user has answered the card | 141 | 108 | 2. the user has answered the card | |
3. the user has self-evaluated their response's correctness | 142 | 109 | 3. the user has self-evaluated their response's correctness | |
143 | 110 | |||
:return: string (evaluated, answered, viewed) | 144 | 111 | :return: string (evaluated, answered, viewed) | |
""" | 145 | 112 | """ | |
if self.correct is not None: return "evaluated" | 146 | 113 | if self.correct is not None: return "evaluated" | |
if self.response: return "answered" | 147 | 114 | if self.response: return "answered" | |
return "viewed" | 148 | 115 | return "viewed" |
flashcards/serializers.py
View file @
e807903
from flashcards.models import Section, LecturePeriod, User | 1 | 1 | from flashcards.models import Section, LecturePeriod, User | |
from rest_framework.fields import EmailField | 2 | 2 | from rest_framework.fields import EmailField | |
from rest_framework.relations import HyperlinkedRelatedField | 3 | 3 | from rest_framework.relations import HyperlinkedRelatedField | |
from rest_framework.serializers import HyperlinkedModelSerializer | 4 | 4 | from rest_framework.serializers import HyperlinkedModelSerializer | |
5 | 5 | |||
6 | 6 | |||
class SectionSerializer(HyperlinkedModelSerializer): | 7 | 7 | class SectionSerializer(HyperlinkedModelSerializer): | |
lectureperiod_set = HyperlinkedRelatedField(many=True, view_name='lectureperiod-detail', read_only=True) | 8 | 8 | lectureperiod_set = HyperlinkedRelatedField(many=True, view_name='lectureperiod-detail', read_only=True) | |
9 | 9 | |||
class Meta: | 10 | 10 | class Meta: | |
model = Section | 11 | 11 | model = Section | |
# exclude = ('members',) | 12 | 12 | # exclude = ('members',) | |
13 | 13 | |||
14 | 14 | |||
class LecturePeriodSerializer(HyperlinkedModelSerializer): | 15 | 15 | class LecturePeriodSerializer(HyperlinkedModelSerializer): | |
class Meta: | 16 | 16 | class Meta: | |
model = LecturePeriod | 17 | 17 | model = LecturePeriod | |
18 | 18 | |||
19 | 19 | |||
class UserSerializer(HyperlinkedModelSerializer): | 20 | 20 | class UserSerializer(HyperlinkedModelSerializer): | |
""" | 21 |
flashy/settings.py
View file @
e807903
""" | 1 | 1 | """ | |
Django settings for flashy project. | 2 | 2 | Django settings for flashy project. | |
3 | 3 | |||
Generated by 'django-admin startproject' using Django 1.8. | 4 | 4 | Generated by 'django-admin startproject' using Django 1.8. | |
5 | 5 | |||
For more information on this file, see | 6 | 6 | For more information on this file, see | |
https://docs.djangoproject.com/en/1.8/topics/settings/ | 7 | 7 | https://docs.djangoproject.com/en/1.8/topics/settings/ | |
8 | 8 | |||
For the full list of settings and their values, see | 9 | 9 | For the full list of settings and their values, see | |
https://docs.djangoproject.com/en/1.8/ref/settings/ | 10 | 10 | https://docs.djangoproject.com/en/1.8/ref/settings/ | |
""" | 11 | 11 | """ | |
12 | 12 | |||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | 13 | 13 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) | |
import os | 14 | 14 | import os | |
15 | 15 | |||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 16 | 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
17 | 17 | |||
# SECURITY WARNING: don't run with debug turned on in production! | 18 | 18 | # SECURITY WARNING: don't run with debug turned on in production! | |
DEBUG = True | 19 | 19 | DEBUG = True | |
20 | 20 | |||
ALLOWED_HOSTS = [] | 21 | 21 | ALLOWED_HOSTS = [] | |
22 | 22 | |||
AUTH_USER_MODEL = 'flashcards.User' | 23 | 23 | AUTH_USER_MODEL = 'flashcards.User' | |
# Application definition | 24 | 24 | # Application definition | |
25 | 25 | |||
INSTALLED_APPS = ( | 26 | 26 | INSTALLED_APPS = ( | |
'simple_email_confirmation', | 27 | 27 | 'simple_email_confirmation', | |
'flashcards', | 28 | 28 | 'flashcards', | |
'django.contrib.admin', | 29 | 29 | 'django.contrib.admin', | |
'django.contrib.admindocs', | 30 | 30 | 'django.contrib.admindocs', | |
'django.contrib.auth', | 31 | 31 | 'django.contrib.auth', | |
'django.contrib.contenttypes', | 32 | 32 | 'django.contrib.contenttypes', | |
'django.contrib.sessions', | 33 | 33 | 'django.contrib.sessions', | |
'django.contrib.messages', | 34 | 34 | 'django.contrib.messages', | |
'django.contrib.staticfiles', | 35 | 35 | 'django.contrib.staticfiles', | |
'django_ses', | 36 | 36 | 'django_ses', | |
'rest_framework', | 37 | 37 | 'rest_framework', | |
38 | 38 | |||
39 | 39 | |||
) | 40 | 40 | ) | |
41 | 41 | |||
REST_FRAMEWORK = { | 42 | 42 | REST_FRAMEWORK = { | |
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.CursorPagination', | 43 | 43 | 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.CursorPagination', | |
'PAGE_SIZE': 20 | 44 | 44 | 'PAGE_SIZE': 20 | |
} | 45 | 45 | } | |
46 | 46 | |||
MIDDLEWARE_CLASSES = ( | 47 | 47 | MIDDLEWARE_CLASSES = ( | |
'django.contrib.sessions.middleware.SessionMiddleware', | 48 | 48 | 'django.contrib.sessions.middleware.SessionMiddleware', | |
'django.middleware.common.CommonMiddleware', | 49 | 49 | 'django.middleware.common.CommonMiddleware', | |
'django.middleware.csrf.CsrfViewMiddleware', | 50 | 50 | 'django.middleware.csrf.CsrfViewMiddleware', | |
'django.contrib.auth.middleware.AuthenticationMiddleware', | 51 | 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', | |
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | 52 | 52 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | |
'django.contrib.messages.middleware.MessageMiddleware', | 53 | 53 | 'django.contrib.messages.middleware.MessageMiddleware', | |
'django.middleware.clickjacking.XFrameOptionsMiddleware', | 54 | 54 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', | |
'django.middleware.security.SecurityMiddleware', | 55 | 55 | 'django.middleware.security.SecurityMiddleware', | |
) | 56 | 56 | ) | |
57 | 57 | |||
ROOT_URLCONF = 'flashy.urls' | 58 | 58 | ROOT_URLCONF = 'flashy.urls' | |
59 | # Authentication backends | |||
60 | AUTHENTICATION_BACKENDS = ( | |||
61 | 'django.contrib.auth.backends.ModelBackend', | |||
62 | ) | |||
59 | 63 | |||
TEMPLATES = [ | 60 | 64 | TEMPLATES = [ | |
{ | 61 | 65 | { | |
'BACKEND': 'django.template.backends.django.DjangoTemplates', | 62 | 66 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', | |
'DIRS': ['templates/'], | 63 | 67 | 'DIRS': ['templates/'], | |
'APP_DIRS': True, | 64 | 68 | 'APP_DIRS': True, | |
'OPTIONS': { | 65 | 69 | 'OPTIONS': { | |
'context_processors': [ | 66 | 70 | 'context_processors': [ | |
'django.template.context_processors.debug', | 67 | 71 | 'django.template.context_processors.debug', | |
'django.template.context_processors.request', | 68 | 72 | 'django.template.context_processors.request', | |
'django.contrib.auth.context_processors.auth', | 69 | 73 | 'django.contrib.auth.context_processors.auth', | |
'django.contrib.messages.context_processors.messages', | 70 | 74 | 'django.contrib.messages.context_processors.messages', | |
], | 71 | 75 | ], | |
}, | 72 | 76 | }, | |
}, | 73 | 77 | }, | |
] | 74 | 78 | ] | |
75 | 79 | |||
WSGI_APPLICATION = 'flashy.wsgi.application' | 76 | 80 | WSGI_APPLICATION = 'flashy.wsgi.application' | |
77 | 81 | |||
78 | 82 | |||
# Database | 79 | 83 | # Database | |
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases | 80 | 84 | # https://docs.djangoproject.com/en/1.8/ref/settings/#databases | |
81 | 85 | |||
DATABASES = { | 82 | 86 | DATABASES = { | |
'default': { | 83 | 87 | 'default': { | |
'ENGINE': 'django.db.backends.sqlite3', | 84 | 88 | 'ENGINE': 'django.db.backends.sqlite3', | |
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | 85 | 89 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | |
} | 86 | 90 | } | |
} | 87 | 91 | } |
flashy/urls.py
View file @
e807903
from django.conf.urls import include, url | 1 | 1 | from django.conf.urls import include, url | |
from django.contrib import admin | 2 | 2 | from django.contrib import admin | |
from flashcards.views import SectionViewSet, LecturePeriodViewSet | 3 | 3 | from flashcards.views import SectionViewSet, LecturePeriodViewSet | |
from rest_framework.routers import DefaultRouter | 4 | 4 | from rest_framework.routers import DefaultRouter | |
from flashcards.api import * | 5 | 5 | from flashcards.api import * | |
6 | 6 | |||
router = DefaultRouter() | 7 | 7 | router = DefaultRouter() | |
router.register(r'sections', SectionViewSet) | 8 | 8 | router.register(r'sections', SectionViewSet) | |
router.register(r'lectureperiods', LecturePeriodViewSet) | 9 | 9 | router.register(r'lectureperiods', LecturePeriodViewSet) | |
10 | 10 | |||
urlpatterns = [ | 11 | 11 | urlpatterns = [ | |
url(r'^api/user/me$', UserDetail.as_view()), | 12 | 12 | url(r'^api/users/me$', UserDetail.as_view()), | |
13 | url(r'^api/login$', UserLogin.as_view()), | |||
14 | url(r'^api/reset_password$', PasswordReset.as_view()), | |||
url(r'^api/', include(router.urls)), | 13 | 15 | url(r'^api/', include(router.urls)), | |
url(r'^admin/doc/', include('django.contrib.admindocs.urls')), | 14 | 16 | url(r'^admin/doc/', include('django.contrib.admindocs.urls')), | |
url(r'^admin/', include(admin.site.urls)), | 15 | 17 | url(r'^admin/', include(admin.site.urls)), | |
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) | 16 | 18 | url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) | |
] | 17 | 19 | ] |