Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
BeHub-web
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
Dominik Rosiek
BeHub-web
Commits
979b183a
Commit
979b183a
authored
Nov 21, 2015
by
Rafal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
394ca98b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
3 deletions
+15
-3
serializers.py
BeHub/Hub/serializers.py
+0
-1
views.py
BeHub/Hub/views.py
+15
-2
No files found.
BeHub/Hub/serializers.py
View file @
979b183a
...
@@ -15,7 +15,6 @@ class BeaconSerializer(serializers.HyperlinkedModelSerializer):
...
@@ -15,7 +15,6 @@ class BeaconSerializer(serializers.HyperlinkedModelSerializer):
fields
=
(
'id'
,
'url'
,
'uuid'
,
'name'
,
'description'
,
'longitude'
,
'latitude'
)
fields
=
(
'id'
,
'url'
,
'uuid'
,
'name'
,
'description'
,
'longitude'
,
'latitude'
)
class
BeaconManagerSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
BeaconManagerSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
class
Meta
:
model
=
BeaconManager
model
=
BeaconManager
fields
=
(
'id'
,
'url'
,
'sites'
,
'beacon'
)
fields
=
(
'id'
,
'url'
,
'sites'
,
'beacon'
)
...
...
BeHub/Hub/views.py
View file @
979b183a
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.shortcuts
import
render
from
django.shortcuts
import
render
# Create your views here.
# Create your views here.
from
rest_framework
import
viewsets
from
rest_framework
import
viewsets
import
rest_framework
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
Hub.models
import
Beacon
,
BeaconManager
,
Site
,
Category
from
Hub.models
import
Beacon
,
BeaconManager
,
Site
,
Category
...
@@ -38,10 +40,21 @@ class UuidBeaconViewSet(APIView):
...
@@ -38,10 +40,21 @@ class UuidBeaconViewSet(APIView):
queryset
=
Beacon
.
objects
.
all
()
queryset
=
Beacon
.
objects
.
all
()
serializer_class
=
BeaconSerializer
serializer_class
=
BeaconSerializer
def
get
(
self
,
request
,
pk
,
format
=
None
):
def
get
(
self
,
request
,
pk
,
category_name
=
None
,
format
=
None
):
beacon
=
Beacon
.
objects
.
get
(
uuid
=
pk
)
beacon
=
Beacon
.
objects
.
get
(
uuid
=
pk
)
beacon_manager
=
BeaconManager
.
objects
.
get
(
beacon
=
beacon
)
beacon_manager
=
BeaconManager
.
objects
.
get
(
beacon
=
beacon
)
serializer
=
BeaconManagerSerializer
(
beacon_manager
,
context
=
{
'request'
:
request
})
if
category_name
:
try
:
category
=
Category
.
objects
.
get
(
name
=
category_name
)
except
ObjectDoesNotExist
:
return
Response
(
status
=
rest_framework
.
status
.
HTTP_400_BAD_REQUEST
,
data
=
{
"This category is not exist"
})
try
:
site
=
beacon_manager
.
sites
.
Category
.
objects
.
get
(
category
=
category
)
except
ObjectDoesNotExist
:
return
Response
(
status
=
rest_framework
.
status
.
HTTP_400_BAD_REQUEST
,
data
=
{
"Any link do not have this category"
})
serializer
=
SiteSerializer
(
site
,
context
=
{
'request'
:
request
})
return
Response
(
serializer
.
data
)
serializer
=
SiteSerializer
(
beacon_manager
.
sites
,
many
=
True
,
context
=
{
'request'
:
request
})
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
class
CategoryViewSet
(
viewsets
.
ModelViewSet
):
class
CategoryViewSet
(
viewsets
.
ModelViewSet
):
...
...
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