def context(self): """The context for this template used in render().""" orgs = [] for org in db.get(self.duplicate.orgs): admins = profile_logic.getOrgAdmins(org.key) data = { 'name': org.name, 'link': links.LINKER.organization(org.key, urls.UrlNames.ORG_HOME), 'admins': admins } orgs.append(data) context = {'orgs': orgs} return context
def context(self): """Returns the context for the current template.""" context = {'duplicate': self.duplicate} # TODO(daniel): it should be done via NDB orgs = db.get(self.duplicate.orgs) proposals = db.get(self.duplicate.duplicates) orgs_details = {} for org in orgs: orgs_details[org.key().id_or_name()] = { 'name': org.name, 'link': links.LINKER.organization(org.key, urls.UrlNames.ORG_HOME), } org_admins = profile_logic.getOrgAdmins(org.key()) orgs_details[org.key().id_or_name()]['admins'] = [] for org_admin in org_admins: orgs_details[org.key().id_or_name()]['admins'].append({ 'name': org_admin.name(), 'email': org_admin.email }) orgs_details[org.key().id_or_name()]['proposals'] = [] for proposal in proposals: org_key = proposal_model.GSoCProposal.org.get_value_for_datastore( proposal) if org_key == org.key(): orgs_details[org.key().id_or_name()]['proposals'].append({ 'key': proposal.key().id_or_name(), 'title': proposal.title, 'link': links.LINKER.userId(proposal.parent_key(), proposal.key().id(), url_names.PROPOSAL_REVIEW), }) context['orgs'] = orgs_details return context
def context(self): """Returns the context for the current template.""" context = {'duplicate': self.duplicate} # TODO(daniel): it should be done via NDB orgs = db.get(self.duplicate.orgs) proposals = db.get(self.duplicate.duplicates) orgs_details = {} for org in orgs: orgs_details[org.key().id_or_name()] = { 'name': org.name, 'link': links.LINKER.organization(org.key, urls.UrlNames.ORG_HOME), } org_admins = profile_logic.getOrgAdmins(org.key()) orgs_details[org.key().id_or_name()]['admins'] = [] for org_admin in org_admins: orgs_details[org.key().id_or_name()]['admins'].append({ 'name': org_admin.name(), 'email': org_admin.email }) orgs_details[org.key().id_or_name()]['proposals'] = [] for proposal in proposals: org_key = proposal_model.GSoCProposal.org.get_value_for_datastore( proposal) if org_key == org.key(): orgs_details[org.key().id_or_name()]['proposals'].append({ 'key': proposal.key().id_or_name(), 'title': proposal.title, 'link': links.LINKER.userId( proposal.parent_key(), proposal.key().id(), url_names.PROPOSAL_REVIEW), }) context['orgs'] = orgs_details return context
def sendSurveyReminderForProject(self, request, *args, **kwargs): """Sends a reminder mail for a given GSoCProject and Survey. A reminder is only send if no record is on file for the given Survey and GSoCProject. Expects the following to be present in the POST dict: survey_key: specifies the key name for the ProjectSurvey to send reminders for survey_type: either project or grading depending on the type of Survey project_key: encoded Key which specifies the project to send a reminder for Args: request: Django Request object """ post_dict = request.POST project_key = post_dict.get('project_key') survey_key = post_dict.get('survey_key') survey_type = post_dict.get('survey_type') if not (project_key and survey_key and survey_type): # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid sendSurveyReminderForProject data: %s' % post_dict) # set model depending on survey type specified in POST if survey_type == 'project': survey_model = ProjectSurvey record_model = GSoCProjectSurveyRecord elif survey_type == 'grading': survey_model = GradingProjectSurvey record_model = GSoCGradingProjectSurveyRecord else: return error_handler.logErrorAndReturnOK( '%s is an invalid survey_type' %survey_type) # retrieve the project and survey project_key = db.Key(project_key) project = GSoCProject.get(project_key) if not project: # no existing project found, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid project specified %s:' % project_key) survey = survey_model.get_by_key_name(survey_key) if not survey: # no existing survey found, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid survey specified %s:' % survey_key) # try to retrieve an existing record q = record_model.all() q.filter('project', project) q.filter('survey', survey) record = q.get() if not record: # send reminder email because we found no record student = ndb.Key.from_old_key(project.parent_key()).get() site_entity = site.singleton() if survey_type == 'project': url_name = 'gsoc_take_student_evaluation' to_name = student.public_name to_address = student.contact.email mail_template = 'modules/gsoc/reminder/student_eval_reminder.html' elif survey_type == 'grading': url_name = 'gsoc_take_mentor_evaluation' mentors = ndb.get_multi(map(ndb.Key.from_old_key, project.mentors)) to_address = [mentor.contact.email for mentor in mentors] to_name = 'mentor(s) for project "%s"' % (project.title) mail_template = ( 'modules/gsoc/reminder/mentor_eval_reminder.html') program = project.program hostname = site.getHostname() url_kwargs = { 'sponsor': program_logic.getSponsorKey(program).name(), 'program': program.link_id, 'survey': survey.link_id, 'user': student.profile_id, 'id': str(project.key().id()), } url_path_and_query = reverse(url_name, kwargs=url_kwargs) survey_url = '%s://%s%s' % ('http', hostname, url_path_and_query) # set the context for the mail template mail_context = { 'student_name': student.public_name, 'project_title': project.title, 'survey_url': survey_url, 'survey_end': survey.survey_end, 'to_name': to_name, 'site_name': site_entity.site_name, 'sender_name': "The %s Team" % site_entity.site_name, } # set the sender _, sender_address = mail_dispatcher.getDefaultMailSender() mail_context['sender'] = sender_address # set the receiver and subject mail_context['to'] = to_address mail_context['subject'] = ( 'Evaluation "%s" Reminder' % survey.title) # find all org admins for the project's organization org_key = ndb.Key.from_old_key( GSoCProject.org.get_value_for_datastore(project)) org_admins = profile_logic.getOrgAdmins(org_key) # collect email addresses for all found org admins org_admin_addresses = [] for org_admin in org_admins: org_admin_addresses.append(org_admin.contact.email) if org_admin_addresses: mail_context['cc'] = org_admin_addresses # send out the email mail_dispatcher.sendMailFromTemplate(mail_template, mail_context) # return OK return http.HttpResponse()
def testNoMentors(self): mentors = profile_logic.getOrgAdmins(self.organization_one.key) self.assertEqual(mentors, [])
def sendSurveyReminderForProject(self, request, *args, **kwargs): """Sends a reminder mail for a given GSoCProject and Survey. A reminder is only send if no record is on file for the given Survey and GSoCProject. Expects the following to be present in the POST dict: survey_key: specifies the key name for the ProjectSurvey to send reminders for survey_type: either project or grading depending on the type of Survey project_key: encoded Key which specifies the project to send a reminder for Args: request: Django Request object """ post_dict = request.POST project_key = post_dict.get('project_key') survey_key = post_dict.get('survey_key') survey_type = post_dict.get('survey_type') if not (project_key and survey_key and survey_type): # invalid task data, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid sendSurveyReminderForProject data: %s' % post_dict) # set model depending on survey type specified in POST if survey_type == 'project': survey_model = ProjectSurvey record_model = GSoCProjectSurveyRecord elif survey_type == 'grading': survey_model = GradingProjectSurvey record_model = GSoCGradingProjectSurveyRecord else: return error_handler.logErrorAndReturnOK( '%s is an invalid survey_type' % survey_type) # retrieve the project and survey project_key = db.Key(project_key) project = GSoCProject.get(project_key) if not project: # no existing project found, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid project specified %s:' % project_key) survey = survey_model.get_by_key_name(survey_key) if not survey: # no existing survey found, log and return OK return error_handler.logErrorAndReturnOK( 'Invalid survey specified %s:' % survey_key) # try to retrieve an existing record q = record_model.all() q.filter('project', project) q.filter('survey', survey) record = q.get() if not record: # send reminder email because we found no record student = ndb.Key.from_old_key(project.parent_key()).get() site_entity = site.singleton() if survey_type == 'project': url_name = 'gsoc_take_student_evaluation' to_name = student.public_name to_address = student.contact.email mail_template = 'modules/gsoc/reminder/student_eval_reminder.html' elif survey_type == 'grading': url_name = 'gsoc_take_mentor_evaluation' mentors = ndb.get_multi( map(ndb.Key.from_old_key, project.mentors)) to_address = [mentor.contact.email for mentor in mentors] to_name = 'mentor(s) for project "%s"' % (project.title) mail_template = ( 'modules/gsoc/reminder/mentor_eval_reminder.html') program = project.program hostname = site.getHostname() url_kwargs = { 'sponsor': program_logic.getSponsorKey(program).name(), 'program': program.link_id, 'survey': survey.link_id, 'user': student.profile_id, 'id': str(project.key().id()), } url_path_and_query = reverse(url_name, kwargs=url_kwargs) survey_url = '%s://%s%s' % ('http', hostname, url_path_and_query) # set the context for the mail template mail_context = { 'student_name': student.public_name, 'project_title': project.title, 'survey_url': survey_url, 'survey_end': survey.survey_end, 'to_name': to_name, 'site_name': site_entity.site_name, 'sender_name': "The %s Team" % site_entity.site_name, } # set the sender _, sender_address = mail_dispatcher.getDefaultMailSender() mail_context['sender'] = sender_address # set the receiver and subject mail_context['to'] = to_address mail_context['subject'] = ('Evaluation "%s" Reminder' % survey.title) # find all org admins for the project's organization org_key = ndb.Key.from_old_key( GSoCProject.org.get_value_for_datastore(project)) org_admins = profile_logic.getOrgAdmins(org_key) # collect email addresses for all found org admins org_admin_addresses = [] for org_admin in org_admins: org_admin_addresses.append(org_admin.contact.email) if org_admin_addresses: mail_context['cc'] = org_admin_addresses # send out the email mail_dispatcher.sendMailFromTemplate(mail_template, mail_context) # return OK return http.HttpResponse()
def sendMailAboutGradingRecordResult(self, request, *args, **kwargs): """Sends out a mail about the result of one GradingRecord. Expects the following to be present in the POST dict: record_key: Specifies the key for the record to process. Args: request: Django Request object """ post_dict = request.POST record_key = post_dict.get('record_key') if not record_key: # no GradingRecord key specified, log and return OK error_handler.logErrorAndReturnOK( 'No valid record_key specified in POST data: %s' % request.POST) record = GSoCGradingRecord.get(db.Key(record_key)) if not record: # no valid GradingRecord key specified, log and return OK error_handler.logErrorAndReturnOK( 'No valid GradingRecord key specified: %s' % record_key) survey_group_entity = record.grading_survey_group project_entity = record.parent() student_entity = ndb.Key.from_old_key(project_entity.parent_key()).get() org_key = GSoCProject.org.get_value_for_datastore(project_entity) org = ndb.Key.from_old_key(org_key).get() site_entity = site.singleton() mail_context = { 'survey_group': survey_group_entity, 'grading_record': record, 'project': project_entity, 'organization': org, 'site_name': site_entity.site_name, 'to_name': student_entity.public_name } # set the sender (_, sender_address) = mail_dispatcher.getDefaultMailSender() mail_context['sender'] = sender_address # set the receiver and subject mail_context['to'] = student_entity.contact.email mail_context['cc'] = [] mail_context['subject'] = '%s results processed for %s' %( survey_group_entity.name, project_entity.title) org_admins = profile_logic.getOrgAdmins(org.key) # collect all mentors mentors = ndb.get_multi( map(ndb.Key.from_old_key, GSoCProject.mentors.get_value_for_datastore(project_entity))) # add them all to the cc list for org_member in org_admins + mentors: mail_context['cc'].append(org_member.contact.email) # send out the email using a template mail_template = 'modules/gsoc/grading_record/mail/result.html' mail_dispatcher.sendMailFromTemplate(mail_template, mail_context) # return OK return http.HttpResponse()