예제 #1
0
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
        })
예제 #2
0
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
        })
예제 #3
0
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
        })
예제 #4
0
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
        })
예제 #5
0
def setting(request):
    if not check_user_login(request):
        return login(request)

    user = request.session.get('user')
    if request.method == 'POST':
        form = UserForm(data=request.POST, id=user.id)
        if form.is_valid():
            name = form.cleaned_data['name']
            gender = int(form.cleaned_data['gender'])
            email = form.cleaned_data['email']
            logo = form.cleaned_data['logo']
            isreceivemail = form.cleaned_data['isreceivemail']
            pagecount = form.cleaned_data['pagecount']
            if logo == '':
                logo = None
            UserService().editCoolUser(user.id, name, gender, email, logo,
                                       isreceivemail, pagecount)
    else:
        form = UserForm(initial={
            'name': user.name,
            'gender': user.gender,
            'logo': user.logo,
            'email': user.email,
            'isreceivemail': user.isreceivemail,
            'pagecount': user.pagecount
        },
                        id=user.id)
    '''
    sina_login_url = None
    if not user.sinaid:
        sina_login_url = _createSinaLoginUrl(request)
    '''
    google_login_url = None
    if not user.googleid:
        google_login_url = _createGoogleLoginUrl(request)
    user = UserService().getUser(user)
    request.session['user'] = user
    page_title = ugettext('Setting')
    pageinfo = PageInfo(page_menu_name='Setting',
                        user=user,
                        page_title=page_title)
    helptext_list = AdminService().getCategoryHelpTextList('Setting')
    form_action_url = '/setting/'
    return render_to_response(
        'user_setting.html',
        {
            'pageinfo': pageinfo,
            'form_action_url': form_action_url,
            'form': form,
            'user': user,
            'helptext_list': helptext_list,
            #'sina_login_url': sina_login_url,
            'google_login_url': google_login_url
        })
예제 #6
0
def index(request):
    if not check_user_login(request):
        return login(request)

    user = request.session.get('user')
    pageinfo = PageInfo(page_menu_name='Account', user=user)
    helptext_list = AdminService().getCategoryHelpTextList('Account')
    return render_to_response('account.html', {
        'user': user,
        'pageinfo': pageinfo,
        'helptext_list': helptext_list
    })
예제 #7
0
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
    })
예제 #8
0
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,
        })
예제 #9
0
def index(request):
    if not check_user_login(request):
        return login(request)

    helptext_list = AdminService().getCategoryHelpTextList('Home')
    user = request.session.get('user', None)
    pageinfo = PageInfo(page_menu_name='Home', user=user)

    begindate = datetime.datetime.strptime(
        common.datetimeutil.get_firstday_month(), '%Y-%m-%d')
    enddate = datetime.date.today()

    moneyio_list = MoneyService().getMoneyIOList(None, '-createtime', 5, 1,
                                                 user)[0]

    account_list = AccountService().getAccountList(None, '-createtime', 5, 1,
                                                   user)[0]

    object_list = ObjectService().getObjectList(None, '-createtime', 5, 1,
                                                user)[0]

    budget_filter_dict = {'begindate >=': begindate, 'begindate <=': enddate}
    budget_list = BudgetService().getBudgetList(budget_filter_dict,
                                                '-begindate', 5, 1, user)[0]

    errormessage = request.session.get('errormessage', None)
    request.session['errormessage'] = None

    return render_to_response(
        'index.html', {
            'user': user,
            'helptext_list': helptext_list,
            'pageinfo': pageinfo,
            'moneyio_list': moneyio_list,
            'account_list': account_list,
            'object_list': object_list,
            'budget_list': budget_list,
            'errormessage': errormessage
        })
예제 #10
0
def message_detail(request, id):
    if not check_user_login(request):
        return login(request)

    user = request.session.get('user')
    message = UserService().getUserMessage(id, user)
    if message:
        UserService().updateUserMessageRead(message)

    page_title = ugettext('Message Detail')
    pageinfo = PageInfo(page_menu_name='Setting',
                        user=user,
                        page_title=page_title)
    helptext_list = AdminService().getCategoryHelpTextList('Setting')

    return render_to_response(
        'message_detail.html', {
            'message': message,
            'user': user,
            'helptext_list': helptext_list,
            'pageinfo': pageinfo
        })
예제 #11
0
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
        })
예제 #12
0
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
        })
예제 #13
0
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
        })