Browse Source

Avatar upload is optional

master
Joshua Rubingh 5 months ago
parent
commit
c65aec0c06
  1. 3
      VRE/apps/researcher/serializers.py
  2. 4
      VRE/apps/researcher/views.py

3
VRE/apps/researcher/serializers.py

@ -54,7 +54,8 @@ class ResearcherSerializer(serializers.ModelSerializer): @@ -54,7 +54,8 @@ class ResearcherSerializer(serializers.ModelSerializer):
instance.user.save()
instance.mobilephone = validated_data.get('mobilephone')
instance.avatar = validated_data.get('avatar')
if validated_data.get('avatar'):
instance.avatar = validated_data.get('avatar')
instance.idnumber = validated_data.get('idnumber')
instance.save()

4
VRE/apps/researcher/views.py

@ -42,6 +42,10 @@ class Researchers(viewsets.ModelViewSet): @@ -42,6 +42,10 @@ class Researchers(viewsets.ModelViewSet):
def update(self, request, *args, **kwargs):
# Set a 'fake' pk value so we can use the normal serializer update
request.parser_context['kwargs']['pk'] = request.user.researcher.id
if request.data['avatar'].startswith('/') or request.data['avatar'].startswith('http://') or request.data['avatar'].startswith('https://'):
# Do not change the existing avatar image.
del(request.data['avatar'])
super().update(request, *args, **kwargs)
# Reload the data from DB
researcher = get_object_or_404(Researcher, pk=request.user.researcher.id)

Loading…
Cancel
Save