def register_view(request): data = json.loads(request.body) username = data.get('username', '') password = data.get('password', '') currency = data.get('currency', '') form = BudgetUserForm(data={ 'username': username, 'password': password, 'currency': currency, 'is_active': True }) if form.is_valid(): budget_user = form.save() for entry_type in EntryType.objects.filter(category='expense'): budget = Budget(user=budget_user, amount=0, entry_type=entry_type) budget.save() data = { "message": "Registration was successful!", "registered": True } else: field_name, error = form.errors.items()[0] data = { "message": field_name.capitalize() + ": " + error[0], "registered": False } return HttpResponse(json.dumps(data), content_type='application/json')
def createFinancialAcc(request): isLoged(request) accFina = '' accFinaName = '' trxs = '' balance = 0.0 msj = '' page = 'financialInterest.html' if request.method == 'POST': faf = FinancialAccForm(request.POST) faftname = request.POST.get('name','') team = getSavedInSession(request, 'team') exist = team.financialacc_set.filter(name = faftname) accFina = team.financialacc_set.all() if not exist: if faf.is_valid(): faft = faf.save(commit = False) acc = getCurrentAccount(request) grupo = acc.equipo_set.filter(nombre = team.nombre) accFinaName = faft.name faft.teamowner = grupo[0] faft.save() budget = Budget(name='Budget ',accOwner=faft) budget.save() saveInSession(request, 'currentAccFina', faft) else: msj = 'Esta cuenta ya existe en este grupo.' page = 'financialInterest.html' return render(request,page,{'msj':msj,'user':getLogin(request),'accFina':accFina,'currentAccFina':accFinaName,'trans':trxs,'balance':balance})
def createBudget(request): isLoged(request) accFina = team.financialacc_set.all() currentAccFinaName = request.GET.get('search','') if not currentAccFinaName: return HttpResponseRedirect('/homeview/') for acc in accFina: if acc.name == currentAccFinaName.strip(): budget = Budget(name='Budget '.join(acc.name),hasBudget=True,teamowner= acc) budget.save() return budgetByFinantialAcc(request)