def getFirstTaskConfirmationContext(student): """Sends notification to the GCI student, when he or she completes their first task. Args: student: the student who should receive the confirmation """ to = student.contact.email subject = DEF_FIRST_TASK_CONFIRMATION_SUBJECT program_key = student.program kwargs = { 'sponsor': profile_model.getSponsorId(student.key), 'program': profile_model.getProgramId(student.key) } url = reverse('gci_student_form_upload', kwargs=kwargs) protocol = 'http' hostname = site.getHostname() context = { 'student_forms_link': '%s://%s%s' % (protocol, hostname, url), } template = DEF_FIRST_TASK_CONFIRMATION_TEMPLATE body = loader.render_to_string(template, context) return mailer.getMailContext(to=to, subject=subject, html=body, bcc=[])
def _getRequestData(profile, postdata=None): """Returns a new request data based on the specified profile and post data. Args: profile: Profile entity. postdata: A dict containing POST data. Returns: RequestData object. """ profile_key = profile.key if isinstance(profile, ndb.Model) else profile.key() kwargs = { 'sponsor': profile_model.getSponsorId(profile_key), 'program': profile_model.getProgramId(profile_key), 'user': profile_model.getUserId(profile_key), } data = request_data.RequestData(None, None, kwargs) data._POST = postdata return data
def userId(self, profile_key, entity_id, url_name): """Returns the URL of a page whose address contains parts associated with the specified profile and numeric identifier of some other entity. Args: profile_key: Profile key. entity_id: Numeric ID of entity. url_name: The name with which a URL was registered with Django. Returns: The URL of the page matching the given names for the given profile and organization. """ kwargs = { 'sponsor': profile_model.getSponsorId(profile_key), 'program': profile_model.getProgramId(profile_key), 'user': profile_model.getUserId(profile_key), 'id': entity_id, } return urlresolvers.reverse(url_name, kwargs=kwargs)
def profile(self, profile, url_name): """Returns the URL of a profile's named page. Args: profile: A profile entity. url_name: The name with which a URL was registered with Django. Returns: The URL of the page matching the given name for the given profile. """ if isinstance(profile, ndb.Model): profile_key = profile.key else: profile_key = profile.key() kwargs = { 'program': profile_model.getProgramId(profile_key), 'sponsor': profile_model.getSponsorId(profile_key), 'user': profile_model.getUserId(profile_key) } return urlresolvers.reverse(url_name, kwargs=kwargs)
def userOrg(self, profile_key, org_key, url_name): """Returns the URL of a page whose address contains parts associated with the specified profile and organization. The specified profile and organization must come from the same program. Args: profile_key: Profile key. org: organization entity. url_name: the name with which a URL was registered with Django. Returns: The URL of the page matching the given names for the given profile and organization. """ kwargs = { 'sponsor': profile_model.getSponsorId(profile_key), 'program': profile_model.getProgramId(profile_key), 'user': profile_model.getUserId(profile_key), 'organization': org_model.getOrgId(org_key), } return urlresolvers.reverse(url_name, kwargs=kwargs)