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
52e88645
Commit
52e88645
authored
Jul 07, 2016
by
Rafal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add user_promotions
parent
d76a29f1
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
79 additions
and
4 deletions
+79
-4
init.py
KawowyDzienniczek/App/user/management/commands/init.py
+2
-0
init_userpromotions.py
...iczek/App/user/management/commands/init_userpromotions.py
+33
-0
models.py
KawowyDzienniczek/App/user/models.py
+11
-0
serializers.py
KawowyDzienniczek/App/user/serializers.py
+12
-1
views.py
KawowyDzienniczek/App/user/views.py
+19
-2
urls.py
KawowyDzienniczek/KawowyDzienniczek/urls.py
+2
-1
No files found.
KawowyDzienniczek/App/user/management/commands/init.py
View file @
52e88645
...
...
@@ -15,4 +15,6 @@ class Command(BaseCommand):
call_command
(
'init_promotionsets'
)
call_command
(
'init_localizations'
)
call_command
(
'init_places'
)
call_command
(
'init_userpromotions'
)
KawowyDzienniczek/App/user/management/commands/init_userpromotions.py
0 → 100644
View file @
52e88645
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
KawowyDzienniczek/App/user/models.py
View file @
52e88645
...
...
@@ -5,6 +5,8 @@ from django.dispatch import receiver
from
rest_framework.authtoken.models
import
Token
# Create your models here.
from
App.loyaltyMe.models
import
Place
,
Promotion
@
receiver
(
post_save
,
sender
=
User
)
def
create_auth_token
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
...
...
@@ -16,3 +18,12 @@ class UserProfile(models.Model):
blank
=
False
,
null
=
False
,
default
=
None
)
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
)
KawowyDzienniczek/App/user/serializers.py
View file @
52e88645
...
...
@@ -4,7 +4,8 @@ from django.shortcuts import get_object_or_404
from
rest_framework
import
serializers
from
django.utils.translation
import
ugettext_lazy
as
_
from
App.user.models
import
UserProfile
from
App.loyaltyMe.serializers
import
PlaceSerializer
,
PromotionSerializer
from
App.user.models
import
UserProfile
,
UserPromotion
class
UserSerializer
(
serializers
.
HyperlinkedModelSerializer
):
...
...
@@ -48,3 +49,13 @@ class AuthTokenSerializerByEmail(serializers.Serializer):
attrs
[
'user'
]
=
user
return
attrs
class
UserPromotionSerializer
(
serializers
.
HyperlinkedModelSerializer
):
user
=
UserSerializer
()
place
=
PlaceSerializer
()
promotion
=
PromotionSerializer
()
class
Meta
:
model
=
UserPromotion
fields
=
(
'url'
,
'id'
,
'user'
,
'place'
,
'promotion'
,
'status'
,
'code'
)
KawowyDzienniczek/App/user/views.py
View file @
52e88645
...
...
@@ -13,8 +13,10 @@ from rest_framework.response import Response
from
rest_framework
import
viewsets
,
permissions
from
rest_framework.views
import
APIView
from
App.user.models
import
UserProfile
from
App.user.serializers
import
UserSerializer
,
AuthTokenSerializerByEmail
,
UserProfileSerializer
from
App.loyaltyMe.serializers
import
LocalizationSerializer
from
App.user.models
import
UserProfile
,
UserPromotion
from
App.user.serializers
import
UserSerializer
,
AuthTokenSerializerByEmail
,
UserProfileSerializer
,
\
UserPromotionSerializer
from
rest_framework
import
parsers
,
renderers
class
UserViewSet
(
viewsets
.
ModelViewSet
):
...
...
@@ -73,3 +75,18 @@ class ObtainAuthToken(APIView):
obtain_auth_token
=
ObtainAuthToken
.
as_view
()
class
UserPromotionViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
UserPromotion
.
objects
.
all
()
serializer_class
=
UserPromotionSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
def
list
(
self
,
request
):
user
=
request
.
user
queryset
=
UserPromotion
.
objects
.
filter
(
user
=
user
)
page
=
self
.
paginate_queryset
(
queryset
)
serializer
=
UserPromotionSerializer
(
page
,
many
=
True
,
context
=
{
'request'
:
request
})
return
self
.
get_paginated_response
(
serializer
.
data
)
\ No newline at end of file
KawowyDzienniczek/KawowyDzienniczek/urls.py
View file @
52e88645
...
...
@@ -26,8 +26,9 @@ from App.loyaltyMe import views as loyalty_views
router
=
routers
.
DefaultRouter
()
router
.
register
(
r'user'
,
user_views
.
UserViewSet
)
router
.
register
(
r'user_profile'
,
user_views
.
UserProfileViewSet
)
router
.
register
(
r'user_promotions'
,
user_views
.
UserPromotionViewSet
)
router
.
register
(
r'products'
,
loyalty_views
.
ProductViewSet
)
router
.
register
(
r'offer
t
s'
,
loyalty_views
.
OfferViewSet
)
router
.
register
(
r'offers'
,
loyalty_views
.
OfferViewSet
)
router
.
register
(
r'promotions'
,
loyalty_views
.
PromotionViewSet
)
router
.
register
(
r'promotion_set'
,
loyalty_views
.
PromotionSetViewSet
)
router
.
register
(
r'places'
,
loyalty_views
.
PlaceViewSet
)
...
...
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