# Path: payway/accounts/views/add_account.py
# class AddAccountView(TemplateView):
#     template_name = 'accounts/list.html'
# 
#     MESSAGES =  {
#         'WRONG_CURRENCY':  _('Currency not allowed!'),
#     }
# 
#     def get(self, request, *args, **kwargs):
#         currency = kwargs.get('currency')
#         if currency not in dict(CURRENCY_CHOICES).keys():
#             messages.warning(request, self.MESSAGES['WRONG_CURRENCY'])
#         else:
#             request.user.accounts.create(user=request.user, currency=currency)
#         return redirect('accounts_list')
# 
# Path: payway/accounts/views/add_money.py
# class AddMoneyView(TemplateView):
#     template_name = 'accounts/add_money.html'
# 
#     def get(self, request, *args, **kwargs):
# 
#         account_uid = int(kwargs.get('account_uid', -1))
#         invoice_uid = int(kwargs.get('invoice_uid', -1))
#         account = get_object_or_404(Account, uid=account_uid)
# 
#         invoice, created = Invoice.objects.get_or_create(
#             uid=invoice_uid,
#             account=account,
#             defaults={
#                 'account': account,
#                 'money_amount': Money(ADD_MONEY_INITIAL_SUM, account.currency)
#             }
#         )
# 
#         context = super(AddMoneyView, self).get_context_data(**kwargs)
#         context['add_money_form'] = AddMoneyForm({
#             'money_amount': invoice.money_amount_without_percent.amount,
#             'payment_system': dict(PAYMENT_SYSTEM_CHOICES).keys()[0],
#             'invoice_uid': invoice.uid
#         })
# 
#         return self.render_to_response(context)
# 
#     def post(self, request):
#         form = AddMoneyForm(request.POST or None)
#         if form.is_valid():
#             invoice = get_object_or_404(Invoice, uid=form.cleaned_data.get('invoice_uid'))
#             new_money_amount = form.cleaned_data.get('money_amount')
#             invoice.money_amount = Money(new_money_amount, invoice.money_amount.currency)
#             invoice.save()
#             return redirect(form.cleaned_data['payment_system'], invoice_uid=invoice.uid)
# 
#         return self.render_to_response({'add_money_form': form})
# 
# Path: payway/accounts/views/invoices_list.py
# class InvoicesListListView(TemplateView):
#     template_name = 'accounts/invoices_list.html'
# 
# 
#     def get(self, request, *args, **kwargs):
#         account_uid = int(kwargs.get('account_uid', -1))
#         account = get_object_or_404(Account, uid=account_uid)
# 
#         invoices_page = create_paginated_page(
#             query_set=account.invoices.all().order_by('-created'),
#             page_number=request.GET.get('page') or 1,
#             objects_per_page=INVOICES_PER_PAGE
#         )
#         return self.render_to_response({'invoices_page': invoices_page})
# 
# Path: payway/accounts/views/list.py
# class AccountsListView(TemplateView):
#     template_name = 'accounts/list.html'
# 
#     def get(self, request):
#         accounts_page = create_paginated_page(
#             query_set=Account.objects.filter(user=request.user).order_by('-id'),
#             page_number=request.GET.get('page') or 1,
#             objects_per_page=ACCOUNTS_PER_PAGE
#         )
#         return self.render_to_response({'accounts_page': accounts_page })
# 
# Path: payway/accounts/views/statement.py
# class AccountStatementView(TemplateView):
#     template_name = 'accounts/statement.html'
# 
#     def get(self, request, *args, **kwargs):
#         account_uid = int(kwargs.get('account_uid', -1))
#         account = get_object_or_404(Account, uid=account_uid)
# 
#         transactions_page = create_paginated_page(
#             query_set=Transaction.objects.filter(account=account).order_by('-created'),
#             page_number=request.GET.get('page') or 1,
#             objects_per_page=TRANSACTIONS_PER_PAGE
#         )
#         return self.render_to_response({'transactions_page': transactions_page})


from django.conf.urls.defaults import patterns, url
from django.contrib.auth.decorators import login_required
from payway.accounts.views.add_account import AddAccountView
from payway.accounts.views.add_money import AddMoneyView
from payway.accounts.views.invoices_list import InvoicesListListView
from payway.accounts.views.list import AccountsListView
from payway.accounts.views.statement import AccountStatementView
# -*- coding: UTF-8 -*-


__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


urlpatterns = patterns('',
    url(r'^add-money/(?P<account_uid>\d+)/(?P<invoice_uid>\d+)$', login_required(AddMoneyView.as_view()), name='accounts_add_money'),
    url(r'^add-money/(?P<account_uid>\d+)/$', login_required(AddMoneyView.as_view()), name='accounts_add_money'),

# Path: payway/accounts/views/add_account.py
# class AddAccountView(TemplateView):
#     template_name = 'accounts/list.html'
# 
#     MESSAGES =  {
#         'WRONG_CURRENCY':  _('Currency not allowed!'),
#     }
# 
#     def get(self, request, *args, **kwargs):
#         currency = kwargs.get('currency')
#         if currency not in dict(CURRENCY_CHOICES).keys():
#             messages.warning(request, self.MESSAGES['WRONG_CURRENCY'])
#         else:
#             request.user.accounts.create(user=request.user, currency=currency)
#         return redirect('accounts_list')
# 
# Path: payway/accounts/views/add_money.py
# class AddMoneyView(TemplateView):
#     template_name = 'accounts/add_money.html'
# 
#     def get(self, request, *args, **kwargs):
# 
#         account_uid = int(kwargs.get('account_uid', -1))
#         invoice_uid = int(kwargs.get('invoice_uid', -1))
#         account = get_object_or_404(Account, uid=account_uid)
# 
#         invoice, created = Invoice.objects.get_or_create(
#             uid=invoice_uid,
#             account=account,
#             defaults={
#                 'account': account,
#                 'money_amount': Money(ADD_MONEY_INITIAL_SUM, account.currency)
#             }
#         )
# 
#         context = super(AddMoneyView, self).get_context_data(**kwargs)
#         context['add_money_form'] = AddMoneyForm({
#             'money_amount': invoice.money_amount_without_percent.amount,
#             'payment_system': dict(PAYMENT_SYSTEM_CHOICES).keys()[0],
#             'invoice_uid': invoice.uid
#         })
# 
#         return self.render_to_response(context)
# 
#     def post(self, request):
#         form = AddMoneyForm(request.POST or None)
#         if form.is_valid():
#             invoice = get_object_or_404(Invoice, uid=form.cleaned_data.get('invoice_uid'))
#             new_money_amount = form.cleaned_data.get('money_amount')
#             invoice.money_amount = Money(new_money_amount, invoice.money_amount.currency)
#             invoice.save()
#             return redirect(form.cleaned_data['payment_system'], invoice_uid=invoice.uid)
# 
#         return self.render_to_response({'add_money_form': form})
# 
# Path: payway/accounts/views/invoices_list.py
# class InvoicesListListView(TemplateView):
#     template_name = 'accounts/invoices_list.html'
# 
# 
#     def get(self, request, *args, **kwargs):
#         account_uid = int(kwargs.get('account_uid', -1))
#         account = get_object_or_404(Account, uid=account_uid)
# 
#         invoices_page = create_paginated_page(
#             query_set=account.invoices.all().order_by('-created'),
#             page_number=request.GET.get('page') or 1,
#             objects_per_page=INVOICES_PER_PAGE
#         )
#         return self.render_to_response({'invoices_page': invoices_page})
# 
# Path: payway/accounts/views/list.py
# class AccountsListView(TemplateView):
#     template_name = 'accounts/list.html'
# 
#     def get(self, request):
#         accounts_page = create_paginated_page(
#             query_set=Account.objects.filter(user=request.user).order_by('-id'),
#             page_number=request.GET.get('page') or 1,
#             objects_per_page=ACCOUNTS_PER_PAGE
#         )
#         return self.render_to_response({'accounts_page': accounts_page })
# 
# Path: payway/accounts/views/statement.py
# class AccountStatementView(TemplateView):
#     template_name = 'accounts/statement.html'
# 
#     def get(self, request, *args, **kwargs):
#         account_uid = int(kwargs.get('account_uid', -1))
#         account = get_object_or_404(Account, uid=account_uid)
# 
#         transactions_page = create_paginated_page(
#             query_set=Transaction.objects.filter(account=account).order_by('-created'),
#             page_number=request.GET.get('page') or 1,
#             objects_per_page=TRANSACTIONS_PER_PAGE
#         )
#         return self.render_to_response({'transactions_page': transactions_page})


# Path: payway/accounts/urls.py
from django.conf.urls.defaults import patterns, url
from django.contrib.auth.decorators import login_required
from payway.accounts.views.add_account import AddAccountView
from payway.accounts.views.add_money import AddMoneyView
from payway.accounts.views.invoices_list import InvoicesListListView
from payway.accounts.views.list import AccountsListView
from payway.accounts.views.statement import AccountStatementView

# -*- coding: UTF-8 -*-


__author__ = 'Razzhivin Alexander'
__email__ = 'admin@httpbots.com'


urlpatterns = patterns('',
    url(r'^add-money/(?P<account_uid>\d+)/(?P<invoice_uid>\d+)$', login_required(AddMoneyView.as_view()), name='accounts_add_money'),
    url(r'^add-money/(?P<account_uid>\d+)/$', login_required(AddMoneyView.as_view()), name='accounts_add_money'),

    url(r'^add-money/$', login_required(AddMoneyView.as_view()), name='accounts_add_money'),