-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
997 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.pyc | ||
db.sqlite3 | ||
__pycache__ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
#%RAML 1.0 | ||
--- | ||
title: Django polls API | ||
baseUri: http://api.example.com/{version} | ||
version: v1 | ||
mediaType: application/json | ||
types: | ||
Poll: | ||
type: object | ||
properties: | ||
question: | ||
required: true | ||
type: string | ||
created_by: | ||
required: true | ||
type: User | ||
pub_date: | ||
required: true | ||
type: date | ||
Choice: | ||
type: object | ||
properties: | ||
poll: | ||
required: true | ||
type: Poll | ||
choice_text: | ||
required: true | ||
type: string | ||
Vote: | ||
type: object | ||
properties: | ||
choice: | ||
required: true | ||
type: Choice | ||
poll: | ||
required: true | ||
type: Poll | ||
voted_by: | ||
required: true | ||
type: User | ||
/polls: | ||
get: | ||
description: Get list of polls | ||
queryParameters: | ||
pollId: | ||
description: Specify the poll id you want to retrieve | ||
type: integer | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
example: | ||
{ | ||
"data": | ||
{ | ||
"Id": 1, | ||
"question": "Will A be the leader next time?", | ||
"created_by": "user1", | ||
"pub_date": "08:02:2014" | ||
}, | ||
"success": true, | ||
"status": 200 | ||
} | ||
post: | ||
description: Post a poll | ||
queryParameters: | ||
question: | ||
description: Question you want to create for poll | ||
type: string | ||
required: true | ||
created_by: | ||
description: Poll created by the user | ||
type: User | ||
required: true | ||
pub_date: | ||
description: Poll created on | ||
type: date | ||
required: true | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
example: | ||
{ | ||
"success": true, | ||
"status": 201 | ||
} | ||
/choices: | ||
get: | ||
description: Get list of choices | ||
queryParameters: | ||
choiceId: | ||
description: Specify the choice id you want to retrieve | ||
type: integer | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
example: | ||
{ | ||
"data": | ||
{ | ||
"Id": 1, | ||
"poll": "Will A be the leader next time?", | ||
"choice_text": "user1" | ||
}, | ||
"success": true, | ||
"status": 200 | ||
} | ||
post: | ||
description: Post a choice | ||
queryParameters: | ||
poll: | ||
description: Choice you want to create for poll | ||
type: string | ||
required: true | ||
choice_text: | ||
description: Choice for the poll | ||
type: string | ||
required: true | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
example: | ||
{ | ||
"success": true, | ||
"status": 201 | ||
} | ||
/votes: | ||
get: | ||
description: Get votes of polls | ||
queryParameters: | ||
pollId: | ||
description: Specify the vote id you want to retrieve | ||
type: integer | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
example: | ||
{ | ||
"data": | ||
{ | ||
"Id": 1, | ||
"poll": "Will A be the leader next time?", | ||
"choice": "user1", | ||
"voted_by": "user2" | ||
}, | ||
"success": true, | ||
"status": 200 | ||
} | ||
post: | ||
description: Post a vote | ||
queryParameters: | ||
choice: | ||
description: Choice for the poll | ||
type: Choice | ||
required: true | ||
poll: | ||
description: Poll to be voted | ||
type: Poll | ||
required: true | ||
voted_by: | ||
description: Poll voted by | ||
type: User | ||
required: true | ||
responses: | ||
200: | ||
body: | ||
application/json: | ||
example: | ||
{ | ||
"success": true, | ||
"status": 201 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
{ | ||
"swagger": "2.0", | ||
"info": { | ||
"description": "This is a sample server for polls api.", | ||
"version": "1.0.0", | ||
"title": "Polls API", | ||
"termsOfService": "http://example.com/terms/", | ||
"contact": {"email": "[email protected]"}, | ||
"license": {"name": "Apache 2.0", "url": "http://www.apache.org/licenses/LICENSE-2.0.html"} | ||
}, | ||
"host": "polls.example.com", | ||
"basePath": "/v2", | ||
"tags": [ | ||
{ | ||
"name": "polls", | ||
"description": "Everything about your Polls", | ||
"externalDocs": {"description": "Find out more","url":"http://example.com"} | ||
}, | ||
{ | ||
"name": "choices", | ||
"description": "Access to choices for the polls" | ||
}, | ||
{ | ||
"name": "user", | ||
"description": "Operations about user", | ||
"externalDocs": {"description": "Find out more about our store","url":"http://example.com"} | ||
} | ||
], | ||
"schemes": ["http"], | ||
"paths": { | ||
"/polls": { | ||
"get": { | ||
"tags": ["poll"], | ||
"summary": "Get all the polls", | ||
"description": "", | ||
"operationId": "pollList", | ||
"consumes": ["application/json","application/xml"], | ||
"produces": ["application/xml","application/json"], | ||
"parameters": [{ | ||
"in": "query", | ||
"name": "body", | ||
"description": "Get all the polls.", | ||
"required": false, | ||
"schema":{"$ref":"#/pollsapi/Poll"} | ||
}], | ||
"responses": {"200":{"description":"Successfull operation"}}, | ||
}, | ||
"post":{ | ||
"tags": ["poll"], | ||
"summary": "Create a new poll", | ||
"description": "Creates a new poll.", | ||
"operationId": "createPoll", | ||
"consumes":["application/json","application/xml"], | ||
"produces":["application/xml","application/json"], | ||
"parameters":[{ | ||
"in":"query", | ||
"name":"body", | ||
"description": "Poll object that needs to be added.", | ||
"required": true, | ||
"schema": {"$ref":"#/pollsapi/Poll"} | ||
}], | ||
"responses": { | ||
"200": {"description":"Poll created successfully"} | ||
} | ||
} | ||
}, | ||
"/choices": { | ||
"get": { | ||
"tags": ["choice"], | ||
"summary": "Get all the choices", | ||
"description": "", | ||
"operationId": "choiceList", | ||
"consumes": ["application/json","application/xml"], | ||
"produces": ["application/xml","application/json"], | ||
"parameters": [{ | ||
"in": "query", | ||
"name": "body", | ||
"description": "Get all the choices.", | ||
"required": false, | ||
"schema":{"$ref":"#/pollsapi/Choice"} | ||
}], | ||
"responses": {"200":{"description":"Successfull operation"}}, | ||
}, | ||
"post":{ | ||
"tags": ["choice"], | ||
"summary": "Create a new choice", | ||
"description": "Creates a new choice.", | ||
"operationId": "createChoice", | ||
"consumes":["application/json","application/xml"], | ||
"produces":["application/xml","application/json"], | ||
"parameters":[{ | ||
"in":"query", | ||
"name":"body", | ||
"description": "Choice object that needs to be added.", | ||
"required": true, | ||
"schema": {"$ref":"#/pollsapi/Poll"} | ||
}], | ||
"responses": { | ||
"200": {"description":"Poll created successfully"} | ||
} | ||
} | ||
}, | ||
"/user": { | ||
"get": { | ||
"tags": ["user"], | ||
"summary": "Get user details", | ||
"description": "", | ||
"operationId": "user", | ||
"consumes": ["application/json","application/xml"], | ||
"produces": ["application/xml","application/json"], | ||
"parameters": [{ | ||
"in": "query", | ||
"name": "body", | ||
"description": "Get the user.", | ||
"required": false, | ||
"schema":{"$ref":"#/pollsapi/User"} | ||
}], | ||
"responses": {"200":{"description":"Successfull operation"}}, | ||
}, | ||
"post":{ | ||
"tags": ["user"], | ||
"summary": "Create a new user", | ||
"description": "Creates a new user.", | ||
"operationId": "createUser", | ||
"consumes":["application/json","application/xml"], | ||
"produces":["application/xml","application/json"], | ||
"parameters":[{ | ||
"in":"query", | ||
"name":"body", | ||
"description": "User object that needs to be added.", | ||
"required": true, | ||
"schema": {"$ref":"#/pollsapi/User"} | ||
}], | ||
"responses": { | ||
"200": {"description":"User created successfully"} | ||
} | ||
} | ||
}, | ||
"/vote": { | ||
"post":{ | ||
"tags": ["vote"], | ||
"summary": "Create a new vote", | ||
"description": "Creates a new vote.", | ||
"operationId": "createVote", | ||
"consumes":["application/json","application/xml"], | ||
"produces":["application/xml","application/json"], | ||
"parameters":[{ | ||
"in":"query", | ||
"name":"body", | ||
"description": "Vote object that needs to be added.", | ||
"required": true, | ||
"schema": {"$ref":"#/pollsapi/Vote"} | ||
}], | ||
"responses": { | ||
"200": {"description":"Vote created successfully"} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pollsapi.settings") | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Poll, Choice | ||
|
||
|
||
@admin.register(Poll) | ||
class PollAdmin(admin.ModelAdmin): | ||
fields = ["question", "created_by", "pub_date"] | ||
readonly_fields = ["pub_date"] | ||
|
||
|
||
admin.site.register(Choice) |
Oops, something went wrong.