Skip to content

Commit

Permalink
remove .pyc files from tracking & rest viewset create now returns ser…
Browse files Browse the repository at this point in the history
…ialized data of created obj
  • Loading branch information
smileservices committed Nov 30, 2020
1 parent b0ddd84 commit 2404912
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
venv/
.idea/
.idea/
*.pyc
Binary file modified dist/django-edit-suggestion-1.25.tar.gz
Binary file not shown.
Binary file added dist/django-edit-suggestion-1.26.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion django_edit_suggestion.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: django-edit-suggestion
Version: 1.25
Version: 1.26
Summary: A django package for creating multiple users editable models
Home-page: https://github.com/smileservices/django-edit-suggestion
Author: Vladimir Gorea
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
20 changes: 17 additions & 3 deletions django_edit_suggestion/rest_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework.viewsets import ModelViewSet
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework import status
from django.core.exceptions import PermissionDenied


Expand Down Expand Up @@ -40,14 +41,14 @@ def edit_suggestion_create(self, request, *args, **kwargs):
m2m_objects = [obj for obj in f['model'].objects.filter(pk__in=request.data[f['name']])]
m2m_attr = getattr(edsug, f['name'])
m2m_attr.add(*m2m_objects)
serializer = self.serializer_class.get_edit_suggestion_serializer()

except Exception as e:
return Response(status=401, data={
'error': True,
'message': str(e)
})
return Response(status=201, data={
'error': False
})
return Response(serializer(edsug).data, status=status.HTTP_201_CREATED)

@action(methods=['POST'], detail=True)
def edit_suggestion_publish(self, request, *args, **kwargs):
Expand Down Expand Up @@ -94,3 +95,16 @@ def edit_suggestion_reject(self, request, *args, **kwargs):
return Response(status=200, data={
'error': False
})

@action(methods=['GET'], detail=False)
def edit_suggestions_all(self, request, *args, **kwargs):
# todo get all edit suggestions for particular model
queryset = self.serializer_class.model.edit_suggestions.all()
page = self.paginate_queryset(queryset)

# if page is not None:
# serializer = serializers.ProblemEditSuggestionSerializer(page, many=True)
# return self.get_paginated_response(serializer.data)
#
# serializer = serializers.ProblemEditSuggestionSerializer(queryset, many=True)
# return Response(serializer.data)
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion django_edit_suggestion/tests/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ParentEditSerializer(ModelSerializer):

class Meta:
model = ParentModel.edit_suggestions.model
fields = ['name', 'tags', 'edit_suggestion_reason', 'edit_suggestion_author']
fields = ['pk', 'name', 'tags', 'edit_suggestion_reason', 'edit_suggestion_author']


class ParentSerializer(EditSuggestionSerializer):
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion django_edit_suggestion/tests/tests/django_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def test_create_edit_suggestion(self):
response = self.client.post(url, {'name': 'edited', 'edit_suggestion_reason': 'test', 'tags': [1, 2]},
format='json')
self.assertEqual(response.status_code, 201)
self.assertEqual(response.data['name'], 'edited')
self.assertEqual(response.data['pk'], 1)

parent = ParentModel.objects.get(pk=1)
ed_sug = parent.edit_suggestions.latest()
self.assertEqual(ed_sug.edit_suggestion_author, logged_user)
Expand Down Expand Up @@ -103,7 +106,9 @@ def test_reject_edit_suggestion(self):
# test for authorized user
staff_user = User.objects.create(username='staff', password=123, is_staff=True)
self.client.force_login(staff_user)
reject_authorized_response = self.client.post(reject_url, {'edit_suggestion_id': ed_sug.pk, 'edit_suggestion_reject_reason': 'just test'}, format='json')
reject_authorized_response = self.client.post(reject_url, {'edit_suggestion_id': ed_sug.pk,
'edit_suggestion_reject_reason': 'just test'},
format='json')
ref_ed_sug = parent.edit_suggestions.latest()

self.assertEqual(reject_authorized_response.status_code, 200)
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ to ``reverse('parent-viewset-create-edit-suggestion', kwargs={'pk': 1})``
The url in string form would be ``/api/parent/1/edit_suggestions/``.


To publish using the viewset send a POST request to ``reverse('parent-viewset-edit-suggestion-publish', kwargs={'pk': 1})``
To **publish** using the viewset send a POST request to ``reverse('parent-viewset-edit-suggestion-publish', kwargs={'pk': 1})``
with a json object having ``edit_suggestion_id`` key with the edit suggestion pk.

To reject using the viewset send a POST request to ``reverse('parent-viewset-edit-suggestion-reject', kwargs={'pk': 1})``
To **reject** using the viewset send a POST request to ``reverse('parent-viewset-edit-suggestion-reject', kwargs={'pk': 1})``
with a json object having ``edit_suggestion_id`` key with the edit suggestion pk and ``edit_suggestion_reject_reason`` as the reason for rejection.

The responses will return status 403 if the rule does not verify, 401 for another exception and 200 for success.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='django-edit-suggestion',
version='1.25',
version='1.26',
description='A django package for creating multiple users editable models',
url='https://github.com/smileservices/django-edit-suggestion',
author='Vladimir Gorea',
Expand Down

0 comments on commit 2404912

Please sign in to comment.