def comment_versions(self, request, pk): obj = self.get_object() history_entry_id = request.QUERY_PARAMS.get('id', None) history_entry = services.get_history_queryset_by_model_instance(obj).filter(id=history_entry_id).first() if history_entry is None: return response.NotFound() self.check_permissions(request, 'comment_versions', history_entry) if history_entry is None: return response.NotFound() history_entry.attach_user_info_to_comment_versions() return response.Ok(history_entry.comment_versions)
def edit_comment(self, request, pk): obj = self.get_object() history_entry_id = request.QUERY_PARAMS.get('id', None) history_entry = services.get_history_queryset_by_model_instance(obj).filter(id=history_entry_id).first() if history_entry is None: return response.NotFound() obj = services.get_instance_from_key(history_entry.key) comment = request.DATA.get("comment", None) self.check_permissions(request, 'edit_comment', history_entry) if history_entry is None: return response.NotFound() if comment is None: return response.BadRequest({"error": _("comment is required")}) if history_entry.delete_comment_date or history_entry.delete_comment_user: return response.BadRequest({"error": _("deleted comments can't be edited")}) # comment_versions can be None if there are no historic versions of the comment comment_versions = history_entry.comment_versions or [] comment_versions.append({ "date": history_entry.created_at, "comment": history_entry.comment, "comment_html": history_entry.comment_html, "user": { "id": request.user.pk, } }) new_mentions = self._get_new_mentions(obj, history_entry.comment, comment) history_entry.edit_comment_date = timezone.now() history_entry.comment = comment history_entry.comment_html = mdrender(obj.project, comment) history_entry.comment_versions = comment_versions history_entry.save() if new_mentions: signal_mentions.send(sender=self.__class__, user=self.request.user, obj=obj, mentions=new_mentions) return response.Ok()
def undelete_comment(self, request, pk): obj = self.get_object() history_entry_id = request.QUERY_PARAMS.get('id', None) history_entry = services.get_history_queryset_by_model_instance(obj).filter(id=history_entry_id).first() if history_entry is None: return response.NotFound() self.check_permissions(request, 'undelete_comment', history_entry) if history_entry is None: return response.NotFound() if not history_entry.delete_comment_date and not history_entry.delete_comment_user: return response.BadRequest({"error": _("Comment not deleted")}) history_entry.delete_comment_date = None history_entry.delete_comment_user = None history_entry.save() return response.Ok()
def delete_comment(self, request, pk): obj = self.get_object() history_entry_id = request.QUERY_PARAMS.get('id', None) history_entry = services.get_history_queryset_by_model_instance(obj).filter(id=history_entry_id).first() if history_entry is None: return response.NotFound() self.check_permissions(request, 'delete_comment', history_entry) if history_entry is None: return response.NotFound() if history_entry.delete_comment_date or history_entry.delete_comment_user: return response.BadRequest({"error": _("Comment already deleted")}) history_entry.delete_comment_date = timezone.now() history_entry.delete_comment_user = {"pk": request.user.pk, "name": request.user.get_full_name()} history_entry.save() return response.Ok()
def csv(self, request): uuid = request.QUERY_PARAMS.get("uuid", None) if uuid is None: return response.NotFound() project = get_object_or_404(Project, epics_csv_uuid=uuid) queryset = project.epics.all().order_by('ref') data = services.epics_to_csv(project, queryset) csv_response = HttpResponse( data.getvalue(), content_type='application/csv; charset=utf-8') csv_response[ 'Content-Disposition'] = 'attachment; filename="epics.csv"' return csv_response
def retrieve(self, request, *args, **kwargs): pk = kwargs.get("pk", None) resource_id = kwargs.get("resource_id", None) resource = get_object_or_404(self.resource_model, pk=resource_id) self.check_permissions(request, 'retrieve', resource) try: self.object = services.get_voters(resource).get(pk=pk) except ObjectDoesNotExist: # or User.DoesNotExist return response.NotFound() serializer = self.get_serializer(self.object) return response.Ok(serializer.data)
def list(self, request): return response.NotFound()