Пример #1
0
    def create(self, request, *args, **kwargs):
        if request.data is None:
            return rc.BAD_REQUEST

        if not self.check_create_permission(request, "x"):
            return rc.FORBIDDEN

        currency = Currency()
        form = CurrencyForm(request.user.get_profile(), request.data, instance=currency)
        if form.is_valid():
            currency = form.save(commit=False)
            cname = dict_currencies[currency.code]
            currency.name = cname[cname.index(' ')+2:]
            #currency.factor = 1.0 #Get currency conversion here
            currency.save()
            currency.set_user_from_request(request)
            return currency
        else:
            self.status = 400
            return form.errors