def post_or_put(self, request, *args, **kwargs): request.data['_id'] = self.kwargs['_id'] request.data['created_by'] = Utility.return_id(UserProfile, request.data.get('created_by'), '_id') request.data['modified_by'] = Utility.return_id(UserProfile, request.data.get('modified_by'), '_id') try: model.objects.get(_id=self.kwargs['_id']) return self.update(request, *args, **kwargs) except model.DoesNotExist: return self.create(request, *args, **kwargs)
def post_or_put(self, request, *args, **kwargs): request.data['_id'] = self.kwargs['_id'] request.data['company'] = Utility.return_id(Company, request.data.get('company', None), 'name') request.data['type'] = Utility.return_id(VisitorTypes, request.data.get('type', None), 'name') try: model.objects.get(_id=self.kwargs['_id']) instance_exists = True except model.DoesNotExist: instance_exists = False if instance_exists: return self.update(request, *args, **kwargs) else: return self.create(request, *args, **kwargs)
def post_or_put(self, request, *args, **kwargs): request.data['_id'] = self.kwargs['_id'] request.data['entrance'] = Utility.return_id(Entrance, request.data.get('entrance'), 'name') request.data['created_by'] = Utility.return_id(UserProfile, request.data.get('created_by'), '_id') request.data['modified_by'] = Utility.return_id(UserProfile, request.data.get('modified_by'), '_id') try: model.objects.get(_id=self.kwargs['_id']) instance_exists = True except model.DoesNotExist: instance_exists = False if instance_exists: return self.update(request, *args, **kwargs) else: return self.create(request, *args, **kwargs)
def post_or_put(self, request, *args, **kwargs): request.data['_id'] = self.kwargs['_id'] request.data['department'] = Utility.return_id(Department, request.data.get('department'), 'name') try: user_instance = UserProfile.objects.get(_id=self.kwargs['_id']) if request.data.get('password', None) is None or request.data.get('password', None) == '': request.data['password'] = user_instance.password elif request.data.get('password', None) is not None and request.data.get('password', None) != '': request.data['password'] = make_password(request.data['password']) return self.update(request, *args, **kwargs) except UserProfile.DoesNotExist: if request.data.get('password', None) is not None and request.data.get('password', None) != '': request.data['password'] = make_password(request.data['password']) return self.create(request, *args, **kwargs)