Skip to content

Commit e0ea993

Browse files
Merge branch 'main' into task-scheduler
2 parents b8dfa69 + 4747b9b commit e0ea993

File tree

12 files changed

+249
-90
lines changed

12 files changed

+249
-90
lines changed

blt/urls.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@
100100
SpecificIssuesView,
101101
UpdateIssue,
102102
change_bid_status,
103-
comment_on_issue,
103+
comment_on_content,
104104
create_github_issue,
105-
delete_comment,
105+
delete_content_comment,
106106
delete_issue,
107107
dislike_issue,
108108
fetch_current_bid,
@@ -120,7 +120,7 @@
120120
submit_bug,
121121
submit_pr,
122122
unsave_issue,
123-
update_comment,
123+
update_content_comment,
124124
vote_count,
125125
)
126126
from website.views.organization import (
@@ -458,19 +458,20 @@
458458
),
459459
re_path(r"^issue/edit/$", IssueEdit, name="edit_issue"),
460460
re_path(r"^issue/update/$", UpdateIssue, name="update_issue"),
461+
# comment on content
461462
path(
462-
"issue/<str:issue_pk>/comment/",
463-
comment_on_issue,
464-
name="comment_on_issue",
463+
"content/<str:content_pk>/comment/",
464+
comment_on_content,
465+
name="comment_on_content",
465466
),
466-
# UPDATE COMMENT
467+
# update comment
467468
path(
468-
"issue/<str:issue_pk>/comment/update/<str:comment_pk>/",
469-
update_comment,
470-
name="update_comment",
469+
"content/<str:content_pk>/comment/update/<str:comment_pk>/",
470+
update_content_comment,
471+
name="update_content_comment",
471472
),
472-
# delete_comment
473-
path("issue2/comment/delete/", delete_comment, name="delete_comment"),
473+
# delete comment
474+
path("content/comment/delete/", delete_content_comment, name="delete_content_comment"),
474475
re_path(r"^issue/(?P<slug>\w+)/$", IssueView.as_view(), name="issue_view"),
475476
re_path(r"^follow/(?P<user>[^/]+)/", follow_user, name="follow_user"),
476477
re_path(r"^all_activity/$", AllIssuesView.as_view(), name="all_activity"),

comments/admin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55

66
class MyCommentsAdmin(admin.ModelAdmin):
7-
list_display = ("id", "author", "issue", "text", "created_date")
7+
list_display = ("id", "author", "get_related_object", "text", "created_date")
8+
9+
def get_related_object(self, obj):
10+
return obj.content_object
11+
12+
get_related_object.short_description = "Related Object"
813

914

1015
admin.site.register(Comment, MyCommentsAdmin)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Generated by Django 5.1.4 on 2025-01-04 19:10
2+
3+
import django.db.models.deletion
4+
import django.utils.timezone
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
dependencies = [
10+
("comments", "0006_comment_author_fk"),
11+
("contenttypes", "0002_remove_content_type_name"),
12+
]
13+
14+
operations = [
15+
migrations.RemoveField(
16+
model_name="comment",
17+
name="issue",
18+
),
19+
migrations.AddField(
20+
model_name="comment",
21+
name="content_type",
22+
field=models.ForeignKey(
23+
default=1,
24+
on_delete=django.db.models.deletion.CASCADE,
25+
to="contenttypes.contenttype",
26+
),
27+
preserve_default=False,
28+
),
29+
migrations.AddField(
30+
model_name="comment",
31+
name="object_id",
32+
field=models.PositiveIntegerField(default=1),
33+
preserve_default=False,
34+
),
35+
]

comments/models.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
from django.contrib.contenttypes.fields import GenericForeignKey
2+
from django.contrib.contenttypes.models import ContentType
13
from django.db import models
24
from django.utils import timezone
35

4-
from website.models import Issue, UserProfile
6+
from website.models import UserProfile
57

68
# Create your models here.
79

810

911
class Comment(models.Model):
1012
parent = models.ForeignKey("self", null=True, on_delete=models.CASCADE)
11-
issue = models.ForeignKey(Issue, on_delete=models.CASCADE, related_name="comments")
13+
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
14+
object_id = models.PositiveIntegerField()
15+
content_object = GenericForeignKey("content_type", "object_id")
1216
author = models.CharField(max_length=200)
1317
author_fk = models.ForeignKey(UserProfile, null=True, on_delete=models.SET_NULL)
1418
author_url = models.CharField(max_length=200)

website/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from colorthief import ColorThief
1414
from django.conf import settings
1515
from django.contrib.auth.models import User
16-
from django.contrib.contenttypes.fields import GenericForeignKey
16+
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
1717
from django.contrib.contenttypes.models import ContentType
1818
from django.core.cache import cache
1919
from django.core.exceptions import ValidationError
@@ -362,6 +362,7 @@ class Issue(models.Model):
362362
cve_id = models.CharField(max_length=16, null=True, blank=True)
363363
cve_score = models.DecimalField(max_digits=2, decimal_places=1, null=True, blank=True)
364364
tags = models.ManyToManyField(Tag, blank=True)
365+
comments = GenericRelation("comments.Comment")
365366

366367
def __unicode__(self):
367368
return self.description
@@ -1204,6 +1205,7 @@ class Post(models.Model):
12041205
created_at = models.DateTimeField(auto_now_add=True)
12051206
updated_at = models.DateTimeField(auto_now=True)
12061207
image = models.ImageField(upload_to="blog_posts")
1208+
comments = GenericRelation("comments.Comment")
12071209

12081210
class Meta:
12091211
db_table = "blog_post"

website/templates/blog/post_details.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ <h1 class="post-title">{{ post.title }}</h1>
119119
<a href="{% url 'post_delete' slug=post.slug %}" class="b-delete">Delete Post</a>
120120
</div>
121121
{% endif %}
122+
<div class="px-10 rounded-lg bg-white">{% include "../comments2.html" %}</div>
122123
</article>
123124
{% endblock content %}

website/templates/comments2.html

Lines changed: 23 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
99
<div class="py-2 px-4 mb-4 bg-white rounded-lg rounded-t-lg border border-gray-200 ">
1010
<label for="comment" class="sr-only">Your comment</label>
1111
<input type="text" id="replying_to_input" hidden>
12+
<input type="hidden"
13+
id="content_type"
14+
name="content_type"
15+
value="{{ content_type }}">
1216
<div id="replying_to_root"></div>
1317
<div id="add_update_label"></div>
1418
<textarea id="comment"
@@ -82,7 +86,7 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
8286
data-name="{{ comment.id }}">Edit</a>
8387
</li>
8488
<li>
85-
<a class="block py-2 px-4 hover:bg-gray-100 del_comment_issue2 cursor-pointer"
89+
<a class="block py-2 px-4 hover:bg-gray-100 del_comment cursor-pointer"
8690
data-name="{{ comment.id }}">Delete</a>
8791
</li>
8892
<li>
@@ -151,7 +155,7 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
151155
data-name="{{ child_comment.id }}">Edit</a>
152156
</li>
153157
<li>
154-
<a class="block py-2 px-4 hover:bg-gray-100 del_comment_issue2 cursor-pointer"
158+
<a class="block py-2 px-4 hover:bg-gray-100 del_comment cursor-pointer"
155159
data-name="{{ child_comment.id }}">Delete</a>
156160
</li>
157161
<li>
@@ -162,12 +166,6 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
162166
{% endif %}
163167
</footer>
164168
<p class="text-xl main_text">{{ child_comment.text | safe }}</p>
165-
<!-- <div class="flex items-center mt-4 space-x-4">
166-
<button type="button" class="flex items-center text-md text-gray-500 hover:underline ">
167-
<svg aria-hidden="true" class="mr-1 w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"></path></svg>
168-
{{ child_comment.children | length }} Replies
169-
</button>
170-
</div> -->
171169
</article>
172170
{% endfor %}
173171
</div>
@@ -192,7 +190,6 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
192190
});
193191
}
194192

195-
196193
function remove_reply(){
197194
document.getElementById("replying_to_cont").remove();
198195
document.getElementById("replying_to_input").value = "";
@@ -221,9 +218,10 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
221218
comment_container.toggleAttribute('hidden');
222219
}
223220

224-
function comment_on_issue(e){
221+
function comment_on_content(e){
225222
e.preventDefault();
226-
let issue_pk = '{{ object.pk|safe }}';
223+
let content_pk = '{{ object.pk|safe }}';
224+
let content_type = '{{ content_type }}';
227225
var csrftoken = $("[name=csrfmiddlewaretoken]").val(); // Get the CSRF token value
228226

229227
let replying_to_input = document.getElementById("replying_to_input").value;
@@ -233,25 +231,26 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
233231
}
234232
$.ajax({
235233
type: 'POST',
236-
url: '/issue/' + issue_pk + '/comment/',
234+
url: '/content/' + content_pk + '/comment/',
237235
data: {
238236
"replying_to_input":replying_to_input,
239-
"comment":comment
237+
"comment":comment,
238+
"content_type": content_type
240239
},
241240
beforeSend: function(xhr, settings) {
242241
xhr.setRequestHeader("X-CSRFToken", csrftoken); // Set the CSRF token in the request header
243242
},
244243
success: function (data) {
245244
$('#comment_root').replaceWith(data);
246-
// initDropDown();
247245
location.reload()
248246
},
249247
});
250248
}
251-
$('#post_comment_btn').click((e)=>comment_on_issue(e))
249+
$('#post_comment_btn').click((e)=>comment_on_content(e))
252250
function update_comment(e,comment_id){
253251
e.preventDefault();
254-
let issue_pk = '{{ object.pk|safe }}';
252+
let content_pk = '{{ object.pk|safe }}';
253+
let content_type = '{{ content_type }}';
255254
var csrftoken = $("[name=csrfmiddlewaretoken]").val(); // Get the CSRF token value
256255

257256
let comment = document.getElementById("comment").value;
@@ -260,16 +259,16 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
260259
}
261260
$.ajax({
262261
type: 'POST',
263-
url: '/issue/' + issue_pk + '/comment/update/' + comment_id + '/',
262+
url: '/content/' + content_pk + '/comment/update/' + comment_id + '/',
264263
data: {
265-
"comment":comment
264+
"comment":comment,
265+
"content_type": content_type
266266
},
267267
beforeSend: function(xhr, settings) {
268268
xhr.setRequestHeader("X-CSRFToken", csrftoken); // Set the CSRF token in the request header
269269
},
270270
success: function (data) {
271271
$('#comment_root').replaceWith(data);
272-
// initDropDown();
273272
location.reload()
274273
},
275274
});
@@ -281,15 +280,13 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
281280
$('#update_comment_btn').text('Post comment');
282281
$('#update_comment_btn').attr('id', 'post_comment_btn');
283282
$('#update_comment_btn').off('click');
284-
$('#post_comment_btn').off('click').on('click', (e) => comment_on_issue(e));
283+
$('#post_comment_btn').off('click').on('click', (e) => comment_on_content(e));
285284
}
286285
$('body').on('click', '.edit_comment', function (e) {
287286
e.preventDefault();
288287
let comment_id = $(this).data('name');
289288
let comment_text = $(this).closest('article').find('.main_text').text();
290-
// Unbind the click event for the post_comment_btn
291289
$('#post_comment_btn').off('click');
292-
//user can update the form using #comments form
293290
$('#comment').val(comment_text);
294291
$('#post_comment_btn').text('Update comment');
295292
$('#post_comment_btn').attr('id', 'update_comment_btn');
@@ -298,59 +295,36 @@ <h2 class="text-xl lg:text-3xl font-bold text-gray-900 ">Comments ({{ all_commen
298295
<p>Update your Comment<p>
299296
<i onclick="remove_update_label()" class="fa-solid fa-xmark ml-3 text-3xl font-bold text-gray-600 hover:text-black"></i>
300297
</div>`;
301-
// Bind a new click event for the update_comment_btn
302298
$('#update_comment_btn').off('click').on('click', (e) => update_comment(e, comment_id));
303299
});
304-
$('body').off('click', '.del_comment_issue2').on('click', '.del_comment_issue2', function (e) {
300+
$('body').off('click', '.del_comment').on('click', '.del_comment', function (e) {
305301
e.preventDefault();
306302

307-
// Store a reference to the clicked element
308303
var clickedElement = $(this);
309304
if (confirm("Delete this comment?") == true) {
310305
var csrftoken = $("[name=csrfmiddlewaretoken]").val();
311306

312307
$.ajax({
313308
type: 'POST',
314-
url: "/issue/comment/delete/",
309+
url: "/content/comment/delete/",
315310
data: {
316311
"comment_pk": clickedElement.attr('data-name'),
317-
"issue_pk": '{{ object.pk|safe }}',
312+
"content_pk": '{{ object.pk|safe }}',
313+
"content_type": '{{ content_type }}'
318314
},
319315
beforeSend: function (xhr, settings) {
320316
xhr.setRequestHeader("X-CSRFToken", csrftoken); // Set the CSRF token in the request header
321317
},
322318
success: function (data) {
323-
// Replace the content of #comment_root with the new data
324319
$('#comment_root').replaceWith(data);
325-
326-
// initDropDown();
327320
location.reload()
328321
},
329322
});
330323
}
331324
});
332-
// refresh comments after x interval
333-
// function get_comments(){
334-
// let issue_pk = '{{ object.pk|safe }}';
335-
336-
// $.ajax({
337-
// type: 'GET',
338-
// url: '/issue/' + issue_pk + '/comment/',
339-
// data: {},
340-
// success: function (data) {
341-
// $('#comment_root').html(data);
342-
// }
343-
// });
344-
// }
345-
346-
// setInterval(get_comments, 10000);
347325

348326
$(document).ready(function(){
349-
// bind event handlers when the page loads.
350327
initDropDown();
351328
});
352-
353-
354-
355329
</script>
356330
</section>

website/templates/sitemap.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ <h2 class="text-6xl text-black font-bold">Sitemap</h2>
208208
</li>
209209
<li class="flex items-center space-x-3 text-black hover:text-red-600 hover:translate-x-1 transition duration-200 cursor-pointer">
210210
<i class="fas fa-comment-dots w-5 h-5 mr-1 align-middle"></i>
211-
<a href="{% url 'comment_on_issue' 1 %}">Comment on Issue // 1</a>
211+
<a href="{% url 'comment_on_content' 1 %}">Comment on Content // 1</a>
212212
</li>
213213
<li class="flex items-center space-x-3 text-black hover:text-red-600 hover:translate-x-1 transition duration-200 cursor-pointer">
214214
<i class="fas fa-sync-alt w-5 h-5 mr-1 align-middle"></i>
215-
<a href="{% url 'update_comment' 1 1 %}">Update Comment // 1</a>
215+
<a href="{% url 'update_content_comment' 1 1 %}">Update Comment // 1</a>
216216
</li>
217217
<li class="flex items-center space-x-3 text-black hover:text-red-600 hover:translate-x-1 transition duration-200 cursor-pointer">
218218
<i class="fas fa-trash-alt w-5 h-5 mr-1 align-middle"></i>

0 commit comments

Comments
 (0)