Skip to content
Snippets Groups Projects
Commit a6d05406 authored by Jean-Baptiste's avatar Jean-Baptiste
Browse files

Merge branch '94-post-nested-fields' into 'master'

Resolve "Error while submiting a form with nested fields"

See merge request startinblox/djangoldp-packages/djangoldp!34
parents 2b242ee0 ed389128
No related branches found
Tags v0.5.41
1 merge request!34Resolve "Error while submiting a form with nested fields"
Pipeline #801 passed with stage
in 1 minute and 21 seconds
......@@ -17,9 +17,9 @@ from rest_framework.utils import model_meta
from rest_framework.utils.field_mapping import get_nested_relation_kwargs
from rest_framework.utils.serializer_helpers import ReturnDict
from djangoldp import permissions
from djangoldp.fields import LDPUrlField, IdURLField
from djangoldp.models import Model
from djangoldp import permissions
class LDListMixin:
......@@ -210,11 +210,11 @@ class LDPSerializer(HyperlinkedModelSerializer):
if hasattr(obj._meta, 'auto_author'):
data['permissions'] += permissions.AnonymousReadOnly.author_perms
else:
data['permissions'] += permissions.AnonymousReadOnly.authenticated_perms
data['permissions'] += permissions.AnonymousReadOnly.authenticated_perms
if hasattr(obj._meta, 'rdf_context'):
data['@context'] = obj._meta.rdf_context
return data
def build_standard_field(self, field_name, model_field):
......
from django.test import TestCase
from djangoldp.serializers import LDPSerializer
from djangoldp.tests.models import Skill, JobOffer
from djangoldp.tests.models import Skill, JobOffer, Invoice
class Save(TestCase):
def test_save_m2m_graph_with_many_nested(self):
invoice = {
"@graph": [
{
"@id": "./",
"batches": {"@id": "_:b381"},
"title": "Nouvelle facture",
},
{
"@id": "_:b381",
"tasks": {"@id": "_:b382"},
"title": "Batch 1"
},
{
"@id": "_:b382",
"title": "Tache 1"
}
]
}
meta_args = {'model': Invoice, 'depth': 2, 'fields': ("@id", "title", "batches")}
meta_class = type('Meta', (), meta_args)
serializer_class = type(LDPSerializer)('InvoiceSerializer', (LDPSerializer,), {'Meta': meta_class})
serializer = serializer_class(data=invoice)
serializer.is_valid()
result = serializer.save()
self.assertEquals(result.title, "Nouvelle facture")
self.assertIs(result.batches.count(), 1)
self.assertEquals(result.batches.all()[0].title, "Batch 1")
self.assertIs(result.batches.all()[0].tasks.count(), 1)
#self.assertEquals(result.batches.all()[0].tasks.all()[0].title, "Tache 1")
def test_save_m2m(self):
skill1 = Skill.objects.create(title="skill1", obligatoire="obligatoire")
skill2 = Skill.objects.create(title="skill2", obligatoire="obligatoire")
......@@ -35,9 +69,9 @@ class Save(TestCase):
def test_save_m2m_graph_simple(self):
job = {"@graph": [
{"title": "job test",
},
]}
{"title": "job test",
},
]}
meta_args = {'model': JobOffer, 'depth': 1, 'fields': ("@id", "title", "skills")}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment