Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
K
KawowyDzienniczek
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rafal
KawowyDzienniczek
Commits
18daeca3
Commit
18daeca3
authored
Jul 18, 2016
by
lizonr1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Tasks and Tasks
parent
25f3edf2
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
98 additions
and
11 deletions
+98
-11
init_promotions.py
...czek/App/loyaltyMe/management/commands/init_promotions.py
+7
-6
init_tasks.py
...ienniczek/App/loyaltyMe/management/commands/init_tasks.py
+27
-0
models.py
KawowyDzienniczek/App/loyaltyMe/models.py
+32
-2
serializers.py
KawowyDzienniczek/App/loyaltyMe/serializers.py
+8
-1
tests.py
KawowyDzienniczek/App/loyaltyMe/tests.py
+14
-0
views.py
KawowyDzienniczek/App/loyaltyMe/views.py
+10
-2
No files found.
KawowyDzienniczek/App/loyaltyMe/management/commands/init_promotions.py
View file @
18daeca3
from
datetime
import
datetime
from
django.core.management.base
import
BaseCommand
from
App.loyaltyMe.models
import
Promotion
from
App.loyaltyMe.models
import
Promotion
,
Task
class
Command
(
BaseCommand
):
...
...
@@ -9,15 +9,16 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
options
):
promotions
=
[
# [name, description, code, img, status]
[
'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
],
[
'50
%
'
,
'Zniżka 50
%
'
,
'5ac7'
,
'/static/img/photo_1.jpg'
,
'
New
'
,
'0'
,
datetime
(
2016
,
5
,
22
,
11
,
30
,
59
),
[
'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'
,
'
AV'
,
'Bądź u nas 10 godzin
'
,
None
,
None
,
None
],
[
'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
)],
]
print
(
"Creating Promotions"
)
for
promotion
in
promotions
:
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
],
img
=
promotion
[
3
],
status
=
promotion
[
4
],
left_number
=
promotion
[
5
],
start_date
=
promotion
[
6
],
end_date
=
promotion
[
7
])
img
=
promotion
[
3
],
status
=
promotion
[
4
],
task
=
task
,
left_number
=
promotion
[
6
],
start_date
=
promotion
[
7
],
end_date
=
promotion
[
8
])
new_promotion
.
save
()
KawowyDzienniczek/App/loyaltyMe/management/commands/init_tasks.py
0 → 100644
View file @
18daeca3
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
()
KawowyDzienniczek/App/loyaltyMe/models.py
View file @
18daeca3
from
django.db
import
models
# Create your models here.
...
...
@@ -16,12 +15,43 @@ class Offer(models.Model):
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
):
USED
=
'US'
ACTIVE
=
'AC'
AVAILABLE
=
'AV'
STATUS_CHOICES
=
(
(
USED
,
'Used'
),
(
ACTIVE
,
'Active'
),
(
AVAILABLE
,
'Available'
),
)
name
=
models
.
CharField
(
max_length
=
50
)
description
=
models
.
CharField
(
max_length
=
50
)
code
=
models
.
CharField
(
max_length
=
50
)
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
)
start_date
=
models
.
DateField
(
null
=
True
)
end_date
=
models
.
DateField
(
null
=
True
)
...
...
KawowyDzienniczek/App/loyaltyMe/serializers.py
View file @
18daeca3
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
):
...
...
@@ -54,3 +54,10 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer):
fields
=
(
'url'
,
'id'
,
'name'
,
'type'
,
'screen_img'
,
'logo_img'
,
'description'
,
'offer'
,
'promotion'
,
'localization'
,
'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'
)
KawowyDzienniczek/App/loyaltyMe/tests.py
View file @
18daeca3
# 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
()
KawowyDzienniczek/App/loyaltyMe/views.py
View file @
18daeca3
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
,
\
PromotionSetSerializer
,
LocalizationSerializer
,
BeaconSerializer
PromotionSetSerializer
,
LocalizationSerializer
,
BeaconSerializer
,
TaskSerializer
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -66,3 +66,11 @@ class BeaconViewSet(viewsets.ModelViewSet):
queryset
=
Beacon
.
objects
.
all
()
serializer_class
=
BeaconSerializer
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment