def canResign(self, entity): """Checks if the Mentor is able to resign. Checks if there are no Student Proposals or Student Projects that have this mentor assigned to it. Args: entity: a Mentor entity """ from soc.logic.models.student_project import logic as \ student_project_logic from soc.logic.models.student_proposal import logic as \ student_proposal_logic fields = {'mentor': entity} student_project_entity = student_project_logic.getForFields(fields, unique=True) if student_project_entity: return DEF_ALREADY_MENTORING_RPOJECT_MSG student_proposal_entity = student_proposal_logic.getForFields(fields, unique=True) if student_proposal_entity: return DEF_ALREADY_MENTORING_PROPOSAL_MSG return super(Logic, self).canResign(entity)
def sendStudentProposalMail(job_entity): """Job that will send out an email to a student that sent in a proposal that either got accepted or rejected. Args: job_entity: a Job entity with key_data set to [student_key] """ from soc.cron.job import FatalJobError student_keyname = job_entity.key_data[0].name() student_entity = student_logic.getFromKeyName(student_keyname) if not student_entity: raise FatalJobError('The student with keyname %s does not exist!' % ( student_keyname)) # only students who have sent in a proposal will be mailed fields = {'scope': student_entity} proposal = proposal_logic.getForFields(fields, unique=True) if proposal: # a proposal has been found we must sent out an email default_sender = mail_dispatcher.getDefaultMailSender() if not default_sender: # no default sender abort raise FatalJobError('No valid sender address could be found, try ' 'setting a no-reply address on the site settings ' 'page') else: (sender_name, sender) = default_sender # construct the contents of the email student_entity = proposal.scope program_entity = proposal.program context = { 'to': student_entity.email, 'to_name': student_entity.given_name, 'sender': sender, 'sender_name': sender_name, 'program_name': program_entity.name, } # check if the student has an accepted proposal fields['status'] = 'accepted' accepted_proposal = proposal_logic.getForFields(fields, unique=True) if accepted_proposal: org_entity = accepted_proposal.org # use the accepted template and subject template = DEF_ACCEPTED_MAIL_TEMPLATE context['subject'] = 'Congratulations!' context['proposal_title'] = accepted_proposal.title context['org_name'] = accepted_proposal.org.name else: # use the rejected template and subject template = DEF_REJECTED_MAIL_TEMPLATE context['subject'] = 'Thank you for applying to %s' % ( program_entity.name) # send out the constructed email mail_dispatcher.sendMailFromTemplate(template, context) # we are done here return