Youniversity¶
Getting started¶
Setup virtual environment:
virtualenv venv source venv/bin/activate
Setup requirements:
pip install -r requirements.txt
Sync database:
python manage.py migrate
Add user:
python manage.py createsuperuser
Run webserver:
python manage.py runserver
Starting the web server¶
Run webserver:
python manage.py runserver
Enter the front page at http://localhost:8000/static/index.html
Configure Facebook login¶
- Enter Django administration page at http://localhost:8000/admin/
- Click Sites then fix the first site name from
example.com
tolocalhost:8000
- Go back to front page and click Social applications
- Add new social application. Enter the following information:
- Name: Facebook
- Client ID, Secret Key: As given by Facebook (Register a new Facebook application)
- Sites: Add
localhost:8000
to the list
API Documentation¶
The API root is at /api
auth¶
This endpoint is handled by authapi.views
-
GET
/api/auth/check
¶ Check whether the current user is logged in and retrieve information about the user.
This endpoint is handled by
authapi.views.UserViewSet.get()
Example request:
GET /api/auth/check HTTP/1.1 Host: social.whs.in.th Accept: application/json, text/javascript Cookie: sessionid=.....
Example response when logged in:
HTTP/1.1 200 OK Content-Type: application/json X-Frame-Options: SAMEORIGIN Allow: GET, HEAD, OPTIONS "whs"
Example response when not logged in:
HTTP/1.1 403 FORBIDDEN Content-Type: application/json X-Frame-Options: SAMEORIGIN Allow: GET, HEAD, OPTIONS ""
Response JSON Object: - username (string) – Username of current user
Status Codes: - 403 Forbidden – User is not logged in
-
POST
/api/auth/login
¶ Authenticate user in by username/password combination. For Youniversity, it is usually used to authenticate against KU database via IMAP.
This endpoint is handled by
authapi.views.LoginViewSet.post()
Example request:
POST /api/auth/login HTTP/1.1 Host: social.whs.in.th Accept: application/json, text/plain, */* Content-Type:application/json;charset=UTF-8 {username: "example", password: "example"}
Example of success response:
HTTP/1.0 200 OK X-Frame-Options: SAMEORIGIN Content-Type: application/json Allow: POST, OPTIONS Set-Cookie: csrftoken=Q0oxVmaGJUkyIV9tWuaLjl5yySa4HMcE; expires=Sun, 02-Oct-2016 09:37:27 GMT; Max-Age=31449600; Path=/ Set-Cookie: sessionid=2cceti4ju0x6t3l8wl62awpdttl6sp2p; expires=Sun, 18-Oct-2015 09:37:27 GMT; httponly; Max-Age=1209600; Path=/ "whs"
Example of failed response:
HTTP/1.0 403 FORBIDDEN X-Frame-Options: SAMEORIGIN Content-Type: application/json Allow: POST, OPTIONS {"detail":"Cannot log you in"}
Request JSON Object: - username (string) – Username
- password (string) – Password
Response JSON Object: - username (string) – Username of current user
Status Codes: - 403 Forbidden – Cannot log user in with given credentials. The credentials may be invalid, the server may not be able to connect to authentication database, or the user may be disabled.
-
POST
/api/auth/logout
¶ This endpoint is handled by
authapi.views.LogoutViewSet.post()
Example request:
POST /api/auth/logout HTTP/1.1 Host: social.whs.in.th Accept: application/json, text/javascript Cookie: sessionid=.....
**Example response*:
HTTP/1.1 200 OK Content-Type: application/json X-Frame-Options: SAMEORIGIN Allow: GET, HEAD, OPTIONS
group¶
This endpoint is handled by group.views
-
GET
/api/group/
¶ This endpoint is handled by
group.views.GroupList()
Example request:
GET /api/group HTTP/1.1 Host: social.whs.in.th Accept: application/json, text/javascript Cookie: sessionid=.....
Example response:
HTTP/1.1 200 OK Content-Type: application/json X-Frame-Options: SAMEORIGIN Allow: GET, HEAD, OPTIONS [{"name":"test","description":"Description text","short_description":"Requirement to join group","activities":"Group activity text","type":0}]
Response JSON Array of Objects: - name (string) – Group name
- description (string) – What’s this group about
- short_description (string) – Requirement to join group
- type (int) – 0 = normal, 1 = classroom
Status Codes: - 401 Unauthorized – Not authenticated
-
GET
/api/group/
(int: id)¶ View basic information about a group
This endpoint is handled by
group.views.GroupViewDetail.get()
Example request:
GET /api/group/1 HTTP/1.1 Host: social.whs.in.th Accept: application/json, text/javascript Cookie: sessionid=.....
Example response:
HTTP/1.1 200 OK Content-Type: application/json X-Frame-Options: SAMEORIGIN Allow: GET, HEAD, OPTIONS {"name":"test","description":"Description text","short_description":"Requirement to join group","activities":"Group activity text","type":0,"member_status":-1}
Response JSON Object: - name (string) – Group name
- description (string) – What’s this group about
- short_description (string) – Requirement to join group
- type (int) – 0 = normal, 1 = classroom
- member_status (int) – -1 = not a member, 0 = request pending, 1 = member, 2 = administrator
Status Codes: - 404 Not Found – No such group
Modules Index¶
User package¶
Submodules¶
User.models module¶
-
class
User.models.
UserProfile
(id, user, firstname, lastname, birthday, gender, faculty, major, types, country, city, created, picture, cover)[source]¶ Bases:
django.db.models.base.Model
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
UserProfile.
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
UserProfile.
get_gender_display
(*moreargs, **morekwargs)¶
-
UserProfile.
objects
= <django.db.models.manager.Manager object>¶
-
UserProfile.
user
¶
-
exception
User.serializers module¶
-
class
User.serializers.
FirstUserProfileSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
User.serializers.
FriendShipSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
User.serializers.
PictureField
(read_only=False, write_only=False, required=None, default=<class rest_framework.fields.empty>, initial=<class rest_framework.fields.empty>, source=None, label=None, help_text=None, style=None, error_messages=None, validators=None, allow_null=False)[source]¶ Bases:
rest_framework.fields.Field
-
class
User.serializers.
UserCoverSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
User.serializers.
UserProfilePictureSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
User.views module¶
authapi package¶
This module contains API related to retrieving current user information.
It should be merged into user module later once that is implemented.
Submodules¶
authapi.views module¶
group package¶
Submodules¶
group.models module¶
-
class
group.models.
Group
(id, name, gtype, type, category, description, short_description, activities, permisssion, date, parent, cover)[source]¶ Bases:
django.db.models.base.Model
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
Group.
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
Group.
category
¶
-
Group.
children
¶
-
Group.
get_next_by_date
(*moreargs, **morekwargs)¶
-
Group.
get_previous_by_date
(*moreargs, **morekwargs)¶
-
Group.
groupmember_set
¶
-
Group.
objects
= <django.db.models.manager.Manager object>¶
-
Group.
parent
¶
-
exception
-
class
group.models.
GroupCategory
(id, name)[source]¶ Bases:
django.db.models.base.Model
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
GroupCategory.
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
GroupCategory.
group_set
¶
-
GroupCategory.
objects
= <django.db.models.manager.Manager object>¶
-
exception
-
class
group.models.
GroupMember
(id, group, user, role)[source]¶ Bases:
django.db.models.base.Model
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
GroupMember.
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
GroupMember.
group
¶
-
GroupMember.
objects
= <django.db.models.manager.Manager object>¶
-
GroupMember.
user
¶
-
exception
group.serializers module¶
-
class
group.serializers.
GroupCategorySerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
group.serializers.
GroupCoverSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
group.serializers.
GroupMemberSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
group.serializers.
GroupSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
Meta
[source]¶ -
app_label
= 'social_group'¶
-
extra_kwargs
= {'category': {'required': False}}¶
-
fields
= ('id', 'name', 'description', 'short_description', 'activities', 'type', 'category', 'member_status', 'date', 'member_count', 'cover', 'gtype')¶
-
model
¶ alias of
Group
-
read_only_fields
= ('cover',)¶
-
-
class
group.views module¶
newsfeed package¶
Submodules¶
newsfeed.models module¶
-
class
newsfeed.models.
Comment
(id, post, user, text, datetime, file)[source]¶ Bases:
django.db.models.base.Model
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
Comment.
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
Comment.
get_next_by_datetime
(*moreargs, **morekwargs)¶
-
Comment.
get_previous_by_datetime
(*moreargs, **morekwargs)¶
-
Comment.
objects
= <django.db.models.manager.Manager object>¶
-
Comment.
post
¶
-
Comment.
user
¶
-
exception
-
class
newsfeed.models.
Post
(id, user, text, datetime, target_type, target_id, target_name, allow_submission, pinned)[source]¶ Bases:
django.db.models.base.Model
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
Post.
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
Post.
comment_set
¶
-
Post.
get_next_by_datetime
(*moreargs, **morekwargs)¶
-
Post.
get_previous_by_datetime
(*moreargs, **morekwargs)¶
-
Post.
objects
= <django.db.models.manager.Manager object>¶
-
Post.
target_object
¶ Provides a generic relation to any object through content-type/object-id fields.
-
Post.
target_type
¶
-
Post.
user
¶
-
exception
newsfeed.serializer module¶
newsfeed.views module¶
notification package¶
Submodules¶
notification.models module¶
-
class
notification.models.
Notification
(id, user, datetime, text, target_type, target_id, link_type, link_item, reference_detail)[source]¶ Bases:
django.db.models.base.Model
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
Notification.
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
Notification.
get_next_by_datetime
(*moreargs, **morekwargs)¶
-
Notification.
get_previous_by_datetime
(*moreargs, **morekwargs)¶
-
Notification.
link_type
¶
-
Notification.
objects
= <django.db.models.manager.Manager object>¶
-
Notification.
readed
¶
-
Notification.
receiver
¶
-
Notification.
target_object
¶ Provides a generic relation to any object through content-type/object-id fields.
-
Notification.
target_type
¶
-
Notification.
user
¶
-
Notification.
usernotification_set
¶
-
exception
-
class
notification.models.
UserNotification
(id, notification, receiver)[source]¶ Bases:
django.db.models.base.Model
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
UserNotification.
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
UserNotification.
notification
¶
-
UserNotification.
objects
= <django.db.models.manager.Manager object>¶
-
UserNotification.
receiver
¶
-
exception
notification.serializer module¶
-
class
notification.serializer.
GetNotificationSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
notification.serializer.
NotificationSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
notification.serializer.
TypeSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
notification.serializer.
UpdateNotificationSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
class
notification.serializer.
UserNotificationSerializer
(instance=None, data=<class rest_framework.fields.empty>, **kwargs)[source]¶ Bases:
rest_framework.serializers.ModelSerializer
-
UserNotificationSerializer.
auto_created
= True¶
-
notification.views module¶
-
class
notification.views.
NotificationView
(**kwargs)[source]¶ Bases:
rest_framework.views.APIView
This class is an API for get specific notification.
-
get
(request)[source]¶ Get notification of specific user. :param request: Django Rest Framework request object. :param format: pattern for Web APIs.
Returns: list of notification of that user.
-
serializer_class
¶ alias of
GetNotificationSerializer
-
-
class
notification.views.
NotificationViewList
(**kwargs)[source]¶ Bases:
rest_framework.views.APIView
This class is an API for create and get all notification.
-
add
(user, data, receiver_set, type, link_item, reference_detail, format=None)[source]¶ Create and save notification to database. :param user: user who create notification. :param data: Json information of target of post :param receiver_set: set of receiver who will receive
this notification.Parameters: - type – type of action that create this notification.
- link_item – information of action that create this notification.
- reference_detail – information of the post target object
- format – pattern for Web APIs.
Return:
-
get
(request, format=None)[source]¶ Get all of notification in database. :param request: Django Rest Framework request object. :param format: pattern for Web APIs.
Returns: list of all notification in database.
-
serializer_class
¶ alias of
NotificationSerializer
-
-
class
notification.views.
UpdateNotification
(**kwargs)[source]¶ Bases:
rest_framework.views.APIView
This class is an API for update readed notification.
-
get
(request, noti_id, format=None)[source]¶ Get notification in database and mark as readed. :param request: Django Rest Framework request object. :param noti_id: id of notification. :param format: pattern for Web APIs.
Returns: updated notificaton.
-
get_object
(noti_id)[source]¶ Get notification object by id. :param noti_id: id of notification.
Returns: notification object.
-
serializer_class
¶ alias of
UpdateNotificationSerializer
-