Commit e4c3292e394167a97f267f18f2542fa7d29df0ea

Authored by Rohan Rangray
Exists in master

merge branch 'master' of git.ucsd.edu:110swag/flashy-backend

Mergin' all day.

Showing 6 changed files Side-by-side Diff

1   -Flashy requires Python 2.
  1 +Flashy requires Python 2. Srsly
2 2  
  3 +All of these commands should be run from this directory (the one containing README.md)
  4 +
3 5 Install virtualenv before continuing. This is most easily accomplished with:
4 6  
5 7 pip install virtualenv
... ... @@ -22,6 +24,7 @@
22 24  
23 25 Run development server (local):
24 26  
  27 + python manage.py runserver
25 28 scripts/run_local.sh
26 29  
27 30 This requires that flashy-backend be in the directory as flashy-frontend.
flashcards/tests/test_api.py View file @ e4c3292
... ... @@ -253,4 +253,8 @@
253 253 def test_section_search(self):
254 254 response = self.client.get('/api/sections/search/?q=Kramer')
255 255 self.assertEqual(response.status_code, HTTP_200_OK)
  256 +
  257 + def test_section_deck(self):
  258 + response = self.client.get('/api/sections/1/deck/')
  259 + self.assertEqual(response.status_code, HTTP_200_OK)
flashcards/views.py View file @ e4c3292
1 1 from django.contrib import auth
2   -from django.db.models import Q
3 2 from flashcards.api import StandardResultsSetPagination
4 3 from flashcards.models import Section, User, Flashcard, FlashcardReport, UserFlashcard
5 4 from flashcards.serializers import SectionSerializer, UserUpdateSerializer, RegistrationSerializer, UserSerializer, \
... ... @@ -33,7 +32,7 @@
33 32 Returned in strictly chronological order (material date).
34 33 """
35 34 flashcards = Flashcard.cards_visible_to(request.user).filter( \
36   - section=self.get_object(), is_hidden=False).all()
  35 + section=self.get_object(), is_hidden=False).all()
37 36  
38 37 return Response(FlashcardSerializer(flashcards, many=True).data)
39 38  
40 39  
41 40  
... ... @@ -77,13 +76,23 @@
77 76  
78 77 @list_route(methods=['get'], permission_classes=[IsAuthenticated])
79 78 def search(self, request):
80   - query = request.GET.get('q',None)
  79 + query = request.GET.get('q', None)
81 80 if not query: return Response('[]')
82 81 qs = Section.search(query.split(' '))[:8]
83 82 serializer = SectionSerializer(qs, many=True)
84 83 return Response(serializer.data)
85 84  
  85 + @detail_route(methods=['get'], permission_classes=[IsAuthenticated])
  86 + def deck(self, request, pk):
  87 + """
  88 + Gets the contents of a user's deck for a given section.
  89 + """
  90 + qs = Flashcard.objects.all()
  91 + qs = qs.filter(userflashcard__user=request.user)
  92 + serializer = FlashcardSerializer(qs, many=True)
  93 + return Response(serializer.data)
86 94  
  95 +
87 96 class UserSectionListView(ListAPIView):
88 97 serializer_class = SectionSerializer
89 98 permission_classes = [IsAuthenticated]
... ... @@ -267,7 +276,7 @@
267 276 self.perform_create(serializer)
268 277 headers = self.get_success_headers(serializer.data)
269 278 return Response(serializer.data, status=HTTP_201_CREATED, headers=headers)
270   -
  279 +
271 280 @detail_route(methods=['post'], permission_classes=[IsAuthenticated])
272 281 def report(self, request, pk):
273 282 """
scripts/check_python_version.py View file @ e4c3292
  1 +
  2 +
  3 +import sys
  4 +
  5 +print(sys.version)
  6 +
  7 +if sys.version == '3':
  8 + print("Flashy requires Python 2 (read the README.md)")
  9 + exit(-1)
scripts/run_local.sh View file @ e4c3292
1 1 #!/bin/bash -xe
  2 +
2 3 if [ ! -d "../flashy-frontend/" ]; then
3 4 echo "In order to serve the frontend, flashy-frontend must be in the parent dir"
4 5 exit 1
5 6 fi
6   -source venv/bin/activate
  7 +
  8 +if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
  9 + source venv/bin/activate
  10 +elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
  11 + source venv/Scripts/activate
  12 +fi
  13 +
7 14 python manage.py runserver 127.0.0.1:8080
scripts/setup.sh View file @ e4c3292
1 1 #!/bin/bash -xe
2 2 virtualenv venv
3   -source venv/bin/activate
  3 +
  4 +if [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
  5 + source venv/bin/activate
  6 +elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
  7 + source venv/Scripts/activate
  8 +fi
  9 +
4 10 pip install -r requirements.txt
5 11 virtualenv --relocatable venv
6   -#git submodule init
7   -#git submodule update --depth 1
8   -#pip install -e django