Commit f5bd0e95 authored by lizonr1's avatar lizonr1

Add peb8 tests

parent f357a71b
from django.contrib import admin
# Register your models here. # Register your models here.
from App.loyaltyMe.models import Beacon from App.loyaltyMe.models import Beacon
__author__ = 'Rafal'
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
...@@ -11,9 +10,10 @@ class Command(BaseCommand): ...@@ -11,9 +10,10 @@ class Command(BaseCommand):
beacons = [ beacons = [
['f7826da6-4fa2-4e98-8024-bc5b71e0893e', 'hPUL', 'Bialy', '2667', '62313'], ['f7826da6-4fa2-4e98-8024-bc5b71e0893e', 'hPUL', 'Bialy', '2667', '62313'],
['74f1f28c-1cb7-11e5-9a21-1697f925ec7b', 'CeH3', 'Czarny', '55059', '55892'], ['74f1f28c-1cb7-11e5-9a21-1697f925ec7b', 'CeH3', 'Czarny', '55059', '55892'],
] ]
print("Creating Beacons") print("Creating Beacons")
for beacon in beacons: for beacon in beacons:
print('Create {0}'.format(beacon[1])) print('Create {0}'.format(beacon[1]))
new_beacon = Beacon.objects.create(uuid=beacon[0], name=beacon[1], description=beacon[2], major=beacon[3], minor=beacon[4]) new_beacon = Beacon.objects.create(uuid=beacon[0], name=beacon[1], description=beacon[2], major=beacon[3],
minor=beacon[4])
new_beacon.save() new_beacon.save()
from django.contrib.auth.models import User from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Offer, Product, Localization from App.loyaltyMe.models import Localization
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand): class Command(BaseCommand):
help = 'Closes the specified poll for voting' help = 'Closes the specified poll for voting'
def handle(self, *args, **options): def handle(self, *args, **options):
localizations = [ localizations = [
['0.0000', '10.0000', 'Kraków', 'Makowicka', '55' ], ['0.0000', '10.0000', 'Kraków', 'Makowicka', '55'],
['10.0000', '0.0000', 'Kraków', 'Rynek', '15' ], ['10.0000', '0.0000', 'Kraków', 'Rynek', '15'],
] ]
print("Creating Localizations") print("Creating Localizations")
for localization in localizations: for localization in localizations:
print('Create {0}'.format(localization[0])) print('Create {0}'.format(localization[0]))
new_localization = Localization.objects.create(latitude=localization[0], longitude=localization[1], city=localization[2], road=localization[3], road_number =localization[4]) new_localization = Localization.objects.create(latitude=localization[0], longitude=localization[1],
new_localization.save() city=localization[2], road=localization[3],
\ No newline at end of file road_number=localization[4])
new_localization.save()
from django.contrib.auth.models import User
from App.loyaltyMe.models import Offer, Product from App.loyaltyMe.models import Offer, Product
__author__ = 'Rafal' from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand): class Command(BaseCommand):
help = 'Closes the specified poll for voting' help = 'Closes the specified poll for voting'
def handle(self, *args, **options): def handle(self, *args, **options):
offers = [ offers = [
#'name',products # 'name',products
['Oferta1', ['Kawa Latte', 'Herbata'] ], ['Oferta1', ['Kawa Latte', 'Herbata']],
['Oferta2', ['Ciasto', 'Espresso'] ], ['Oferta2', ['Ciasto', 'Espresso']],
] ]
print("Creating Offers") print("Creating Offers")
for offer in offers: for offer in offers:
print('Create {0}'.format(offer[0])) print('Create {0}'.format(offer[0]))
...@@ -22,4 +20,4 @@ class Command(BaseCommand): ...@@ -22,4 +20,4 @@ class Command(BaseCommand):
print(product) print(product)
pro_obj = Product.objects.filter(name=product)[0] pro_obj = Product.objects.filter(name=product)[0]
new_offer.products.add(pro_obj) new_offer.products.add(pro_obj)
new_offer.save() new_offer.save()
\ No newline at end of file
from App.loyaltyMe.models import Place, Offer, Promotion, PromotionSet, Localization, Beacon from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Place, Offer, PromotionSet, Localization, Beacon
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand): class Command(BaseCommand):
help = 'Closes the specified poll for voting' help = 'Closes the specified poll for voting'
def handle(self, *args, **options): def handle(self, *args, **options):
places = [ places = [
#['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'], # ['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'],
['Kocia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' , 'Makowicka', 'hPUL'], ['Kocia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
['Kafcia u Olczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2' ,'Makowicka', 'CeH3'], 'Oferta1', 'Promocja1', 'Makowicka', 'hPUL'],
['Psia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Rynek', None], ['Kafcia u Olczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
['Kafcia u Iwczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek', None], 'Oferta2', 'Promocja2', 'Makowicka', 'CeH3'],
['Lemingowa Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Makowicka', None ], ['Psia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
['Kafcia u Ewelinczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek', None], 'Oferta1', 'Promocja1', 'Rynek', None],
] ['Kafcia u Iwczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta2', 'Promocja2', 'Rynek', None],
['Lemingowa Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta1', 'Promocja1', 'Makowicka', None],
['Kafcia u Ewelinczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta2', 'Promocja2', 'Rynek', None],
]
print("Creating Places") print("Creating Places")
for place in places: for place in places:
print('Create {0}'.format(place[0])) print('Create {0}'.format(place[0]))
...@@ -25,6 +31,8 @@ class Command(BaseCommand): ...@@ -25,6 +31,8 @@ class Command(BaseCommand):
if place[8]: if place[8]:
beacon = Beacon.objects.filter(name=place[8])[0] beacon = Beacon.objects.filter(name=place[8])[0]
else: else:
beacon=None beacon = None
new_place = Place.objects.create(name=place[0], type=place[1], screen_img=place[2], logo_img=place[3], description=place[4], offer=offer, promotion=promotion_set, localization=localization, beacon=beacon) new_place = Place.objects.create(name=place[0], type=place[1], screen_img=place[2], logo_img=place[3],
new_place.save() description=place[4], offer=offer, promotion=promotion_set,
\ No newline at end of file localization=localization, beacon=beacon)
new_place.save()
from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Product from App.loyaltyMe.models import Product
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand): class Command(BaseCommand):
help = 'Closes the specified poll for voting' help = 'Closes the specified poll for voting'
def handle(self, *args, **options): def handle(self, *args, **options):
products = [ products = [
#['name', 'description', 'price', 'img' ], # ['name', 'description', 'price', 'img' ],
['Kawa Latte', 'Z nutą czekolady', '7 zł', '/static/img/photo_1.jpg'], ['Kawa Latte', 'Z nutą czekolady', '7 zł', '/static/img/photo_1.jpg'],
['Herbata', 'Z nutą czekolady', '4 zł', '/static/img/photo_1.jpg'], ['Herbata', 'Z nutą czekolady', '4 zł', '/static/img/photo_1.jpg'],
['Ciasto', 'Z nutą czekolady', '5 zł', '/static/img/photo_1.jpg'], ['Ciasto', 'Z nutą czekolady', '5 zł', '/static/img/photo_1.jpg'],
['Espresso', 'Mała czarna', '5 zł', '/static/img/photo_1.jpg'], ['Espresso', 'Mała czarna', '5 zł', '/static/img/photo_1.jpg'],
] ]
print("Creating Products") print("Creating Products")
for product in products: for product in products:
print('Create {0}'.format(product[0])) print('Create {0}'.format(product[0]))
new_product = Product.objects.create(name=product[0], description=product[1], price=product[2], img=product[3]) new_product = Product.objects.create(name=product[0], description=product[1], price=product[2],
new_product.save() img=product[3])
\ No newline at end of file new_product.save()
from App.loyaltyMe.models import Promotion
from datetime import datetime from datetime import datetime
from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Promotion
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand): class Command(BaseCommand):
help = 'Closes the specified poll for voting' help = 'Closes the specified poll for voting'
def handle(self, *args, **options): def handle(self, *args, **options):
promotions = [ promotions = [
#[name, description, code, img, status] # [name, description, code, img, status]
['10%', 'Zniżka 10%', '5ac5','/static/img/photo_1.jpg' , 'New', '200', None, None], ['10%', 'Zniżka 10%', '5ac5', '/static/img/photo_1.jpg', 'New', '200', None, None],
['20%', 'Zniżka 20%', '5ac6','/static/img/photo_1.jpg' , 'New', None, None, None], ['20%', 'Zniżka 20%', '5ac6', '/static/img/photo_1.jpg', 'New', None, None, None],
['50%', 'Zniżka 50%', '5ac7','/static/img/photo_1.jpg' , 'New', '0', datetime(2016, 5, 22, 11, 30, 59), datetime(2017, 12, 22, 11, 30, 59)], ['50%', 'Zniżka 50%', '5ac7', '/static/img/photo_1.jpg', 'New', '0', datetime(2016, 5, 22, 11, 30, 59),
] datetime(2017, 12, 22, 11, 30, 59)],
]
print("Creating Promotions") print("Creating Promotions")
for promotion in promotions: for promotion in promotions:
print('Create {0}'.format(promotion[0])) print('Create {0}'.format(promotion[0]))
new_promotion = Promotion.objects.create(name=promotion[0], description=promotion[1], code=promotion[2], img=promotion[3], status=promotion[4], left_number=promotion[5], start_date=promotion[6], end_date=promotion[7]) new_promotion = Promotion.objects.create(name=promotion[0], description=promotion[1], code=promotion[2],
new_promotion.save() img=promotion[3], status=promotion[4], left_number=promotion[5],
\ No newline at end of file start_date=promotion[6], end_date=promotion[7])
new_promotion.save()
from django.contrib.auth.models import User
from App.loyaltyMe.models import PromotionSet, Promotion from App.loyaltyMe.models import PromotionSet, Promotion
from django.core.management.base import BaseCommand
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand): class Command(BaseCommand):
help = 'Closes the specified poll for voting' help = 'Closes the specified poll for voting'
def handle(self, *args, **options): def handle(self, *args, **options):
promotion_sets = [ promotion_sets = [
#'name',products # 'name',products
['Promocja1', ['10%', '20%'] ], ['Promocja1', ['10%', '20%']],
['Promocja2', ['20%', '50%'] ], ['Promocja2', ['20%', '50%']],
] ]
print("Creating PromotionSets") print("Creating PromotionSets")
for promotion_set in promotion_sets: for promotion_set in promotion_sets:
print('Create {0}'.format(promotion_set[0])) print('Create {0}'.format(promotion_set[0]))
...@@ -23,4 +19,4 @@ class Command(BaseCommand): ...@@ -23,4 +19,4 @@ class Command(BaseCommand):
print(product) print(product)
pro_obj = Promotion.objects.filter(name=product)[0] pro_obj = Promotion.objects.filter(name=product)[0]
new_promotion_set.promotions.add(pro_obj) new_promotion_set.promotions.add(pro_obj)
new_promotion_set.save() new_promotion_set.save()
\ No newline at end of file
...@@ -31,12 +31,13 @@ class PromotionSet(models.Model): ...@@ -31,12 +31,13 @@ class PromotionSet(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
promotions = models.ManyToManyField(Promotion, default='') promotions = models.ManyToManyField(Promotion, default='')
class Localization(models.Model): class Localization(models.Model):
latitude = models.CharField(max_length=50,) latitude = models.CharField(max_length=50, )
longitude = models.CharField(max_length=50,) longitude = models.CharField(max_length=50, )
city = models.CharField(max_length=50,) city = models.CharField(max_length=50, )
road = models.CharField(max_length=50,) road = models.CharField(max_length=50, )
road_number = models.CharField(max_length=50,) road_number = models.CharField(max_length=50, )
class Beacon(models.Model): class Beacon(models.Model):
...@@ -47,10 +48,9 @@ class Beacon(models.Model): ...@@ -47,10 +48,9 @@ class Beacon(models.Model):
description = models.CharField(max_length=300, null=True) description = models.CharField(max_length=300, null=True)
class Place(models.Model): class Place(models.Model):
name = models.CharField(max_length=50, unique=True) name = models.CharField(max_length=50, unique=True)
type = models.CharField(max_length=50,) type = models.CharField(max_length=50, )
screen_img = models.ImageField() screen_img = models.ImageField()
logo_img = models.ImageField() logo_img = models.ImageField()
description = models.CharField(max_length=50) description = models.CharField(max_length=50)
...@@ -58,4 +58,3 @@ class Place(models.Model): ...@@ -58,4 +58,3 @@ class Place(models.Model):
promotion = models.ForeignKey(PromotionSet, null=True, blank=True) promotion = models.ForeignKey(PromotionSet, null=True, blank=True)
localization = models.ForeignKey(Localization, null=True, blank=True) localization = models.ForeignKey(Localization, null=True, blank=True)
beacon = models.ForeignKey(Beacon, null=True, blank=True) beacon = models.ForeignKey(Beacon, null=True, blank=True)
...@@ -42,6 +42,7 @@ class BeaconSerializer(serializers.HyperlinkedModelSerializer): ...@@ -42,6 +42,7 @@ class BeaconSerializer(serializers.HyperlinkedModelSerializer):
model = Beacon model = Beacon
fields = ('url', 'id', 'uuid', 'major', 'minor', 'name', 'description') fields = ('url', 'id', 'uuid', 'major', 'minor', 'name', 'description')
class PlaceSerializer(serializers.HyperlinkedModelSerializer): class PlaceSerializer(serializers.HyperlinkedModelSerializer):
offer = OfferSerializer() offer = OfferSerializer()
promotion = PromotionSetSerializer() promotion = PromotionSetSerializer()
...@@ -50,4 +51,6 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer): ...@@ -50,4 +51,6 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Place model = Place
fields = ('url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion', 'localization' ,'beacon') fields = (
'url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion', 'localization',
'beacon')
from django.test import TestCase
# Create your tests here. # Create your tests here.
from django.shortcuts import render
from rest_framework import viewsets, permissions from rest_framework import viewsets, permissions
from rest_framework.decorators import list_route
from App.loyaltyMe.models import Product, Offer, Promotion, Place, PromotionSet, Localization, Beacon from App.loyaltyMe.models import Product, Offer, Promotion, Place, PromotionSet, Localization, Beacon
from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer, \ from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer, \
...@@ -15,6 +13,7 @@ class ProductViewSet(viewsets.ModelViewSet): ...@@ -15,6 +13,7 @@ class ProductViewSet(viewsets.ModelViewSet):
serializer_class = ProductSerializer serializer_class = ProductSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class OfferViewSet(viewsets.ModelViewSet): class OfferViewSet(viewsets.ModelViewSet):
""" """
API for articles API for articles
...@@ -23,6 +22,7 @@ class OfferViewSet(viewsets.ModelViewSet): ...@@ -23,6 +22,7 @@ class OfferViewSet(viewsets.ModelViewSet):
serializer_class = OfferSerializer serializer_class = OfferSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PromotionViewSet(viewsets.ModelViewSet): class PromotionViewSet(viewsets.ModelViewSet):
""" """
API for articles API for articles
...@@ -31,6 +31,7 @@ class PromotionViewSet(viewsets.ModelViewSet): ...@@ -31,6 +31,7 @@ class PromotionViewSet(viewsets.ModelViewSet):
serializer_class = PromotionSerializer serializer_class = PromotionSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PromotionSetViewSet(viewsets.ModelViewSet): class PromotionSetViewSet(viewsets.ModelViewSet):
""" """
API for articles API for articles
...@@ -40,7 +41,6 @@ class PromotionSetViewSet(viewsets.ModelViewSet): ...@@ -40,7 +41,6 @@ class PromotionSetViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PlaceViewSet(viewsets.ModelViewSet): class PlaceViewSet(viewsets.ModelViewSet):
""" """
API for articles API for articles
...@@ -58,10 +58,11 @@ class LocalizationViewSet(viewsets.ModelViewSet): ...@@ -58,10 +58,11 @@ class LocalizationViewSet(viewsets.ModelViewSet):
serializer_class = LocalizationSerializer serializer_class = LocalizationSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class BeaconViewSet(viewsets.ModelViewSet): class BeaconViewSet(viewsets.ModelViewSet):
""" """
API for articles API for articles
""" """
queryset = Beacon.objects.all() queryset = Beacon.objects.all()
serializer_class = BeaconSerializer serializer_class = BeaconSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
\ No newline at end of file
from django.contrib import admin
# Register your models here. # Register your models here.
from django.db import models
# Create your models here. # Create your models here.
import sys
from io import StringIO
from django.test import TestCase from django.test import TestCase
from flake8.engine import get_style_guide
from KawowyDzienniczek.settings import BASE_DIR
EXCLUDE_FROM_PEP8_TESTS = ['manage.py', '__init__.py']
# core/tests/io.py
class CaptureStdout(object):
"""
Capture STDOUT as self.value when used as a context manager.
Example:
class PrintingTestCase(SimpleTestCase):
def test_printing(self):
with CaptureStdout() as stdout:
print('oh hi')
self.assertEqual(str(stdout), 'oh hi\n')
"""
def __init__(self):
self.value = ''
self.old_stdout = None
def __str__(self):
return self.value
def __enter__(self):
self.old_stdout = sys.stdout
sys.stdout = StringIO()
return self
def __exit__(self, *exc_info):
self.value = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = self.old_stdout
# Create your tests here. class Flake8ConformanceTestCase(TestCase):
def test_flake8_conformance(self):
with CaptureStdout() as stdout:
flake8_style = get_style_guide(paths=[BASE_DIR])
report = flake8_style.check_files()
if report.total_errors > 0:
self.fail(
'Got some flake8 errors:\n{0}'.format(stdout),
)
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
def coming_soon_page(request): def coming_soon_page(request):
return render(request, 'page/index.html', {}) return render(request, 'page/index.html', {})
def main_page(request): def main_page(request):
return render(request, 'main_page/index.html', {}) return render(request, 'main_page/index.html', {})
\ No newline at end of file
from django.contrib import admin
# Register your models here. # Register your models here.
from django.contrib.auth.models import User
from django.core.management import call_command from django.core.management import call_command
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand
class Command(BaseCommand): class Command(BaseCommand):
help = '' help = ''
...@@ -16,6 +16,3 @@ class Command(BaseCommand): ...@@ -16,6 +16,3 @@ class Command(BaseCommand):
call_command('init_promotionsets') call_command('init_promotionsets')
call_command('init_localizations') call_command('init_localizations')
call_command('init_places') call_command('init_places')
call_command('init_userpromotions')
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from App.user.models import UserProfile from App.user.models import UserProfile
__author__ = 'Rafal'
from django.core.management.base import BaseCommand
class Command(BaseCommand): class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
data = [ data = [
['admin', '/static/img/users/photos/default_avatar.png',], ['admin', '/static/img/users/photos/default_avatar.png', ],
['Antek', '/static/img/users/photos/antek.jpg',], ['Antek', '/static/img/users/photos/antek.jpg', ],
['Rafal', '/static/img/users/photos/rafal.jpg'], ['Rafal', '/static/img/users/photos/rafal.jpg'],
['Klaudia', '/static/img/users/photos/klaudia.jpg'], ['Klaudia', '/static/img/users/photos/klaudia.jpg'],
] ]
print("Creating UsersProfile") print("Creating UsersProfile")
for user_data in data: for user_data in data:
...@@ -22,4 +19,3 @@ class Command(BaseCommand): ...@@ -22,4 +19,3 @@ class Command(BaseCommand):
user = User.objects.filter(username=user_data[0])[0] user = User.objects.filter(username=user_data[0])[0]
new_userapi = UserProfile.objects.create(user=user, photo=user_data[1]) new_userapi = UserProfile.objects.create(user=user, photo=user_data[1])
new_userapi.save() new_userapi.save()
from django.contrib.auth.models import User
from App.loyaltyMe.models import Place, Promotion
from App.user.models import UserPromotion
__author__ = 'Rafal'
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
user_promotions = [
# user = models.ForeignKey(User, related_name='user_promotion',
# blank=False, null=False, default=None)
# place = models.ForeignKey(Place)
# promotion = models.ForeignKey(Promotion)
# status = models.CharField(max_length=30)
# code = models.CharField(max_length=20)
['Klaudia', 'Kocia Kawiarnia', '10%', 'used' ,'abcd'],
['Klaudia', 'Kafcia u Olczaka', '20%', 'in_progress', None],
['Antek', 'Kafcia u Olczaka', '50%', 'in_progress', None],
['admin', 'Kafcia u Olczaka', '10%', 'in_progress', None],
]
print("Creating Awards")
for user_promotion in user_promotions:
print('Create {0}'.format(user_promotion[0]))
user = User.objects.filter(username=user_promotion[0])[0]
place = Place.objects.filter(name=user_promotion[1])[0]
promotion = Promotion.objects.filter(name=user_promotion[2])[0]
new_user_promotion = UserPromotion.objects.create(user=user, place=place, promotion=promotion, status=user_promotion[3], code=user_promotion[4])
new_user_promotion.save()
\ No newline at end of file
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand): class Command(BaseCommand):
help = 'Closes the specified poll for voting' help = 'Closes the specified poll for voting'
...@@ -10,12 +9,13 @@ class Command(BaseCommand): ...@@ -10,12 +9,13 @@ class Command(BaseCommand):
users = [ users = [
['admin', 'admin', 'admin@gmail.com', ], ['admin', 'admin', 'admin@gmail.com', ],
['Antek', 'Antek', 'antek@gmail.com'], ['Antek', 'Antek', 'antek@gmail.com'],
['Rafal','Rafal', 'rafal@gmail.com'], ['Rafal', 'Rafal', 'rafal@gmail.com'],
['Klaudia','Klaudia', 'klaudia@gmail.com'] ['Klaudia', 'Klaudia', 'klaudia@gmail.com']
] ]
print("Creating Users") print("Creating Users")
for user in users: for user in users:
print('Create {0}'.format(user[0])) print('Create {0}'.format(user[0]))
new_user = User.objects.create(username=user[0], password=user[1], email=user[2],is_active=True, is_superuser=True, is_staff=True,) new_user = User.objects.create(username=user[0], password=user[1], email=user[2], is_active=True,
is_superuser=True, is_staff=True, )
new_user.set_password(user[1]) new_user.set_password(user[1])
new_user.save() new_user.save()
\ No newline at end of file
...@@ -13,11 +13,13 @@ def create_auth_token(sender, instance=None, created=False, **kwargs): ...@@ -13,11 +13,13 @@ def create_auth_token(sender, instance=None, created=False, **kwargs):
if created: if created:
Token.objects.create(user=instance) Token.objects.create(user=instance)
class UserProfile(models.Model): class UserProfile(models.Model):
user = models.ForeignKey(User, related_name='user_profile', user = models.ForeignKey(User, related_name='user_profile',
blank=False, null=False, default=None) blank=False, null=False, default=None)
photo = models.ImageField() photo = models.ImageField()
class UserPromotion(models.Model): class UserPromotion(models.Model):
user = models.ForeignKey(User, related_name='user_promotion', user = models.ForeignKey(User, related_name='user_promotion',
blank=False, null=False, default=None) blank=False, null=False, default=None)
...@@ -25,5 +27,3 @@ class UserPromotion(models.Model): ...@@ -25,5 +27,3 @@ class UserPromotion(models.Model):
promotion = models.ForeignKey(Promotion) promotion = models.ForeignKey(Promotion)
status = models.CharField(max_length=30) status = models.CharField(max_length=30)
code = models.CharField(max_length=20, null=True) code = models.CharField(max_length=20, null=True)
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from rest_framework import serializers
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
from App.loyaltyMe.serializers import PlaceSerializer, PromotionSerializer from App.loyaltyMe.serializers import PlaceSerializer, PromotionSerializer
from App.user.models import UserProfile, UserPromotion from App.user.models import UserProfile, UserPromotion
...@@ -16,6 +15,7 @@ class UserSerializer(serializers.HyperlinkedModelSerializer): ...@@ -16,6 +15,7 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
class UserProfileSerializer(serializers.HyperlinkedModelSerializer): class UserProfileSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer() user = UserSerializer()
class Meta: class Meta:
model = UserProfile model = UserProfile
fields = ('url', 'id', 'user', 'photo') fields = ('url', 'id', 'user', 'photo')
...@@ -50,6 +50,7 @@ class AuthTokenSerializerByEmail(serializers.Serializer): ...@@ -50,6 +50,7 @@ class AuthTokenSerializerByEmail(serializers.Serializer):
attrs['user'] = user attrs['user'] = user
return attrs return attrs
class UserPromotionSerializer(serializers.HyperlinkedModelSerializer): class UserPromotionSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer() user = UserSerializer()
place = PlaceSerializer() place = PlaceSerializer()
...@@ -58,4 +59,3 @@ class UserPromotionSerializer(serializers.HyperlinkedModelSerializer): ...@@ -58,4 +59,3 @@ class UserPromotionSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = UserPromotion model = UserPromotion
fields = ('url', 'id', 'user', 'place', 'promotion', 'status', 'code') fields = ('url', 'id', 'user', 'place', 'promotion', 'status', 'code')
from django.test import TestCase
# Create your tests here. # Create your tests here.
from xml import parsers
import rest_framework import rest_framework
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.shortcuts import render
# Create your views here. # Create your views here.
from rest_framework import viewsets
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.authtoken.serializers import AuthTokenSerializer from rest_framework.decorators import list_route
from rest_framework.decorators import list_route, detail_route
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework import viewsets, permissions from rest_framework import viewsets, permissions
from rest_framework.views import APIView from rest_framework.views import APIView
from App.loyaltyMe.models import Place
from App.loyaltyMe.serializers import LocalizationSerializer
from App.user.models import UserProfile, UserPromotion from App.user.models import UserProfile, UserPromotion
from App.user.serializers import UserSerializer, AuthTokenSerializerByEmail, UserProfileSerializer, \ from App.user.serializers import UserSerializer, AuthTokenSerializerByEmail, UserProfileSerializer, \
UserPromotionSerializer UserPromotionSerializer
...@@ -95,17 +88,3 @@ class UserPromotionViewSet(viewsets.ModelViewSet): ...@@ -95,17 +88,3 @@ class UserPromotionViewSet(viewsets.ModelViewSet):
page = self.paginate_queryset(queryset) page = self.paginate_queryset(queryset)
serializer = UserPromotionSerializer(page, many=True, context={'request': request}) serializer = UserPromotionSerializer(page, many=True, context={'request': request})
return self.get_paginated_response(serializer.data) return self.get_paginated_response(serializer.data)
class PlaceUserPromotionsViewSet(viewsets.ModelViewSet):
base_name = "place_user_promotions"
queryset = UserPromotion.objects.all()
serializer_class = UserPromotionSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
def retrieve(self, request, pk):
place = Place.objects.filter(pk=pk)[0]
user_promotions = request.user.user_promotion.filter(place=place)
page = self.paginate_queryset(user_promotions)
serializer = UserPromotionSerializer(page, many=True, context={'request': request})
return self.get_paginated_response(serializer.data)
...@@ -10,4 +10,3 @@ DATABASES = { ...@@ -10,4 +10,3 @@ DATABASES = {
'PORT': '5432', 'PORT': '5432',
} }
} }
...@@ -148,4 +148,4 @@ PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) ...@@ -148,4 +148,4 @@ PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static') STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media') MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
APPEND_SLASH = True APPEND_SLASH = True
\ No newline at end of file
...@@ -14,20 +14,17 @@ Including another URLconf ...@@ -14,20 +14,17 @@ Including another URLconf
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
""" """
from django.conf.urls import url, include from django.conf.urls import url, include
from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from rest_framework import routers from rest_framework import routers
from App.loyaltyMe import views as loyalty_views
from App.page.views import coming_soon_page, main_page from App.page.views import coming_soon_page, main_page
from App.user import views as user_views from App.user import views as user_views
from App.loyaltyMe import views as loyalty_views
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'user', user_views.UserViewSet) router.register(r'user', user_views.UserViewSet)
router.register(r'user_profile', user_views.UserProfileViewSet) router.register(r'user_profile', user_views.UserProfileViewSet)
router.register(r'user_promotions', user_views.UserPromotionViewSet, base_name='user_promotions') router.register(r'user_promotions', user_views.UserPromotionViewSet, base_name='user_promotions')
router.register(r'place_user_promotions', user_views.PlaceUserPromotionsViewSet)
router.register(r'products', loyalty_views.ProductViewSet) router.register(r'products', loyalty_views.ProductViewSet)
router.register(r'offers', loyalty_views.OfferViewSet) router.register(r'offers', loyalty_views.OfferViewSet)
router.register(r'promotions', loyalty_views.PromotionViewSet) router.register(r'promotions', loyalty_views.PromotionViewSet)
......
# setup.cfg
[flake8]
exclude = migrations,local_settings.py,production_settings.py
max-complexity = 10
max-line-length = 120
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment