def create(self, validated_data): try: favourite = self.profile.follow_company(validated_data['company']) return favourite except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err)))
def create(self, validated_data): try: profile = self.request.user.create_main_profile(validated_data) return profile except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err)))
def create(self, validated_data): self.get_array_from_string(validated_data) try: photo = self.profile.create_photo(validated_data) return photo except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err)) )
def update(self, instance, validated_data): try: partnership = self.profile.refuse_partnership( validated_data['guest_company']) return partnership except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err)))
def update(self, instance, validated_data): try: generic_profile = self.request.user.get_profile_by_id( instance.id, instance.status) profile = generic_profile.disable_profile() return profile except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err)))
def perform_destroy(self, instance): try: main_profile = self.request.user.get_main_profile() main_profile.remove_profile(instance) except django_exception.MainProfileDoesNotExist as err: raise django_api_exception.MainProfileAPIDoesNotExist( status.HTTP_403_FORBIDDEN, self.request, _(err.msg) ) except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err)) )
def get_queryset(self): try: self.queryset = self.request.user.get_all_profiles() return super(ProfilesActiveListView, self).get_queryset() except django_exception.MainProfileDoesNotExist as err: raise django_api_exception.MainProfileAPIDoesNotExist( status.HTTP_403_FORBIDDEN, self.request, _(err.msg) ) except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err)) )
def create(self, validated_data): try: if 'pk' in self.request.parser_context['kwargs'].keys(): main_profile = self.profile.get_main_profile() sponsor = main_profile.create_sponsor_request(validated_data) else: sponsor = self.profile.create_sponsor_request(validated_data) return sponsor except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err)))
def create(self, validated_data): try: main_profile = self.request.user.get_main_profile() company, profile = main_profile.create_company(validated_data) return company except django_exception.MainProfileDoesNotExist as err: raise django_api_exception.MainProfileAPIDoesNotExist( status.HTTP_403_FORBIDDEN, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err))) except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err)))
def create(self, validated_data): try: # main_profile = self.request.user.get_main_profile() # company_profile = main_profile.create_company_profile(validated_data) # return company_profile user = validated_data['company'].profiles.order_by( 'date_create').first().user main_profile = user.get_main_profile() company_profile = main_profile.create_company_profile( validated_data) return company_profile except Exception as err: raise django_api_exception.WhistleAPIException( status.HTTP_500_INTERNAL_SERVER_ERROR, self.request, _("{}".format(err.msg if hasattr(err, 'msg') else err)))