Skip to content

Commit

Permalink
Merge 41388cc into 62c6d5a
Browse files Browse the repository at this point in the history
  • Loading branch information
fristonio committed Jul 9, 2018
2 parents 62c6d5a + 41388cc commit fef2999
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
20 changes: 20 additions & 0 deletions apps/demos/migrations/0005_demo_deployed_on_cloudcv.py
@@ -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),
),
]
1 change: 1 addition & 0 deletions apps/demos/models.py
Expand Up @@ -16,6 +16,7 @@ class Demo(models.Model):
paper_url = models.URLField(max_length=100, null=True, blank=True)
is_disabled = models.BooleanField(default=False)
sample = models.BooleanField(default=False)
deployed_on_cloudcv = models.BooleanField(default=False)
from_origami = models.BooleanField(default=True)
text_inputs = models.IntegerField()
image_inputs = models.IntegerField()
Expand Down
35 changes: 28 additions & 7 deletions apps/demos/views.py
@@ -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)
4 changes: 3 additions & 1 deletion frontend/src/components/projects/index.js
Expand Up @@ -33,7 +33,9 @@ class Projects extends React.Component {

fetchDemos() {
axios
.get(`${process.env.AJAX_ROOT}/api/demos/demos/`)
.get(`${process.env.AJAX_ROOT}/api/demos/demos/`, {
params: { filter: "deployed" }
})
.then(response => {
this.setState({ isFetching: false, demos: response.data });
})
Expand Down
2 changes: 1 addition & 1 deletion requirements/base.txt
@@ -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
Expand Down

0 comments on commit fef2999

Please sign in to comment.