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
0eed7be0
Commit
0eed7be0
authored
Jul 26, 2016
by
lizonr1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add correct timezone and project status
parent
ba71abf6
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
125 additions
and
60 deletions
+125
-60
init_products.py
...niczek/App/loyaltyMe/management/commands/init_products.py
+4
-3
init_tasks.py
...ienniczek/App/loyaltyMe/management/commands/init_tasks.py
+4
-3
models.py
KawowyDzienniczek/App/loyaltyMe/models.py
+5
-5
test_models.py
KawowyDzienniczek/App/loyaltyMe/test_models.py
+32
-16
views.py
KawowyDzienniczek/App/loyaltyMe/views.py
+15
-0
init.py
KawowyDzienniczek/App/user/management/commands/init.py
+1
-1
init_userpromotions.py
...iczek/App/user/management/commands/init_userpromotions.py
+12
-8
init_usertasks.py
...zienniczek/App/user/management/commands/init_usertasks.py
+8
-5
models.py
KawowyDzienniczek/App/user/models.py
+38
-17
serializers.py
KawowyDzienniczek/App/user/serializers.py
+5
-2
requirements.txt
requirements.txt
+1
-0
No files found.
KawowyDzienniczek/App/loyaltyMe/management/commands/init_products.py
View file @
0eed7be0
...
@@ -11,7 +11,8 @@ class Command(BaseCommand):
...
@@ -11,7 +11,8 @@ class Command(BaseCommand):
products
=
PRODUCTS_SAMPLE_DATA
products
=
PRODUCTS_SAMPLE_DATA
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
[
'name'
]))
new_product
=
Product
.
objects
.
create
(
name
=
product
[
0
],
description
=
product
[
1
],
price
=
product
[
2
],
new_product
=
Product
.
objects
.
create
(
name
=
product
[
'name'
],
description
=
product
[
'description'
],
img
=
product
[
3
])
price
=
product
[
'price'
],
img
=
product
[
'img'
])
new_product
.
save
()
new_product
.
save
()
KawowyDzienniczek/App/loyaltyMe/management/commands/init_tasks.py
View file @
0eed7be0
...
@@ -14,16 +14,17 @@ class Command(BaseCommand):
...
@@ -14,16 +14,17 @@ class Command(BaseCommand):
# 'name',products
# 'name',products
[
'Bądź u nas 10 godzin'
,
timedelta
(
seconds
=
10
),
'description'
,
'TM'
,
4
,
[
'Bądź u nas 10 godzin'
,
timedelta
(
seconds
=
10
),
'description'
,
'TM'
,
4
,
15
,
15
,
timedelta
(
seconds
=
15
)],
15
,
15
,
timedelta
(
seconds
=
15
)
,
timedelta
(
seconds
=
300
)
],
[
'Przyjdz 10 razy'
,
timedelta
(
seconds
=
10
),
'description'
,
'TM'
,
4
,
[
'Przyjdz 10 razy'
,
timedelta
(
seconds
=
10
),
'description'
,
'TM'
,
4
,
15
,
15
,
timedelta
(
seconds
=
15
)],
15
,
15
,
timedelta
(
seconds
=
15
)
,
timedelta
(
seconds
=
300
)
],
]
]
print
(
"Creating Tasks"
)
print
(
"Creating Tasks"
)
for
task
in
tasks
:
for
task
in
tasks
:
print
(
'Create {0}'
.
format
(
task
[
0
]))
print
(
'Create {0}'
.
format
(
task
[
0
]))
new_task
=
Task
.
objects
.
create
(
name
=
task
[
0
],
update_delay
=
task
[
1
],
description
=
task
[
2
],
type
=
task
[
3
],
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_target
=
task
[
4
],
beacon_counter_target
=
task
[
5
],
counter_incrementation
=
task
[
6
],
beacon_signal_delay
=
task
[
7
])
counter_incrementation
=
task
[
6
],
beacon_signal_delay
=
task
[
7
],
beacon_singal_delay_maximum_delay
=
task
[
8
])
...
...
KawowyDzienniczek/App/loyaltyMe/models.py
View file @
0eed7be0
...
@@ -32,18 +32,18 @@ class Task(models.Model):
...
@@ -32,18 +32,18 @@ class Task(models.Model):
counter_incrementation
=
models
.
IntegerField
()
# o 1 # Tego nie widzi user
counter_incrementation
=
models
.
IntegerField
()
# o 1 # Tego nie widzi user
beacon_counter_target
=
models
.
IntegerField
()
# 3x # 1x # tego nie widiz user
beacon_counter_target
=
models
.
IntegerField
()
# 3x # 1x # tego nie widiz user
beacon_signal_delay
=
models
.
DurationField
()
# przez 5minut # co 5 minut #tego nie widzi user
beacon_signal_delay
=
models
.
DurationField
()
# przez 5minut # co 5 minut #tego nie widzi user
beacon_singal_delay_maximum_delay
=
models
.
DurationField
()
# ale po 20 minutach sie restartuje
def
__str__
(
self
):
return
self
.
name
class
Promotion
(
models
.
Model
):
class
Promotion
(
models
.
Model
):
USED
=
'US'
ACTIVE
=
'AC'
AVAILABLE
=
'AV'
AVAILABLE
=
'AV'
NON_AVAILABLE
=
'NAV'
STATUS_CHOICES
=
(
STATUS_CHOICES
=
(
(
USED
,
'Used'
),
(
ACTIVE
,
'Active'
),
(
AVAILABLE
,
'Available'
),
(
AVAILABLE
,
'Available'
),
(
NON_AVAILABLE
,
'Non Available'
),
)
)
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
...
...
KawowyDzienniczek/App/loyaltyMe/test_models.py
View file @
0eed7be0
# Create your tests here.
# Create your tests here.
from
datetime
import
datetime
,
timedelta
from
datetime
import
timedelta
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.utils
import
timezone
from
App.loyaltyMe.models
import
Task
from
App.loyaltyMe.models
import
Task
from
App.user.models
import
UserTask
from
App.user.models
import
UserTask
...
@@ -13,7 +14,11 @@ class TaskTestCase(TestCase):
...
@@ -13,7 +14,11 @@ class TaskTestCase(TestCase):
self
.
task
=
Task
.
objects
.
get_or_create
(
type
=
"TM"
,
update_delay
=
timedelta
(
seconds
=
10
),
self
.
task
=
Task
.
objects
.
get_or_create
(
type
=
"TM"
,
update_delay
=
timedelta
(
seconds
=
10
),
description
=
"Test_description"
,
name
=
"test_name"
,
counter_target
=
1
,
description
=
"Test_description"
,
name
=
"test_name"
,
counter_target
=
1
,
beacon_counter_target
=
2
,
counter_incrementation
=
1
,
beacon_counter_target
=
2
,
counter_incrementation
=
1
,
beacon_signal_delay
=
timedelta
(
seconds
=
15
))[
0
]
beacon_signal_delay
=
timedelta
(
seconds
=
15
),
beacon_singal_delay_maximum_delay
=
timedelta
(
seconds
=
300
))[
0
]
def
test_pass
(
self
):
pass
class
UserTaskTestCase
(
TestCase
):
class
UserTaskTestCase
(
TestCase
):
...
@@ -22,37 +27,48 @@ class UserTaskTestCase(TestCase):
...
@@ -22,37 +27,48 @@ class UserTaskTestCase(TestCase):
self
.
task
=
Task
.
objects
.
get_or_create
(
type
=
"TM"
,
update_delay
=
timedelta
(
seconds
=
10
),
self
.
task
=
Task
.
objects
.
get_or_create
(
type
=
"TM"
,
update_delay
=
timedelta
(
seconds
=
10
),
description
=
"Test_description"
,
name
=
"test_name"
,
counter_target
=
1
,
description
=
"Test_description"
,
name
=
"test_name"
,
counter_target
=
1
,
beacon_counter_target
=
2
,
counter_incrementation
=
1
,
beacon_counter_target
=
2
,
counter_incrementation
=
1
,
beacon_signal_delay
=
timedelta
(
seconds
=
15
))[
0
]
beacon_signal_delay
=
timedelta
(
seconds
=
15
),
beacon_signal_last_update
=
datetime
.
now
()
-
timedelta
(
seconds
=
15
)
beacon_singal_delay_maximum_delay
=
timedelta
(
seconds
=
300
))[
0
]
self
.
task
.
save
()
beacon_signal_last_update
=
timezone
.
now
()
-
timedelta
(
seconds
=
15
)
self
.
user_task
=
UserTask
.
objects
.
get_or_create
(
task
=
self
.
task
,
user
=
self
.
user
,
done
=
False
,
self
.
user_task
=
UserTask
.
objects
.
get_or_create
(
task
=
self
.
task
,
user
=
self
.
user
,
done
=
False
,
last_update
=
datetim
e
.
now
(),
last_update
=
timezon
e
.
now
(),
counter
=
0
,
beacon_counter
=
0
,
counter
=
0
,
beacon_counter
=
0
,
beacon_signal_last_update
=
beacon_signal_last_update
)[
0
]
beacon_signal_last_update
=
beacon_signal_last_update
)[
0
]
self
.
user_task
.
save
()
def
set_data_beacon_singal_passed
(
self
):
def
set_data_beacon_singal_passed
(
self
):
self
.
user_task
.
task
.
beacon_signal_delay
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
task
.
beacon_signal_delay
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
beacon_signal_last_update
=
datetim
e
.
now
()
-
timedelta
(
seconds
=
15
)
self
.
user_task
.
beacon_signal_last_update
=
timezon
e
.
now
()
-
timedelta
(
seconds
=
15
)
def
set_data_task_signal_passed
(
self
):
def
set_data_task_signal_passed
(
self
):
self
.
user_task
.
update_delay
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
update_delay
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
last_update
=
datetime
.
now
()
-
timedelta
(
seconds
=
20
)
self
.
user_task
.
last_update
=
timezone
.
now
()
-
timedelta
(
seconds
=
20
)
def
set_data_maximum_beacon_singal_passed
(
self
):
self
.
user_task
.
task
.
beacon_signal_delay
=
timedelta
(
seconds
=
15
)
self
.
task
.
beacon_singal_delay_maximum_delay
=
timedelta
(
seconds
=
300
)
self
.
user_task
.
beacon_signal_last_update
=
timezone
.
now
()
-
timedelta
(
seconds
=
305
)
def
test_maximum_delay_passed
(
self
):
self
.
set_data_maximum_beacon_singal_passed
()
self
.
assertFalse
(
self
.
user_task
.
ready_to_update
())
def
test_delay_passed
(
self
):
def
test_delay_passed
(
self
):
signal_last_update
=
datetim
e
.
now
()
-
timedelta
(
seconds
=
16
)
signal_last_update
=
timezon
e
.
now
()
-
timedelta
(
seconds
=
16
)
signal_delay
=
timedelta
(
seconds
=
15
)
signal_delay
=
timedelta
(
seconds
=
15
)
result
=
self
.
user_task
.
delay_passed
(
signal_last_update
,
signal_delay
)
result
=
self
.
user_task
.
delay_passed
(
signal_last_update
,
signal_delay
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
result
)
def
test_delay_passed_limit_value
(
self
):
def
test_delay_passed_limit_value
(
self
):
signal_last_update
=
timedelta
(
seconds
=
15
)
signal_last_update
=
timedelta
(
seconds
=
15
)
signal_delay
=
datetim
e
.
now
()
-
timedelta
(
seconds
=
15
)
signal_delay
=
timezon
e
.
now
()
-
timedelta
(
seconds
=
15
)
result
=
self
.
user_task
.
delay_passed
(
signal_last_update
,
signal_delay
)
result
=
self
.
user_task
.
delay_passed
(
signal_last_update
,
signal_delay
)
self
.
assertTrue
(
result
)
self
.
assertTrue
(
result
)
def
test_delay_not_passed
(
self
):
def
test_delay_not_passed
(
self
):
signal_last_update
=
timedelta
(
seconds
=
15
)
signal_last_update
=
timedelta
(
seconds
=
15
)
signal_delay
=
datetim
e
.
now
()
-
timedelta
(
seconds
=
14
)
signal_delay
=
timezon
e
.
now
()
-
timedelta
(
seconds
=
14
)
result
=
self
.
user_task
.
delay_passed
(
signal_last_update
,
signal_delay
)
result
=
self
.
user_task
.
delay_passed
(
signal_last_update
,
signal_delay
)
self
.
assertFalse
(
result
)
self
.
assertFalse
(
result
)
...
@@ -65,7 +81,7 @@ class UserTaskTestCase(TestCase):
...
@@ -65,7 +81,7 @@ class UserTaskTestCase(TestCase):
def
test_ready_to_update_beacon_counter_not_increase
(
self
):
def
test_ready_to_update_beacon_counter_not_increase
(
self
):
self
.
user_task
.
task
.
beacon_signal_delay
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
task
.
beacon_signal_delay
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
beacon_signal_last_update
=
datetim
e
.
now
()
-
timedelta
(
seconds
=
14
)
self
.
user_task
.
beacon_signal_last_update
=
timezon
e
.
now
()
-
timedelta
(
seconds
=
14
)
self
.
user_task
.
beacon_counter
=
0
self
.
user_task
.
beacon_counter
=
0
self
.
user_task
.
task
.
beacon_counter_target
=
2
self
.
user_task
.
task
.
beacon_counter_target
=
2
result
=
self
.
user_task
.
ready_to_update
()
result
=
self
.
user_task
.
ready_to_update
()
...
@@ -94,8 +110,8 @@ class UserTaskTestCase(TestCase):
...
@@ -94,8 +110,8 @@ class UserTaskTestCase(TestCase):
def
test_update_counter_not_increase
(
self
):
def
test_update_counter_not_increase
(
self
):
self
.
set_data_beacon_singal_passed
()
self
.
set_data_beacon_singal_passed
()
self
.
user_task
.
update_delay
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
update_delay
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
last_update
=
datetim
e
.
now
()
self
.
user_task
.
last_update
=
timezon
e
.
now
()
self
.
user_task
.
beacon_counter
=
0
self
.
user_task
.
beacon_counter
=
0
self
.
user_task
.
task
.
beacon_counter_target
=
1
self
.
user_task
.
task
.
beacon_counter_target
=
1
...
@@ -121,7 +137,7 @@ class UserTaskTestCase(TestCase):
...
@@ -121,7 +137,7 @@ class UserTaskTestCase(TestCase):
def
test_update_test_not_ready_to_update
(
self
):
def
test_update_test_not_ready_to_update
(
self
):
self
.
user_task
.
signal_last_update
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
signal_last_update
=
timedelta
(
seconds
=
15
)
self
.
user_task
.
signal_delay
=
datetim
e
.
now
()
-
timedelta
(
seconds
=
14
)
self
.
user_task
.
signal_delay
=
timezon
e
.
now
()
-
timedelta
(
seconds
=
14
)
result
=
self
.
user_task
.
update
()
result
=
self
.
user_task
.
update
()
self
.
assertFalse
(
result
)
self
.
assertFalse
(
result
)
...
...
KawowyDzienniczek/App/loyaltyMe/views.py
View file @
0eed7be0
import
rest_framework
from
django.db.models
import
Q
from
rest_framework
import
viewsets
,
permissions
from
rest_framework
import
viewsets
,
permissions
from
rest_framework.decorators
import
detail_route
from
rest_framework.response
import
Response
from
App.loyaltyMe.models
import
Product
,
Offer
,
Promotion
,
Place
,
PromotionSet
,
Localization
,
Beacon
,
Task
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
,
TaskSerializer
PromotionSetSerializer
,
LocalizationSerializer
,
BeaconSerializer
,
TaskSerializer
from
App.user.models
import
UserPromotion
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
...
@@ -49,6 +54,16 @@ class PlaceViewSet(viewsets.ModelViewSet):
...
@@ -49,6 +54,16 @@ class PlaceViewSet(viewsets.ModelViewSet):
serializer_class
=
PlaceSerializer
serializer_class
=
PlaceSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
@
detail_route
(
methods
=
[
'get'
])
def
refresh
(
self
,
request
,
pk
=
None
):
user
=
request
.
user
place
=
Place
.
objects
.
filter
(
pk
=
pk
)[
0
]
user_promotions
=
UserPromotion
.
objects
.
filter
(
Q
(
user
=
user
)
&
Q
(
place
=
place
))
for
user_promotion
in
user_promotions
:
user_promotion
.
update_user_task
()
return
Response
(
status
=
rest_framework
.
status
.
HTTP_200_OK
)
class
LocalizationViewSet
(
viewsets
.
ModelViewSet
):
class
LocalizationViewSet
(
viewsets
.
ModelViewSet
):
"""
"""
...
...
KawowyDzienniczek/App/user/management/commands/init.py
View file @
0eed7be0
...
@@ -17,5 +17,5 @@ class Command(BaseCommand):
...
@@ -17,5 +17,5 @@ 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'
)
call_command
(
'init_usertasks'
)
call_command
(
'init_usertasks'
)
call_command
(
'init_userpromotions'
)
KawowyDzienniczek/App/user/management/commands/init_userpromotions.py
View file @
0eed7be0
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.db.models
import
Q
from
App.loyaltyMe.models
import
Place
,
Promotion
from
App.loyaltyMe.models
import
Place
,
Promotion
,
Task
from
App.user.models
import
UserPromotion
from
App.user.models
import
UserPromotion
,
UserTask
from
django.core.management.base
import
BaseCommand
from
django.core.management.base
import
BaseCommand
...
@@ -17,17 +18,20 @@ class Command(BaseCommand):
...
@@ -17,17 +18,20 @@ class Command(BaseCommand):
# 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)
# code = models.CharField(max_length=20)
[
'Klaudia'
,
'Kocia Kawiarnia'
,
'10
%
'
,
'
used'
,
'abcd
'
],
[
'Klaudia'
,
'Kocia Kawiarnia'
,
'10
%
'
,
'
US'
,
'abcd'
,
'Bądź u nas 10 godzin
'
],
[
'Klaudia'
,
'Kafcia u Olczaka'
,
'20
%
'
,
'
in_progress'
,
None
],
[
'Klaudia'
,
'Kafcia u Olczaka'
,
'20
%
'
,
'
AC'
,
'abcd'
,
'Przyjdz 10 razy'
],
[
'Antek'
,
'Kafcia u Olczaka'
,
'50
%
'
,
'
in_progress'
,
None
],
[
'Antek'
,
'Kafcia u Olczaka'
,
'50
%
'
,
'
AC'
,
'abcd'
,
'Bądź u nas 10 godzin'
],
[
'admin'
,
'Kafcia u Olczaka'
,
'10
%
'
,
'
in_progress'
,
None
],
[
'admin'
,
'Kafcia u Olczaka'
,
'10
%
'
,
'
AC'
,
'abcd'
,
'Przyjdz 10 razy'
],
]
]
print
(
"Creating UserPromotions"
)
print
(
"Creating UserPromotions"
)
for
user_promotion
in
user_promotions
:
for
user_promotion
in
user_promotions
:
print
(
'Create {0}'
.
format
(
user_promotion
[
0
]))
print
(
'Create {0}
UserPromotion
'
.
format
(
user_promotion
[
0
]))
user
=
User
.
objects
.
filter
(
username
=
user_promotion
[
0
])[
0
]
user
=
User
.
objects
.
filter
(
username
=
user_promotion
[
0
])[
0
]
place
=
Place
.
objects
.
filter
(
name
=
user_promotion
[
1
])[
0
]
place
=
Place
.
objects
.
filter
(
name
=
user_promotion
[
1
])[
0
]
promotion
=
Promotion
.
objects
.
filter
(
name
=
user_promotion
[
2
])[
0
]
promotion
=
Promotion
.
objects
.
filter
(
name
=
user_promotion
[
2
])[
0
]
task
=
Task
.
objects
.
filter
(
name
=
user_promotion
[
5
])[
0
]
user_task
=
UserTask
.
objects
.
filter
(
Q
(
task
=
task
),
Q
(
user
=
user
))[
0
]
new_user_promotion
=
UserPromotion
.
objects
.
create
(
user
=
user
,
place
=
place
,
promotion
=
promotion
,
new_user_promotion
=
UserPromotion
.
objects
.
create
(
user
=
user
,
place
=
place
,
promotion
=
promotion
,
status
=
user_promotion
[
3
],
code
=
user_promotion
[
4
])
progress
=
user_promotion
[
3
],
code
=
user_promotion
[
4
],
user_task
=
user_task
)
new_user_promotion
.
save
()
new_user_promotion
.
save
()
KawowyDzienniczek/App/user/management/commands/init_usertasks.py
View file @
0eed7be0
...
@@ -2,23 +2,26 @@ import datetime
...
@@ -2,23 +2,26 @@ import datetime
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.management.base
import
BaseCommand
from
django.core.management.base
import
BaseCommand
from
django.utils.timezone
import
is_naive
,
is_aware
from
App.loyaltyMe.models
import
Task
from
App.loyaltyMe.models
import
Task
from
App.user.models
import
UserTask
from
App.user.models
import
UserTask
from
django.utils
import
timezone
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
data
=
[
data
=
[
[
'Bądź u nas 10 godzin'
,
'
admin'
,
True
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetim
e
.
now
()],
[
'Bądź u nas 10 godzin'
,
'
Antek'
,
True
,
timezone
.
now
(),
15
,
15
,
timezon
e
.
now
()],
[
'Bądź u nas 10 godzin'
,
'Klaudia'
,
False
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetim
e
.
now
()],
[
'Bądź u nas 10 godzin'
,
'Klaudia'
,
False
,
timezone
.
now
(),
15
,
15
,
timezon
e
.
now
()],
[
'Przyjdz 10 razy'
,
'admin'
,
False
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetim
e
.
now
()],
[
'Przyjdz 10 razy'
,
'admin'
,
False
,
timezone
.
now
(),
15
,
15
,
timezon
e
.
now
()],
[
'Przyjdz 10 razy'
,
'
Antek'
,
True
,
datetime
.
datetime
.
now
(),
15
,
15
,
datetime
.
datetim
e
.
now
()],
[
'Przyjdz 10 razy'
,
'
Klaudia'
,
True
,
timezone
.
now
(),
15
,
15
,
timezon
e
.
now
()],
]
]
print
(
"Creating UsersTasks"
)
print
(
"Creating UsersTasks"
)
for
user_task
in
data
:
for
user_task
in
data
:
print
(
"{0} take {1} Task"
.
format
(
user_task
[
0
],
user_task
[
1
]))
print
(
is_aware
(
timezone
.
now
()))
print
(
"{1} take {0} Task"
.
format
(
user_task
[
0
],
user_task
[
1
]))
task
=
Task
.
objects
.
filter
(
name
=
user_task
[
0
])[
0
]
task
=
Task
.
objects
.
filter
(
name
=
user_task
[
0
])[
0
]
user
=
User
.
objects
.
filter
(
username
=
user_task
[
1
])[
0
]
user
=
User
.
objects
.
filter
(
username
=
user_task
[
1
])[
0
]
counter
=
user_task
[
4
]
counter
=
user_task
[
4
]
...
...
KawowyDzienniczek/App/user/models.py
View file @
0eed7be0
...
@@ -8,6 +8,7 @@ from rest_framework.authtoken.models import Token
...
@@ -8,6 +8,7 @@ from rest_framework.authtoken.models import Token
from
django.test
import
TestCase
from
django.test
import
TestCase
# Create your models here.
# Create your models here.
from
App.loyaltyMe.models
import
Place
,
Promotion
,
Task
from
App.loyaltyMe.models
import
Place
,
Promotion
,
Task
from
django.utils
import
timezone
@
receiver
(
post_save
,
sender
=
User
)
@
receiver
(
post_save
,
sender
=
User
)
...
@@ -22,25 +23,15 @@ class UserProfile(models.Model):
...
@@ -22,25 +23,15 @@ class UserProfile(models.Model):
photo
=
models
.
ImageField
()
photo
=
models
.
ImageField
()
class
UserPromotion
(
models
.
Model
):
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
,
null
=
True
)
class
UserTask
(
models
.
Model
):
class
UserTask
(
models
.
Model
):
task
=
models
.
ForeignKey
(
Task
)
task
=
models
.
ForeignKey
(
Task
)
user
=
models
.
ForeignKey
(
User
,
related_name
=
'user_task'
,
user
=
models
.
ForeignKey
(
User
,
related_name
=
'user_task'
,
blank
=
False
,
null
=
False
,
default
=
None
)
blank
=
False
,
null
=
False
,
default
=
None
)
done
=
models
.
BooleanField
(
default
=
False
)
done
=
models
.
BooleanField
(
default
=
False
)
last_update
=
models
.
DateField
()
last_update
=
models
.
Date
Time
Field
()
counter
=
models
.
IntegerField
()
#akutalnie bylem 3 razy # aktualny status uzytkwonika w zadaniu
counter
=
models
.
IntegerField
()
#
akutalnie bylem 3 razy # aktualny status uzytkwonika w zadaniu
beacon_counter
=
models
.
IntegerField
()
# juz 10 minut, jeszcze raz i bedzie hyvka # status czy zaliczyc z beaconow taska
beacon_counter
=
models
.
IntegerField
()
# juz 10 minut, jeszcze raz i bedzie hyvka # status czy zaliczyc z beaconow taska
beacon_signal_last_update
=
models
.
Date
Field
()
#
ostatnio 23 h temu # last update
beacon_signal_last_update
=
models
.
Date
TimeField
()
#
ostatnio 23 h temu # last update
def
update
(
self
):
def
update
(
self
):
if
not
self
.
ready_to_update
():
if
not
self
.
ready_to_update
():
...
@@ -55,14 +46,19 @@ class UserTask(models.Model):
...
@@ -55,14 +46,19 @@ class UserTask(models.Model):
return
False
return
False
def
ready_to_update
(
self
):
def
ready_to_update
(
self
):
if
self
.
maximum_beacon_delay_passed
():
self
.
beacon_counter
=
0
if
self
.
beacon_delay_passed
():
if
self
.
beacon_delay_passed
():
self
.
beacon_counter
=
+
1
self
.
beacon_counter
=
+
1
self
.
beacon_signal_last_update
=
datetim
e
.
now
()
self
.
beacon_signal_last_update
=
timezon
e
.
now
()
if
self
.
beacon_counter
==
self
.
task
.
beacon_counter_target
:
if
self
.
beacon_counter
==
self
.
task
.
beacon_counter_target
:
self
.
beacon_counter
=
0
self
.
beacon_counter
=
0
return
True
return
True
return
False
return
False
def
maximum_beacon_delay_passed
(
self
):
return
self
.
delay_passed
(
self
.
beacon_signal_last_update
,
self
.
task
.
beacon_singal_delay_maximum_delay
)
def
beacon_delay_passed
(
self
):
def
beacon_delay_passed
(
self
):
return
self
.
delay_passed
(
self
.
beacon_signal_last_update
,
self
.
task
.
beacon_signal_delay
)
return
self
.
delay_passed
(
self
.
beacon_signal_last_update
,
self
.
task
.
beacon_signal_delay
)
...
@@ -70,6 +66,31 @@ class UserTask(models.Model):
...
@@ -70,6 +66,31 @@ class UserTask(models.Model):
return
self
.
delay_passed
(
self
.
last_update
,
self
.
task
.
update_delay
)
return
self
.
delay_passed
(
self
.
last_update
,
self
.
task
.
update_delay
)
def
delay_passed
(
self
,
last_update
,
signal_delay
):
def
delay_passed
(
self
,
last_update
,
signal_delay
):
actual_time
=
datetim
e
.
now
()
actual_time
=
timezon
e
.
now
()
time_difference
=
actual_time
-
last_update
time_difference
=
actual_time
-
last_update
return
time_difference
>
signal_delay
return
time_difference
>
signal_delay
class
UserPromotion
(
models
.
Model
):
USED
=
'US'
ACTIVE
=
'AC'
NON_AVAILABLE
=
'NAV'
AVAILABLE
=
'AV'
PROGRESS_CHOICES
=
(
(
USED
,
'Used'
),
(
ACTIVE
,
'Active'
),
(
NON_AVAILABLE
,
'Non Available'
),
(
AVAILABLE
,
'Available'
),
)
user
=
models
.
ForeignKey
(
User
,
related_name
=
'user_promotion'
,
blank
=
False
,
null
=
False
,
default
=
None
)
place
=
models
.
ForeignKey
(
Place
)
promotion
=
models
.
ForeignKey
(
Promotion
)
progress
=
models
.
CharField
(
max_length
=
2
,
choices
=
PROGRESS_CHOICES
,
default
=
ACTIVE
)
code
=
models
.
CharField
(
max_length
=
20
,
null
=
True
)
user_task
=
models
.
ForeignKey
(
UserTask
)
def
update_user_task
(
self
):
self
.
user_task
.
update
()
KawowyDzienniczek/App/user/serializers.py
View file @
0eed7be0
...
@@ -3,7 +3,7 @@ from django.contrib.auth.models import User
...
@@ -3,7 +3,7 @@ from django.contrib.auth.models import User
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.translation
import
ugettext_lazy
as
_
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
App.loyaltyMe.serializers
import
PromotionSerializer
from
App.loyaltyMe.serializers
import
PromotionSerializer
,
TaskSerializer
from
App.user.models
import
UserProfile
,
UserPromotion
,
UserTask
from
App.user.models
import
UserProfile
,
UserPromotion
,
UserTask
...
@@ -24,6 +24,9 @@ class UserProfileSerializer(serializers.HyperlinkedModelSerializer):
...
@@ -24,6 +24,9 @@ class UserProfileSerializer(serializers.HyperlinkedModelSerializer):
class
UserTaskSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
UserTaskSerializer
(
serializers
.
HyperlinkedModelSerializer
):
user
=
UserSerializer
()
user
=
UserSerializer
()
task
=
TaskSerializer
()
last_update
=
serializers
.
DateTimeField
(
format
=
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S"
)
beacon_signal_last_update
=
serializers
.
DateTimeField
(
format
=
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S"
)
class
Meta
:
class
Meta
:
model
=
UserTask
model
=
UserTask
...
@@ -66,4 +69,4 @@ class UserPromotionSerializer(serializers.HyperlinkedModelSerializer):
...
@@ -66,4 +69,4 @@ class UserPromotionSerializer(serializers.HyperlinkedModelSerializer):
class
Meta
:
class
Meta
:
model
=
UserPromotion
model
=
UserPromotion
fields
=
(
'url'
,
'id'
,
'user'
,
'place'
,
'promotion'
,
'
statu
s'
,
'code'
)
fields
=
(
'url'
,
'id'
,
'user'
,
'place'
,
'promotion'
,
'
progres
s'
,
'code'
)
\ No newline at end of file
requirements.txt
View file @
0eed7be0
...
@@ -10,3 +10,4 @@ pyflakes==1.2.3
...
@@ -10,3 +10,4 @@ pyflakes==1.2.3
psycopg2
psycopg2
drfdocs
drfdocs
coverage
coverage
pytz
\ 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