Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for uploaded_style in default_style.itervalues():
uploaded_style["default"] = True
#save style
styles= []
for style_serializer in style_serializers:
if http_status != status.HTTP_201_CREATED:
#record is already exist,should check whether style exist or not.
try:
style_serializer.instance = Style.objects.get(record=record,name=style_serializer.validated_data["name"],format=style_serializer.validated_data["format"])
except Style.DoesNotExist:
pass
styles.append(style_serializer.save())
record.styles = styles
serializer = RecordSerializer(record)
return Response(serializer.data,status=http_status)
def create(self,request):
styles_data = None
http_status = status.HTTP_200_OK
if "styles" in request.data:
styles_data = request.data.pop("styles")
#parse and valid record data
serializer = RecordSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
#parse and valid styles data
style_serializers = [StyleSerializer(data=style) for style in styles_data] if styles_data else []
if style_serializers:
for style_serializer in style_serializers:
style_serializer.is_valid(raise_exception=True)
#save record data.
identifier = "{}:{}".format(serializer.validated_data['workspace'],serializer.validated_data['name'])
try:
serializer.instance = Record.objects.get(identifier=identifier)
if not serializer.instance.auto_update:
#auto update disabled
for key in ["title","abstract","auto_update","modified","insert_date"]:
if key in serializer.validated_data: serializer.validated_data.pop(key)