diff options
author | CruiseDevice | 2020-10-01 14:17:56 +0530 |
---|---|---|
committer | ankitjavalkar | 2020-10-08 10:42:51 +0530 |
commit | edf3b4c5d9afdaeb7c6d8e45484401bdce26e23c (patch) | |
tree | d8454d5a418da7309a9714f6389efe7bef2930f8 | |
parent | 86a8e2d43294eadf164710589c70bf497f65d801 (diff) | |
download | online_test-edf3b4c5d9afdaeb7c6d8e45484401bdce26e23c.tar.gz online_test-edf3b4c5d9afdaeb7c6d8e45484401bdce26e23c.tar.bz2 online_test-edf3b4c5d9afdaeb7c6d8e45484401bdce26e23c.zip |
User can create anonymous post and comment
-rw-r--r-- | yaksh/forms.py | 4 | ||||
-rw-r--r-- | yaksh/models.py | 1 | ||||
-rw-r--r-- | yaksh/templates/yaksh/course_forum.html | 8 | ||||
-rw-r--r-- | yaksh/templates/yaksh/lessons_forum.html | 8 | ||||
-rw-r--r-- | yaksh/templates/yaksh/post_comments.html | 36 | ||||
-rw-r--r-- | yaksh/templates/yaksh/show_video.html | 16 | ||||
-rw-r--r-- | yaksh/views.py | 3 |
7 files changed, 54 insertions, 22 deletions
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 @@ <small class="text-muted d-block">{{ post.description|truncatewords:30 }}</small> <small class="text-muted"><strong>Last updated: {{post.modified_at}}</strong></small> </td> - <td>{{post.creator.username}}</td> + <td> + {% if post.anonymous %} + Anonymous + {% else %} + {{post.creator.username}} + {% endif %} + </td> <td>{{post.get_comments_count}}</td> <td> {% 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 @@ <small class="text-muted d-block">{{ post.description|truncatewords:30 }}</small> <small class="text-muted"><strong>Last updated: {{post.modified_at}}</strong></small> </td> - <td>{{post.creator.username}}</td> + <td> + {% if post.anonymouse %} + Anonymous + {% else %} + {{post.creator.username}} + {% endif %} + </td> <td>{{post.get_comments_count}}</td> <td> {% 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}} <br> <small> - <strong>{{post.creator.username}}</strong> + <strong> + {% if post.anonymous %} + Anonymous + {% else %} + {{post.creator.username}} + {% endif %} + </strong> {{post.created_at}} {% if user == course.creator %}<a href="{% url 'yaksh:hide_post' post.target.id post.uid %}" class="pull-right fa fa-trash"></a>{% endif %} </small> @@ -45,6 +51,16 @@ {% endif %} </div> </div> + <div> + <b><u>Add comment:</u></b> + <form action="" method="POST" enctype='multipart/form-data'> + <div class="form-group"> + {% csrf_token %} + {{form}} + </div> + <input type="submit" value="Submit" class="btn btn-success"> + </form> + </div> <br> {% if comments %} {% for comment in comments %} @@ -52,7 +68,13 @@ <div class="card-body p-3"> <div class="row mb-3"> <div class="col-6"> - <strong class="text-muted">{{comment.creator.username}}</strong> + <strong class="text-muted"> + {% if comment.anonymous %} + Anonymous + {% else %} + {{comment.creator.username}} + {% endif %} + </strong> </div> <div class="col-6 text-right"> <small class="text-muted">{{comment.created_at}} {% if user == course.creator %} <a href="{% url 'yaksh:hide_comment' post.target.id comment.uid %}" class="fa fa-trash"></a>{% endif %}</small> @@ -71,16 +93,6 @@ {% endfor %} {% endif %} <br> - <div> - <b><u>Add comment:</u></b> - <form action="" method="POST" enctype='multipart/form-data'> - <div class="form-group"> - {% csrf_token %} - {{form}} - </div> - <input type="submit" value="Submit" class="btn btn-success"> - </form> - </div> </div> {% 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 @@ <div class="card-body p-3"> <div class="row mb-3"> <div class="col-6"> - <strong class="text-muted">{{comment.creator.username}}</strong> + <strong class="text-muted"> + {% if comment.anonymous %} + Anonymous + {% else %} + {{comment.creator.username}} + {% endif %} + </strong> + </div> + <div class="col-6 text-right"> + <small class="text-muted">{{comment.created_at}} {% if user.profile.is_moderator %} <a href="{% url 'yaksh:hide_comment' course.id comment.uid %}" class="fa fa-trash"></a>{% endif %}</small> </div> - {% if user == course.creator %} - <div class="col-6 text-right"> - <small class="text-muted">{{comment.created_at}} {% if user.profile.is_moderator %} <a href="{% url 'yaksh:hide_comment' course.id comment.uid %}" class="fa fa-trash"></a>{% endif %}</small> - </div> - {% endif %} </div> <p class="card-text description">{{comment.description}}</p> <div> 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', { |