예제 #1
0
 def get(self, request, *args, **kwargs):
     if (request.path in [site_prefixed('/app'),
                          site_prefixed('/app/')]
             and self.manages(settings.APP_NAME)):
         return http.HttpResponseRedirect(
             reverse('homepage_organization', args=(settings.APP_NAME, )))
     return super(AccountRedirectView, self).get(request, *args, **kwargs)
예제 #2
0
 def get_context_data(self, **kwargs):
     context = super(SuppliersView, self).get_context_data(**kwargs)
     root, trail = self.breadcrumbs
     update_context_urls(context, {
         'api_suppliers': reverse('api_suppliers',
             args=(self.account, root)),
         'api_accessibles': site_prefixed(
             "/api/profile/%(account)s/plans/%(account)s-report/"\
             "subscriptions/" % {'account': self.account}),
         'api_organizations': site_prefixed("/api/profile/"),
         'api_organization_profile': site_prefixed(
             "/api/profile/%(account)s/" % {'account': self.account}),
         'download': reverse('reporting_organization_download',
                             args=(self.account, root)),
         'improvements_download': reverse(
             'reporting_organization_improvements_download',
             args=(self.account, root))
     })
     try:
         extra = json.loads(self.account.extra)
     except (IndexError, TypeError, ValueError) as err:
         extra = {}
     start_at = extra.get('start_at', None)
     context.update({
         'score_toggle': True,
         'account_extra': self.account.extra,
         'date_range': {
             'start_at': start_at,
             'ends_at': (datetime_or_now() + relativedelta(days=1)
             ).isoformat(),
         }
     })
     return context
예제 #3
0
    def get_context_data(self, **kwargs):
        context = super(ImprovementView, self).get_context_data(**kwargs)
        segment_url, segment_prefix, segment_element = self.segment

        organization = context['organization']
        update_context_urls(
            context, {
                'api_improvements':
                reverse('api_improvement_base', args=(organization, )),
                'api_organizations':
                site_prefixed("/api/profile/"),
                'api_viewers':
                site_prefixed("/api/profile/%s/roles/viewers/" % self.account),
            })
        if self.improvement_sample:
            update_context_urls(
                context, {
                    'print':
                    reverse('improve_organization_sample_print',
                            args=(organization, self.improvement_sample,
                                  '/%s' % segment_prefix.split('/')[-1])),
                    'download':
                    reverse('improve_organization_sample_download',
                            args=(organization, self.improvement_sample,
                                  '/%s' % segment_prefix.split('/')[-1]))
                })
        if self.assessment_sample:
            update_context_urls(
                context, {
                    'api_account_benchmark':
                    reverse('api_benchmark',
                            args=(organization, self.assessment_sample,
                                  segment_prefix))
                })
        return context
예제 #4
0
 def get_context_data(self, **kwargs):
     context = super(ShareView, self).get_context_data(**kwargs)
     from_root, trail = self.breadcrumbs
     # Find supplier managers subscribed to this profile
     # to share scorecard with.
     is_account_manager = self.manages(self.account)
     if is_account_manager:
         context.update({'is_account_manager': is_account_manager})
     context.update({
         'supplier_managers':
         json.dumps(get_supplier_managers(self.account))
     })
     update_context_urls(
         context, {
             'api_scorecard_share':
             reverse('api_scorecard_share',
                     args=(context['organization'], from_root[1:])),
             'api_organizations':
             site_prefixed("/api/profile/"),
             'api_viewers':
             site_prefixed("/api/profile/%s/roles/viewers/" % self.account),
         })
     breadcrumbs = context.get('breadcrumbs', [])
     if breadcrumbs:
         context.update({'segment_title': breadcrumbs[0][0].title})
     context.update({'sample': self.sample})
     return context
예제 #5
0
파일: mixins.py 프로젝트: HelpPal/tcap
 def fail_requires_subscription(request, application):
     for organization in request.session.get('roles',
                                             {}).get('manager', []):
         if organization.get('slug') == application.lihtc_property.slug:
             for subscription in organization.get('subscriptions', []):
                 if application.created_at < parse_datetime(
                         subscription['ends_at']):
                     return None
     return site_prefixed('/pricing/')
예제 #6
0
파일: application.py 프로젝트: HelpPal/tcap
 def get_context_data(self, **kwargs):
     context = super(ApplicationDocumentsView, self).get_context_data(
         **kwargs)
     context.update({'application_js': self.get_application_context()})
     self.update_context_urls(context, {
         'edit': {'media_upload': site_prefixed("/api/credentials/%s/"
             % str(self.application.lihtc_property))},
         'api_document_upload': reverse('api_document_upload',
             args=(self.application.lihtc_property, self.application))})
     return context
예제 #7
0
 def get_context_data(self, **kwargs):
     context = super(ReportingEntitiesView, self).get_context_data(**kwargs)
     accounts = self.managed_accounts
     if len(accounts) == 1:
         totals = get_object_or_404(Matrix,
                                    account__slug=accounts[0],
                                    metric__slug='totals')
         totals_chart_url = reverse('matrix_chart',
                                    args=(accounts[0], '/%s' % totals.slug))
     else:
         totals_chart_url = reverse('envconnect_portfolio',
                                    args=('/totals', ))
     urls = {
         'api_suppliers': reverse('api_suppliers', args=(self.account,)),
         'api_accessibles': site_prefixed(
             "/api/profile/%(account)s/plans/%(account)s-reporting/"\
             "subscriptions/" % {'account': self.account}),
         'api_organizations': site_prefixed("/api/profile/"),
         'totals_chart': totals_chart_url,
     }
     context.update({'score_toggle': True})
     self.update_context_urls(context, urls)
     return context
예제 #8
0
def path_to_legend(root):
    legend = 'legend-1'
    try:
        tags = json.loads(root[0]['tag'])['tags']
        for tag in tags:
            if tag.startswith('legend'):
                legend = tag
                break
    except json.JSONDecodeError:
        pass
    except TypeError:
        # If we have a pb, better to use a default legend rather than
        # blowing up with a 500 error.
        pass
    return site_prefixed("/docs/" + legend + "/")
예제 #9
0
파일: application.py 프로젝트: HelpPal/tcap
 def get_context_data(self, **kwargs):
     context = super(ApplicationBaseView, self).get_context_data(**kwargs)
     by_accounts = {}
     for account in self.managed_accounts:
         try:
             project = Property.objects.get(slug=account)
             project.urls = {'api': {'applications': reverse(
                 'api_applications', args=(project,))}}
             by_accounts[account] = {'project': project}
         except Property.DoesNotExist:
             # ``request.user`` could be a manager for tcapp proper.
             pass
     url_projects = reverse('project_search')
     if not self.manages(settings.APP_NAME):
         url_projects = "%s?next=%s" % (
             site_prefixed('logout/'), url_projects)
     context.update({'by_accounts': by_accounts,
         'statuses': [
             (str(status[1]), Application.HUMANIZED_STATUS[status[0]][1])
             for status in Application.STATUS],
         'urls': {'applications': reverse('application_base'),
                  'projects': url_projects}})
     return context
예제 #10
0
    def get_context_data(self, **kwargs):
        #pylint:disable=too-many-statements
        context = super(UpdateIncomeView, self).get_context_data(**kwargs)
        incomes = []
        source = {'avg_per_year': 1}
        group = self.kwargs.get(self.slug_url_kwarg, None)
        today = datetime_or_now(datetime.date.today())
        beg_of_year = datetime_or_now(datetime.date(today.year, 1, 1))
        self.update_context_urls(
            context, {
                'edit': {
                    'media_upload':
                    site_prefixed("/api/credentials/%s/" %
                                  str(self.application.lihtc_property))
                },
                'api_document_upload':
                reverse(
                    'api_document_upload',
                    args=(self.application.lihtc_property, self.application))
            })
        if group is not None:
            income_url = reverse('tenant_income_entry',
                                 args=(self.application.lihtc_property,
                                       self.resident, group))
        else:
            income_url = self.request.path
        self.update_context_urls(context, {'income': income_url})
        categories = []
        if self.question.pk in Question.INCOME_EMPLOYEE:
            categories = Income.EMPLOYEE_CATEGORY
        elif self.question.pk in Question.CHILD_SPOUSAL_SUPPORT:
            for category in Question.CHILD_SPOUSAL_SUPPORT:
                if self.get_queryset().filter(category=category).exists():
                    categories = [category]
                    break
            if not categories:
                categories = [Question.CHILD_SPOUSAL_SUPPORT[0]]
        elif self.question.pk in Question.INCOME_TRUSTS:
            for category in Income.TRUSTS_CATEGORY:
                if self.get_queryset().filter(category=category).exists():
                    categories = [category]
                    break
            if not categories:
                categories = [Income.PENSIONS]
        else:
            categories = [Income.OTHER]
        for category in categories:
            income = None
            if group is not None:
                try:
                    income = self.get_queryset().get(category=category)
                    # Find supporting documentation.
                    documents = UploadedDocument.objects.filter(
                        application=self.application,
                        resident=self.resident,
                        source=income.source)
                    source.update(SourceSerializer().to_representation(
                        income.source))
                    source.update({
                        'verified':
                        Income.VERIFIED_SLUG[income.verified],
                        'starts_at':
                        datetime_or_now(income.starts_at).isoformat(),
                        'ends_at':
                        datetime_or_now(income.ends_at).isoformat(),
                        'cash_wages':
                        income.cash_wages,
                        'docs':
                        UploadedDocumentSerializer(
                            many=True).to_representation(documents)
                    })
                    incomes.append(
                        IncomeSerializer().to_representation(income))
                except Income.DoesNotExist:
                    income = None
            if income is None:
                incomes.append(IncomeSerializer().to_representation(
                    Income(resident=self.resident,
                           question=self.question,
                           source=None,
                           period=Income.MONTHLY,
                           verified=Income.VERIFIED_EMPLOYER,
                           category=category,
                           starts_at=beg_of_year,
                           ends_at=today)))

        if 'verified' not in source:
            context.update({
                'sources':
                json.dumps(
                    SourceSerializer(many=True).to_representation(
                        Source.objects.filter(resident=self.resident).order_by(
                            '-pk').distinct()))
            })
            self.update_context_urls(
                context, {
                    'add_source':
                    "%s?next=%s" %
                    (reverse('tenant_income_source_new',
                             args=(
                                 self.application.lihtc_property,
                                 self.resident,
                             )), self.request.path)
                })
            source.update({'verified': ""})
        source.update({"incomes": incomes})
        rel = ApplicationResident.objects.filter(
            application=self.application, resident=self.resident).first()
        if rel:
            relation_to_head = rel.get_relation_to_head_display()
        else:
            relation_to_head = None
        context.update({
            'entry_position':
            self.get_entry_position(),
            'entry_title':
            self.get_entry_title(),
            'entry_slug':
            self.get_entry_slug(),
            'lihtc_property':
            self.application.lihtc_property,
            'application_js':
            self.get_application_context(
                tenants=[{
                    "slug": self.resident.slug,
                    "email": self.resident.email,
                    "phone": self.resident.phone,
                    "relation_to_head": relation_to_head,
                    self.get_entry_slug(): [source]
                }]),
        })
        return context
예제 #11
0
    def get_context_data(self, **kwargs):
        context = super(UpdateAssetsView, self).get_context_data(**kwargs)
        assets = []
        source = {}
        group = self.kwargs.get(self.slug_url_kwarg, None)
        self.update_context_urls(
            context, {
                'edit': {
                    'media_upload':
                    site_prefixed("/api/credentials/%s/" %
                                  str(self.application.lihtc_property))
                },
                'api_document_upload':
                reverse(
                    'api_document_upload',
                    args=(self.application.lihtc_property, self.application))
            })
        if group is not None:
            self.update_context_urls(
                context, {
                    'asset':
                    reverse('tenant_asset_entry',
                            args=(self.application.lihtc_property,
                                  self.resident, group))
                })
        if group is not None:
            assets = self.get_queryset().filter(slug=group)
            # Find supporting documentation.
            documents = UploadedDocument.objects.filter(
                application=self.application,
                resident=self.resident,
                source__in=[asset.source for asset in assets])
        if assets:
            source.update(SourceSerializer().to_representation(
                assets[0].source))
            source.update({
                'verified':
                Asset.VERIFIED_SLUG[assets[0].verified],
                'docs':
                UploadedDocumentSerializer(
                    many=True).to_representation(documents)
            })
            assets = AssetSerializer(many=True).to_representation(assets)
        else:
            assets = [
                AssetSerializer().to_representation(
                    Asset(category=Asset.BANK_CHECKING,
                          resident=self.resident,
                          source=None))
            ]
        # Avoid an error on the way back because `{'question': null}`.
        for asset in assets:
            if 'question' in asset and not asset['question']:
                del asset['question']

        if 'verified' not in source:
            context.update({
                'sources':
                json.dumps(
                    SourceSerializer(many=True).to_representation(
                        Source.objects.filter(resident=self.resident).order_by(
                            '-pk').distinct()))
            })
            self.update_context_urls(
                context, {
                    'add_source':
                    "%s?next=%s" %
                    (reverse('tenant_asset_source_new',
                             args=(
                                 self.application.lihtc_property,
                                 self.resident,
                             )), self.request.path)
                })
            source.update({'verified': ""})
        source.update({"assets": assets})
        rel = ApplicationResident.objects.filter(
            application=self.application, resident=self.resident).first()
        if rel:
            relation_to_head = rel.get_relation_to_head_display()
        else:
            relation_to_head = None
        context.update({
            'lihtc_property':
            self.application.lihtc_property,
            'application_js':
            self.get_application_context(tenants=[{
                "slug": self.resident.slug,
                "email": self.resident.email,
                "phone": self.resident.phone,
                "relation_to_head": relation_to_head,
                "fiduciaries": [source]
            }]),
        })
        return context
예제 #12
0
from deployutils.apps.django.templatetags.deployutils_prefixtags import (
    site_prefixed)
from rules.urldecorators import include, url

from ...views.redirects import AccountRedirectView, MyTSPRedirectView
from ...views.detail import ContentDetailXLSXView, DetailView, DetailXLSXView

PATH_RE = r'(/[a-zA-Z0-9\-]+)*'

urlpatterns = [

    # authenticated user
    url(r'app/portfolios(?P<path>%s)/' % PATH_RE,
        MyTSPRedirectView.as_view(
            pattern_name='matrix_chart',
            new_account_url=site_prefixed('/users/roles/accept/')),
        name='envconnect_portfolio'),
    url(r'app/reporting(?P<path>%s)/' % PATH_RE,
        MyTSPRedirectView.as_view(
            pattern_name='reporting_organization',
            new_account_url=site_prefixed('/users/roles/accept/')),
        name='reporting_redirect'),
    url(r'app/assess(?P<path>%s)/' % PATH_RE,
        AccountRedirectView.as_view(
            pattern_name='assess_organization_redirect',
            new_account_url=site_prefixed('/users/roles/accept/')),
        name='assess_redirect'),
    url(r'app/improve(?P<path>%s)/' % PATH_RE,
        AccountRedirectView.as_view(
            pattern_name='improve_organization_redirect',
            new_account_url=site_prefixed('/users/roles/accept/')),
예제 #13
0
def path_to_legend(root):
    tags = json.loads(root[0]['tag'])['tags']
    for tag in tags:
        if tag.startswith('legend'):
            return site_prefixed("/docs/" + tag + "/")