示例#1
0
  def grant_link(self, obj):
    if obj:
      if hasattr(obj, 'givingprojectgrant'):
        return utils.create_link(
          '/admin/grants/givingprojectgrant/{}/'.format(obj.givingprojectgrant.pk),
          'View grant')

      if hasattr(obj, 'screening_status') and obj.screening_status > 80:
        return utils.create_link(
          '/admin/grants/givingprojectgrant/add/?projectapp={}'.format(obj.pk),
          'Add grant')
    else:
      return ''
示例#2
0
文件: admin.py 项目: aisapatino/sjfnw
    def grant_link(self, obj):
        if obj:
            if hasattr(obj, "givingprojectgrant"):
                return utils.create_link(
                    "/admin/grants/givingprojectgrant/{}/".format(obj.givingprojectgrant.pk), "View grant"
                )

            if hasattr(obj, "screening_status") and obj.screening_status > 80:
                return utils.create_link(
                    "/admin/grants/givingprojectgrant/add/?projectapp={}".format(obj.pk), "Add grant"
                )
        else:
            return ""
示例#3
0
 def award_link(self, obj):
     if obj.pk:
         url = reverse('admin:grants_givingprojectgrant_change',
                       args=(obj.pk, ))
         return utils.create_link(url,
                                  obj.award.full_description(),
                                  new_tab=True)
示例#4
0
 def app_link(self, obj):
   if obj and hasattr(obj, 'application'):
     return utils.create_link(
       '/admin/grants/grantapplication/{}/'.format(obj.application.pk),
       'View application')
   else:
     return ''
示例#5
0
文件: admin.py 项目: aisapatino/sjfnw
 def app_link(self, obj):
     if obj and hasattr(obj, "application"):
         return utils.create_link(
             "/admin/grants/grantapplication/{}/".format(obj.application.pk), "View application"
         )
     else:
         return ""
示例#6
0
    def get_files_display(self, obj):
        files = ''

        for field_name in models.GrantApplication.file_fields():
            # attribute is a FieldFile instance if set
            field_file = getattr(obj, field_name) if hasattr(
                obj, field_name) else None

            if field_file:
                url = reverse('sjfnw.grants.views.view_file',
                              kwargs={
                                  'obj_type': 'app',
                                  'obj_id': obj.pk,
                                  'field_name': field_name
                              })

                file_link = utils.create_link(url,
                                              obj.get_file_name(field_name),
                                              new_tab=True)

                # to get the human-readable field name, we need to access the FileField
                verbose_name = obj._meta.get_field(field_name).verbose_name

                files += '<tr><td>{}</td><td>{}</td></tr>'.format(
                    verbose_name, file_link)

        return '<table>' + (files or 'No files uploaded') + '</table>'
示例#7
0
文件: admin.py 项目: aisapatino/sjfnw
 def edit(self, obj):
   if not obj or not obj.organization:
     return '-'
   url = reverse('sjfnw.grants.views.grant_application',
                 kwargs={'cycle_id': obj.grant_cycle_id})
   url += '?user='******'<br>(logs you in as the organization)')
示例#8
0
 def edit(self, obj):
     if not obj or not obj.organization:
         return '-'
     url = reverse('sjfnw.grants.views.grant_application',
                   kwargs={'cycle_id': obj.grant_cycle_id})
     url += '?user='******'<br>(logs you in as the organization)')
示例#9
0
文件: admin.py 项目: aisapatino/sjfnw
 def year_end_report(self, obj):
   if obj.pk:
     reports = (models.YearEndReport.objects.select_related('award')
                                           .filter(award__projectapp_id=obj.pk))
     yer_link = ""
     for i, report in enumerate(reports):
       if i > 0:
         yer_link += " | "
       yer_link += utils.create_link('/admin/grants/yearendreport/{}/'.format(report.pk),
                                     'Year {}'.format(i + 1), new_tab=True)
     return mark_safe(yer_link)
   else:
     return ''
示例#10
0
 def get_display(self):
   question_type = self.cycle_report_question.report_question.input_type
   if question_type == gc.QuestionTypes.FILE or question_type == gc.QuestionTypes.PHOTO:
     filename = self.text.split('/')[-1]
     url = reverse('sjfnw.grants.views.view_file_direct', kwargs={'answer_id': self.pk})
     return mark_safe(create_link(url, filename, new_tab=True))
   elif self.cycle_report_question.report_question.name == 'stay_informed':
     try:
       return '\n'.join([value for value in json.loads(self.text).values()])
     except:
       return 'Could not parse answer'
   else:
     return self.text
示例#11
0
 def year_end_report(self, obj):
     if obj.pk:
         reports = (
             models.YearEndReport.objects.select_related('award').filter(
                 award__projectapp_id=obj.pk))
         yer_link = ""
         for i, report in enumerate(reports):
             if i > 0:
                 yer_link += " | "
             yer_link += utils.create_link(
                 '/admin/grants/yearendreport/{}/'.format(report.pk),
                 'Year {}'.format(i + 1),
                 new_tab=True)
         return mark_safe(yer_link)
     else:
         return ''
示例#12
0
文件: admin.py 项目: dougcole/sjfnw
 def grantee_report(self, obj):
     if obj.pk:
         reports = (models.GranteeReport.objects.select_related(
             'giving_project_grant').filter(
                 giving_project_grant__projectapp_id=obj.pk))
         report_link = ""
         for i, report in enumerate(reports):
             if i > 0:
                 report_link += " | "
             report_link += utils.create_link(
                 '/admin/grants/granteereport/{}/'.format(report.pk),
                 'Year {}'.format(i + 1),
                 new_tab=True)
         return mark_safe(report_link)
     else:
         return ''
示例#13
0
文件: admin.py 项目: aisapatino/sjfnw
  def get_files_display(self, obj):
    files = ''

    for field_name in models.GrantApplication.file_fields():
      # attribute is a FieldFile instance if set
      field_file = getattr(obj, field_name) if hasattr(obj, field_name) else None

      if field_file:
        url = reverse('sjfnw.grants.views.view_file', kwargs={
          'obj_type': 'app', 'obj_id': obj.pk, 'field_name': field_name
        })

        file_link = utils.create_link(url, obj.get_file_name(field_name), new_tab=True)

        # to get the human-readable field name, we need to access the FileField
        verbose_name = obj._meta.get_field(field_name).verbose_name

        files += '<tr><td>{}</td><td>{}</td></tr>'.format(verbose_name, file_link)

    return '<table>' + (files or 'No files uploaded') + '</table>'
示例#14
0
 def read(self, obj):
     return utils.create_link('/grants/view/{}'.format(obj.pk),
                              'Read application',
                              new_tab=True)
示例#15
0
 def organization_link(self, obj):
     return utils.create_link(
         '/admin/grants/organization/{}/'.format(obj.organization.pk),
         unicode(obj.organization))
示例#16
0
 def test_new_window(self):
   link = utils.create_link(self.url, self.text, new_tab=True)
   self.assertEqual(link, '<a href="{}" target="_blank">{}</a>'.format(self.url, self.text))
示例#17
0
 def test_simple(self):
     link = utils.create_link(self.url, self.text)
     self.assertEqual(link,
                      '<a href="{}">{}</a>'.format(self.url, self.text))
示例#18
0
文件: admin.py 项目: aisapatino/sjfnw
 def view(self, obj):
   return utils.create_link('/report/view/{}'.format(obj.pk), 'View')
示例#19
0
文件: admin.py 项目: aisapatino/sjfnw
 def revert_grant(self, _):
   return utils.create_link('revert', 'Revert to draft')
示例#20
0
文件: admin.py 项目: aisapatino/sjfnw
 def organization_link(self, obj):
   return utils.create_link('/admin/grants/organization/{}/'.format(obj.organization.pk),
                            unicode(obj.organization))
示例#21
0
def fund_register(request):
    error_msg = ''
    if request.method == 'POST':
        register = forms.RegistrationForm(request.POST)
        if register.is_valid():

            username_email = request.POST['email'].lower()
            password = request.POST['password']
            first_name = request.POST['first_name']
            last_name = request.POST['last_name']

            try:
                member = models.Member.objects.create_with_user(
                    username_email,
                    password=password,
                    first_name=first_name,
                    last_name=last_name)
            except ValueError as err:
                logger.warning(username_email + ' tried to re-register')
                login_link = utils.create_link('/fund/login/', 'Login')
                error_msg = '{} {} instead.'.format(err.message, login_link)

            if not error_msg:
                logger.info(
                    'Registration - user and member objects created for ' +
                    username_email)
                # if they specified a GP, create Membership
                membership = None
                if request.POST['giving_project']:
                    giv = models.GivingProject.objects.get(
                        pk=request.POST['giving_project'])
                    notif = (
                        '<table><tr><td>Welcome to Project Central!<br>'
                        'I\'m Odo, your Online Donor Organizing assistant. I\'ll be here to '
                        'guide you through the fundraising process and cheer you on.</td>'
                        '<td><img src="/static/images/odo1.png" height=88 width=54 alt="Odo waving">'
                        '</td></tr></table>')
                    membership, _ = _create_membership(member,
                                                       giv,
                                                       notif=notif)
                    logger.info(
                        'Registration - membership in %s created, welcome message set',
                        unicode(giv))

                # try to log in
                user = auth.authenticate(username=username_email,
                                         password=password)
                if user:
                    if user.is_active:
                        # success! log in and redirect
                        auth.login(request, user)
                        if not membership:
                            return redirect(manage_account)
                        if membership.approved:
                            return redirect(home)
                        return render(request, 'fund/registered.html', {
                            'member': member,
                            'proj': giv
                        })
                    else:  # not active
                        error_msg = 'Your account is not active. Please contact a site admin for assistance.'
                        logger.error(
                            'Inactive right after registering. Email: ' +
                            username_email)
                else:  # email & pw didn't match
                    error_msg = (
                        'There was a problem with your registration.  Please '
                        '<a href="/fund/support# contact">contact a site admin</a> for assistance.'
                    )
                    logger.error(
                        'Password didn\'t match right after registering. Email: %s',
                        username_email)

    else:  # GET
        register = forms.RegistrationForm()

    return render(request, 'fund/register.html', {
        'form': register,
        'error_msg': error_msg
    })
示例#22
0
from sjfnw.admin import BaseModelAdmin, BaseShowInline, YearFilter
from sjfnw.grants import models
from sjfnw.grants.modelforms import (DraftAdminForm, LogAdminForm,
                                     CycleNarrativeFormset,
                                     NarrativeQuestionForm)

logger = logging.getLogger('sjfnw')

# Note: some non-standard fields have been added in order to add text to templates
# from a centralized location:
#  - list_help_text: display help text at top of changelist page
#  - list_action_link: display link at top of changelist page
# see sjfnw/templates/admin/change_list.html

LOG_IN_AS_ORG = utils.create_link(
    '/admin/grants/organization/login',  # reverse crashes, don't know why
    'Log in as an organization',
    new_tab=True)
# -----------------------------------------------------------------------------
#  CUSTOM FILTERS
# -----------------------------------------------------------------------------


class GPGYearFilter(YearFilter):
    filter_model = models.GivingProjectGrant
    field = 'created'


class GrantApplicationYearFilter(YearFilter):
    filter_model = models.GrantApplication
    field = 'submission_time'
示例#23
0
文件: admin.py 项目: dougcole/sjfnw
 def grant(self, obj):
     return utils.create_link(
         reverse('admin:grants_givingprojectgrant_change',
                 args=(obj.giving_project_grant_id, )), 'View')
示例#24
0
文件: admin.py 项目: dougcole/sjfnw
 def grant_display(self, obj):
     return utils.create_link(
         reverse('admin:grants_givingprojectgrant_change',
                 args=(obj.giving_project_grant_id, )),
         unicode(obj.giving_project_grant))
示例#25
0
 def test_simple(self):
   link = utils.create_link(self.url, self.text)
   self.assertEqual(link, '<a href="{}">{}</a>'.format(self.url, self.text))
示例#26
0
文件: admin.py 项目: aisapatino/sjfnw
 def read(self, obj):
   return utils.create_link('/grants/view/{}'.format(obj.pk), 'Read application', new_tab=True)
示例#27
0
 def view_link(self, obj):
     if obj.pk:
         url = reverse('sjfnw.grants.views.view_yer',
                       kwargs={'report_id': obj.pk})
         return utils.create_link(url, 'View report', new_tab=True)
示例#28
0
 def view(self, obj):
     return utils.create_link('/report/view/{}'.format(obj.pk), 'View')
示例#29
0
文件: admin.py 项目: aisapatino/sjfnw
 def rollover(self, _):
   return utils.create_link('rollover', 'Copy to another grant cycle')
示例#30
0
class GrantApplicationA(BaseModelAdmin):
    list_display = ['organization', 'grant_cycle', 'submission_time', 'read']
    list_filter = (GrantApplicationYearFilter, 'pre_screening_status')
    list_action_link = utils.create_link('/admin/grants/search',
                                         'Run a report',
                                         new_tab=True)
    search_fields = ['organization__name', 'grant_cycle__title']
    ordering = ('-submission_time', )

    fieldsets = [
        ('Application', {
            'fields':
            (('organization_link', 'grant_cycle', 'submission_time', 'read'), )
        }),
        ('Application contact info', {
            'classes': ('collapse', ),
            'description':
            ('Contact information as entered in the grant application. '
             'You may edit this as needed.  Note that the contact information '
             'you see on the organization page is always from the most recent '
             'application, whether that is this or a different one.'),
            'fields':
            (('address', 'city', 'state', 'zip', 'telephone_number',
              'fax_number', 'email_address', 'website'), ('status', 'ein'))
        }),
        ('Uploaded files', {
            'classes': ('collapse', ),
            'fields': ('get_files_display', )
        }),
        ('Administration', {
            'fields':
            (('pre_screening_status', 'scoring_bonus_poc', 'scoring_bonus_geo',
              'site_visit_report'), ('revert_grant', 'rollover'))
        })
    ]
    readonly_fields = ('organization_link', 'grant_cycle', 'submission_time',
                       'read', 'revert_grant', 'rollover', 'get_files_display')
    inlines = [ProjectAppI, LogReadonlyI, LogI]

    def get_files_display(self, obj):
        files = ''

        for field_name in models.GrantApplication.file_fields():
            # attribute is a FieldFile instance if set
            field_file = getattr(obj, field_name) if hasattr(
                obj, field_name) else None

            if field_file:
                url = reverse('sjfnw.grants.views.view_file',
                              kwargs={
                                  'obj_type': 'app',
                                  'obj_id': obj.pk,
                                  'field_name': field_name
                              })

                file_link = utils.create_link(url,
                                              obj.get_file_name(field_name),
                                              new_tab=True)

                # to get the human-readable field name, we need to access the FileField
                verbose_name = obj._meta.get_field(field_name).verbose_name

                files += '<tr><td>{}</td><td>{}</td></tr>'.format(
                    verbose_name, file_link)

        return '<table>' + (files or 'No files uploaded') + '</table>'

    get_files_display.allow_tags = True
    get_files_display.short_description = 'Uploaded files'

    def has_add_permission(self, request):
        return False

    def revert_grant(self, _):
        return utils.create_link('revert', 'Revert to draft')

    revert_grant.allow_tags = True

    def rollover(self, _):
        return utils.create_link('rollover', 'Copy to another grant cycle')

    rollover.allow_tags = True

    def organization_link(self, obj):
        return utils.create_link(
            '/admin/grants/organization/{}/'.format(obj.organization.pk),
            unicode(obj.organization))

    organization_link.allow_tags = True
    organization_link.short_description = 'Organization'

    def read(self, obj):
        return utils.create_link('/grants/view/{}'.format(obj.pk),
                                 'Read application',
                                 new_tab=True)

    read.allow_tags = True
示例#31
0
文件: admin.py 项目: aisapatino/sjfnw
 def view_link(self, obj):
   if obj.pk:
     url = reverse('sjfnw.grants.views.view_yer', kwargs={'report_id': obj.pk})
     return utils.create_link(url, 'View report', new_tab=True)
示例#32
0
 def revert_grant(self, _):
     return utils.create_link('revert', 'Revert to draft')
示例#33
0
 def change_password(self, obj):
     return utils.create_link(
         reverse('admin:auth_user_password_change', args=(obj.pk, )),
         'Change password')
示例#34
0
 def rollover(self, _):
     return utils.create_link('rollover', 'Copy to another grant cycle')
示例#35
0
 def test_new_window(self):
     link = utils.create_link(self.url, self.text, new_tab=True)
     self.assertEqual(
         link,
         '<a href="{}" target="_blank">{}</a>'.format(self.url, self.text))
示例#36
0
文件: admin.py 项目: aisapatino/sjfnw
 def award_link(self, obj):
   if obj.pk:
     url = reverse('admin:grants_givingprojectgrant_change', args=(obj.pk,))
     return utils.create_link(url, obj.award.full_description(), new_tab=True)