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
a5264315
Commit
a5264315
authored
Jul 06, 2016
by
Rafal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add localization
parent
d903ec8a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
11 deletions
+63
-11
init_localizations.py
...k/App/loyaltyMe/management/commands/init_localizations.py
+20
-0
init_places.py
...enniczek/App/loyaltyMe/management/commands/init_places.py
+9
-8
models.py
KawowyDzienniczek/App/loyaltyMe/models.py
+10
-0
serializers.py
KawowyDzienniczek/App/loyaltyMe/serializers.py
+12
-1
views.py
KawowyDzienniczek/App/loyaltyMe/views.py
+11
-2
init.py
KawowyDzienniczek/App/user/management/commands/init.py
+1
-0
No files found.
KawowyDzienniczek/App/loyaltyMe/management/commands/init_localizations.py
0 → 100644
View file @
a5264315
from
django.contrib.auth.models
import
User
from
App.loyaltyMe.models
import
Offer
,
Product
,
Localization
__author__
=
'Rafal'
from
django.core.management.base
import
BaseCommand
,
CommandError
class
Command
(
BaseCommand
):
help
=
'Closes the specified poll for voting'
def
handle
(
self
,
*
args
,
**
options
):
localizations
=
[
[
'0.0000'
,
'10.0000'
,
'Kraków'
,
'Makowicka'
,
'55'
],
[
'10.0000'
,
'0.0000'
,
'Kraków'
,
'Rynek'
,
'15'
],
]
print
(
"Creating Localizations"
)
for
localization
in
localizations
:
print
(
'Create {0}'
.
format
(
localization
[
0
]))
new_localization
=
Localization
.
objects
.
create
(
latitude
=
localization
[
0
],
longitude
=
localization
[
1
],
city
=
localization
[
2
],
road
=
localization
[
3
],
road_number
=
localization
[
4
])
new_localization
.
save
()
\ No newline at end of file
KawowyDzienniczek/App/loyaltyMe/management/commands/init_places.py
View file @
a5264315
from
App.loyaltyMe.models
import
Place
,
Offer
,
Promotion
,
PromotionSet
from
App.loyaltyMe.models
import
Place
,
Offer
,
Promotion
,
PromotionSet
,
Localization
__author__
=
'Rafal'
__author__
=
'Rafal'
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
...
@@ -9,17 +9,18 @@ class Command(BaseCommand):
...
@@ -9,17 +9,18 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
places
=
[
places
=
[
#['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'],
#['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'],
[
'Kocia Kawiarnia'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
'Promocja1'
],
[
'Kocia Kawiarnia'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
'Promocja1'
,
'Makowicka'
],
[
'Kafcia u Olczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
],
[
'Kafcia u Olczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
,
'Makowicka'
],
[
'Psia Kawiarnia'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
'Promocja1'
],
[
'Psia Kawiarnia'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
'Promocja1'
,
'Rynek'
],
[
'Kafcia u Iwczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
],
[
'Kafcia u Iwczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
,
'Rynek'
],
[
'Lemingowa Kawiarnia'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
'Promocja1'
],
[
'Lemingowa Kawiarnia'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta1'
,
'Promocja1'
,
'Makowicka'
],
[
'Kafcia u Ewelinczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
],
[
'Kafcia u Ewelinczaka'
,
'Cafeteria'
,
'/static/img/photo_1.jpg'
,
'/static/img/photo_1.jpg'
,
'description'
,
'Oferta2'
,
'Promocja2'
,
'Rynek'
],
]
]
print
(
"Creating Places"
)
print
(
"Creating Places"
)
for
place
in
places
:
for
place
in
places
:
print
(
'Create {0}'
.
format
(
place
[
0
]))
print
(
'Create {0}'
.
format
(
place
[
0
]))
offer
=
Offer
.
objects
.
filter
(
name
=
place
[
5
])[
0
]
offer
=
Offer
.
objects
.
filter
(
name
=
place
[
5
])[
0
]
promotion_set
=
PromotionSet
.
objects
.
filter
(
name
=
place
[
6
])[
0
]
promotion_set
=
PromotionSet
.
objects
.
filter
(
name
=
place
[
6
])[
0
]
new_place
=
Place
.
objects
.
create
(
name
=
place
[
0
],
type
=
place
[
1
],
screen_img
=
place
[
2
],
logo_img
=
place
[
3
],
description
=
place
[
4
],
offer
=
offer
,
promotion
=
promotion_set
)
localization
=
Localization
.
objects
.
filter
(
road
=
place
[
7
])[
0
]
new_place
=
Place
.
objects
.
create
(
name
=
place
[
0
],
type
=
place
[
1
],
screen_img
=
place
[
2
],
logo_img
=
place
[
3
],
description
=
place
[
4
],
offer
=
offer
,
promotion
=
promotion_set
,
localization
=
localization
)
new_place
.
save
()
new_place
.
save
()
\ No newline at end of file
KawowyDzienniczek/App/loyaltyMe/models.py
View file @
a5264315
...
@@ -27,6 +27,14 @@ class PromotionSet(models.Model):
...
@@ -27,6 +27,14 @@ class PromotionSet(models.Model):
name
=
models
.
CharField
(
max_length
=
50
)
name
=
models
.
CharField
(
max_length
=
50
)
promotions
=
models
.
ManyToManyField
(
Promotion
,
default
=
''
)
promotions
=
models
.
ManyToManyField
(
Promotion
,
default
=
''
)
class
Localization
(
models
.
Model
):
latitude
=
models
.
CharField
(
max_length
=
50
,)
longitude
=
models
.
CharField
(
max_length
=
50
,)
city
=
models
.
CharField
(
max_length
=
50
,)
road
=
models
.
CharField
(
max_length
=
50
,)
road_number
=
models
.
CharField
(
max_length
=
50
,)
class
Place
(
models
.
Model
):
class
Place
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
)
name
=
models
.
CharField
(
max_length
=
50
,
unique
=
True
)
type
=
models
.
CharField
(
max_length
=
50
,)
type
=
models
.
CharField
(
max_length
=
50
,)
...
@@ -35,3 +43,5 @@ class Place(models.Model):
...
@@ -35,3 +43,5 @@ class Place(models.Model):
description
=
models
.
CharField
(
max_length
=
50
)
description
=
models
.
CharField
(
max_length
=
50
)
offer
=
models
.
ForeignKey
(
Offer
,
null
=
True
,
blank
=
True
)
offer
=
models
.
ForeignKey
(
Offer
,
null
=
True
,
blank
=
True
)
promotion
=
models
.
ForeignKey
(
PromotionSet
,
null
=
True
,
blank
=
True
)
promotion
=
models
.
ForeignKey
(
PromotionSet
,
null
=
True
,
blank
=
True
)
localization
=
models
.
ForeignKey
(
Localization
,
null
=
True
,
blank
=
True
)
KawowyDzienniczek/App/loyaltyMe/serializers.py
View file @
a5264315
...
@@ -8,8 +8,10 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):
...
@@ -8,8 +8,10 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):
model
=
Product
model
=
Product
fields
=
(
'url'
,
'id'
,
'name'
,
'description'
,
'price'
,
'img'
)
fields
=
(
'url'
,
'id'
,
'name'
,
'description'
,
'price'
,
'img'
)
class
OfferSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
OfferSerializer
(
serializers
.
HyperlinkedModelSerializer
):
products
=
ProductSerializer
(
many
=
True
)
products
=
ProductSerializer
(
many
=
True
)
class
Meta
:
class
Meta
:
model
=
Offer
model
=
Offer
fields
=
(
'url'
,
'id'
,
'products'
)
fields
=
(
'url'
,
'id'
,
'products'
)
...
@@ -23,13 +25,22 @@ class PromotionSerializer(serializers.HyperlinkedModelSerializer):
...
@@ -23,13 +25,22 @@ class PromotionSerializer(serializers.HyperlinkedModelSerializer):
class
PromotionSetSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
PromotionSetSerializer
(
serializers
.
HyperlinkedModelSerializer
):
promotions
=
PromotionSerializer
(
many
=
True
)
promotions
=
PromotionSerializer
(
many
=
True
)
class
Meta
:
class
Meta
:
model
=
Offer
model
=
Offer
fields
=
(
'url'
,
'id'
,
'promotions'
)
fields
=
(
'url'
,
'id'
,
'promotions'
)
class
LocalizationSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Place
fields
=
(
'url'
,
'id'
,
'latitude'
,
'longitude'
,
'city'
,
'road'
,
'road_number'
)
class
PlaceSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
PlaceSerializer
(
serializers
.
HyperlinkedModelSerializer
):
offer
=
OfferSerializer
()
offer
=
OfferSerializer
()
promotion
=
PromotionSetSerializer
()
promotion
=
PromotionSetSerializer
()
localization
=
LocalizationSerializer
()
class
Meta
:
class
Meta
:
model
=
Place
model
=
Place
...
...
KawowyDzienniczek/App/loyaltyMe/views.py
View file @
a5264315
...
@@ -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
from
App.loyaltyMe.models
import
Product
,
Offer
,
Promotion
,
Place
,
PromotionSet
,
Localization
from
App.loyaltyMe.serializers
import
ProductSerializer
,
OfferSerializer
,
PromotionSerializer
,
PlaceSerializer
,
\
from
App.loyaltyMe.serializers
import
ProductSerializer
,
OfferSerializer
,
PromotionSerializer
,
PlaceSerializer
,
\
PromotionSetSerializer
PromotionSetSerializer
,
LocalizationSerializer
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
class
ProductViewSet
(
viewsets
.
ModelViewSet
):
...
@@ -48,3 +48,12 @@ class PlaceViewSet(viewsets.ModelViewSet):
...
@@ -48,3 +48,12 @@ class PlaceViewSet(viewsets.ModelViewSet):
queryset
=
Place
.
objects
.
all
()
queryset
=
Place
.
objects
.
all
()
serializer_class
=
PlaceSerializer
serializer_class
=
PlaceSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
class
LocalizationViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
Localization
.
objects
.
all
()
serializer_class
=
LocalizationSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
\ No newline at end of file
KawowyDzienniczek/App/user/management/commands/init.py
View file @
a5264315
...
@@ -13,5 +13,6 @@ class Command(BaseCommand):
...
@@ -13,5 +13,6 @@ class Command(BaseCommand):
call_command
(
'init_offers'
)
call_command
(
'init_offers'
)
call_command
(
'init_promotions'
)
call_command
(
'init_promotions'
)
call_command
(
'init_promotionsets'
)
call_command
(
'init_promotionsets'
)
call_command
(
'init_localizations'
)
call_command
(
'init_places'
)
call_command
(
'init_places'
)
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