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
bce19eaa
Commit
bce19eaa
authored
Jul 07, 2016
by
Rafal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add beacon model
parent
8dff21eb
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
34 deletions
+59
-34
init_beacons.py
...nniczek/App/loyaltyMe/management/commands/init_beacons.py
+19
-0
models.py
KawowyDzienniczek/App/loyaltyMe/models.py
+7
-0
serializers.py
KawowyDzienniczek/App/loyaltyMe/serializers.py
+6
-1
views.py
KawowyDzienniczek/App/loyaltyMe/views.py
+10
-2
init.py
KawowyDzienniczek/App/user/management/commands/init.py
+1
-0
views.py
KawowyDzienniczek/App/user/views.py
+14
-30
urls.py
KawowyDzienniczek/KawowyDzienniczek/urls.py
+2
-1
No files found.
KawowyDzienniczek/App/loyaltyMe/management/commands/init_beacons.py
0 → 100644
View file @
bce19eaa
from
App.loyaltyMe.models
import
Beacon
__author__
=
'Rafal'
from
django.core.management.base
import
BaseCommand
class
Command
(
BaseCommand
):
help
=
'Closes the specified poll for voting'
def
handle
(
self
,
*
args
,
**
options
):
beacons
=
[
[
'f7826da6-4fa2-4e98-8024-bc5b71e0893e'
,
'hPUL'
,
'Bialy'
,
'2667'
,
'62313'
],
[
'74f1f28c-1cb7-11e5-9a21-1697f925ec7b'
,
'CeH3'
,
'Czarny'
,
'55059'
,
'55892'
],
]
print
(
"Creating Beacons"
)
for
beacon
in
beacons
:
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
.
save
()
KawowyDzienniczek/App/loyaltyMe/models.py
View file @
bce19eaa
...
@@ -49,3 +49,10 @@ class Place(models.Model):
...
@@ -49,3 +49,10 @@ 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
)
class
Beacon
(
models
.
Model
):
uuid
=
models
.
CharField
(
max_length
=
300
,
unique
=
True
)
major
=
models
.
CharField
(
max_length
=
300
,
unique
=
True
)
minor
=
models
.
CharField
(
max_length
=
300
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
300
)
description
=
models
.
CharField
(
max_length
=
300
,
null
=
True
)
KawowyDzienniczek/App/loyaltyMe/serializers.py
View file @
bce19eaa
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
App.loyaltyMe.models
import
Product
,
Offer
,
Promotion
,
Place
,
Localization
from
App.loyaltyMe.models
import
Product
,
Offer
,
Promotion
,
Place
,
Localization
,
Beacon
class
ProductSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
ProductSerializer
(
serializers
.
HyperlinkedModelSerializer
):
...
@@ -45,3 +45,8 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer):
...
@@ -45,3 +45,8 @@ 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'
)
fields
=
(
'url'
,
'id'
,
'name'
,
'type'
,
'screen_img'
,
'logo_img'
,
'description'
,
'offer'
,
'promotion'
,
'localization'
)
class
BeaconSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Beacon
fields
=
(
'url'
,
'id'
,
'uuid'
,
'major'
,
'minor'
,
'name'
,
'description'
)
\ No newline at end of file
KawowyDzienniczek/App/loyaltyMe/views.py
View file @
bce19eaa
...
@@ -2,9 +2,9 @@ from django.shortcuts import render
...
@@ -2,9 +2,9 @@ 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
rest_framework.decorators
import
list_route
from
App.loyaltyMe.models
import
Product
,
Offer
,
Promotion
,
Place
,
PromotionSet
,
Localization
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
,
\
PromotionSetSerializer
,
LocalizationSerializer
PromotionSetSerializer
,
LocalizationSerializer
,
BeaconSerializer
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
...
@@ -56,4 +56,12 @@ class LocalizationViewSet(viewsets.ModelViewSet):
...
@@ -56,4 +56,12 @@ class LocalizationViewSet(viewsets.ModelViewSet):
"""
"""
queryset
=
Localization
.
objects
.
all
()
queryset
=
Localization
.
objects
.
all
()
serializer_class
=
LocalizationSerializer
serializer_class
=
LocalizationSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
class
BeaconViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
Beacon
.
objects
.
all
()
serializer_class
=
BeaconSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
\ No newline at end of file
KawowyDzienniczek/App/user/management/commands/init.py
View file @
bce19eaa
...
@@ -8,6 +8,7 @@ class Command(BaseCommand):
...
@@ -8,6 +8,7 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
call_command
(
'init_users'
)
call_command
(
'init_users'
)
call_command
(
'init_beacons'
)
call_command
(
'init_userprofile'
)
call_command
(
'init_userprofile'
)
call_command
(
'init_products'
)
call_command
(
'init_products'
)
call_command
(
'init_offers'
)
call_command
(
'init_offers'
)
...
...
KawowyDzienniczek/App/user/views.py
View file @
bce19eaa
...
@@ -80,36 +80,20 @@ class ObtainAuthToken(APIView):
...
@@ -80,36 +80,20 @@ class ObtainAuthToken(APIView):
obtain_auth_token
=
ObtainAuthToken
.
as_view
()
obtain_auth_token
=
ObtainAuthToken
.
as_view
()
# class UserPromotionViewSet(viewsets.ModelViewSet):
class
UserPromotionViewSet
(
viewsets
.
ModelViewSet
):
# """
"""
# API for articles
API for articles
# """
"""
# queryset = UserPromotion.objects.all()
queryset
=
UserPromotion
.
objects
.
all
()
# serializer_class = UserPromotionSerializer
serializer_class
=
UserPromotionSerializer
# permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
#
# def list(self, request):
def
list
(
self
,
request
):
# user = request.user
user
=
request
.
user
# queryset = UserPromotion.objects.filter(user=user)
queryset
=
UserPromotion
.
objects
.
filter
(
user
=
user
)
# 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
)
# @list_route(methods=['post', 'get'], permission_classes=[permissions.IsAuthenticated])
# def place(self, request, pk=None):
# place = Place.objects.filter(pk=pk)[0]
# user_promotions = request.user.user_promotions.filter(place=place)
# print(user_promotions)
#
# # if (user_profile.like_counter>=award.like_needed):
# # user_profile.like_counter-=award.like_needed
# # user_profile.save()
# # new_user_award = UserAward.objects.create(award=award, user=request.user)
# # new_user_award.save()
# # new_user_award_data = UserAwardSerializer(new_user_award, context={'request': request}).data
# # return Response(status=rest_framework.status.HTTP_200_OK, data=new_user_award_data)
# # else:
# # return Response(status=rest_framework.status.HTTP_405_METHOD_NOT_ALLOWED, data= "Not enough likes!")
class
PlaceUserPromotionsViewSet
(
viewsets
.
ModelViewSet
):
class
PlaceUserPromotionsViewSet
(
viewsets
.
ModelViewSet
):
base_name
=
"place_user_promotions"
base_name
=
"place_user_promotions"
...
...
KawowyDzienniczek/KawowyDzienniczek/urls.py
View file @
bce19eaa
...
@@ -26,7 +26,7 @@ from App.loyaltyMe import views as loyalty_views
...
@@ -26,7 +26,7 @@ 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)
router
.
register
(
r'user_promotions'
,
user_views
.
UserPromotionViewSet
)
router
.
register
(
r'place_user_promotions'
,
user_views
.
PlaceUserPromotionsViewSet
)
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
)
...
@@ -34,6 +34,7 @@ router.register(r'promotions', loyalty_views.PromotionViewSet)
...
@@ -34,6 +34,7 @@ router.register(r'promotions', loyalty_views.PromotionViewSet)
router
.
register
(
r'promotion_set'
,
loyalty_views
.
PromotionSetViewSet
)
router
.
register
(
r'promotion_set'
,
loyalty_views
.
PromotionSetViewSet
)
router
.
register
(
r'places'
,
loyalty_views
.
PlaceViewSet
)
router
.
register
(
r'places'
,
loyalty_views
.
PlaceViewSet
)
router
.
register
(
r'localizations'
,
loyalty_views
.
LocalizationViewSet
)
router
.
register
(
r'localizations'
,
loyalty_views
.
LocalizationViewSet
)
router
.
register
(
r'beacons'
,
loyalty_views
.
BeaconViewSet
)
urlpatterns
=
[
urlpatterns
=
[
url
(
r'^api/'
,
include
(
router
.
urls
)),
url
(
r'^api/'
,
include
(
router
.
urls
)),
...
...
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