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 ''
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 ""
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)
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 ''
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 ""
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>'
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)')
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 ''
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
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 ''
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 ''
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>'
def read(self, obj): return utils.create_link('/grants/view/{}'.format(obj.pk), 'Read application', new_tab=True)
def organization_link(self, obj): return utils.create_link( '/admin/grants/organization/{}/'.format(obj.organization.pk), unicode(obj.organization))
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))
def test_simple(self): link = utils.create_link(self.url, self.text) self.assertEqual(link, '<a href="{}">{}</a>'.format(self.url, self.text))
def view(self, obj): return utils.create_link('/report/view/{}'.format(obj.pk), 'View')
def revert_grant(self, _): return utils.create_link('revert', 'Revert to draft')
def organization_link(self, obj): return utils.create_link('/admin/grants/organization/{}/'.format(obj.organization.pk), unicode(obj.organization))
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 })
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'
def grant(self, obj): return utils.create_link( reverse('admin:grants_givingprojectgrant_change', args=(obj.giving_project_grant_id, )), 'View')
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))
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)
def rollover(self, _): return utils.create_link('rollover', 'Copy to another grant cycle')
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
def change_password(self, obj): return utils.create_link( reverse('admin:auth_user_password_change', args=(obj.pk, )), 'Change password')
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))
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)