Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(demo-views): Demos now have different views on home and project #80

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions apps/demos/migrations/0005_demo_deployed_on_cloudcv.py
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),
),
]
1 change: 1 addition & 0 deletions apps/demos/models.py
Original file line number Diff line number Diff line change
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
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)
4 changes: 3 additions & 1 deletion frontend/src/components/projects/index.js
Original file line number Diff line number Diff line change
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
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
Expand Down