From edf3b4c5d9afdaeb7c6d8e45484401bdce26e23c Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Thu, 1 Oct 2020 14:17:56 +0530 Subject: User can create anonymous post and comment --- yaksh/forms.py | 4 ++-- yaksh/models.py | 1 + yaksh/templates/yaksh/course_forum.html | 8 ++++++- yaksh/templates/yaksh/lessons_forum.html | 8 ++++++- yaksh/templates/yaksh/post_comments.html | 36 +++++++++++++++++++++----------- yaksh/templates/yaksh/show_video.html | 16 ++++++++------ yaksh/views.py | 3 +++ 7 files changed, 54 insertions(+), 22 deletions(-) (limited to 'yaksh') diff --git a/yaksh/forms.py b/yaksh/forms.py index c179081..091505d 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -613,7 +613,7 @@ class TestcaseForm(forms.ModelForm): class PostForm(forms.ModelForm): class Meta: model = Post - fields = ["title", "description", "image"] + fields = ["title", "description", "image", "anonymous"] widgets = { 'title': forms.TextInput( attrs={ @@ -636,7 +636,7 @@ class PostForm(forms.ModelForm): class CommentForm(forms.ModelForm): class Meta: model = Comment - fields = ["description", "image"] + fields = ["description", "image", "anonymous"] widgets = { 'description': forms.Textarea( attrs={ diff --git a/yaksh/models.py b/yaksh/models.py index 2ed03ed..da2327c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -2769,6 +2769,7 @@ class ForumBase(models.Model): image = models.ImageField(upload_to=get_image_dir, blank=True, null=True, validators=[validate_image]) active = models.BooleanField(default=True) + anonymous = models.BooleanField(default=False) class Post(ForumBase): diff --git a/yaksh/templates/yaksh/course_forum.html b/yaksh/templates/yaksh/course_forum.html index 3190245..fce58fe 100644 --- a/yaksh/templates/yaksh/course_forum.html +++ b/yaksh/templates/yaksh/course_forum.html @@ -111,7 +111,13 @@ {{ post.description|truncatewords:30 }} Last updated: {{post.modified_at}} - {{post.creator.username}} + + {% if post.anonymous %} + Anonymous + {% else %} + {{post.creator.username}} + {% endif %} + {{post.get_comments_count}} {% with post.get_last_comment as last_comment %} diff --git a/yaksh/templates/yaksh/lessons_forum.html b/yaksh/templates/yaksh/lessons_forum.html index f8d1912..250536d 100644 --- a/yaksh/templates/yaksh/lessons_forum.html +++ b/yaksh/templates/yaksh/lessons_forum.html @@ -43,7 +43,13 @@ {{ post.description|truncatewords:30 }} Last updated: {{post.modified_at}} - {{post.creator.username}} + + {% if post.anonymouse %} + Anonymous + {% else %} + {{post.creator.username}} + {% endif %} + {{post.get_comments_count}} {% with post.get_last_comment as last_comment %} diff --git a/yaksh/templates/yaksh/post_comments.html b/yaksh/templates/yaksh/post_comments.html index 4038afb..1480264 100644 --- a/yaksh/templates/yaksh/post_comments.html +++ b/yaksh/templates/yaksh/post_comments.html @@ -30,7 +30,13 @@ {{post.title}}
- {{post.creator.username}} + + {% if post.anonymous %} + Anonymous + {% else %} + {{post.creator.username}} + {% endif %} + {{post.created_at}} {% if user == course.creator %}{% endif %} @@ -45,6 +51,16 @@ {% endif %} +
+ Add comment: +
+
+ {% csrf_token %} + {{form}} +
+ +
+

{% if comments %} {% for comment in comments %} @@ -52,7 +68,13 @@
- {{comment.creator.username}} + + {% if comment.anonymous %} + Anonymous + {% else %} + {{comment.creator.username}} + {% endif %} +
{{comment.created_at}} {% if user == course.creator %} {% endif %} @@ -71,16 +93,6 @@ {% endfor %} {% endif %}
-
- Add comment: -
-
- {% csrf_token %} - {{form}} -
- -
-
{% endblock content %} {% block script %} diff --git a/yaksh/templates/yaksh/show_video.html b/yaksh/templates/yaksh/show_video.html index 022ba9c..0e16e37 100644 --- a/yaksh/templates/yaksh/show_video.html +++ b/yaksh/templates/yaksh/show_video.html @@ -246,13 +246,17 @@
- {{comment.creator.username}} + + {% if comment.anonymous %} + Anonymous + {% else %} + {{comment.creator.username}} + {% endif %} + +
+
+ {{comment.created_at}} {% if user.profile.is_moderator %} {% endif %}
- {% if user == course.creator %} -
- {{comment.created_at}} {% if user.profile.is_moderator %} {% endif %} -
- {% endif %}

{{comment.description}}

diff --git a/yaksh/views.py b/yaksh/views.py index 8c9a9e4..69a7414 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -2824,6 +2824,7 @@ def show_lesson(request, lesson_id, module_id, course_id): new_comment = form.save(commit=False) new_comment.creator = request.user new_comment.post_field = post + new_comment.anonymous = request.POST.get('anonymous', '') == 'on' new_comment.save() return redirect(request.path_info) else: @@ -3500,6 +3501,7 @@ def course_forum(request, course_id): new_post = form.save(commit=False) new_post.creator = user new_post.target = course + new_post.anonymous = request.POST.get('anonymous', '') == 'on' new_post.save() return redirect('yaksh:post_comments', course_id=course.id, uuid=new_post.uid) @@ -3557,6 +3559,7 @@ def post_comments(request, course_id, uuid): new_comment = form.save(commit=False) new_comment.creator = request.user new_comment.post_field = post + new_comment.anonymous = request.POST.get('anonymous', '') == 'on' new_comment.save() return redirect(request.path_info) return render(request, 'yaksh/post_comments.html', { -- cgit