def update(self, request, id=None): ready_data_true = {'success': True } ready_data_false = {'success': False} if not request.user.is_authenticated(): #return rc.FORBIDDEN ready_data_false["error"] = "Authorization is failed" return ready_data_false ext_posted_data = simplejson.loads(request.POST.get('items')) attrs = self.flatten_dict(ext_posted_data) try: del attrs['id'] except KeyError: pass try: del attrs['password'] except KeyError: pass reason=[] if id: req = check(request, id, attrs=attrs) if req == True: try: currentProfile = Profile.getProfile(request.user) if str(id) == str(currentProfile.id) or currentProfile.get_role_display() == 'Admin' : Profile.objects.filter(pk=id).update(**attrs) profile = Profile.objects.get(pk=id) else: ready_data_false['error'] = 'Not Allowed' return ready_data_false except Exception, err: ready_data_false['errors'] = err return ready_data_false if profile.get_role_display() == 'Vendor' or profile.get_role_display() == 'Vendor salesmen': updateVendorDependencies(profile) ready_data_true['items'] = profile return ready_data_true else: ready_data_false['errors'] = req ready_data_false['debug_attrs'] = attrs return ready_data_false
def delete(self, request, id=None): ready_data_true = {'success': True } ready_data_false = {'success': False} if not request.user.is_authenticated(): #return rc.FORBIDDEN ready_data_false["error"] = "Authorization is failed" return ready_data_false reason = [] if id: req = check(request, id, attrs=None) if req == True: profile = Profile.objects.get(pk=id) profile.delete() return ready_data_true else: ready_data_false['errors'] = req return ready_data_false else: reason.append(u'Profile ID is required') ready_data_false['errors'] = reason return ready_data_false