Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

Commit e944973

Browse files
author
Arjun
committed
beta 5.6
Added API access Minor UI Changes Bug Fixes
1 parent 69b9821 commit e944973

File tree

7 files changed

+138
-1
lines changed

7 files changed

+138
-1
lines changed

db.sqlite3

0 Bytes
Binary file not shown.

qa/static/qa/icon.ico

1.12 KB
Binary file not shown.

qa/templates/qa/detail.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
<style>
2+
.closed {
3+
width:100%;
4+
height:7px;
5+
position: absolute;
6+
7+
background: #FF4444;
8+
}
9+
10+
.open {
11+
width:100%;
12+
height:7px;
13+
position: absolute;
14+
15+
background: #99CC00;
16+
}
17+
18+
.rewarding {
19+
width:100%;
20+
height:7px;
21+
position: absolute;
22+
23+
background: #AA66CC;
24+
}
25+
</style>
26+
127
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
228
<script>
329
$(function () {
@@ -21,6 +47,16 @@
2147
}
2248
</style>
2349

50+
{% if question.reward %}
51+
<div class="rewarding"></div>
52+
{% else %}
53+
{% if question.closed %}
54+
<div class="closed"></div>
55+
{% else %}
56+
<div class="open"></div>
57+
{% endif %}
58+
{% endif %}
59+
2460
<div class="container">
2561

2662
{% include "qa/header.html" %}

qa/templates/qa/footer.html

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<hr>
22
<center>
3-
<a href="http://www.djangoproject.com/"><img src="https://www.djangoproject.com/m/img/badges/djangoproject120x25.gif" border="0" alt="A Django project." title="A Django project." /></a> · <a href="https://github.com/arjunkomath/Simple-Q-A-App-using-Python-Django">Github</a> · <a href="/admin">Admin Panel</a></small></center>
3+
<a href="http://www.djangoproject.com/"><img src="https://www.djangoproject.com/m/img/badges/djangoproject120x25.gif" border="0" alt="A Django project." title="A Django project." /></a> ·
4+
<a href="https://github.com/arjunkomath/Simple-Q-A-App-using-Python-Django">Github</a> ·
5+
<a data-toggle="modal" data-target="#apiModal">API</a> ·
6+
<a href="/admin">Admin Panel</a></small></center>
47
<br/><br/>
58

69
<div id="search">
@@ -11,3 +14,52 @@
1114
<input class="btn btn-lg btn-warning" type="submit" value="Find" />
1215
</form>
1316
</div>
17+
18+
<style>
19+
code {
20+
font-family: Monaco, Consolas, "Andale Mono", "DejaVu Sans Mono", monospace;
21+
font-size: 95%;
22+
line-height: 140%;
23+
white-space: pre;
24+
white-space: pre-wrap;
25+
white-space: -moz-pre-wrap;
26+
white-space: -o-pre-wrap;
27+
background: #faf8f0;
28+
}
29+
30+
#content code {
31+
display: block;
32+
padding: 0.5em 1em;
33+
border: 1px solid #bebab0;
34+
}
35+
</style>
36+
37+
<!-- Modal -->
38+
<div class="modal fade" id="apiModal" tabindex="-1" role="dialog" aria-labelledby="APIModal" aria-hidden="true">
39+
<div class="modal-dialog">
40+
<div class="modal-content">
41+
<div class="modal-header">
42+
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
43+
<h4 class="modal-title" id="myModalLabel"><span class="glyphicon glyphicon-cloud" aria-hidden="true"></span> API Access</h4>
44+
</div>
45+
<div class="modal-body">
46+
<ul>
47+
<li>
48+
<b>List of Questions</b>
49+
<br/>Retrieve the list of questions.
50+
<br/>json URL : <code>http://djangoqa.azurewebsites.net/api/questions/?format=json</code>
51+
</li>
52+
<br/>
53+
<li>
54+
<b>List of Users</b>
55+
<br/>Retrieve the list of users.
56+
<br/>json URL : <code>http://djangoqa.azurewebsites.net/api/users/?format=json</code>
57+
</li>
58+
<ul>
59+
</div>
60+
<div class="modal-footer">
61+
<button type="button" class="btn btn-info" data-dismiss="modal">Close</button>
62+
</div>
63+
</div>
64+
</div>
65+
</div>

qa/templates/qa/header.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
{% bootstrap_css %}
44

5+
<title>Simple QA</title>
6+
<link rel="icon" type="image/png" href="static/qa/icon.ico">
57
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
68

79
{% bootstrap_javascript %}

simpleqa/settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'qa',
4141
'bootstrap3',
4242
'django_markdown',
43+
'rest_framework',
4344
)
4445

4546
MIDDLEWARE_CLASSES = (
@@ -67,6 +68,14 @@
6768
}
6869
}
6970

71+
REST_FRAMEWORK = {
72+
# Use Django's standard `django.contrib.auth` permissions,
73+
# or allow read-only access for unauthenticated users.
74+
'DEFAULT_PERMISSION_CLASSES': [
75+
'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
76+
]
77+
}
78+
7079
# Internationalization
7180
# https://docs.djangoproject.com/en/1.7/topics/i18n/
7281

simpleqa/urls.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,41 @@
33

44
from qa import views
55

6+
from django.conf.urls import url, include
7+
from django.contrib.auth.models import User
8+
from qa.models import Question, Tag
9+
from rest_framework import routers, serializers, viewsets
10+
11+
# Serializers define the API representation.
12+
class UserSerializer(serializers.HyperlinkedModelSerializer):
13+
class Meta:
14+
model = User
15+
fields = ('url', 'username', 'email', 'is_staff')
16+
17+
class QuestionSerializer(serializers.HyperlinkedModelSerializer):
18+
tags = serializers.SlugRelatedField(
19+
many=True,
20+
read_only=True,
21+
slug_field='slug'
22+
)
23+
class Meta:
24+
model = Question
25+
fields = ('id', 'pub_date', 'question_text', 'tags', 'views')
26+
27+
# ViewSets define the view behavior.
28+
class UserViewSet(viewsets.ModelViewSet):
29+
queryset = User.objects.all()
30+
serializer_class = UserSerializer
31+
32+
class QuestionViewSet(viewsets.ModelViewSet):
33+
queryset = Question.objects.all()
34+
serializer_class = QuestionSerializer
35+
36+
# Routers provide an easy way of automatically determining the URL conf.
37+
router = routers.DefaultRouter()
38+
router.register(r'api/users', UserViewSet)
39+
router.register(r'api/questions', QuestionViewSet)
40+
641
urlpatterns = patterns('',
742

843
url(r'^$', views.index, name='index'),
@@ -24,4 +59,7 @@
2459

2560
url('^markdown/', include( 'django_markdown.urls')),
2661

62+
url(r'^', include(router.urls)),
63+
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
64+
2765
)

0 commit comments

Comments
 (0)