Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Interviewbook/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
from .models import *
# Register your models here.

class CommentAdmin(admin.ModelAdmin):
list_display = ('username', 'body', 'response', 'created_on', 'active')
list_filter = ('active', 'created_on')
search_fields = ('username', 'body')
actions = ['disapprove_comment']
def disapprove_comment(self, request, queryset):
queryset.update(active=False)


admin.site.register(InterviewResponse)
admin.site.register(Company)
admin.site.register(Comment)
7 changes: 7 additions & 0 deletions Interviewbook/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django import forms
from django.forms import ModelForm, Textarea
from .models import *
from django.contrib.auth.models import User
Expand All @@ -21,3 +22,9 @@ class CompanyForm(ModelForm):
class Meta:
model = Company
exclude =()

class CommentForm(forms.ModelForm):

class Meta:
model = Comment
fields = ('body', )
15 changes: 15 additions & 0 deletions Interviewbook/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ def __str__(self):
def increase(self):
self.hits += 1
self.save()

class Comment(models.Model):
response = models.ForeignKey(InterviewResponse, on_delete=models.CASCADE, related_name='comments')
username = models.CharField(max_length=200)
body = models.TextField(null=True)
created_on = models.DateTimeField(auto_now_add=True)
active = models.BooleanField(default=True)
replies = models

class Meta:
ordering = ['created_on']

def __str__(self):
return 'Comment {} by {}'.format(self.body, self.username)

39 changes: 39 additions & 0 deletions Interviewbook/templates/Interviewbook/response.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,46 @@
<strong><span class="text-dark">No of rounds</span> : {{response.rounds}}</strong>
</div>
</div>
<div class="col-md-8 card mb-4 mt-3 ">
<div class="card-body">
<!-- comments -->
<h2>{{ comments.count }} comments</h2>

{% for comment in comments %}
<div class="comments" style="padding: 10px;">
<p class="font-weight-bold">
{{ comment.username }}
<span class=" text-muted font-weight-normal">
{{ comment.created_on }}
</span>
</p>
{{ comment.body | linebreaks }}
</div>
{% endfor %}
</div>
</div>
<div class="col-md-8 card mb-4 mt-3 ">
<div class="card-body">
{% if not user.is_authenicated %}
<a href="/login">Login or Signup to comment</a>
{% endif %}
{% if new_comment %}
<div class="alert alert-success" role="alert">
Your comment has been recorded
</div>
{% else %}
<h3>Leave a comment</h3>
<form method="post" style="margin-top: 1.3em;">
{{ comment_form.as_p }}
{% csrf_token %}
<button type="submit" class="btn btn-sm btn-light border" type="button" name="button">Submit</button>
</form>
{% endif %}
</div>
</div>
</div>
</div>



{% endblock %}
23 changes: 20 additions & 3 deletions Interviewbook/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,26 @@ def ListResponsesbyCompany(request):


def viewResponse(request, response_id):
response = get_object_or_404(InterviewResponse, id=response_id)
response.increase()
return render(request, 'Interviewbook/response.html', {'response': response})
# response = get_object_or_404(InterviewResponse, id=response_id)
#response.increase()
# return render(request, 'Interviewbook/response.html', {'response': response})
response = get_object_or_404(InterviewResponse, id=response_id)
comments = response.comments.filter(active=True)
comment_form = CommentForm()
new_comment = None
new_reply = None
if request.method == 'POST':
comment_form = CommentForm(data=request.POST)
if comment_form.is_valid():
if not (request.user.is_authenticated):
return render(request, 'Interviewbook/login.html')
new_comment = comment_form.save(commit=False)
new_comment.response = response
new_comment.username = request.user.username
new_comment.created_on = timezone.now()
new_comment.active = True
new_comment = comment_form.save()
return render(request, 'Interviewbook/response.html', { 'response': response, 'comments': comments,'new_comment':new_comment, 'comment_form':comment_form })

@login_required(login_url='login')
def updateResponse(request, response_id):
Expand Down