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

Commit 4f3cc3f

Browse files
author
Arjun
committed
beta 5.3
Several New Features Bug Fixes
1 parent 6801686 commit 4f3cc3f

File tree

11 files changed

+262
-20
lines changed

11 files changed

+262
-20
lines changed

db.sqlite3

12 KB
Binary file not shown.

qa/migrations/0016_question_reward.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('qa', '0015_answer_votes'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='question',
16+
name='reward',
17+
field=models.IntegerField(default=0),
18+
preserve_default=True,
19+
),
20+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('qa', '0016_question_reward'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='question',
16+
name='user_data',
17+
field=models.ForeignKey(default=5, to='qa.UserProfile'),
18+
preserve_default=False,
19+
),
20+
]

qa/migrations/0018_qvoter.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('qa', '0017_question_user_data'),
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='QVoter',
16+
fields=[
17+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
18+
('question', models.ForeignKey(to='qa.Question')),
19+
('user', models.ForeignKey(to='qa.UserProfile')),
20+
],
21+
options={
22+
},
23+
bases=(models.Model,),
24+
),
25+
]

qa/migrations/0019_question_closed.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('qa', '0018_qvoter'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='question',
16+
name='closed',
17+
field=models.BooleanField(default=False),
18+
preserve_default=True,
19+
),
20+
]

qa/models.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ def __str__(self):
99
class Meta:
1010
ordering = ('slug',)
1111

12-
class Question(models.Model):
13-
question_text = models.CharField(max_length=200)
14-
pub_date = models.DateTimeField('date published')
15-
tags = models.ManyToManyField(Tag)
16-
views = models.IntegerField(default=0)
17-
18-
def __str__(self):
19-
return self.question_text
20-
2112
from django.contrib.auth.models import User
2213

2314
class UserProfile(models.Model):
@@ -35,6 +26,18 @@ def __unicode__(self):
3526

3627
from django_markdown.models import MarkdownField
3728

29+
class Question(models.Model):
30+
question_text = models.CharField(max_length=200)
31+
pub_date = models.DateTimeField('date published')
32+
tags = models.ManyToManyField(Tag)
33+
reward = models.IntegerField(default=0)
34+
views = models.IntegerField(default=0)
35+
user_data = models.ForeignKey(UserProfile)
36+
closed = models.BooleanField(default=False)
37+
38+
def __str__(self):
39+
return self.question_text
40+
3841
class Answer(models.Model):
3942
question = models.ForeignKey(Question)
4043
answer_text = MarkdownField()
@@ -48,6 +51,10 @@ class Voter(models.Model):
4851
user = models.ForeignKey(UserProfile)
4952
answer = models.ForeignKey(Answer)
5053

54+
class QVoter(models.Model):
55+
user = models.ForeignKey(UserProfile)
56+
question = models.ForeignKey(Question)
57+
5158
class Comment(models.Model):
5259
answer = models.ForeignKey(Answer)
5360
comment_text = models.CharField(max_length=200)

qa/templates/qa/add.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ <h1><a href="/">Simple QA </a><small>Add Question</small></h1>
1919
<input class="input-lg" style="width:100%" placeholder="Enter your question....." type="text" name="question"/> <br/><br/>
2020

2121
<input class="input-lg" style="width:100%" placeholder="Enter tags separates by comma!" type="text" name="tags"/> <br/><br/>
22-
22+
<input type="hidden" value="{{ user.id }}" name="user" />
2323
<input class="btn pull-right btn-success" type="submit" value="Submit Question" />
2424
</form>
2525
<p>Note. Question cannot be empty!</p>

qa/templates/qa/detail.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,28 @@ <h1><a href="/">Simple QA </a><small>Open Questions</small></h1>
3838
</div>
3939
{% endif %}
4040

41+
{% if question.reward %}
42+
<div class="alert alert-info" role="alert">This question has been marked to be worth a reward of <b>{{ question.reward }}<b> points!
43+
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
44+
<span aria-hidden="true">&times;</span>
45+
</button>
46+
</div>
47+
{% endif %}
48+
4149
<div class="jumbotron">
42-
<p class="pull-right">{{ question.pub_date }}</p>
50+
<small class="pull-right">Posted by {{ question.user_data.user.username }}, {{ question.pub_date }}</small>
4351
<h3><cool>Q: </cool>{{ question.question_text }}</h3>
44-
<p><a class="btn btn-primary btn-sm pull-right" href="/answer/{{ question.id }}" role="button">Answer this Question!</a></p>
52+
<p>
53+
{% if user.is_authenticated %}
54+
<a href="/thumb/{{ user.id }}/{{ question.id }}/0/" class="btn btn-success"><span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span></a>
55+
<a href="/thumb/{{ user.id }}/{{ question.id }}/1/" class="btn btn-danger"><span class="glyphicon glyphicon-thumbs-down" aria-hidden="true"></span></a>
56+
{% endif %}
57+
{% if question.closed %}
58+
<p class="pull-right">This Question has been closed.</p>
59+
{% else %}
60+
<a class="btn btn-primary btn-sm pull-right" href="/answer/{{ question.id }}" role="button">Answer this Question!</a>
61+
{% endif %}
62+
</p>
4563
</div>
4664

4765
{% if answers %}

qa/templates/qa/index.html

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
font-size: 20px;
1616
}
1717

18+
reward {
19+
font-size: 15px;
20+
color: #FF4444;
21+
}
22+
1823
.ans {
1924
height: 40px;
2025
width: 75px;
@@ -116,12 +121,23 @@
116121
</script>
117122

118123
<div class="container">
119-
124+
120125
<div class="page-header">
121126
<a class="btn btn-lg btn-warning pull-right" href="#search"><span class="glyphicon glyphicon-search" aria-hidden="true"></span> Find</a><a class="btn btn-lg btn-danger pull-right" href="/add/">Ask Question</a><h1><a href="/">Simple QA </a><small>Open Questions</small></h1>
122127
</div>
123128

124129
<div class="col-md-8">
130+
131+
<ul class="nav nav-tabs nav-justified">
132+
<li role="presentation" class="active"><a href="#latest" aria-controls="latest" role="tab" data-toggle="tab">Latest</a></li>
133+
<li role="presentation"><a href="#unans" aria-controls="unans" role="tab" data-toggle="tab">Unanswered <span class="badge">{{ noans.count }}</span></a></li>
134+
<li role="presentation"><a href="#reward" aria-controls="reward" role="tab" data-toggle="tab">Most Rewarding <span class="badge">{{ reward.count }}</span></a></li>
135+
</ul>
136+
<br/>
137+
138+
139+
<div class="tab-content">
140+
<div role="tabpanel" class="tab-pane active" id="latest">
125141
{% if questions %}
126142
{% for question in questions %}
127143
<div class="row">
@@ -156,9 +172,58 @@
156172
</div>
157173

158174
{% else %}
159-
<p>No Questions are available.</p>
175+
<div class="alert alert-warning" role="alert">No Questions are available!</div>
176+
{% endif %}
177+
</div>
178+
179+
<div role="tabpanel" class="tab-pane" id="unans">
180+
{% if noans %}
181+
{% for question in noans %}
182+
<div class="row">
183+
<div class="col-sm-1 ans"><small><div class="ques">{{ question.answer_set.count }}</div>Answers</small></div>
184+
<div class="col-sm-1 ans"><small><div class="ques">{{ question.views }}</div>Views</small></div>
185+
<p>
186+
{% if question.answer_set.count %}<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>{% endif %} <a class="ques" href="/q/{{ question.id }}/">{{ question.question_text }}</a>
187+
<br/>
188+
{% for tag in question.tags.all %}
189+
<tag>{{ tag.slug }}</tag>
190+
{% endfor %}
191+
<small> {{ question.pub_date}}</small>
192+
</p>
193+
</div>
194+
<hr>
195+
{% endfor %}
196+
197+
{% else %}
198+
<div class="alert alert-warning" role="alert">No Questions are available!</div>
160199
{% endif %}
200+
</div>
161201

202+
<div role="tabpanel" class="tab-pane" id="reward">
203+
{% if reward %}
204+
{% for question in reward %}
205+
<div class="row">
206+
<div class="col-sm-1 ans"><small><div class="ques">{{ question.answer_set.count }}</div>Answers</small></div>
207+
<div class="col-sm-1 ans"><small><div class="ques">{{ question.views }}</div>Views</small></div>
208+
<p>
209+
{% if question.answer_set.count %}<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>{% endif %} <a class="ques" href="/q/{{ question.id }}/">{{ question.question_text }}</a>
210+
<br/>
211+
<reward>Earn <b>{{ question.reward }}</b> points</reward>
212+
{% for tag in question.tags.all %}
213+
<tag>{{ tag.slug }}</tag>
214+
{% endfor %}
215+
<small> {{ question.pub_date}}</small>
216+
</p>
217+
</div>
218+
<hr>
219+
{% endfor %}
220+
221+
{% else %}
222+
<div class="alert alert-warning" role="alert">No Questions are available!</div>
223+
{% endif %}
224+
</div>
225+
226+
</div>
162227
</div>
163228

164229
<div class="col-md-4">

0 commit comments

Comments
 (0)