Skip to content

Commit 5a2f174

Browse files
Pr 61 (#62)
* Added reCAPTCHA to new question form * hide captcha from ilw participants * settings * settings * page reload on show/hide * added captcha for answers --------- Co-authored-by: Naman Sharma <namansharma567891@gmail.com>
1 parent 563a122 commit 5a2f174

10 files changed

Lines changed: 309 additions & 35 deletions

File tree

forums/settings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
1919

2020

21+
# reCAPTCHA Settings
22+
23+
RECAPTCHA_SITE_KEY = os.getenv("RECAPTCHA_SITE_KEY")
24+
RECAPTCHA_SECRET_KEY = os.getenv("RECAPTCHA_SECRET_KEY")
25+
2126
# Quick-start development settings - unsuitable for production
2227
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
2328

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ django-debug-toolbar==1.4
1515
python-dotenv==0.10.3
1616
nltk==3.5
1717
sklearn==0.0
18+
requests>=2.25.0

spoken_auth/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,11 @@ class TutorialResources(models.Model):
8282

8383
class Meta:
8484
db_table = 'creation_tutorialresource'
85+
86+
class Participant(models.Model):
87+
id = models.IntegerField(primary_key=True)
88+
email = models.EmailField(max_length=255,null=True)
89+
user = models.ForeignKey(Users, on_delete=models.PROTECT)
90+
91+
class Meta:
92+
db_table = 'training_participant'

static/website/js/thread-user.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,19 @@ $(document).ready(function() {
356356
/* hide */
357357
$('.hide-question').on('click', function(e){
358358
question_id = parseInt($('.hide-question').data("qid"));
359-
status = parseInt($('.hide-question').data("status"));
359+
s = parseInt($('.hide-question').data("status"));
360360
$('#confirm-hide').modal({ backdrop: 'static', keyboard: false })
361361
.one('click', '#chide', function() {
362362
$.ajax({
363363
url: "/ajax-hide-question/",
364364
type: "POST",
365365
data: {
366366
question_id: question_id,
367-
status : status,
367+
status : s,
368368

369369
},
370370
success: function(data) {
371+
$('.hide-question').hide();
371372
$hide_qmsg.hide();
372373
$hide_qmsg.show();
373374
$hide_qmsg.fadeOut(10000);

static/website/templates/get-question.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@
99
{{ question.category }} - {{ question.title }} - Spoken Tutorial Forums
1010
{% endblock %}
1111
{% block content %}
12+
{% if messages %}
13+
<ul class="messages">
14+
{% for message in messages %}
15+
<li class="{{ message.tags }} alert alert-info">{{ message }}</li>
16+
{% endfor %}
17+
</ul>
18+
{% endif %}
19+
1220
<span class="saving hideme">saving . . .</span>
1321
<span class="saved hideme">saved</span>
1422
<span class="deleted hideme">{{ question.title }} has been deleted.</span>
1523
<span class="hide-qmsg hideme">{{ question.title }} has been {% if question.status == 1 %} hidden {% else %} Shown {% endif %}.</span>
1624

25+
1726
<div class="row">
1827
<div class="question-wrapper col-lg-12 col-md-12 col-sm-12 col-xs-12">
1928
<div class="question {% if user|can_edit:question or user|can_hide_delete:question %}editable{% endif %}">
@@ -71,7 +80,7 @@ <h5>Question</h5>
7180
<span class="modify question-midify">
7281
{% if user|can_edit:question or user|can_hide_delete:question %}
7382

74-
<a class="hide-question btn btn-xs btn-info" data-qid="{{ question.id }}" data-status="{{ question.status }} href="#">{% if question.status == 1 %} Hide {% else %} Show {% endif %}</a>
83+
<a class="hide-question btn btn-xs btn-info" data-qid="{{ question.id }}" data-status="{{ question.status }} href="#">{{ label }}</a>
7584
<a class="delete-question btn btn-xs btn-info" data-qid="{{ question.id }}" href="#">Delete</a>
7685
<a class="edit btn btn-xs btn-info" href="#">Edit</a>
7786
<a class="save btn btn-xs btn-success" data-qid="{{ question.id }}" href="#">Save</a>
@@ -110,7 +119,7 @@ <h5>Question</h5>
110119
<div class="modal-dialog">
111120
<div class="modal-content">
112121
<div class="modal-body">
113-
Are you sure want to {% if question.status %} Hide {% else %} Show {% endif %} this question?
122+
Are you sure want to {{ label }} this question?
114123
</div>
115124
<div class="modal-footer">
116125
<button type="button" data-dismiss="modal" class="btn btn-primary btn-sm" id="chide">Yes</button>
@@ -246,6 +255,11 @@ <h4><u>Answers:</u></h4>
246255
</div>
247256
</div>
248257
{% endwith %}
258+
{% if require_recaptcha %}
259+
<div class="form-group" style="margin-top: 20px; margin-bottom: 15px;">
260+
<div class="g-recaptcha" data-sitekey="{{ recaptcha_site_key }}"></div>
261+
</div>
262+
{% endif %}
249263
<input class="btn btn-sm btn-info" type="submit" value="Submit Answer">
250264
</form>
251265
{% else %}
@@ -311,6 +325,7 @@ <h5>Move the question to:</h5>
311325
</div><!-- /.modal -->
312326

313327
<script src="{% static 'website/js/nicEdit.js' %}" type="text/javascript"></script>
328+
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
314329
<script type="text/javascript">
315330
bkLib.onDomLoaded(function() {
316331
new nicEditor({

static/website/templates/index.html

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ <h3 align="center">Answers</h3>
9393
<ul class="nav nav-tabs">
9494
<li class="active"><a data-toggle="tab" href="#recent_question">Recent questions</a></li>
9595
<li><a data-toggle="tab" href="#most_active">Most active questions</a></li>
96+
{% if show_spam_list %}<li><a data-toggle="tab" href="#marked_as_spam">Marked as spam</a></li>{% endif %}
9697
</ul>
9798
</div>
9899
<div class="panel-body">
@@ -279,6 +280,107 @@ <h3 align="center">Answers</h3>
279280
</tbody>
280281
</table>
281282
</div>
283+
<!-- spam questions -->
284+
{% if show_spam_list %}
285+
<div id="marked_as_spam" class="tab-pane fade">
286+
287+
<table id = "spamlistTable" class="tablesorter-blue">
288+
<thead>
289+
<tr>
290+
<th> FOSS </th>
291+
<th> Tutorial</th>
292+
<th> Min </th>
293+
<th> Sec </th>
294+
<th> Question <span class="glyphicon glyphicon-link"></span></th>
295+
<th> First Post on</th>
296+
<th> First Post by</th>
297+
<th>Recent Post on </th>
298+
<th>Recent Post by</th>
299+
<th> Views</th>
300+
<th> Answers</th>
301+
</tr>
302+
</thead>
303+
<tbody>
304+
{% for question in spam_questions %}
305+
<tr>
306+
<td>
307+
<span href="#" class="category" data-toggle="tooltip" data-placement="top" title="{{ question.category}}">
308+
{{ question.category|truncatechars:12 }}
309+
</span>
310+
<a class="pull-right" href="{% url 'website:filter' question.category %}?qid={{ question.id }}">
311+
<span class="glyphicon glyphicon-search"></span>
312+
</a>
313+
</td>
314+
315+
<td>
316+
<span class="tutorial" data-toggle="tooltip" data-placement="top" title="{{ question.tutorial}}">
317+
{{ question.tutorial|truncatechars:12 }}
318+
</span>
319+
<a class="pull-right" href="{% url 'website:filter' question.category question.tutorial %}?qid={{ question.id }}">
320+
<span class="glyphicon glyphicon-search"></span>
321+
</a>
322+
</td>
323+
324+
<td>
325+
<span>
326+
<a href="{% url 'website:filter' question.category question.tutorial question.minute_range %}?qid={{ question.id }}">
327+
{{ question.minute_range }}
328+
</a>
329+
</span>
330+
</td>
331+
332+
<td>
333+
<span>
334+
<a href="{% url 'website:filter' question.category question.tutorial question.minute_range question.second_range%}?qid={{ question.id }}">
335+
{{ question.second_range }}
336+
</a>
337+
</span>
338+
</td>
339+
340+
<td>
341+
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.title }}">
342+
<a href="{% url 'website:get_question' question.id %}{% prettify question.title %}">{{ question.title|truncatechars:40 }}</a>
343+
</span>
344+
</td>
345+
<td>
346+
<span>
347+
<i>
348+
{{ question.date_created|date:"d-m-y" }}
349+
</i>
350+
</span>
351+
</td>
352+
<td>
353+
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.user }}">
354+
{{ question.user|truncatechars:10 }}
355+
</span>
356+
</td>
357+
358+
<td>
359+
<span>
360+
<i>
361+
{{ question.last_active }}
362+
</i>
363+
</span>
364+
</td>
365+
<td>
366+
<span class="title" data-toggle="tooltip" data-placement="top" title="{{ question.last_post_user }}">
367+
{{ question.last_post_user|truncatechars:10 }}
368+
</span>
369+
</td>
370+
371+
<td>
372+
{{ question.views}}
373+
</td>
374+
375+
<td>
376+
{{ question.answer_set.count }}
377+
</td>
378+
</tr>
379+
{% endfor %}
380+
</tbody>
381+
</table>
382+
</div>
383+
{% endif %}
282384
</div>
283385
</div> <!-- /.panel-body -->
284386
</div> <!-- /.panel -->

static/website/templates/new-question.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
{% load static %}
33
{% load widget_tweaks %}
44
{% block content %}
5+
{% if messages %}
6+
<ul class="messages">
7+
{% for message in messages %}
8+
<li class="{{ message.tags }} alert alert-info">{{ message }}</li>
9+
{% endfor %}
10+
</ul>
11+
{% endif %}
512
<h4>
613
<span class="glyphicon glyphicon-pencil">
714
</span> Create a new question . . .
@@ -54,6 +61,13 @@ <h4>
5461
<label for="id_body">Question:</label>
5562
{% render_field form.body class+="form-control" %}
5663
</div>
64+
65+
<!-- reCAPTCHA widget, only for users without a role -->
66+
{% if require_recaptcha %}
67+
<div class="form-group" style="margin-top: 20px; margin-bottom: 15px;">
68+
<div class="g-recaptcha" data-sitekey="{{ recaptcha_site_key }}"></div>
69+
</div>
70+
{% endif %}
5771
</div>
5872
</div>
5973
<input class="btn btn-success" type="submit" value="Submit Question">
@@ -76,6 +90,7 @@ <h4 class="modal-title" id="myModalLabel">Similar Questions</h4>
7690
</div><!-- /.modal -->
7791

7892
<script src="{% static 'website/js/nicEdit.js' %}" type="text/javascript"></script>
93+
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
7994
<script type="text/javascript">
8095
bkLib.onDomLoaded(function() {
8196
new nicEditor({

website/forms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
class NewQuestionForm(forms.Form):
1313
category = forms.ChoiceField(choices=[('', 'Select a Category'), ] + list(TutorialResources.objects.filter(
14-
Q(status=1) | Q(status=2), language__name='English',tutorial_detail__foss__show_on_homepage=1).values('tutorial_detail__foss__foss').order_by(
15-
'tutorial_detail__foss__foss').values_list('tutorial_detail__foss__foss',
14+
Q(status=1) | Q(status=2), language__name='English',tutorial_detail__foss__show_on_homepage=1).values_list('tutorial_detail__foss__foss',
1615
'tutorial_detail__foss__foss').distinct()),
1716
widget=forms.Select(attrs={}), required=True, error_messages={'required': 'State field is required.'})
1817
title = forms.CharField(max_length=200)

website/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Question(models.Model):
1515
date_created = models.DateTimeField(auto_now_add=True)
1616
date_modified = models.DateTimeField(auto_now=True)
1717
views = models.IntegerField(default=1)
18-
status = models.IntegerField(default=1)
18+
status = models.IntegerField(default=1) # 2 = spam
1919
last_active = models.DateTimeField(null=True)
2020
last_post_by = models.IntegerField(null=True)
2121
# votes = models.IntegerField(default=0)

0 commit comments

Comments
 (0)