Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
JoinTheCity
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
JoinTheCity
Commits
463f9aeb
Commit
463f9aeb
authored
Jan 02, 2016
by
Eryk Leniart
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
67a7428a
ab0c7336
Show whitespace changes
Inline
Side-by-side
Showing
60 changed files
with
676 additions
and
12 deletions
+676
-12
settings.py
JoinTheCityREST/JoinTheCityREST/settings.py
+12
-3
urls.py
JoinTheCityREST/JoinTheCityREST/urls.py
+23
-3
models.py
JoinTheCityREST/RESTAPI/models.py
+0
-3
views.py
JoinTheCityREST/RESTAPI/views.py
+0
-3
__init__.py
JoinTheCityREST/app/API/__init__.py
+0
-0
admin.py
JoinTheCityREST/app/API/admin.py
+0
-0
0001_initial.py
JoinTheCityREST/app/API/migrations/0001_initial.py
+22
-0
__init__.py
JoinTheCityREST/app/API/migrations/__init__.py
+0
-0
models.py
JoinTheCityREST/app/API/models.py
+13
-0
serializers.py
JoinTheCityREST/app/API/serializers.py
+9
-0
tests.py
JoinTheCityREST/app/API/tests.py
+0
-0
views.py
JoinTheCityREST/app/API/views.py
+13
-0
__init__.py
JoinTheCityREST/app/Discussion/__init__.py
+0
-0
admin.py
JoinTheCityREST/app/Discussion/admin.py
+3
-0
0001_initial.py
JoinTheCityREST/app/Discussion/migrations/0001_initial.py
+31
-0
__init__.py
JoinTheCityREST/app/Discussion/migrations/__init__.py
+0
-0
models.py
JoinTheCityREST/app/Discussion/models.py
+22
-0
serializers.py
JoinTheCityREST/app/Discussion/serializers.py
+14
-0
tests.py
JoinTheCityREST/app/Discussion/tests.py
+3
-0
views.py
JoinTheCityREST/app/Discussion/views.py
+22
-0
__init__.py
JoinTheCityREST/app/Event/__init__.py
+0
-0
admin.py
JoinTheCityREST/app/Event/admin.py
+3
-0
0001_initial.py
JoinTheCityREST/app/Event/migrations/0001_initial.py
+22
-0
__init__.py
JoinTheCityREST/app/Event/migrations/__init__.py
+0
-0
models.py
JoinTheCityREST/app/Event/models.py
+20
-0
serializers.py
JoinTheCityREST/app/Event/serializers.py
+8
-0
tests.py
JoinTheCityREST/app/Event/tests.py
+3
-0
views.py
JoinTheCityREST/app/Event/views.py
+13
-0
__init__.py
JoinTheCityREST/app/Friendship/__init__.py
+0
-0
admin.py
JoinTheCityREST/app/Friendship/admin.py
+3
-0
0001_initial.py
JoinTheCityREST/app/Friendship/migrations/0001_initial.py
+31
-0
__init__.py
JoinTheCityREST/app/Friendship/migrations/__init__.py
+0
-0
models.py
JoinTheCityREST/app/Friendship/models.py
+19
-0
serializers.py
JoinTheCityREST/app/Friendship/serializers.py
+8
-0
tests.py
JoinTheCityREST/app/Friendship/tests.py
+3
-0
views.py
JoinTheCityREST/app/Friendship/views.py
+37
-0
__init__.py
JoinTheCityREST/app/Localization/__init__.py
+0
-0
admin.py
JoinTheCityREST/app/Localization/admin.py
+3
-0
0001_initial.py
JoinTheCityREST/app/Localization/migrations/0001_initial.py
+22
-0
__init__.py
JoinTheCityREST/app/Localization/migrations/__init__.py
+0
-0
models.py
JoinTheCityREST/app/Localization/models.py
+12
-0
serializers.py
JoinTheCityREST/app/Localization/serializers.py
+9
-0
tests.py
JoinTheCityREST/app/Localization/tests.py
+3
-0
views.py
JoinTheCityREST/app/Localization/views.py
+12
-0
__init__.py
JoinTheCityREST/app/Tag/__init__.py
+0
-0
admin.py
JoinTheCityREST/app/Tag/admin.py
+3
-0
0001_initial.py
JoinTheCityREST/app/Tag/migrations/0001_initial.py
+22
-0
__init__.py
JoinTheCityREST/app/Tag/migrations/__init__.py
+0
-0
models.py
JoinTheCityREST/app/Tag/models.py
+14
-0
serializers.py
JoinTheCityREST/app/Tag/serializers.py
+9
-0
tests.py
JoinTheCityREST/app/Tag/tests.py
+3
-0
views.py
JoinTheCityREST/app/Tag/views.py
+12
-0
__init__.py
JoinTheCityREST/app/User/__init__.py
+0
-0
admin.py
JoinTheCityREST/app/User/admin.py
+3
-0
__init__.py
JoinTheCityREST/app/User/migrations/__init__.py
+0
-0
models.py
JoinTheCityREST/app/User/models.py
+48
-0
serializers.py
JoinTheCityREST/app/User/serializers.py
+30
-0
tests.py
JoinTheCityREST/app/User/tests.py
+3
-0
views.py
JoinTheCityREST/app/User/views.py
+110
-0
__init__.py
JoinTheCityREST/app/__init__.py
+1
-0
No files found.
JoinTheCityREST/JoinTheCityREST/settings.py
View file @
463f9aeb
...
@@ -10,6 +10,8 @@ https://docs.djangoproject.com/en/1.7/ref/settings/
...
@@ -10,6 +10,8 @@ https://docs.djangoproject.com/en/1.7/ref/settings/
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import
os
import
os
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
BASE_DIR
=
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))
...
@@ -38,14 +40,21 @@ INSTALLED_APPS = (
...
@@ -38,14 +40,21 @@ INSTALLED_APPS = (
'django.contrib.staticfiles'
,
'django.contrib.staticfiles'
,
'rest_framework'
,
'rest_framework'
,
'rest_framework.authtoken'
,
'rest_framework.authtoken'
,
'app.API'
,
'app.Discussion'
,
'app.Event'
,
'app.Friendship'
,
'app.Localization'
,
'app.Tag'
,
'app.User'
,
)
)
REST_FRAMEWORK
=
{
REST_FRAMEWORK
=
{
'DEFAULT_PERMISSION_CLASSES'
:
(
'rest_framework.permissions.
AllowAny
'
,),
'DEFAULT_PERMISSION_CLASSES'
:
(
'rest_framework.permissions.
IsAuthenticated
'
,),
'DEFAULT_FILTER_BACKENDS'
:
(
'rest_framework.filters.DjangoFilterBackend'
,),
'DEFAULT_FILTER_BACKENDS'
:
(
'rest_framework.filters.DjangoFilterBackend'
,),
'DEFAULT_AUTHENTICATION_CLASSES'
:
(
'DEFAULT_AUTHENTICATION_CLASSES'
:
(
#
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.SessionAuthentication'
,
#
'rest_framework.authentication.TokenAuthentication',
'rest_framework.authentication.TokenAuthentication'
,
),
),
'DEFAULT_PAGINATION_CLASS'
:
'rest_framework.pagination.LimitOffsetPagination'
,
'DEFAULT_PAGINATION_CLASS'
:
'rest_framework.pagination.LimitOffsetPagination'
,
'PAGE_SIZE'
:
10
'PAGE_SIZE'
:
10
...
...
JoinTheCityREST/JoinTheCityREST/urls.py
View file @
463f9aeb
...
@@ -5,10 +5,30 @@ from rest_framework import routers
...
@@ -5,10 +5,30 @@ from rest_framework import routers
router
=
routers
.
DefaultRouter
()
router
=
routers
.
DefaultRouter
()
from
app.API
import
views
as
api_views
from
app.Discussion
import
views
as
discussion_views
from
app.Event
import
views
as
event_views
from
app.Friendship
import
views
as
friendship_views
from
app.Localization
import
views
as
localization_views
from
app.Tag
import
views
as
tag_views
from
app.User
import
views
as
user_views
router
.
register
(
r'user'
,
user_views
.
UserViewSet
)
router
.
register
(
r'api'
,
api_views
.
APIViewSet
)
router
.
register
(
r'discussion'
,
discussion_views
.
DiscussionViewSet
)
router
.
register
(
r'text_message'
,
discussion_views
.
TextMessageViewSet
)
router
.
register
(
r'event'
,
event_views
.
EventViewSet
)
router
.
register
(
r'localization'
,
localization_views
.
LocalizationViewSet
)
router
.
register
(
r'tag'
,
tag_views
.
TagViewSet
)
router
.
register
(
r'user_friendship_request'
,
friendship_views
.
FriendshipRequestViewSet
)
router
.
register
(
r'user_friendship'
,
user_views
.
UserFriendshipViewSet
)
router
.
register
(
r'user_event_request'
,
user_views
.
UserEventRequestViewSet
)
router
.
register
(
r'user_event'
,
user_views
.
UserEventViewSet
)
router
.
register
(
r'user_api'
,
user_views
.
UserAPIViewSet
)
urlpatterns
=
patterns
(
''
,
urlpatterns
=
patterns
(
''
,
# Examples:
# url(r'^$', 'JoinTheCityREST.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url
(
r'^api/'
,
include
(
router
.
urls
)),
url
(
r'^api/'
,
include
(
router
.
urls
)),
url
(
r'^api-auth/'
,
include
(
'rest_framework.urls'
,
url
(
r'^api-auth/'
,
include
(
'rest_framework.urls'
,
namespace
=
'rest_framework'
)),
namespace
=
'rest_framework'
)),
...
...
JoinTheCityREST/RESTAPI/models.py
deleted
100644 → 0
View file @
67a7428a
from
django.db
import
models
# Create your models here.
JoinTheCityREST/RESTAPI/views.py
deleted
100644 → 0
View file @
67a7428a
from
django.shortcuts
import
render
# Create your views here.
JoinTheCityREST/
REST
API/__init__.py
→
JoinTheCityREST/
app/
API/__init__.py
View file @
463f9aeb
File moved
JoinTheCityREST/
REST
API/admin.py
→
JoinTheCityREST/
app/
API/admin.py
View file @
463f9aeb
File moved
JoinTheCityREST/app/API/migrations/0001_initial.py
0 → 100644
View file @
463f9aeb
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'API'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
]
JoinTheCityREST/
REST
API/migrations/__init__.py
→
JoinTheCityREST/
app/
API/migrations/__init__.py
View file @
463f9aeb
File moved
JoinTheCityREST/app/API/models.py
0 → 100644
View file @
463f9aeb
from
django.db
import
models
# Create your models here.
from
app.Tag.models
import
Tag
class
API
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
tag
=
models
.
ManyToManyField
(
Tag
,
related_name
=
'API_tags'
,
blank
=
False
,
null
=
False
,
default
=
None
)
def
__str__
(
self
):
return
self
.
name
\ No newline at end of file
JoinTheCityREST/app/API/serializers.py
0 → 100644
View file @
463f9aeb
from
rest_framework
import
serializers
from
app.API.models
import
API
class
APISerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
API
fields
=
(
'url'
,
'name'
,
'tag'
)
\ No newline at end of file
JoinTheCityREST/
REST
API/tests.py
→
JoinTheCityREST/
app/
API/tests.py
View file @
463f9aeb
File moved
JoinTheCityREST/app/API/views.py
0 → 100644
View file @
463f9aeb
# Create your views here.
from
rest_framework
import
viewsets
,
permissions
from
app.API.models
import
API
from
app.API.serializers
import
APISerializer
class
APIViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
API
.
objects
.
all
()
serializer_class
=
APISerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
\ No newline at end of file
JoinTheCityREST/app/Discussion/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Discussion/admin.py
0 → 100644
View file @
463f9aeb
from
django.contrib
import
admin
# Register your models here.
JoinTheCityREST/app/Discussion/migrations/0001_initial.py
0 → 100644
View file @
463f9aeb
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Discussion'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
migrations
.
CreateModel
(
name
=
'Message'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
]
JoinTheCityREST/app/Discussion/migrations/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Discussion/models.py
0 → 100644
View file @
463f9aeb
from
django.contrib.auth.models
import
User
from
django.db
import
models
from
app.Tag.models
import
Tag
from
django.utils.datetime_safe
import
datetime
class
TextMessage
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
'user_creator_of_message'
,
blank
=
False
,
null
=
False
,
default
=
None
)
text
=
models
.
CharField
(
max_length
=
1000
)
created_at
=
models
.
DateTimeField
(
default
=
datetime
.
now
)
def
__str__
(
self
):
return
self
.
text
class
Discussion
(
models
.
Model
):
question
=
models
.
CharField
(
max_length
=
100
)
message
=
models
.
ManyToManyField
(
TextMessage
,
blank
=
True
,
null
=
True
,
related_name
=
"conversations_participant"
)
tag
=
models
.
ForeignKey
(
Tag
,
related_name
=
'place_of_discussion'
,
blank
=
False
,
null
=
False
,
default
=
None
)
def
__str__
(
self
):
return
self
.
question
JoinTheCityREST/app/Discussion/serializers.py
0 → 100644
View file @
463f9aeb
from
rest_framework
import
serializers
from
app.Discussion.models
import
Discussion
,
TextMessage
from
app.User.serializers
import
UserSerializer
class
DiscussionSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Discussion
fields
=
(
'url'
,
'question'
,
'message'
,
'tag'
)
class
TextMessageSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
TextMessage
fields
=
(
'url'
,
'user'
,
'text'
,
'created_at'
)
\ No newline at end of file
JoinTheCityREST/app/Discussion/tests.py
0 → 100644
View file @
463f9aeb
from
django.test
import
TestCase
# Create your tests here.
JoinTheCityREST/app/Discussion/views.py
0 → 100644
View file @
463f9aeb
# Create your views here.
from
rest_framework
import
viewsets
,
permissions
from
app.API.serializers
import
APISerializer
from
app.Discussion.models
import
Discussion
,
TextMessage
from
app.Discussion.serializers
import
TextMessageSerializer
,
DiscussionSerializer
class
DiscussionViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
Discussion
.
objects
.
all
()
serializer_class
=
DiscussionSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
class
TextMessageViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
TextMessage
.
objects
.
all
()
serializer_class
=
TextMessageSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
\ No newline at end of file
JoinTheCityREST/app/Event/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Event/admin.py
0 → 100644
View file @
463f9aeb
from
django.contrib
import
admin
# Register your models here.
JoinTheCityREST/app/Event/migrations/0001_initial.py
0 → 100644
View file @
463f9aeb
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Event'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
]
JoinTheCityREST/app/Event/migrations/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Event/models.py
0 → 100644
View file @
463f9aeb
from
django.contrib.auth.models
import
User
from
django.db
import
models
# Create your models here.
from
app.Localization.models
import
Localization
from
app.Tag.models
import
Tag
class
Event
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
)
private
=
models
.
BooleanField
(
default
=
False
)
tag
=
models
.
ManyToManyField
(
Tag
,
related_name
=
'event_tag'
,
blank
=
False
,
null
=
False
,
default
=
None
)
localization
=
models
.
ForeignKey
(
Localization
,
related_name
=
'event_tag'
,
blank
=
False
,
null
=
False
,
default
=
None
)
user
=
models
.
ForeignKey
(
User
,
related_name
=
'event_author'
,
blank
=
False
,
null
=
False
,
default
=
None
)
def
__str__
(
self
):
return
self
.
name
JoinTheCityREST/app/Event/serializers.py
0 → 100644
View file @
463f9aeb
from
rest_framework
import
serializers
from
app.Event.models
import
Event
class
EventSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Event
fields
=
(
'url'
,
'name'
,
'private'
,
'localization'
,
'tag'
,
'user'
)
\ No newline at end of file
JoinTheCityREST/app/Event/tests.py
0 → 100644
View file @
463f9aeb
from
django.test
import
TestCase
# Create your tests here.
JoinTheCityREST/app/Event/views.py
0 → 100644
View file @
463f9aeb
# Create your views here.
from
rest_framework
import
viewsets
,
permissions
from
app.Event.models
import
Event
from
app.Event.serializers
import
EventSerializer
class
EventViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
Event
.
objects
.
all
()
serializer_class
=
EventSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
\ No newline at end of file
JoinTheCityREST/app/Friendship/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Friendship/admin.py
0 → 100644
View file @
463f9aeb
from
django.contrib
import
admin
# Register your models here.
JoinTheCityREST/app/Friendship/migrations/0001_initial.py
0 → 100644
View file @
463f9aeb
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Friendship'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
migrations
.
CreateModel
(
name
=
'FriendshipRequest'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
]
JoinTheCityREST/app/Friendship/migrations/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Friendship/models.py
0 → 100644
View file @
463f9aeb
from
django.contrib.auth.models
import
User
from
django.db
import
models
# Create your models here.
from
app.User.models
import
UserFriendship
class
FriendshipRequest
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
'user_friendship_request_target'
,
blank
=
False
,
null
=
False
,
default
=
None
)
created_by
=
models
.
ForeignKey
(
User
,
related_name
=
'user_friendship_request_creator'
,
blank
=
False
,
null
=
False
,
default
=
None
)
def
accept
(
self
):
user_friendship
=
UserFriendship
(
user
=
self
.
user
,
friend
=
self
.
created_by
)
user_friendship
.
save
()
user_friendship
=
UserFriendship
(
friend
=
self
.
user
,
user
=
self
.
created_by
)
user_friendship
.
save
()
self
.
delete
()
\ No newline at end of file
JoinTheCityREST/app/Friendship/serializers.py
0 → 100644
View file @
463f9aeb
from
rest_framework
import
serializers
from
app.Friendship.models
import
FriendshipRequest
class
FriendshipRequestSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
FriendshipRequest
fields
=
(
'url'
,
'created_by'
,
'user'
)
JoinTheCityREST/app/Friendship/tests.py
0 → 100644
View file @
463f9aeb
from
django.test
import
TestCase
# Create your tests here.
JoinTheCityREST/app/Friendship/views.py
0 → 100644
View file @
463f9aeb
# Create your views here.
from
django.shortcuts
import
get_object_or_404
from
requests
import
Response
from
rest_framework
import
viewsets
,
permissions
import
rest_framework
from
rest_framework.decorators
import
detail_route
from
app.Friendship.models
import
FriendshipRequest
from
app.Friendship.serializers
import
FriendshipRequestSerializer
class
FriendshipRequestViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
FriendshipRequest
.
objects
.
all
()
serializer_class
=
FriendshipRequestSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
def
list
(
self
,
request
):
user
=
request
.
user
queryset
=
FriendshipRequest
.
objects
.
filter
(
user
=
user
)
.
all
()
page
=
self
.
paginate_queryset
(
queryset
)
serializer
=
FriendshipRequestSerializer
(
page
,
many
=
True
,
context
=
{
'request'
:
request
})
return
self
.
get_paginated_response
(
serializer
.
data
)
@
detail_route
()
def
accept
(
self
,
request
,
pk
=
None
):
friendship_request
=
get_object_or_404
(
self
.
queryset
,
pk
=
pk
)
friendship_request
.
accept
()
return
Response
(
status
=
rest_framework
.
status
.
HTTP_200_OK
)
@
detail_route
()
def
decline
(
self
,
request
,
pk
=
None
):
friendship_request
=
get_object_or_404
(
self
.
queryset
,
pk
=
pk
)
friendship_request
.
delete
()
return
Response
(
status
=
rest_framework
.
status
.
HTTP_200_OK
)
JoinTheCityREST/app/Localization/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Localization/admin.py
0 → 100644
View file @
463f9aeb
from
django.contrib
import
admin
# Register your models here.
JoinTheCityREST/app/Localization/migrations/0001_initial.py
0 → 100644
View file @
463f9aeb
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Localization'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
]
JoinTheCityREST/app/Localization/migrations/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Localization/models.py
0 → 100644
View file @
463f9aeb
from
django.db
import
models
# Create your models here.
class
Localization
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
300
)
longitude
=
models
.
DecimalField
(
max_digits
=
9
,
decimal_places
=
6
,
default
=
None
)
latitude
=
models
.
DecimalField
(
max_digits
=
9
,
decimal_places
=
6
,
default
=
None
)
def
__str__
(
self
):
return
self
.
name
\ No newline at end of file
JoinTheCityREST/app/Localization/serializers.py
0 → 100644
View file @
463f9aeb
from
rest_framework
import
serializers
from
app.Localization.models
import
Localization
class
LocalizationSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Localization
fields
=
(
'url'
,
'name'
,
'longitude'
,
'latitude'
)
JoinTheCityREST/app/Localization/tests.py
0 → 100644
View file @
463f9aeb
from
django.test
import
TestCase
# Create your tests here.
JoinTheCityREST/app/Localization/views.py
0 → 100644
View file @
463f9aeb
from
rest_framework
import
viewsets
,
permissions
from
app.Localization.models
import
Localization
from
app.Localization.serializers
import
LocalizationSerializer
class
LocalizationViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
Localization
.
objects
.
all
()
serializer_class
=
LocalizationSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
\ No newline at end of file
JoinTheCityREST/app/Tag/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Tag/admin.py
0 → 100644
View file @
463f9aeb
from
django.contrib
import
admin
# Register your models here.
JoinTheCityREST/app/Tag/migrations/0001_initial.py
0 → 100644
View file @
463f9aeb
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Tag'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
],
options
=
{
},
bases
=
(
models
.
Model
,),
),
]
JoinTheCityREST/app/Tag/migrations/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/Tag/models.py
0 → 100644
View file @
463f9aeb
from
django.db
import
models
# Create your models here.
from
app.Localization.models
import
Localization
class
Tag
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
300
)
localization
=
models
.
ForeignKey
(
Localization
,
related_name
=
'tag_localization'
,
blank
=
False
,
null
=
False
,
default
=
None
)
def
__str__
(
self
):
return
self
.
name
\ No newline at end of file
JoinTheCityREST/app/Tag/serializers.py
0 → 100644
View file @
463f9aeb
from
rest_framework
import
serializers
from
app.Tag.models
import
Tag
class
TagSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Tag
fields
=
(
'url'
,
'name'
,
'localization'
)
JoinTheCityREST/app/Tag/tests.py
0 → 100644
View file @
463f9aeb
from
django.test
import
TestCase
# Create your tests here.
JoinTheCityREST/app/Tag/views.py
0 → 100644
View file @
463f9aeb
from
rest_framework
import
viewsets
,
permissions
from
app.Tag.models
import
Tag
from
app.Tag.serializers
import
TagSerializer
class
TagViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
Tag
.
objects
.
all
()
serializer_class
=
TagSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
\ No newline at end of file
JoinTheCityREST/app/User/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/User/admin.py
0 → 100644
View file @
463f9aeb
from
django.contrib
import
admin
# Register your models here.
JoinTheCityREST/app/User/migrations/__init__.py
0 → 100644
View file @
463f9aeb
JoinTheCityREST/app/User/models.py
0 → 100644
View file @
463f9aeb
from
django.contrib.auth.models
import
User
from
django.db
import
models
# Create your models here.
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
rest_framework.authtoken.models
import
Token
from
JoinTheCityREST
import
settings
from
app.API.models
import
API
from
app.Event.models
import
Event
class
UserFriendship
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
'user_friendship'
,
blank
=
False
,
null
=
False
,
default
=
None
)
friend
=
models
.
ForeignKey
(
User
,
related_name
=
'user_friend'
,
blank
=
False
,
null
=
False
,
default
=
None
)
class
UserAPI
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
'api_participant'
,
blank
=
False
,
null
=
False
,
default
=
None
)
api
=
models
.
ForeignKey
(
API
,
related_name
=
'api_choosen_by_user'
,
blank
=
False
,
null
=
False
,
default
=
None
)
class
UserEvent
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
'event_participant'
,
blank
=
False
,
null
=
False
,
default
=
None
)
event
=
models
.
ForeignKey
(
Event
,
related_name
=
'event_choosen_by_user'
,
blank
=
False
,
null
=
False
,
default
=
None
)
class
UserEventRequest
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
related_name
=
'user_event_request_recived'
,
blank
=
False
,
null
=
False
,
default
=
None
)
created_by
=
models
.
ForeignKey
(
User
,
related_name
=
'user_event_requeset_creator'
,
blank
=
False
,
null
=
False
,
default
=
None
)
event
=
models
.
ForeignKey
(
Event
,
related_name
=
'event'
,
blank
=
False
,
null
=
False
,
default
=
None
)
def
accept
(
self
):
user_event
=
UserEvent
(
user
=
self
.
user
,
event
=
self
.
event
)
user_event
.
save
()
self
.
delete
()
@
receiver
(
post_save
,
sender
=
User
)
def
create_auth_token
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
created
:
Token
.
objects
.
create
(
user
=
instance
)
\ No newline at end of file
JoinTheCityREST/app/User/serializers.py
0 → 100644
View file @
463f9aeb
from
django.contrib.auth.models
import
User
from
rest_framework
import
serializers
from
app.Event.serializers
import
EventSerializer
from
app.User.models
import
UserFriendship
,
UserAPI
,
UserEvent
,
UserEventRequest
class
UserSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
User
fields
=
(
'url'
,
'id'
,
'username'
,
'email'
)
class
UserFriendshipSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
UserFriendship
fields
=
(
'url'
,
'friend'
)
class
UserEventRequestSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
UserEventRequest
fields
=
(
'url'
,
'event'
,
'created_by'
)
class
UserAPISerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
UserAPI
fields
=
(
'url'
,
'api'
)
class
UserEventSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
UserEvent
fields
=
(
'url'
,
'event'
)
\ No newline at end of file
JoinTheCityREST/app/User/tests.py
0 → 100644
View file @
463f9aeb
from
django.test
import
TestCase
# Create your tests here.
JoinTheCityREST/app/User/views.py
0 → 100644
View file @
463f9aeb
from
django.contrib.auth.models
import
User
from
django.shortcuts
import
get_object_or_404
from
rest_framework
import
viewsets
,
permissions
import
rest_framework
from
rest_framework.decorators
import
list_route
,
detail_route
from
rest_framework.response
import
Response
from
app.User.models
import
UserFriendship
,
UserAPI
,
UserEvent
,
UserEventRequest
from
app.User.serializers
import
UserFriendshipSerializer
,
UserAPISerializer
,
\
UserEventSerializer
,
UserEventRequestSerializer
,
UserSerializer
class
UserViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
User
.
objects
.
all
()
serializer_class
=
UserSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
@
list_route
(
methods
=
[
'get'
])
def
me
(
self
,
request
,
pk
=
None
):
user
=
User
.
objects
.
filter
(
pk
=
request
.
user
.
id
)[
0
]
user_data
=
UserSerializer
(
user
,
context
=
{
'request'
:
request
})
.
data
return
Response
(
status
=
rest_framework
.
status
.
HTTP_200_OK
,
data
=
user_data
)
class
UserFriendshipViewSet
(
viewsets
.
ModelViewSet
):
"""
API for articles
"""
queryset
=
UserFriendship
.
objects
.
all
()
serializer_class
=
UserFriendshipSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
def
perform_create
(
self
,
serializer
):
serializer
.
save
(
user
=
self
.
request
.
user
)
def
list
(
self
,
request
):
user
=
request
.
user
queryset
=
UserFriendship
.
objects
.
filter
(
user
=
user
)
.
all
()
page
=
self
.
paginate_queryset
(
queryset
)
serializer
=
UserFriendshipSerializer
(
page
,
many
=
True
,
context
=
{
'request'
:
request
})
return
self
.
get_paginated_response
(
serializer
.
data
)
class
UserEventRequestViewSet
(
viewsets
.
ModelViewSet
):
"""
User Friendships
"""
queryset
=
UserEventRequest
.
objects
.
all
()
serializer_class
=
UserEventRequestSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
def
perform_create
(
self
,
serializer
):
serializer
.
save
(
user
=
self
.
request
.
user
)
def
list
(
self
,
request
):
user
=
request
.
user
queryset
=
UserEventRequest
.
objects
.
filter
(
user
=
user
)
.
all
()
page
=
self
.
paginate_queryset
(
queryset
)
serializer
=
UserEventRequestSerializer
(
page
,
many
=
True
,
context
=
{
'request'
:
request
})
return
self
.
get_paginated_response
(
serializer
.
data
)
@
detail_route
()
def
accept
(
self
,
request
,
pk
=
None
):
event_request
=
get_object_or_404
(
self
.
queryset
,
pk
=
pk
)
event_request
.
accept
()
return
Response
(
status
=
rest_framework
.
status
.
HTTP_200_OK
)
@
detail_route
()
def
decline
(
self
,
request
,
pk
=
None
):
event_request
=
get_object_or_404
(
self
.
queryset
,
pk
=
pk
)
event_request
.
delete
()
return
Response
(
status
=
rest_framework
.
status
.
HTTP_200_OK
)
class
UserAPIViewSet
(
viewsets
.
ModelViewSet
):
"""
User favorite api
"""
queryset
=
UserAPI
.
objects
.
all
()
serializer_class
=
UserAPISerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
def
perform_create
(
self
,
serializer
):
serializer
.
save
(
user
=
self
.
request
.
user
)
def
list
(
self
,
request
):
user
=
request
.
user
queryset
=
UserAPI
.
objects
.
filter
(
user
=
user
)
.
all
()
page
=
self
.
paginate_queryset
(
queryset
)
serializer
=
UserAPISerializer
(
page
,
many
=
True
,
context
=
{
'request'
:
request
})
return
self
.
get_paginated_response
(
serializer
.
data
)
class
UserEventViewSet
(
viewsets
.
ModelViewSet
):
"""
User participant in this event
"""
queryset
=
UserEvent
.
objects
.
all
()
serializer_class
=
UserEventSerializer
permission_classes
=
(
permissions
.
IsAuthenticatedOrReadOnly
,)
def
perform_create
(
self
,
serializer
):
serializer
.
save
(
user
=
self
.
request
.
user
)
def
list
(
self
,
request
):
user
=
request
.
user
queryset
=
UserEvent
.
objects
.
filter
(
user
=
user
)
.
all
()
page
=
self
.
paginate_queryset
(
queryset
)
serializer
=
UserEventSerializer
(
page
,
many
=
True
,
context
=
{
'request'
:
request
})
return
self
.
get_paginated_response
(
serializer
.
data
)
\ No newline at end of file
JoinTheCityREST/app/__init__.py
0 → 100644
View file @
463f9aeb
__author__
=
'Rafal'
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