def add(request): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = AlarmForm(data=request.POST, user=user, id=None) if form.is_valid(): name = form.cleaned_data['name'] account = AccountService().getAccount(form.cleaned_data['account'], user) begindate = form.cleaned_data['begindate'] enddate = form.cleaned_data['enddate'] cycletype = form.cleaned_data['cycletype'] cyclevalue = form.cleaned_data['cyclevalue'] isautogenmoneyio = form.cleaned_data['isautogenmoneyio'] moneyiousertype = MoneyService().getMoneyIOUserType(form.cleaned_data['moneyiousertype'], user) money = form.cleaned_data['money'] currency = AccountService().getCurrency(form.cleaned_data['currency']) description = form.cleaned_data['description'] AlarmService().addAlarm(name, account, begindate, enddate, cycletype, cyclevalue, isautogenmoneyio, moneyiousertype, money, currency, description, user) return HttpResponseRedirect('/alarm/') else: form = AlarmForm(user=user, id=None) pageinfo = PageInfo(page_menu_name='Alarm', user=user, page_title=ugettext('Add Alarm')) helptext_list = AdminService().getCategoryHelpTextList('Alarm') form_action_url='/alarm/add/' return render_to_response('common_add_edit.html', {'pageinfo':pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user })
def moneyio_add(request): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = MoneyIOForm(data=request.POST, user=user) if form.is_valid(): account = AccountService().getAccount(form.cleaned_data['account'], user) happentime = form.cleaned_data['happentime'] moneyiotype = MoneyService().getMoneyIOUserType(form.cleaned_data['moneyiotype'], user) money = form.cleaned_data['money'] currency = AccountService().getCurrency(form.cleaned_data['currency']) isshare = form.cleaned_data['isshare'] description = form.cleaned_data['description'] MoneyService().addMoneyIO(account, happentime, moneyiotype, money, currency, isshare, description, user) return HttpResponseRedirect('/moneyio/') else: form = MoneyIOForm(user=user) page_title=ugettext('Add Money Income and Expense') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Money Income and Expense') form_action_url='/moneyio/add' return render_to_response('common_add_edit.html', {'pageinfo':pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user, })
def user_view_page(request, id, pagenum): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Sinaapp', user=user) sinauser = UserService().getCoolUser(id) if sinauser: current_page = int(id) filter_dict={'isshare': True} orderby = '-createtime' moneyiosharelist, total_records = MoneyService().getMoneyIOList(filter_dict, orderby, pageinfo.page_size, current_page, sinauser) total_page = (total_records + pageinfo.page_size - 1) / pageinfo.page_size page_begin_num = 1 + (current_page - 1) * pageinfo.page_size if page_begin_num > total_records: page_begin_num = total_records if total_page > current_page: page_end_num = current_page * pageinfo.page_size else: page_end_num = total_records recomuserlist = UserService().getRecomUserList(user) return render_to_response('sinaapp_user_view.html', {'user':user, 'sinauser':sinauser, 'pageinfo': pageinfo, 'total_records': total_records, 'current_page': current_page, 'total_page': total_page, 'page_begin_num': page_begin_num, 'page_end_num': page_end_num, 'moneyiosharelist': moneyiosharelist, 'recomuserlist': recomuserlist }) else: return HttpResponseRedirect('/sinaapp/')
def moneyiousertype_edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = MoneyIOUserTypeForm(data=request.POST, user=user, id=id) if form.is_valid(): name = form.cleaned_data['name'] isio = int(form.cleaned_data['isio']) MoneyService().editMoneyIOUserType(id, name, isio, user) return HttpResponseRedirect('/moneyiousertype/') else: moneyiousertype = MoneyService().getMoneyIOUserType(id, user) if moneyiousertype: form = MoneyIOUserTypeForm(initial= {'name': moneyiousertype.name, 'isio':moneyiousertype.isio}, user=user, id=id) else: return HttpResponseRedirect('/moneyiousertype/') page_title=ugettext('Edit Money Income and Expense Type') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Money Income and Expense') form_action_url='/moneyiousertype/edit/' + id return render_to_response('common_add_edit.html', {'pageinfo':pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user })
def add(request): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = AccountForm(data = request.POST, user = user, id=None) if form.is_valid(): name = form.cleaned_data['name'] type = AccountService().getAccountType(form.cleaned_data['type']) currency = AccountService().getCurrency(form.cleaned_data['currency']) initmoney = float(form.cleaned_data['initmoney']) description = form.cleaned_data['description'] AccountService().addAccount(name, type, currency, initmoney, description, user) return HttpResponseRedirect('/account/') else: form = AccountForm(user=user, id=None) page_title=ugettext('Add Account') pageinfo = PageInfo(page_menu_name='Account', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Account') form_action_url='/account/add/' return render_to_response('common_add_edit.html', {'pageinfo':pageinfo, 'helptext_list':helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user })
def moneyio_analyze_index(request): if not check_user_login(request): return login(request) user = request.session.get('user') page_title=ugettext('Money Income and Expense Analyze') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Money Income and Expense') year = common.datetimeutil.year month = int(common.datetimeutil.month) yearmonthlist = [(year + '/' + str(i)) for i in range(1, month)] + [year + '/' +str(month)] if request.method == 'POST': form = MoneyIOStatSearchForm(data=request.POST, user=user) if form.is_valid(): filter_dict = {} begindate = form.cleaned_data['begindate'] if begindate: filter_dict.update({'happentime >=': begindate}) enddate = form.cleaned_data['enddate'] if enddate: enddate = common.datetimeutil.getdayofday(enddate, 1) filter_dict.update({'happentime <': enddate}) account = AccountService().getAccount(form.cleaned_data['account'], user) if account: filter_dict.update({'account': account}) currency = AccountService().getCurrency(form.cleaned_data['currency']) if currency: filter_dict.update({'currency': currency}) else: form = MoneyIOStatSearchForm(user=user) try: yearmonth=request.GET['yearmonth'] except: yearmonth='' if not yearmonth or yearmonth == '': yearmonth = year + '/' + str(month) begindate = datetime.datetime.strptime(yearmonth, '%Y/%m') enddate = common.datetimeutil.datetime_offset_by_month(begindate, 1) filter_dict = {'happentime >=': begindate, 'happentime <': enddate} begindatestr = datetime.datetime.strftime(begindate, '%Y-%m-%d') enddatestr = datetime.datetime.strftime(enddate, '%Y-%m-%d') moneystat_list = MoneyService().getMoneyStatList(filter_dict, user) return render_to_response('moneyioanalyze.html', {'yearmonthlist': yearmonthlist, 'form': form, 'moneystat_list': moneystat_list, 'begindate': begindatestr, 'enddate': enddatestr, 'user':user, 'pageinfo': pageinfo, 'helptext_list': helptext_list })
def detail(request, id): if not check_user_login(request): return login(request) user = request.session.get("user") object = ObjectService().getObject(id, user) object_list = [] if object: object_list.append(object) page_title = ugettext("Object Detail") pageinfo = PageInfo(page_menu_name="Object", user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList("Object") account_list = AccountService().getAccountListByIDList(object.accountlist, user) return render_to_response( "object_detail.html", { "object": object, "object_list": object_list, "user": user, "pageinfo": pageinfo, "helptext_list": helptext_list, "account_list": account_list, }, ) else: return render_to_response("object_detail.html", {"object": None})
def moneybl_add(request): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = MoneyBLForm(data=request.POST, user=user) if form.is_valid(): account = AccountService().getAccount(form.cleaned_data['account'], user) isio = int(form.cleaned_data['isio']) happentime = form.cleaned_data['happentime'] money = form.cleaned_data['money'] currency = AccountService().getCurrency( form.cleaned_data['currency']) description = form.cleaned_data['description'] MoneyService().addMoneyBL(account, isio, happentime, money, currency, description, user) return HttpResponseRedirect('/moneybl/') else: form = MoneyBLForm(user=user) pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=ugettext('Add Money Borrow and Lend')) helptext_list = AdminService().getCategoryHelpTextList( 'Money Income and Expense') form_action_url = '/moneybl/add' return render_to_response( 'common_add_edit.html', { 'pageinfo': pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user': user })
def add(request): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = AccountForm(data=request.POST, user=user, id=None) if form.is_valid(): name = form.cleaned_data['name'] type = AccountService().getAccountType(form.cleaned_data['type']) currency = AccountService().getCurrency( form.cleaned_data['currency']) initmoney = float(form.cleaned_data['initmoney']) description = form.cleaned_data['description'] AccountService().addAccount(name, type, currency, initmoney, description, user) return HttpResponseRedirect('/account/') else: form = AccountForm(user=user, id=None) page_title = ugettext('Add Account') pageinfo = PageInfo(page_menu_name='Account', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Account') form_action_url = '/account/add/' return render_to_response( 'common_add_edit.html', { 'pageinfo': pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user': user })
def moneyiousertype_add(request): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = MoneyIOUserTypeForm(data=request.POST, user=user, id=None) if form.is_valid(): name = form.cleaned_data['name'] isio = int(form.cleaned_data['isio']) MoneyService().addMoneyIOUserType(name, isio, user) return HttpResponseRedirect('/moneyiousertype/') else: form = MoneyIOUserTypeForm(user=user, id=None) page_title = ugettext('Add Money Income and Expense Type') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList( 'Money Income and Expense') form_action_url = '/moneyiousertype/add' return render_to_response( 'common_add_edit.html', { 'pageinfo': pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user': user })
def add(request): if not check_user_login(request): return login(request) user = request.session.get("user") if request.method == "POST": form = ObjectForm(data=request.POST, user=user, id=None) if form.is_valid(): name = form.cleaned_data["name"] finishdate = form.cleaned_data["finishdate"] money = float(form.cleaned_data["money"]) currency = AccountService().getCurrency(form.cleaned_data["currency"]) accountlist = form.cleaned_data["accountlist"] description = form.cleaned_data["description"] ObjectService().addObject(name, finishdate, money, currency, accountlist, description, user) return HttpResponseRedirect("/object/") else: form = ObjectForm(user=user, id=None) page_title = ugettext("Add Object") pageinfo = PageInfo(page_menu_name="Object", user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList("Object") form_action_url = "/object/add/" return render_to_response( "common_add_edit.html", { "pageinfo": pageinfo, "helptext_list": helptext_list, "form_action_url": form_action_url, "form": form, "user": user, }, )
def user_index_page(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Sinaapp', user=user) current_page = int(id) orderby = '-createtime' sinauserlist, total_records = UserService().getCoolUserList(None, orderby, pageinfo.page_size, current_page) total_page = (total_records + pageinfo.page_size - 1) / pageinfo.page_size page_begin_num = 1 + (current_page - 1) * pageinfo.page_size if page_begin_num > total_records: page_begin_num = total_records if total_page > current_page: page_end_num = current_page * pageinfo.page_size else: page_end_num = total_records recomuserlist = UserService().getRecomUserList(user) return render_to_response('sinaapp_user_index.html', {'user':user, 'pageinfo': pageinfo, 'total_records': total_records, 'current_page': current_page, 'total_page': total_page, 'page_begin_num': page_begin_num, 'page_end_num': page_end_num, 'sinauserlist': sinauserlist, 'recomuserlist': recomuserlist })
def add(request): if not check_user_login(request): return login(request) user = request.session.get('user') moneyiousertype_list = MoneyService().getMoneyIOUserTypeList(user) moneyiousertype_count = MoneyService().getMoneyIOUserTypeCount(user) BudgetDetailFormSet = formset_factory(BudgetDetailForm, max_num=moneyiousertype_count) if request.method == 'POST': budgetform = BudgetForm(request.POST) budgetdetailformset = BudgetDetailFormSet(request.POST) if budgetform.is_valid() and budgetdetailformset.is_valid(): name = budgetform.cleaned_data['name'] begindate = budgetform.cleaned_data['begindate'] enddate = budgetform.cleaned_data['enddate'] currency = AccountService().getCurrency( budgetform.cleaned_data['currency']) description = budgetform.cleaned_data['description'] budget = BudgetService().addBudget(name, begindate, enddate, currency, description, user) for budgetdetailform in budgetdetailformset.forms: moneyiousertypeid = budgetdetailform.cleaned_data[ 'moneyiousertypeid'] moneyiousertype = MoneyService().getMoneyIOUserType( moneyiousertypeid, user) money = budgetdetailform.cleaned_data['money'] if money > 0.0: BudgetService().addBudgetDetail(budget, moneyiousertype, money) return HttpResponseRedirect('/budget/') else: budgetform = BudgetForm() formsetinitdata = [{ 'moneyiousertypeid': moneyiousertype.id, 'moneyiousertypename': moneyiousertype.name, 'money': 0.0 } for moneyiousertype in moneyiousertype_list] budgetdetailformset = BudgetDetailFormSet(initial=formsetinitdata) page_title = ugettext('Add Budget') pageinfo = PageInfo(page_menu_name='Budget', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Budget') form_action_url = '/budget/add/' return render_to_response( 'budget_add_edit.html', { 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'budgetform': budgetform, 'budgetdetailformset': budgetdetailformset, 'user': user, 'pageinfo': pageinfo })
def moneytransfer_edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = MoneyTransferForm(data=request.POST, user=user) if form.is_valid(): fromaccount = AccountService().getAccount( form.cleaned_data['fromaccount'], user) toaccount = AccountService().getAccount( form.cleaned_data['toaccount'], user) happentime = form.cleaned_data['happentime'] money = form.cleaned_data['money'] currency = AccountService().getCurrency( form.cleaned_data['currency']) description = form.cleaned_data['description'] MoneyService().editMoneyTransfer(id, fromaccount, toaccount, happentime, money, currency, description, user) return HttpResponseRedirect('/moneytransfer/') else: moneytransfer = MoneyService().getMoneyTransfer(id, user) if moneytransfer: moneytransfer_currency_id = None if moneytransfer.currency: moneytransfer_currency_id = moneytransfer.currency.id moneytransfer_fromaccount_id = None if moneytransfer.fromaccount: moneytransfer_fromaccount_id = moneytransfer.fromaccount.id moneytransfer_toaccount_id = None if moneytransfer.toaccount: moneytransfer_toaccount_id = moneytransfer.toaccount.id form = MoneyTransferForm(initial={ 'fromaccount': moneytransfer_fromaccount_id, 'toaccount': moneytransfer_toaccount_id, 'happentime': moneytransfer.happentime, 'money': moneytransfer.money, 'currency': moneytransfer_currency_id, 'description': moneytransfer.description }, user=user) else: return HttpResponseRedirect('/moneytransfer/') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=ugettext('Edit Money Transfer')) helptext_list = AdminService().getCategoryHelpTextList( 'Money Income and Expense') form_action_url = '/moneytransfer/edit/' + id return render_to_response( 'common_add_edit.html', { 'pageinfo': pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user': user })
def moneyiousertype_delete(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') MoneyService().deleteMoneyIOUserType(id, user) return HttpResponseRedirect('/moneyiousertype/')
def open(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') AccountService().openAccount(id, user) return HttpResponseRedirect('/account/')
def moneytransfer_delete(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') MoneyService().deleteMoneyTransfer(id, user) return HttpResponseRedirect('/moneytransfer/')
def delete(request, id): if not check_user_login(request): return login(request) user = request.session.get("user") ObjectService().deleteObject(id, user) return HttpResponseRedirect("/object/")
def delete(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') BudgetService().deleteBudget(id, user) return HttpResponseRedirect('/budget/')
def index(request): if not check_user_login(request): return login(request) user = request.session.get("user") pageinfo = PageInfo(page_menu_name="Object", user=user) helptext_list = AdminService().getCategoryHelpTextList("Object") return render_to_response("object.html", {"user": user, "pageinfo": pageinfo, "helptext_list": helptext_list})
def edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = AlarmForm(data=request.POST, user=user, id=id) if form.is_valid(): name = form.cleaned_data['name'] account = AccountService().getAccount(form.cleaned_data['account'], user) begindate = form.cleaned_data['begindate'] enddate = form.cleaned_data['enddate'] cycletype = form.cleaned_data['cycletype'] cyclevalue = form.cleaned_data['cyclevalue'] isautogenmoneyio = form.cleaned_data['isautogenmoneyio'] moneyiousertype = MoneyService().getMoneyIOUserType(form.cleaned_data['moneyiousertype'], user) money = form.cleaned_data['money'] currency = AccountService().getCurrency(form.cleaned_data['currency']) description = form.cleaned_data['description'] AlarmService().editAlarm(id, name, account, begindate, enddate, cycletype, cyclevalue, isautogenmoneyio, moneyiousertype, money, currency, description, user) return HttpResponseRedirect('/alarm/') else: alarm = AlarmService().getAlarm(id, user) if alarm: alarm_account_id = None if alarm.account: alarm_account_id = alarm.account.id alarm_moneyiousertype_id = None if alarm.moneyiousertype: alarm_moneyiousertype_id = alarm.moneyiousertype.id form = AlarmForm(initial= {'name': alarm.name, 'account':alarm_account_id, 'begindate':alarm.begindate, 'enddate':alarm.enddate, 'cycletype':alarm.cycletype, 'cyclevalue':alarm.cyclevalue, 'isautogenmoneyio':alarm.isautogenmoneyio, 'moneyiousertype':alarm_moneyiousertype_id, 'money':alarm.money, 'currency':alarm.currency.id, 'description':alarm.description, }, user=user, id =id) else: return HttpResponseRedirect('/alarm/') page_title=ugettext('Edit Alarm') helptext_list = AdminService().getCategoryHelpTextList('Alarm') form_action_url='/alarm/edit/' + id page_module='Alarm' return render_to_response('common_add_edit.html', {'page_title':page_title, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user, 'page_module' : page_module })
def delete(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') AlarmService().deleteAlarm(id, user) return HttpResponseRedirect('/alarm/')
def edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') account = AccountService().getAccount(id, user) if account: if account.isclosed: return HttpResponseRedirect('/account/') if request.method == 'POST': form = AccountForm(data=request.POST, id=id, user=user) if form.is_valid(): name = form.cleaned_data['name'] type = AccountService().getAccountType(form.cleaned_data['type']) currency = AccountService().getCurrency( form.cleaned_data['currency']) initmoney = float(form.cleaned_data['initmoney']) description = form.cleaned_data['description'] AccountService().editAccount(id, name, type, currency, initmoney, description, user) return HttpResponseRedirect('/account/') else: if account: account_type_id = None if account.type: account_type_id = account.type.id account_currency_id = None if account.currency: account_currency_id = account.currency.id form = AccountForm(initial={ 'name': account.name, 'type': account_type_id, 'currency': account_currency_id, 'initmoney': account.initmoney, 'description': account.description }, id=id, user=user) else: return HttpResponseRedirect('/account/') page_title = ugettext('Edit Account') helptext_list = AdminService().getCategoryHelpTextList('Account') form_action_url = '/account/edit/' + id page_module = 'Account' return render_to_response( 'common_add_edit.html', { 'page_title': page_title, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user': user, 'page_module': page_module })
def moneytransfer_index(request): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=ugettext('Money Transfer')) helptext_list = AdminService().getCategoryHelpTextList('Money Income and Expense') return render_to_response('moneytransfer.html', {'user':user, 'pageinfo': pageinfo, 'helptext_list': helptext_list })
def index(request): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Alarm', user=user) helptext_list = AdminService().getCategoryHelpTextList('Alarm') return render_to_response('alarm.html', {'user':user, 'pageinfo': pageinfo, 'helptext_list': helptext_list })
def index(request): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Budget', user=user) helptext_list = AdminService().getCategoryHelpTextList('Budget') return render_to_response('budget.html', { 'user': user, 'pageinfo': pageinfo, 'helptext_list': helptext_list })
def detail(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Account', user=user) account = AccountService().getAccount(id, user) helptext_list = AdminService().getCategoryHelpTextList('Account') return render_to_response('account_detail.html', {'account': account, 'user':user, 'pageinfo': pageinfo, 'helptext_list':helptext_list })
def edit(request, id): if not check_user_login(request): return login(request) user = request.session.get("user") if request.method == "POST": form = ObjectForm(data=request.POST, user=user, id=id) if form.is_valid(): name = form.cleaned_data["name"] finishdate = form.cleaned_data["finishdate"] money = float(form.cleaned_data["money"]) currency = AccountService().getCurrency(form.cleaned_data["currency"]) accountlist = form.cleaned_data["accountlist"] description = form.cleaned_data["description"] ObjectService().editObject(id, name, finishdate, money, currency, accountlist, description, user) return HttpResponseRedirect("/object/") else: object = ObjectService().getObject(id, user) if object: object_currency_id = None if object.currency: object_currency_id = object.currency.id form = ObjectForm( initial={ "name": object.name, "finishdate": object.finishdate, "money": object.money, "currency": object_currency_id, "accountlist": object.accountlist, "description": object.description, }, user=user, id=id, ) else: return HttpResponseRedirect("/object/") page_title = ugettext("Edit Object") pageinfo = PageInfo(page_menu_name="Object", user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList("Object") form_action_url = "/object/edit/" + id return render_to_response( "common_add_edit.html", { "pageinfo": pageinfo, "helptext_list": helptext_list, "form_action_url": form_action_url, "form": form, "user": user, }, )
def delete(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') account = AccountService().getAccount(id, user) if account: if account.isclosed: return HttpResponseRedirect('/account/') AccountService().deleteAccount(id, user) return HttpResponseRedirect('/account/')
def moneyio_edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = MoneyIOForm(data=request.POST, user=user) if form.is_valid(): account = AccountService().getAccount(form.cleaned_data['account'], user) happentime = form.cleaned_data['happentime'] moneyiotype = MoneyService().getMoneyIOUserType(form.cleaned_data['moneyiotype'], user) money = form.cleaned_data['money'] currency = AccountService().getCurrency(form.cleaned_data['currency']) isshare = form.cleaned_data['isshare'] description = form.cleaned_data['description'] MoneyService().editMoneyIO(id, account, happentime, moneyiotype, money, currency, isshare, description, user) return HttpResponseRedirect('/moneyio/') else: moneyio = MoneyService().getMoneyIO(id, user) if moneyio: moneyio_account_id =None if moneyio.account: moneyio_account_id = moneyio.account.id moneyio_moneyiotype_id = None if moneyio.moneyiotype: moneyio_moneyiotype_id = moneyio.moneyiotype.id moneyio_currency_id = None if moneyio.currency: moneyio_currency_id = moneyio.currency.id form = MoneyIOForm(initial= {'account': moneyio_account_id, 'happentime':moneyio.happentime, 'moneyiotype':moneyio_moneyiotype_id, 'money':moneyio.money, 'currency':moneyio_currency_id, 'isshare':moneyio.isshare, 'description':moneyio.description}, user=user) else: return HttpResponseRedirect('/moneyio/') page_title=ugettext('Edit Money Income and Expense') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Money Income and Expense') form_action_url='/moneyio/edit/' + id return render_to_response('common_add_edit.html', {'pageinfo':pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user })
def detail(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Account', user=user) account = AccountService().getAccount(id, user) helptext_list = AdminService().getCategoryHelpTextList('Account') return render_to_response( 'account_detail.html', { 'account': account, 'user': user, 'pageinfo': pageinfo, 'helptext_list': helptext_list })
def moneyiousertype_index(request): if not check_user_login(request): return login(request) user = request.session.get('user') page_title=ugettext('Money Income and Expense Type') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Money Income and Expense') moneyiousertype_list = MoneyService().getMoneyIOUserTypeList(user) return render_to_response('moneyiousertype.html', {'moneyiousertype_list': moneyiousertype_list, 'user':user, 'pageinfo': pageinfo, 'helptext_list': helptext_list, })
def moneytransfer_index(request): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=ugettext('Money Transfer')) helptext_list = AdminService().getCategoryHelpTextList( 'Money Income and Expense') return render_to_response('moneytransfer.html', { 'user': user, 'pageinfo': pageinfo, 'helptext_list': helptext_list })
def add(request): if not check_user_login(request): return login(request) user = request.session.get('user') moneyiousertype_list = MoneyService().getMoneyIOUserTypeList(user) moneyiousertype_count = MoneyService().getMoneyIOUserTypeCount(user) BudgetDetailFormSet = formset_factory(BudgetDetailForm, max_num=moneyiousertype_count) if request.method == 'POST': budgetform = BudgetForm(request.POST) budgetdetailformset = BudgetDetailFormSet(request.POST) if budgetform.is_valid() and budgetdetailformset.is_valid(): name = budgetform.cleaned_data['name'] begindate = budgetform.cleaned_data['begindate'] enddate = budgetform.cleaned_data['enddate'] currency = AccountService().getCurrency(budgetform.cleaned_data['currency']) description = budgetform.cleaned_data['description'] budget = BudgetService().addBudget(name, begindate, enddate, currency, description, user) for budgetdetailform in budgetdetailformset.forms: moneyiousertypeid = budgetdetailform.cleaned_data['moneyiousertypeid'] moneyiousertype = MoneyService().getMoneyIOUserType(moneyiousertypeid, user) money = budgetdetailform.cleaned_data['money'] if money > 0.0 : BudgetService().addBudgetDetail(budget, moneyiousertype, money) return HttpResponseRedirect('/budget/') else: budgetform = BudgetForm() formsetinitdata=[{'moneyiousertypeid': moneyiousertype.id, 'moneyiousertypename': moneyiousertype.name, 'money': 0.0} for moneyiousertype in moneyiousertype_list] budgetdetailformset = BudgetDetailFormSet(initial=formsetinitdata) page_title=ugettext('Add Budget') pageinfo = PageInfo(page_menu_name='Budget', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Budget') form_action_url='/budget/add/' return render_to_response('budget_add_edit.html', {'helptext_list': helptext_list, 'form_action_url': form_action_url, 'budgetform': budgetform, 'budgetdetailformset': budgetdetailformset, 'user':user, 'pageinfo' : pageinfo })
def edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') account = AccountService().getAccount(id, user) if account: if account.isclosed: return HttpResponseRedirect('/account/') if request.method == 'POST': form = AccountForm(data=request.POST, id=id, user=user) if form.is_valid(): name = form.cleaned_data['name'] type = AccountService().getAccountType(form.cleaned_data['type']) currency = AccountService().getCurrency(form.cleaned_data['currency']) initmoney = float(form.cleaned_data['initmoney']) description = form.cleaned_data['description'] AccountService().editAccount(id, name, type, currency, initmoney, description, user) return HttpResponseRedirect('/account/') else: if account: account_type_id = None if account.type: account_type_id = account.type.id account_currency_id = None if account.currency: account_currency_id = account.currency.id form = AccountForm(initial= {'name': account.name, 'type':account_type_id, 'currency':account_currency_id, 'initmoney':account.initmoney, 'description':account.description}, id=id, user=user) else: return HttpResponseRedirect('/account/') page_title=ugettext('Edit Account') helptext_list = AdminService().getCategoryHelpTextList('Account') form_action_url='/account/edit/' + id page_module='Account' return render_to_response('common_add_edit.html', {'page_title':page_title, 'helptext_list':helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user, 'page_module' : page_module })
def detail_data(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') budget = BudgetService().getBudget(id, user) if budget: budgetdetail_list = BudgetService().getBudgetDetailList(budget) filter_dict = {'happentime >=': budget.begindate, 'happentime <=': budget.enddate} moneystat = MoneyService().getMoneyStat(filter_dict, budget.currency, user) for budgetdetail in budgetdetail_list: BudgetService().updateBudgetDetailActualMoney(budgetdetail, moneystat) jsondata = BudgetService().encode(budgetdetail_list) return HttpResponse(JSONEncoder().encode(jsondata)) else: return HttpResponse('')
def moneytransfer_edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = MoneyTransferForm(data=request.POST, user=user) if form.is_valid(): fromaccount = AccountService().getAccount(form.cleaned_data['fromaccount'], user) toaccount = AccountService().getAccount(form.cleaned_data['toaccount'], user) happentime = form.cleaned_data['happentime'] money = form.cleaned_data['money'] currency = AccountService().getCurrency(form.cleaned_data['currency']) description = form.cleaned_data['description'] MoneyService().editMoneyTransfer(id, fromaccount, toaccount, happentime, money, currency, description, user) return HttpResponseRedirect('/moneytransfer/') else: moneytransfer = MoneyService().getMoneyTransfer(id, user) if moneytransfer: moneytransfer_currency_id = None if moneytransfer.currency: moneytransfer_currency_id = moneytransfer.currency.id moneytransfer_fromaccount_id = None if moneytransfer.fromaccount: moneytransfer_fromaccount_id = moneytransfer.fromaccount.id moneytransfer_toaccount_id = None if moneytransfer.toaccount: moneytransfer_toaccount_id = moneytransfer.toaccount.id form = MoneyTransferForm(initial= {'fromaccount': moneytransfer_fromaccount_id, 'toaccount': moneytransfer_toaccount_id, 'happentime':moneytransfer.happentime, 'money':moneytransfer.money, 'currency':moneytransfer_currency_id, 'description':moneytransfer.description}, user=user) else: return HttpResponseRedirect('/moneytransfer/') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=ugettext('Edit Money Transfer')) helptext_list = AdminService().getCategoryHelpTextList('Money Income and Expense') form_action_url='/moneytransfer/edit/' + id return render_to_response('common_add_edit.html', {'pageinfo':pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user })
def detail(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') budget = BudgetService().getBudget(id, user) if budget: page_title = ugettext('Budget Detail') pageinfo = PageInfo(page_menu_name='Budget', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Budget') return render_to_response('budget_detail.html', {'budget': budget, 'user':user, 'helptext_list':helptext_list, 'pageinfo' : pageinfo }) else: return render_to_response('budget_detail.html', {'budget': None})
def add(request): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = AlarmForm(data=request.POST, user=user, id=None) if form.is_valid(): name = form.cleaned_data['name'] account = AccountService().getAccount(form.cleaned_data['account'], user) begindate = form.cleaned_data['begindate'] enddate = form.cleaned_data['enddate'] cycletype = form.cleaned_data['cycletype'] cyclevalue = form.cleaned_data['cyclevalue'] isautogenmoneyio = form.cleaned_data['isautogenmoneyio'] moneyiousertype = MoneyService().getMoneyIOUserType( form.cleaned_data['moneyiousertype'], user) money = form.cleaned_data['money'] currency = AccountService().getCurrency( form.cleaned_data['currency']) description = form.cleaned_data['description'] AlarmService().addAlarm(name, account, begindate, enddate, cycletype, cyclevalue, isautogenmoneyio, moneyiousertype, money, currency, description, user) return HttpResponseRedirect('/alarm/') else: form = AlarmForm(user=user, id=None) pageinfo = PageInfo(page_menu_name='Alarm', user=user, page_title=ugettext('Add Alarm')) helptext_list = AdminService().getCategoryHelpTextList('Alarm') form_action_url = '/alarm/add/' return render_to_response( 'common_add_edit.html', { 'pageinfo': pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user': user })
def moneyiousertype_index(request): if not check_user_login(request): return login(request) user = request.session.get('user') page_title = ugettext('Money Income and Expense Type') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList( 'Money Income and Expense') moneyiousertype_list = MoneyService().getMoneyIOUserTypeList(user) return render_to_response( 'moneyiousertype.html', { 'moneyiousertype_list': moneyiousertype_list, 'user': user, 'pageinfo': pageinfo, 'helptext_list': helptext_list, })
def edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = ObjectForm(data=request.POST, user=user, id=id) if form.is_valid(): name = form.cleaned_data['name'] finishdate = form.cleaned_data['finishdate'] money = float(form.cleaned_data['money']) currency = AccountService().getCurrency(form.cleaned_data['currency']) accountlist = form.cleaned_data['accountlist'] description = form.cleaned_data['description'] ObjectService().editObject(id, name, finishdate, money, currency, accountlist, description, user) return HttpResponseRedirect('/object/') else: object = ObjectService().getObject(id, user) if object: object_currency_id = None if object.currency: object_currency_id = object.currency.id form = ObjectForm(initial= {'name': object.name, 'finishdate':object.finishdate, 'money':object.money, 'currency':object_currency_id, 'accountlist':object.accountlist, 'description':object.description}, user=user, id=id) else: return HttpResponseRedirect('/object/') page_title=ugettext('Edit Object') pageinfo = PageInfo(page_menu_name='Object', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Object') form_action_url='/object/edit/' + id return render_to_response('common_add_edit.html', {'pageinfo':pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user':user })
def detail_data(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') budget = BudgetService().getBudget(id, user) if budget: budgetdetail_list = BudgetService().getBudgetDetailList(budget) filter_dict = { 'happentime >=': budget.begindate, 'happentime <=': budget.enddate } moneystat = MoneyService().getMoneyStat(filter_dict, budget.currency, user) for budgetdetail in budgetdetail_list: BudgetService().updateBudgetDetailActualMoney( budgetdetail, moneystat) jsondata = BudgetService().encode(budgetdetail_list) return HttpResponse(JSONEncoder().encode(jsondata)) else: return HttpResponse('')
def detail(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') budget = BudgetService().getBudget(id, user) if budget: page_title = ugettext('Budget Detail') pageinfo = PageInfo(page_menu_name='Budget', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Budget') return render_to_response( 'budget_detail.html', { 'budget': budget, 'user': user, 'helptext_list': helptext_list, 'pageinfo': pageinfo }) else: return render_to_response('budget_detail.html', {'budget': None})
def detail(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') object = ObjectService().getObject(id, user) object_list = [] if object: object_list.append(object) page_title = ugettext('Object Detail') pageinfo = PageInfo(page_menu_name='Object', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList('Object') account_list = AccountService().getAccountListByIDList(object.accountlist, user) return render_to_response('object_detail.html', {'object': object, 'object_list': object_list, 'user':user, 'pageinfo': pageinfo, 'helptext_list':helptext_list, 'account_list' : account_list }) else: return render_to_response('object_detail.html', {'object': None})
def moneyio_stat_index(request): if not check_user_login(request): return login(request) user = request.session.get('user') page_title = ugettext('Money Income and Expense Statistics') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList( 'Money Income and Expense') year = common.datetimeutil.year month = int(common.datetimeutil.month) yearmonthlist = [(year + '/' + str(i)) for i in range(1, month)] + [year + '/' + str(month)] account_id = '-1' currency_id = '-1' if request.method == 'POST': form = MoneyIOStatSearchForm(data=request.POST, user=user) if form.is_valid(): filter_dict = {} begindate = form.cleaned_data['begindate'] if begindate: filter_dict.update({'happentime >=': begindate}) enddate = form.cleaned_data['enddate'] if enddate: enddate = common.datetimeutil.getdayofday(enddate, 1) filter_dict.update({'happentime <': enddate}) account = AccountService().getAccount(form.cleaned_data['account'], user) if account: filter_dict.update({'account': account}) account_id = account.id currency = AccountService().getCurrency( form.cleaned_data['currency']) if currency: filter_dict.update({'currency': currency}) currency_id = currency.id else: form = MoneyIOStatSearchForm(user=user) try: yearmonth = request.GET['yearmonth'] except: yearmonth = '' if not yearmonth or yearmonth == '': yearmonth = year + '/' + str(month) begindate = datetime.datetime.strptime(yearmonth, '%Y/%m') enddate = common.datetimeutil.datetime_offset_by_month(begindate, 1) filter_dict = {'happentime >=': begindate, 'happentime <': enddate} begindatestr = datetime.datetime.strftime(begindate, '%Y-%m-%d') enddatestr = datetime.datetime.strftime(enddate, '%Y-%m-%d') '''getMoneyStatList will return a money stat list, every currency has one''' moneystat_list = MoneyService().getMoneyStatList(filter_dict, user) return render_to_response( 'moneyiostat.html', { 'yearmonthlist': yearmonthlist, 'form': form, 'moneystat_list': moneystat_list, 'begindate': begindatestr, 'enddate': enddatestr, 'account_id': account_id, 'currency_id': currency_id, 'user': user, 'pageinfo': pageinfo, 'helptext_list': helptext_list })
def moneyio_index(request): if not check_user_login(request): return login(request) user = request.session.get('user') pageinfo = PageInfo(page_menu_name='Money', user=user) helptext_list = AdminService().getCategoryHelpTextList( 'Money Income and Expense') year = common.datetimeutil.year month = int(common.datetimeutil.month) yearmonthlist = [(year + '/' + str(i)) for i in range(1, month)] + [year + '/' + str(month)] if request.method == 'POST': form = MoneyIOSearchForm(data=request.POST, user=user) if form.is_valid(): filter_dict = {} begindate = form.cleaned_data['begindate'] if begindate: filter_dict.update({'happentime >=': begindate}) enddate = form.cleaned_data['enddate'] if enddate: enddate = common.datetimeutil.getdayofday(enddate, 1) filter_dict.update({'happentime <': enddate}) account = AccountService().getAccount(form.cleaned_data['account'], user) if account: filter_dict.update({'account': account}) moneyiotype = MoneyService().getMoneyIOUserType( form.cleaned_data['moneyiotype'], user) if moneyiotype: filter_dict.update({'moneyiotype': moneyiotype}) currency = AccountService().getCurrency( form.cleaned_data['currency']) if currency: filter_dict.update({'currency': currency}) else: form = MoneyIOSearchForm(user=user) try: yearmonth = request.GET['yearmonth'] except: yearmonth = '' if not yearmonth or yearmonth == '': yearmonth = year + '/' + str(month) begindate = datetime.datetime.strptime(yearmonth, '%Y/%m') enddate = common.datetimeutil.datetime_offset_by_month(begindate, 1) filter_dict = {'happentime >=': begindate, 'happentime <': enddate} request.session['moneyio_filter_dict'] = filter_dict return render_to_response( 'moneyio.html', { 'user': user, 'pageinfo': pageinfo, 'helptext_list': helptext_list, 'yearmonthlist': yearmonthlist, 'form': form })
def moneyio_edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = MoneyIOForm(data=request.POST, user=user) if form.is_valid(): account = AccountService().getAccount(form.cleaned_data['account'], user) happentime = form.cleaned_data['happentime'] moneyiotype = MoneyService().getMoneyIOUserType( form.cleaned_data['moneyiotype'], user) money = form.cleaned_data['money'] currency = AccountService().getCurrency( form.cleaned_data['currency']) isshare = form.cleaned_data['isshare'] description = form.cleaned_data['description'] MoneyService().editMoneyIO(id, account, happentime, moneyiotype, money, currency, isshare, description, user) return HttpResponseRedirect('/moneyio/') else: moneyio = MoneyService().getMoneyIO(id, user) if moneyio: moneyio_account_id = None if moneyio.account: moneyio_account_id = moneyio.account.id moneyio_moneyiotype_id = None if moneyio.moneyiotype: moneyio_moneyiotype_id = moneyio.moneyiotype.id moneyio_currency_id = None if moneyio.currency: moneyio_currency_id = moneyio.currency.id form = MoneyIOForm(initial={ 'account': moneyio_account_id, 'happentime': moneyio.happentime, 'moneyiotype': moneyio_moneyiotype_id, 'money': moneyio.money, 'currency': moneyio_currency_id, 'isshare': moneyio.isshare, 'description': moneyio.description }, user=user) else: return HttpResponseRedirect('/moneyio/') page_title = ugettext('Edit Money Income and Expense') pageinfo = PageInfo(page_menu_name='Money', user=user, page_title=page_title) helptext_list = AdminService().getCategoryHelpTextList( 'Money Income and Expense') form_action_url = '/moneyio/edit/' + id return render_to_response( 'common_add_edit.html', { 'pageinfo': pageinfo, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user': user })
def edit(request, id): if not check_user_login(request): return login(request) user = request.session.get('user') if request.method == 'POST': form = AlarmForm(data=request.POST, user=user, id=id) if form.is_valid(): name = form.cleaned_data['name'] account = AccountService().getAccount(form.cleaned_data['account'], user) begindate = form.cleaned_data['begindate'] enddate = form.cleaned_data['enddate'] cycletype = form.cleaned_data['cycletype'] cyclevalue = form.cleaned_data['cyclevalue'] isautogenmoneyio = form.cleaned_data['isautogenmoneyio'] moneyiousertype = MoneyService().getMoneyIOUserType( form.cleaned_data['moneyiousertype'], user) money = form.cleaned_data['money'] currency = AccountService().getCurrency( form.cleaned_data['currency']) description = form.cleaned_data['description'] AlarmService().editAlarm(id, name, account, begindate, enddate, cycletype, cyclevalue, isautogenmoneyio, moneyiousertype, money, currency, description, user) return HttpResponseRedirect('/alarm/') else: alarm = AlarmService().getAlarm(id, user) if alarm: alarm_account_id = None if alarm.account: alarm_account_id = alarm.account.id alarm_moneyiousertype_id = None if alarm.moneyiousertype: alarm_moneyiousertype_id = alarm.moneyiousertype.id form = AlarmForm(initial={ 'name': alarm.name, 'account': alarm_account_id, 'begindate': alarm.begindate, 'enddate': alarm.enddate, 'cycletype': alarm.cycletype, 'cyclevalue': alarm.cyclevalue, 'isautogenmoneyio': alarm.isautogenmoneyio, 'moneyiousertype': alarm_moneyiousertype_id, 'money': alarm.money, 'currency': alarm.currency.id, 'description': alarm.description, }, user=user, id=id) else: return HttpResponseRedirect('/alarm/') page_title = ugettext('Edit Alarm') helptext_list = AdminService().getCategoryHelpTextList('Alarm') form_action_url = '/alarm/edit/' + id page_module = 'Alarm' return render_to_response( 'common_add_edit.html', { 'page_title': page_title, 'helptext_list': helptext_list, 'form_action_url': form_action_url, 'form': form, 'user': user, 'page_module': page_module })