Guest User

Untitled

a guest
Jan 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. class TechnologyDetailView(DetailView):
  2. model = Technology
  3.  
  4. def get_queryset(self):
  5. group_permissions =
  6. Permission.objects.filter(group__user=self.request.user)
  7. query = Technology.objects.filter(pk=self.kwargs['pk'],
  8. is_active=True, permission__in=group_permissions)
  9.  
  10. for tech in query:
  11. comments = Comment.objects.filter(technology=tech)
  12. now = datetime.now()
  13.  
  14. for comment in comments:
  15. comment.timestamp = datetime.strptime('Jun 1 2005 1:33PM',
  16. '%b %d %Y %I:%M%p')
  17. print(comment.timestamp)
  18.  
  19. age = now - comment.timestamp
  20.  
  21. if age < 604800:
  22. comment.is_removable = True
  23. else:
  24. comment.is_removable = False
  25.  
  26. return query
  27.  
  28. <h3>Comments</h3>
  29. {% for comment in technology.comment_set.all %}
  30. <div class="row" style="border-bottom-style:solid;
  31. border-bottom-width:1px; border-color:gray;">
  32. <h6 style="font-weight:bold">Written by {{
  33. comment.user.name }}
  34. on {{ comment.timestamp }}</h6>
  35. <span>{{ comment.content|breaks }}</span>
  36. <p>{{ comment.timestamp | timesince }}</p>
  37.  
  38.  
  39. {% if comment.user == request.user %}
  40. <a class="modal-trigger right"
  41. href="#modal_{{ comment.pk }}">Delete Comment</a>
  42. {% endif %}
  43. <div id="modal_{{ comment.pk }}" class="modal">
  44. <div class="modal-content">
  45. <iframe frameborder="0"
  46. id="encoder_iframe" height=300px width="100%" src="{% url 'delete-
  47. comment' comment.pk %}"></iframe>
  48. </div>
  49. </div>
  50. </div>
  51. {% empty %}
  52. <p>There are no comments</p>
  53. {% endfor %}
  54. <br>
  55. <h5>Add new Comment</h5>
  56. <iframe frameborder="0" id="encoder_iframe"
  57. height=300px width="100%" src="{% url 'add-comment' technology.pk %}">
  58. </iframe>
  59. </div>
  60. </div>
  61. </div>
  62.  
  63. # Comment model
  64. class Comment(models.Model):
  65. user = models.ForeignKey(User, null=True)
  66. technology = models.ForeignKey(Technology, null=True)
  67. parent = models.ForeignKey('self', null=True, blank=True)
  68. content = models.TextField(null=True)
  69. timestamp = models.DateTimeField(null=True)
  70. is_active = models.BooleanField(default=True)
Add Comment
Please, Sign In to add comment