# Path: aninstance_framework/base.py
# class AninstanceGenericView(AccessMixin, generic.View):
#     NEVER_CACHE_TTL = 0  # set to 0 to prevent caching when this TTL is selected
#     CACHE_TTL = settings.DEFAULT_CACHES_TTL
#     TEMPLATE_NAME = None
#     FOOTER_TEXT = None  # None value means default is used, as defined in custom_context_processors.py
#     PANEL_HEADING = None  # None value means default is used, as defined in custom_context_processors.py
#     PANEL_FOOTER = None  # None value means default is used, as defined in custom_context_processors.py
#     FRAGMENT_KEY = ''
#     USE_CACHE = settings.DEFAULT_USE_TEMPLATE_FRAGMENT_CACHING  # overridden in child views!
#     PAGINATION = False
#     PAGINATION_ITEMS_PER_PAGE = 5
#     PARAM_STR = 'default_param'
#     PAGE_STR = 'p'
#     STATUS_MESSAGE = None
#     AUTHENTICATION_REQUIRED = False  # authorization not required for views by default. Overwrite in CVBs for auth.
#     RIGHT_SIDEBAR_SEARCH_PLACEHOLDER_TEXT = _('Search for')
#     RIGHT_SIDEBAR_SEARCH_BUTTON_TEXT = _('Search')
#     MODELS_TO_SEARCH = {
#         '': [],  # e.g. '<url_action_param'>: ['<app.model>', '<app.another_model>']
#     }
# DEFAULT_FROM_EMAIL = settings.DEFAULT_FROM_EMAIL
# SITE_FQDN = settings.SITE_FQDN if not settings.DEBUG else 'localhost:8000'
#     def __init__(self, **kwargs):
#     def __str__(self):
#     def view_cacher(self, request):
#     def dispatch(self, request, *args, **kwargs):
#     def get(self, request):
#     def post(self, request):
# 
# Path: aninstance_framework/helpers.py
# def set_session_data(request):
# def get_page(request):
# def get_client_ip(request):
# def utc_to_local(value, client_timezone, autoescape=True):
# def format_utc_str_for_template(value, autoescape=True):
# def local_to_utc(value):
# def is_num(value):
# def update_url_param(request, param_name):
# def remove_url_param(request, param):
# def strip_url_params(request):
# def sanitize_url_param(param):
# def sanitize_post_data(data):
# def format_data_for_display(data, file_formatting, media_type):
# def phrase_check(string):
# 
# Path: aninstance_framework/auth.py
# def auth(self):
#     return self.test_func()
# 
# Path: invoicing/forms.py
# class AccountForm(ModelForm):
#     class Meta:
# class InvoiceForm(ModelForm):
#     class Meta:
#     class MyNumberInput(TextInput):
# class InvoiceItemForm(ModelForm):
#     class Meta:
#     def __init__(self, *args, **kwargs):
#     def clean_logo(self):
#     def __init__(self, *args, **kwargs):
#     def __init__(self, *args, **kwargs):
# 
# Path: aninstance_framework/search_forms.py
# class RightSidebarSearchForm(SearchForm):
#     # override elements of default SearchForm to add styling classes to fields
# 
#     def __init__(self, *args, **kwargs):
#         super(RightSidebarSearchForm, self).__init__()
#         self.placeholder = kwargs.get('placeholder') if 'placeholder' in kwargs else _('Search')
#         self.fields['q'] = forms.CharField(required=False,
#                                            label=_('Search for'),
#                                            widget=forms.TextInput(attrs={'type': 'search',
#                                                                          'class': 'form-control',
#                                                                          'size': '15',
#                                                                          'placeholder': self.placeholder,
#                                                                          }))
# 
#     def get_models(self):
#         return self.models
# 
#     def search(self):
#         # First, store the SearchQuerySet received from other processing.
#         sqs = super(RightSidebarSearchForm, self).search()
#         if not self.is_valid():
#             return self.no_query_found()
#         return sqs


import smtplib
import decimal
import html2text
from django.db.models import Q
from django.shortcuts import render, redirect
from django.template import RequestContext
from django.template.loader import get_template
from django.test import RequestFactory
from weasyprint import HTML, CSS
from aninstance_framework import base, helpers, auth
from invoicing import forms
from invoicing.models import *
from django.conf import settings
from math import ceil
from django.db import IntegrityError
from aninstance_framework.search_forms import RightSidebarSearchForm
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext as __
from collections import OrderedDict
from django.utils import timezone as utc
from django.http import HttpResponse
from django.core.mail import EmailMultiAlternatives
from django.core.files.uploadedfile import SimpleUploadedFile
from django.template.loader import render_to_string
    """
    GET REQUEST HANDLERS
    """

    def default_view(self, request):
        self.context.update({'panel_heading': _('Invoicing'),
                             'dash_blurb': _('Please select a task from the menu above!'),
                             'dash_image': '{}/{}'.format(settings.STATIC_URL,
                                                          'images/aninstance_invoicing_wierd_logo.png'),
                             })
        return render(request, self.TEMPLATE_NAME, self.context)

    def app_docs_view(self, request):
        self.context.update({
            'panel_heading': _('Documents: Usage Instructions'),
            'dash_blurb': _('Usage instructions for Aninstance Invoicing'),
        })
        return render(request, self.TEMPLATE_NAME, self.context)

    def create_or_edit_account(self, request, account_id=None):
        """
        Note: A business profile is just another Client profile, but with "own_business" field set to "True".
        """
        if account_id:  # edit existing client account
            try:
                # set initial and get existing instance
                initial = {self.POST_ACTION_FIELD: self.PARAM_STR_POST_ACTION_EDIT_ACCOUNT,
                           self.POST_ACCOUNT_ID_FIELD: account_id}
                existing_instance = Account.objects.get(account_id=account_id)
                # create the form

# Path: aninstance_framework/base.py
# class AninstanceGenericView(AccessMixin, generic.View):
#     NEVER_CACHE_TTL = 0  # set to 0 to prevent caching when this TTL is selected
#     CACHE_TTL = settings.DEFAULT_CACHES_TTL
#     TEMPLATE_NAME = None
#     FOOTER_TEXT = None  # None value means default is used, as defined in custom_context_processors.py
#     PANEL_HEADING = None  # None value means default is used, as defined in custom_context_processors.py
#     PANEL_FOOTER = None  # None value means default is used, as defined in custom_context_processors.py
#     FRAGMENT_KEY = ''
#     USE_CACHE = settings.DEFAULT_USE_TEMPLATE_FRAGMENT_CACHING  # overridden in child views!
#     PAGINATION = False
#     PAGINATION_ITEMS_PER_PAGE = 5
#     PARAM_STR = 'default_param'
#     PAGE_STR = 'p'
#     STATUS_MESSAGE = None
#     AUTHENTICATION_REQUIRED = False  # authorization not required for views by default. Overwrite in CVBs for auth.
#     RIGHT_SIDEBAR_SEARCH_PLACEHOLDER_TEXT = _('Search for')
#     RIGHT_SIDEBAR_SEARCH_BUTTON_TEXT = _('Search')
#     MODELS_TO_SEARCH = {
#         '': [],  # e.g. '<url_action_param'>: ['<app.model>', '<app.another_model>']
#     }
# DEFAULT_FROM_EMAIL = settings.DEFAULT_FROM_EMAIL
# SITE_FQDN = settings.SITE_FQDN if not settings.DEBUG else 'localhost:8000'
#     def __init__(self, **kwargs):
#     def __str__(self):
#     def view_cacher(self, request):
#     def dispatch(self, request, *args, **kwargs):
#     def get(self, request):
#     def post(self, request):
# 
# Path: aninstance_framework/helpers.py
# def set_session_data(request):
# def get_page(request):
# def get_client_ip(request):
# def utc_to_local(value, client_timezone, autoescape=True):
# def format_utc_str_for_template(value, autoescape=True):
# def local_to_utc(value):
# def is_num(value):
# def update_url_param(request, param_name):
# def remove_url_param(request, param):
# def strip_url_params(request):
# def sanitize_url_param(param):
# def sanitize_post_data(data):
# def format_data_for_display(data, file_formatting, media_type):
# def phrase_check(string):
# 
# Path: aninstance_framework/auth.py
# def auth(self):
#     return self.test_func()
# 
# Path: invoicing/forms.py
# class AccountForm(ModelForm):
#     class Meta:
# class InvoiceForm(ModelForm):
#     class Meta:
#     class MyNumberInput(TextInput):
# class InvoiceItemForm(ModelForm):
#     class Meta:
#     def __init__(self, *args, **kwargs):
#     def clean_logo(self):
#     def __init__(self, *args, **kwargs):
#     def __init__(self, *args, **kwargs):
# 
# Path: aninstance_framework/search_forms.py
# class RightSidebarSearchForm(SearchForm):
#     # override elements of default SearchForm to add styling classes to fields
# 
#     def __init__(self, *args, **kwargs):
#         super(RightSidebarSearchForm, self).__init__()
#         self.placeholder = kwargs.get('placeholder') if 'placeholder' in kwargs else _('Search')
#         self.fields['q'] = forms.CharField(required=False,
#                                            label=_('Search for'),
#                                            widget=forms.TextInput(attrs={'type': 'search',
#                                                                          'class': 'form-control',
#                                                                          'size': '15',
#                                                                          'placeholder': self.placeholder,
#                                                                          }))
# 
#     def get_models(self):
#         return self.models
# 
#     def search(self):
#         # First, store the SearchQuerySet received from other processing.
#         sqs = super(RightSidebarSearchForm, self).search()
#         if not self.is_valid():
#             return self.no_query_found()
#         return sqs


# Path: invoicing/views.py
import smtplib
import decimal
import html2text
from django.db.models import Q
from django.shortcuts import render, redirect
from django.template import RequestContext
from django.template.loader import get_template
from django.test import RequestFactory
from weasyprint import HTML, CSS
from aninstance_framework import base, helpers, auth
from invoicing import forms
from invoicing.models import *
from django.conf import settings
from math import ceil
from django.db import IntegrityError
from aninstance_framework.search_forms import RightSidebarSearchForm
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext as __
from collections import OrderedDict
from django.utils import timezone as utc
from django.http import HttpResponse
from django.core.mail import EmailMultiAlternatives
from django.core.files.uploadedfile import SimpleUploadedFile
from django.template.loader import render_to_string

    """
    GET REQUEST HANDLERS
    """

    def default_view(self, request):
        self.context.update({'panel_heading': _('Invoicing'),
                             'dash_blurb': _('Please select a task from the menu above!'),
                             'dash_image': '{}/{}'.format(settings.STATIC_URL,
                                                          'images/aninstance_invoicing_wierd_logo.png'),
                             })
        return render(request, self.TEMPLATE_NAME, self.context)

    def app_docs_view(self, request):
        self.context.update({
            'panel_heading': _('Documents: Usage Instructions'),
            'dash_blurb': _('Usage instructions for Aninstance Invoicing'),
        })
        return render(request, self.TEMPLATE_NAME, self.context)

    def create_or_edit_account(self, request, account_id=None):
        """
        Note: A business profile is just another Client profile, but with "own_business" field set to "True".
        """
        if account_id:  # edit existing client account
            try:
                # set initial and get existing instance
                initial = {self.POST_ACTION_FIELD: self.PARAM_STR_POST_ACTION_EDIT_ACCOUNT,
                           self.POST_ACCOUNT_ID_FIELD: account_id}
                existing_instance = Account.objects.get(account_id=account_id)
                # create the form

                form = forms.AccountForm(instance=existing_instance,