def create(self, request, *args, **kwargs): wealth = request.session['wealth'] params = load_params(request) accounts_list = get_list(Account.objects, wealth) if params['type'] == Transaction.TYPE_TRANSFER: form = TransactionAddTransferForm(params, wealth=wealth, accounts_list=accounts_list) else: if 'tags' in params: params['tags'] = self._get_tag_ids(params['tags']) tag_list=[(tag.id, tag.name) for tag in Tag.objects.filter(wealth=wealth)] categories_list = get_list(Category.objects, wealth) form = TransactionAddNonTransferForm(params, wealth=wealth, categories_list=categories_list, accounts_list=accounts_list, tag_list=tag_list) if form.is_valid(): transaction = form.save() return {'success': True, 'id': transaction.id} else: return {'success': False, 'errors': form.get_errors()}
def update(self, request, transaction_type, object_id): params = load_params(request) wealth = request.session['wealth'] params['id'] = object_id transaction = Transaction.objects.get( wealth=wealth, id=object_id) accounts_list = get_list(Account.objects, wealth) if 'type' not in params: resp = rc.BAD_REQUEST resp.write("'type' is a compulsory argument") return resp if params['type'] == Transaction.TYPE_TRANSFER: form = TransactionEditTransferForm( params, wealth=wealth, accounts_list=accounts_list) else: categories_list = get_list(Category.objects, wealth) form = TransactionEditNonTransferForm( params, wealth=wealth, categories_list=categories_list) if form.is_valid(): form.save() return {'success': True} else: return {'success': False, 'errors': form.get_errors()}
def create(self, request, *args, **kwargs): params = load_params(request) form = WatchAddForm(params) if form.is_valid(): watched = form.save() return {'success': True, 'id': watched.id} else: return {'success': False, 'errors': form.get_errors()}
def create(self, request, *args, **kwargs): params = load_params(request) form = TransactionAddForm(params) if form.is_valid(): transaction = form.save() return {'success': True, 'id': transaction.id} else: return {'success': False, 'errors': form.get_errors()}
def create(self, request, *args, **kwargs): wealth = request.session['wealth'] params = load_params(request) form = CategoryAddForm(params, wealth=wealth) if form.is_valid(): category = form.save() return {'success': True, 'id': category.id} else: return {'success': False, 'errors': form.get_errors()}
def update(self, request, breakout_id): params = load_params(request) params['id'] = breakout_id form = BreakoutEditForm(params) if form.is_valid(): form.save() return {'success': True} else: return {'success': False, 'errors': form.get_errors()}
def update(self, request, transaction_id): params = load_params(request) params['id'] = transaction_id form = TransactionEditForm(params) if form.is_valid(): form.save() return {'success': True} else: return {'success': False, 'errors': form.get_errors()}
def remove_tags(request): wealth = request.session['wealth'] params = load_params(request) form = DeAssociateTagsForm( params, wealth=wealth) if form.is_valid(): form.save() return HttpResponse(JSON_SUCCESS) else: return get_json_errors(form.errors)
def move(request): wealth = request.session['wealth'] try: params = load_params(request) except ValueError: return HttpResponse(JSON_FAILURE % 'Invalid arguments') form = CategoryMoveForm(params, wealth=wealth) if form.is_valid(): form.save() return HttpResponse(JSON_SUCCESS) else: return get_json_errors(form.errors)
def update(self, request, category_id): wealth = request.session['wealth'] params = load_params(request) params['id'] = category_id category = Category.objects.get(wealth=wealth, id=category_id) form = CategoryEditForm(params, wealth=wealth) if form.is_valid(): form.save() return {'success': True} else: return {'success': False, 'errors': form.get_errors()}
def create(self, request, *args, **kwargs): wealth = request.session['wealth'] params = load_params(request) params['budget'] = request.GET['budget'] form = BudgetLineAddForm( params, wealth=wealth) if form.is_valid(): budgetline = form.save() return {'success': True, 'id': budgetline.id} else: return {'success': False, 'errors': form.get_errors()}
def update(self, request, account_id): wealth = request.session['wealth'] params = load_params(request) params['id'] = account_id account = Account.objects.get(wealth=wealth, id=account_id) form = AccountEditForm(params, wealth=wealth) if form.is_valid(): form.save() return {'success': True} else: return {'success': False, 'errors': form.get_errors()}
def update(self, request, budgetline_id): wealth = request.session['wealth'] params = load_params(request) params['budget'] = request.GET['budget'] params['id'] = budgetline_id budgetline = BudgetLine.objects.get( wealth=wealth, id=budgetline_id) form = BudgetLineEditForm( params, wealth=wealth) if form.is_valid(): form.save() return {'success': True} else: return {'success': False, 'errors': form.get_errors()}
def create(self, request, *args, **kwargs): params = load_params(request) if 'opportunity' in params and int(params['opportunity']) == 0: del params['opportunity'] try: if 'type' in params and int(params['type']) == Opportunity.TYPE_SELL: form = OrderSellForm(params) else: form = OrderBuyForm(params) except ValueError: return rc.BAD_REQUEST if form.is_valid(): order = form.save() return {'success': True, 'id': order.id} else: return {'success': False, 'errors': form.get_errors()}