-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demo-views): Demos now have different views on home and project …
…page (#80) feat(demo-views): Demos now have different views on home and project
- Loading branch information
1 parent
62c6d5a
commit 3b4aa27
Showing
5 changed files
with
53 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.1 on 2018-07-09 17:45 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('demos', '0004_demo_from_origami'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='demo', | ||
name='deployed_on_cloudcv', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,54 @@ | ||
from rest_framework import permissions, status | ||
from rest_framework.decorators import (api_view, permission_classes, throttle_classes,) | ||
from rest_framework.decorators import ( | ||
api_view, | ||
permission_classes, | ||
throttle_classes, | ||
) | ||
from rest_framework.response import Response | ||
from rest_framework.throttling import AnonRateThrottle | ||
|
||
from .models import Demo, Project | ||
from .serializers import DemoSerializer, ProjectSerializer | ||
|
||
|
||
@throttle_classes([AnonRateThrottle, ]) | ||
@throttle_classes([ | ||
AnonRateThrottle, | ||
]) | ||
@api_view(['GET']) | ||
@permission_classes((permissions.AllowAny,)) | ||
@permission_classes((permissions.AllowAny, )) | ||
def get_demos(request): | ||
""" | ||
Get a list of demos | ||
""" | ||
demos = Demo.objects.filter(is_disabled=False).order_by('title') | ||
# By default return all the demos, whether deployed | ||
# or not. | ||
demo_filter = request.GET.get('filter', 'all') | ||
|
||
if demo_filter == 'all': | ||
demos = Demo.objects.filter(is_disabled=False).order_by('title') | ||
elif demo_filter == 'deployed': | ||
demos = Demo.objects.filter( | ||
is_disabled=False, deployed_on_cloudcv=True).order_by('title') | ||
else: | ||
error = {'error': 'Invalid filter'} | ||
return Response(error, status.HTTP_400_BAD_REQUEST) | ||
|
||
serializer = DemoSerializer(demos, many=True, context={'request': request}) | ||
response_data = serializer.data | ||
return Response(response_data, status=status.HTTP_200_OK) | ||
|
||
|
||
@throttle_classes([AnonRateThrottle, ]) | ||
@throttle_classes([ | ||
AnonRateThrottle, | ||
]) | ||
@api_view(['GET']) | ||
@permission_classes((permissions.AllowAny,)) | ||
@permission_classes((permissions.AllowAny, )) | ||
def get_projects(request): | ||
""" | ||
Get a list of projects | ||
""" | ||
projects = Project.objects.filter(is_visible=True).order_by('title') | ||
serializer = ProjectSerializer(projects, many=True, context={'request': request}) | ||
serializer = ProjectSerializer( | ||
projects, many=True, context={'request': request}) | ||
response_data = serializer.data | ||
return Response(response_data, status=status.HTTP_200_OK) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Django==1.11.1 | ||
psycopg2==2.7.1 | ||
psycopg2==2.7.4 | ||
Pillow==4.1.1 | ||
python-memcached==1.58 | ||
djangorestframework==3.6.3 | ||
|