Commit 07a9ebffbae02d0055aa182d75b2acd3b02156d2

Authored by Andrew Buss
Exists in master

merge

Showing 6 changed files Side-by-side Diff

flashcards/serializers.py View file @ 07a9ebf
1   -from flashcards.models import Section, LecturePeriod, User
  1 +from flashcards.models import Section, LecturePeriod, User, Flashcard
2 2 from rest_framework import serializers
3 3 from rest_framework.fields import EmailField, BooleanField, CharField, IntegerField
4 4 from rest_framework.relations import HyperlinkedRelatedField
... ... @@ -78,4 +78,10 @@
78 78 class Meta:
79 79 model = User
80 80 fields = ("sections", "email", "is_confirmed", "last_login", "date_joined")
  81 +
  82 +class FlashcardSerializer(HyperlinkedModelSerializer):
  83 +
  84 + class Meta:
  85 + model = Flashcard
  86 + exclude = 'author', 'mask',
flashcards/tests.py View file @ 07a9ebf
1   -from django.test import TestCase
2   -
3   -# Create your tests here.
flashcards/tests/test_api.py View file @ 07a9ebf
1 1 from django.core import mail
  2 +<<<<<<< HEAD
2 3 from flashcards.models import User
3 4 from rest_framework.generics import RetrieveAPIView
  5 +=======
  6 +from flashcards.models import User, Section, Flashcard
  7 +>>>>>>> 2a9edd990f102b292ef4fb59c0688f6ed5ab56f5
4 8 from rest_framework.status import HTTP_204_NO_CONTENT, HTTP_201_CREATED, HTTP_200_OK, HTTP_401_UNAUTHORIZED
5 9 from rest_framework.test import APITestCase
6 10 from re import search
  11 +from django.utils.timezone import now
7 12  
8 13  
9 14 class LoginTests(APITestCase):
10 15  
... ... @@ -186,6 +191,26 @@
186 191  
187 192 self.client.login(email='none@none.com', password='1234')
188 193 self.client.delete(url)
189   -
190 194 self.assertFalse(User.objects.filter(email='none@none.com').exists())
  195 +
  196 +class FlashcardDetailTest(APITestCase):
  197 + def setUp(self):
  198 + section = Section( department="cse", course_num="5", \
  199 + course_title="cool course", \
  200 + instructor="gary", quarter="fa15")
  201 + section.save()
  202 +
  203 + user = User.objects.create_user( email="jacob@aaa.com", \
  204 + password="top_secret" )
  205 + user.save()
  206 +
  207 + self.flashcard = Flashcard( text="jason", section=section, \
  208 + material_date=now(), author=user )
  209 + self.flashcard.save()
  210 +
  211 + def test_get_flashcard(self):
  212 +
  213 + response = self.client.get("/api/flashcards/%d"%self.flashcard.id, format="json")
  214 + self.assertEqual(response.status_code, HTTP_200_OK)
  215 + self.assertEqual(response.data["text"], "jason")
flashcards/views.py View file @ 07a9ebf
1 1 from flashcards.api import StandardResultsSetPagination
2   -from flashcards.models import Section, User
  2 +from flashcards.models import Section, User, Flashcard
3 3 from flashcards.serializers import SectionSerializer, UserUpdateSerializer, RegistrationSerializer, UserSerializer, \
4   - PasswordResetSerializer, PasswordResetRequestSerializer, EmailPasswordSerializer
  4 + PasswordResetSerializer, PasswordResetRequestSerializer, EmailPasswordSerializer, FlashcardSerializer
5 5 from rest_framework.permissions import IsAuthenticated
6 6 from rest_framework.viewsets import ReadOnlyModelViewSet, ModelViewSet
7 7 from django.core.mail import send_mail
... ... @@ -10,6 +10,7 @@
10 10 from rest_framework.status import HTTP_204_NO_CONTENT, HTTP_401_UNAUTHORIZED, HTTP_201_CREATED
11 11 from rest_framework.views import APIView
12 12 from rest_framework.response import Response
  13 +from rest_framework.generics import RetrieveAPIView
13 14 from rest_framework.exceptions import AuthenticationFailed, NotAuthenticated, ValidationError
14 15 from simple_email_confirmation import EmailAddress
15 16 from rest_framework import filters
... ... @@ -182,4 +183,12 @@
182 183 else:
183 184 raise ValidationError('Could not verify reset token')
184 185 return Response(status=HTTP_204_NO_CONTENT)
  186 +
  187 +class FlashcardDetail(RetrieveAPIView):
  188 + queryset = Flashcard.objects.all()
  189 + serializer_class = FlashcardSerializer
  190 +## def get(self, request):
  191 +
  192 +
  193 +
flashy/urls.py View file @ 07a9ebf
1 1 from django.conf.urls import include, url
2 2 from django.contrib import admin
3   -from flashcards.views import SectionViewSet, UserDetail, UserLogin, UserLogout, PasswordReset, UserSectionViewSet
  3 +from flashcards.views import SectionViewSet, UserDetail, UserLogin, UserLogout, PasswordReset, UserSectionViewSet, FlashcardDetail
4 4 from rest_framework.routers import DefaultRouter
5 5 from flashcards.api import *
6 6  
... ... @@ -19,7 +19,9 @@
19 19 url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
20 20 url(r'^admin/', include(admin.site.urls)),
21 21 url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'
22   -))
  22 +)),
  23 + url(r'^api/flashcards/(?P<pk>[0-9]+)$', FlashcardDetail.as_view(), name \
  24 + ="flashcard-detail"),
23 25 ]
24 26  
25 27 urlpatterns += (url(r'^admin/django-ses/', include('django_ses.urls')),)
nginxconf/flashy.cards View file @ 07a9ebf
... ... @@ -29,18 +29,18 @@
29 29  
30 30 server_name flashy.cards;
31 31 listen 443 ssl;
32   - location ~ \.php$ {
  32 +
  33 +
  34 + location / {
  35 + root /srv/flashy.cards/;
  36 + index index.html /docs/_h5ai/server/php/index.php;
  37 + location ~ \.php$ {
33 38 try_files $uri =404;
34 39 fastcgi_pass unix:/var/run/php5-fpm.sock;
35   - fastcgi_index index.php;
36   - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
37 40 include fastcgi_params;
  41 + }
38 42 }
39 43  
40   - location / {
41   - root /srv/flashy.cards/;
42   - }
43   -
44 44 location ^~ /static {
45 45 root /srv/;
46 46 access_log off;
... ... @@ -49,7 +49,7 @@
49 49  
50 50 location ^~ /app/ {
51 51 alias /srv/flashy-frontend/;
52   - try_files $uri /app/home.html;
  52 + try_files $uri /app/home.html;
53 53 }
54 54  
55 55 location ~ /(api|admin|api-auth)/ {