Commit 18daeca3 authored by lizonr1's avatar lizonr1

Add Tasks and Tasks

parent 25f3edf2
from datetime import datetime from datetime import datetime
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Promotion from App.loyaltyMe.models import Promotion, Task
class Command(BaseCommand): class Command(BaseCommand):
...@@ -9,15 +9,16 @@ class Command(BaseCommand): ...@@ -9,15 +9,16 @@ class Command(BaseCommand):
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', 'AV','Bądź u nas 10 godzin', '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', 'AV', 'Bądź u nas 10 godzin', None, None, None],
['50%', 'Zniżka 50%', '5ac7', '/static/img/photo_1.jpg', 'New', '0', datetime(2016, 5, 22, 11, 30, 59), ['50%', 'Zniżka 50%', '5ac7', '/static/img/photo_1.jpg', 'AV', 'Przyjdz 10 razy', '0', datetime(2016, 5, 22, 11, 30, 59),
datetime(2017, 12, 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]))
task = Task.objects.filter(name=promotion[5])[0]
new_promotion = Promotion.objects.create(name=promotion[0], description=promotion[1], code=promotion[2], new_promotion = Promotion.objects.create(name=promotion[0], description=promotion[1], code=promotion[2],
img=promotion[3], status=promotion[4], left_number=promotion[5], img=promotion[3], status=promotion[4], task=task, left_number=promotion[6],
start_date=promotion[6], end_date=promotion[7]) start_date=promotion[7], end_date=promotion[8])
new_promotion.save() new_promotion.save()
import datetime
from django.core.management.base import BaseCommand
from django.forms import DateField
from App.loyaltyMe.models import Task
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
tasks = [
# 'name',products
['Bądź u nas 10 godzin', datetime.datetime.now(), 'description', 'TM', datetime.timedelta(seconds=15),
datetime.timedelta(seconds=15), datetime.timedelta(seconds=15), datetime.timedelta(seconds=15)],
['Przyjdz 10 razy', datetime.datetime.now(), 'description', 'PR', datetime.timedelta(seconds=15),
datetime.timedelta(seconds=15), datetime.timedelta(seconds=15), datetime.timedelta(seconds=15)],
]
print("Creating Offers")
for task in tasks:
print('Create {0}'.format(task[0]))
new_task = Task.objects.create(name=task[0], update_delay=task[1], description=task[2], type=task[3],
counter_target=task[4], beacon_counter_target=task[5],
counter_incrementation=task[6], beacon_signal_delay=task[7])
new_task.save()
from django.db import models from django.db import models
# Create your models here. # Create your models here.
...@@ -16,12 +15,43 @@ class Offer(models.Model): ...@@ -16,12 +15,43 @@ class Offer(models.Model):
products = models.ManyToManyField(Product) products = models.ManyToManyField(Product)
class Task(models.Model):
TIME = 'TM'
PRESENCE = 'PR'
TYPE_CHOICES = (
(TIME, 'Time'),
(PRESENCE, 'Presence'),
)
type = models.CharField(max_length=2, choices=TYPE_CHOICES, default=PRESENCE)
update_delay = models.DateField()
description = models.CharField(max_length=50)
name = models.CharField(max_length=50)
counter_target = models.DurationField()
beacon_counter_target = models.DurationField()
counter_incrementation = models.DurationField()
beacon_signal_delay = models.DurationField()
class Promotion(models.Model): class Promotion(models.Model):
USED = 'US'
ACTIVE = 'AC'
AVAILABLE = 'AV'
STATUS_CHOICES = (
(USED, 'Used'),
(ACTIVE, 'Active'),
(AVAILABLE, 'Available'),
)
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
description = models.CharField(max_length=50) description = models.CharField(max_length=50)
code = models.CharField(max_length=50) code = models.CharField(max_length=50)
img = models.ImageField() img = models.ImageField()
status = models.CharField(max_length=50) status = models.CharField(max_length=2, choices=STATUS_CHOICES, default=AVAILABLE)
task = models.ForeignKey(Task)
left_number = models.IntegerField(null=True) left_number = models.IntegerField(null=True)
start_date = models.DateField(null=True) start_date = models.DateField(null=True)
end_date = models.DateField(null=True) end_date = models.DateField(null=True)
......
from rest_framework import serializers from rest_framework import serializers
from App.loyaltyMe.models import Product, Offer, Promotion, Place, Localization, Beacon from App.loyaltyMe.models import Product, Offer, Promotion, Place, Localization, Beacon, Task
class ProductSerializer(serializers.HyperlinkedModelSerializer): class ProductSerializer(serializers.HyperlinkedModelSerializer):
...@@ -54,3 +54,10 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer): ...@@ -54,3 +54,10 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer):
fields = ( fields = (
'url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion', 'localization', 'url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion', 'localization',
'beacon') 'beacon')
class TaskSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Task
fields = ('url', 'id', 'type', 'update_delay', 'description', 'name', 'counter_target', 'beacon_counter_target',
'counter_incrementation', 'beacon_signal_delay')
# Create your tests here. # Create your tests here.
import datetime
from unittest import TestCase
from App.loyaltyMe.models import Task, UserTask
class UserTaskTestCase(TestCase):
def setUp(self):
self.task = Task(beacon_signal_delay=10)
self.beacon_signal_last_update = datetime.datetime.now() - datetime.timedelta(seconds=15)
self.user_task = UserTask(task=self.task, beacon_signal_last_update=self.beacon_signal_last_update)
def test_lol(self):
self.user_task.update()
from rest_framework import viewsets, permissions from rest_framework import viewsets, permissions
from App.loyaltyMe.models import Product, Offer, Promotion, Place, PromotionSet, Localization, Beacon from App.loyaltyMe.models import Product, Offer, Promotion, Place, PromotionSet, Localization, Beacon, Task
from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer, \ from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer, \
PromotionSetSerializer, LocalizationSerializer, BeaconSerializer PromotionSetSerializer, LocalizationSerializer, BeaconSerializer, TaskSerializer
class ProductViewSet(viewsets.ModelViewSet): class ProductViewSet(viewsets.ModelViewSet):
...@@ -66,3 +66,11 @@ class BeaconViewSet(viewsets.ModelViewSet): ...@@ -66,3 +66,11 @@ class BeaconViewSet(viewsets.ModelViewSet):
queryset = Beacon.objects.all() queryset = Beacon.objects.all()
serializer_class = BeaconSerializer serializer_class = BeaconSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,) permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class TaskViewSet(viewsets.ModelViewSet):
"""
API for articles
"""
queryset = Task.objects.all()
serializer_class = TaskSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
\ 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