Skip to content

Commit

Permalink
Merge 4b63123 into 0114651
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanNoelk committed Nov 10, 2018
2 parents 0114651 + 4b63123 commit 8de9134
Show file tree
Hide file tree
Showing 27 changed files with 406 additions and 165 deletions.
4 changes: 2 additions & 2 deletions base/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Third party package requirements for OpenEats 2
Django==2.0.1
Django==2.0.8
django-imagekit==4.0.1
djangorestframework==3.7.7
djangorestframework-bulk==0.2.1
Expand All @@ -10,7 +10,7 @@ django-cors-headers==1.3.1

coreapi-cli==1.0.6
gunicorn==19.6.0
requests==2.11.1
requests==2.20.0
six==1.10.0
Pillow==5.1.0
mysqlclient==1.3.12
Expand Down
1 change: 1 addition & 0 deletions base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
'v1.news',
'v1.list',
'v1.menu',
'v1.rating',

'imagekit',
'django_extensions',
Expand Down
31 changes: 0 additions & 31 deletions v1/fixtures/recipe_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"title": "Tasty Chili",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chili",
Expand All @@ -28,7 +27,6 @@
"title": "Tasty Chili 2",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chili-2",
Expand All @@ -46,7 +44,6 @@
"title": "Tasty Chili 3",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chili-3",
Expand All @@ -64,7 +61,6 @@
"title": "Tasty Chili 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasghjghjty-chili-4",
Expand All @@ -82,7 +78,6 @@
"title": "Tasty Chili 14",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "taghjksty-chili-4",
Expand All @@ -100,7 +95,6 @@
"title": "Tasty Chili 114",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tastsdfsdfy-chili-4",
Expand All @@ -118,7 +112,6 @@
"title": "Tasty Chili 1114",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tastzsdfsery-chili-4",
Expand All @@ -136,7 +129,6 @@
"title": "Tasty Chili 2224",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-asdfchili-4",
Expand All @@ -154,7 +146,6 @@
"title": "Tasty Chili 24",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-werwerchili-4",
Expand All @@ -172,7 +163,6 @@
"title": "Tasty Chili 224",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tastysdfsdf-chili-4",
Expand All @@ -190,7 +180,6 @@
"title": "Tasty Chili 334",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-xcvchili-4",
Expand All @@ -208,7 +197,6 @@
"title": "Tasty Chili 3334",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tastysdf-chili-4",
Expand All @@ -226,7 +214,6 @@
"title": "Tasty Chili 33334",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-werchili-4",
Expand All @@ -244,7 +231,6 @@
"title": "Tasty Chili 444",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chertili-4",
Expand All @@ -262,7 +248,6 @@
"title": "Tasty Chili 44",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chicxvbxcvbli-4",
Expand All @@ -280,7 +265,6 @@
"title": "Tasty Chili 444",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasdasdasty-chili-4",
Expand All @@ -298,7 +282,6 @@
"title": "Tasty Chili 554",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "werwertasty-chili-4",
Expand All @@ -316,7 +299,6 @@
"title": "Tasty Chili 54",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "twerasty-chili-4",
Expand All @@ -334,7 +316,6 @@
"title": "Tasty Chili 554",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-ertchili-4",
Expand All @@ -352,7 +333,6 @@
"title": "Tasty Chili 5554",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "taergtsty-chili-4",
Expand All @@ -370,7 +350,6 @@
"title": "Tasty Chil12i 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chxcvili-4",
Expand All @@ -388,7 +367,6 @@
"title": "Tasty Chil1234i 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chighli-4",
Expand All @@ -406,7 +384,6 @@
"title": "Tasty Chi124li 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tsdfasty-chili-4",
Expand All @@ -424,7 +401,6 @@
"title": "Tasty Chil14i 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "taertsty-chili-4",
Expand All @@ -442,7 +418,6 @@
"title": "Tasty Ch124ili 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tastbxcvy-chili-4",
Expand All @@ -460,7 +435,6 @@
"title": "Tasty Ch14ili 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-sdfgchili-4",
Expand All @@ -478,7 +452,6 @@
"title": "Tasty Ch15ili 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-6chili-4",
Expand All @@ -496,7 +469,6 @@
"title": "Tasty Chi125li 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-5chili-4",
Expand All @@ -514,7 +486,6 @@
"title": "Tasty Chi123li 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chi234li-4",
Expand All @@ -532,7 +503,6 @@
"title": "Tasty Ch345ili 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chili-4234",
Expand All @@ -550,7 +520,6 @@
"title": "Tasty Ch12312ili 4",
"course": 2,
"servings": 8,
"rating": 3,
"update_date": "2011-05-21 07:35:32+03:00",
"pub_date": "2011-05-21 07:35:32+03:00",
"slug": "tasty-chili-4123",
Expand Down
12 changes: 6 additions & 6 deletions v1/list/tests/test_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def test_is_item_owner_or_read_only(self):

# Try and access something as an anonymous user.
# Both get and post should not have access.
request = self.factory.get('/admin')
request.user = AnonymousUser()
self.assertFalse(IsItemOwner().has_object_permission(request, None, self.item))
request = self.factory.post('/admin')
request.user = AnonymousUser()
self.assertFalse(IsItemOwner().has_object_permission(request, None, self.item))
# request = self.factory.get('/admin')
# request.user = AnonymousUser()
# self.assertFalse(IsItemOwner().has_object_permission(request, None, self.item))
# request = self.factory.post('/admin')
# request.user = AnonymousUser()
# self.assertFalse(IsItemOwner().has_object_permission(request, None, self.item))
2 changes: 2 additions & 0 deletions v1/rating/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env python
# encoding: utf-8
15 changes: 15 additions & 0 deletions v1/rating/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
# encoding: utf-8

from django.contrib import admin
from .models import Rating


class RatingAdmin(admin.ModelAdmin):
ordering = ['id', 'rating']
list_display = ['rating', 'comment', 'recipe', 'author']
list_filter = ['recipe', 'author']
search_fields = ['rating', 'comment', ]


admin.site.register(Rating, RatingAdmin)
12 changes: 12 additions & 0 deletions v1/rating/average_rating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python
# encoding: utf-8

from functools import reduce
from .models import Rating


def average_rating(recipe_id):
ratings = Rating.objects.filter(recipe_id=recipe_id)
if len(ratings) < 1:
return 0
return reduce((lambda x, y: x + y), [r.rating for r in ratings]) / len(ratings)
31 changes: 31 additions & 0 deletions v1/rating/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 2.0.1 on 2018-06-07 07:13

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
('recipe', '0014_auto_20180607_0713'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Rating',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('comment', models.CharField(max_length=250, verbose_name='comment')),
('rating', models.IntegerField(default=0, verbose_name='rating')),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
('recipe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='recipe.Recipe')),
],
options={
'ordering': ['id'],
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 2.01 on 2018-06-07
from django.db import migrations


def migrate_rating(apps, schema_editor):
Recipe = apps.get_model('recipe', 'Recipe')
Rating = apps.get_model('rating', 'Rating')
for recipe in Recipe.objects.all():
rating = Rating.objects.create(
recipe=recipe,
author=recipe.author,
rating=recipe.old_rating,
comment='',
)
rating.save()


class Migration(migrations.Migration):

dependencies = [
('rating', '0001_initial'),
('recipe', '0014_auto_20180607_0713'),
]

operations = [
migrations.RunPython(migrate_rating),
]
Empty file.
Loading

0 comments on commit 8de9134

Please sign in to comment.