def render_change_form(self, request, context, *args, **kwargs): if 'original' in context: txt = context['original'].student.primary_contact context['adminform'].form.fields['supervisor_comment'].help_text = txt from django.conf import settings from django.core.urlresolvers import reverse from ecwsp.work_study.views import approve url = get_base_url() + reverse(approve) + '?key=' + context['original'].supervisor_key context['adminform'].form.fields['approved'].help_text = 'Supervisor Approve Link <a href="%s">%s</a>' % (url,url) return super(TimeSheetAdmin, self).render_change_form(request, context, args, kwargs)
def save(self, *args, **kwargs): email = False emailStu = False if not self.supervisor_key or self.supervisor_key == "": # Use previous key if one exists if self.id: ts = TimeSheet.objects.get(id=self.id) self.supervisor_key = ts.supervisor_key else: self.genKey() email = True # set hours hours = self.time_lunch.hour - self.time_in.hour mins = self.time_lunch.minute - self.time_in.minute hours += self.time_out.hour - self.time_lunch_return.hour mins += self.time_out.minute - self.time_lunch_return.minute hours += mins / Decimal(60) self.hours = hours # set pay rates if self.for_pay and not self.school_pay_rate and not self.student_pay_rate: try: self.school_pay_rate = self.student.school_pay_rate self.student_pay_rate = self.student.student_pay_rate except: print >> sys.stderr, "warning: pay rate for company not set. " # set payment net sum if self.school_pay_rate: self.school_net = self.hours * self.school_pay_rate if self.student_pay_rate: self.student_net = self.hours * self.student_pay_rate super(TimeSheet, self).save(*args, **kwargs) self.student = StudentWorker.objects.get( id=self.student.id) # refresh data for p contact if email and self.student.primary_contact: try: sendTo = self.student.primary_contact.email subject = "Time Sheet for " + str(self.student) msg = "Hello " + unicode(self.student.primary_contact.fname) + ",\nPlease click on the link below to approve the time sheet.\n" + \ get_base_url() + "/work_study/approve?key=" + str(self.supervisor_key) from_addr = Configuration.get_or_default( "From Email Address", "*****@*****.**").value send_mail(subject, msg, from_addr, [sendTo]) except: print >> sys.stderr, "Unable to send e-mail to supervisor! %s" % ( self, )
def send_email_approval(self): """ Send email to supervisor for approval """ if not self.site_supervisor or not self.site_supervisor.email: return None try: sendTo = self.site_supervisor.email subject = "Volunteer hours approval for " + unicode(self.student) msg = "Hello " + unicode(self.site_supervisor.name) + ",\nPlease click on the link below to approve the time sheet\n" + \ get_base_url() + "/volunteer_tracker/approve?key=" + str(self.secret_key) from_addr = Configuration.get_or_default("From Email Address", "*****@*****.**").value send_mail(subject, msg, from_addr, [sendTo]) except: logging.warning("Unable to send email to volunteer's supervisor! %s" % (self,), exc_info=True)
def save(self, *args, **kwargs): email = False emailStu = False if not self.supervisor_key or self.supervisor_key == "": # Use previous key if one exists if self.id: ts = TimeSheet.objects.get(id=self.id) self.supervisor_key = ts.supervisor_key else: self.genKey() email = True # set hours hours = self.time_lunch.hour - self.time_in.hour mins = self.time_lunch.minute - self.time_in.minute hours += self.time_out.hour - self.time_lunch_return.hour mins += self.time_out.minute - self.time_lunch_return.minute hours += mins/Decimal(60) self.hours = hours # set pay rates if self.for_pay and not self.school_pay_rate and not self.student_pay_rate: try: self.school_pay_rate = self.student.school_pay_rate self.student_pay_rate = self.student.student_pay_rate except: print >> sys.stderr, "warning: pay rate for company not set. " # set payment net sum if self.school_pay_rate: self.school_net = self.hours * self.school_pay_rate if self.student_pay_rate: self.student_net = self.hours * self.student_pay_rate super(TimeSheet, self).save(*args, **kwargs) self.student = StudentWorker.objects.get(id=self.student.id) # refresh data for p contact if email and self.student.primary_contact: try: sendTo = self.student.primary_contact.email subject = "Time Sheet for " + str(self.student) msg = "Hello " + unicode(self.student.primary_contact.fname) + ",\nPlease click on the link below to approve the time sheet.\n" + \ get_base_url() + "/work_study/approve?key=" + str(self.supervisor_key) from_addr = Configuration.get_or_default("From Email Address", "*****@*****.**").value send_mail(subject, msg, from_addr, [sendTo]) except: print >> sys.stderr, "Unable to send e-mail to supervisor! %s" % (self,)
def render_change_form(self, request, context, *args, **kwargs): if 'original' in context and context['original']: txt = context['original'].student.primary_contact context['adminform'].form.fields[ 'supervisor_comment'].help_text = txt from django.conf import settings from django.core.urlresolvers import reverse from ecwsp.work_study.views import approve url = get_base_url() + reverse( approve) + '?key=' + context['original'].supervisor_key context['adminform'].form.fields[ 'approved'].help_text = 'Supervisor Approve Link <a href="%s">%s</a>' % ( url, url) return super(TimeSheetAdmin, self).render_change_form(request, context, args, kwargs)
def email_admissions_new_inquiries(): """ Email Admissions team about new online inquiries """ from_email = Configuration.get_or_default("From Email Address").value to_email = Configuration.get_or_default('admissions_notify_email').value if not len(to_email): # don't complain if no one wants this report, just quit return # validate the from address try: validate_email(from_email) except ValidationError: logging.warning( 'email_admissions_new_inquiries failed because of invalid From Email Address "{}"' .format(from_email), exc_info=True) return # validate the to addresses to_email_list = [] for addr in to_email.split(','): try: validate_email(addr) to_email_list.append(addr) except ValidationError: logging.warning( 'email_admissions_new_inquiries omitting invalid address "{}" in admissions_notify_email' .format(addr), exc_info=True) subject = "New online inquiries" today = datetime.date.today() new_inquiries = Applicant.objects.filter(date_added=today, from_online_inquiry=True) if new_inquiries: msg = "The following inquiries were submitted today\n" for inquiry in new_inquiries: msg += '\n<a href="{0}{1}">{2} {3}</a>\n'.format( get_base_url(), reverse('admin:admissions_applicant_change', args=(inquiry.id, )), inquiry.fname, inquiry.lname) if Applicant.objects.filter(fname=inquiry.fname, lname=inquiry.lname).count() > 1: msg += "(May be duplicate)\n" send_mail(subject, msg, from_email, to_email_list)
def save(self, *args, **kwargs): if not self.id: new = True else: new = False super(ReferralForm, self).save(*args, **kwargs) if new: try: subject = 'New counseling referral for %s.' % (self.student,) msg = '%s has submitted a counseling referral form for %s. Click this link to view \n%s%s' % \ (self.referred_by, self.student, get_base_url(), reverse('admin:counseling_referralform_change',args=(self.id,)),) from_addr = Configuration.get_or_default("From Email Address", "*****@*****.**").value to_addr = Configuration.get_or_default("counseling_referral_notice_email_to", "").value.split(',') if to_addr and to_addr != ['']: send_mail(subject, msg, from_addr, to_addr) except: logging.error('Couldn\'t email counseling referral form.', exc_info=True)
def send_email_approval(self): """ Send email to supervisor for approval """ if not self.site_supervisor or not self.site_supervisor.email: return None try: sendTo = self.site_supervisor.email subject = "Volunteer hours approval for " + unicode(self.student) msg = "Hello " + unicode(self.site_supervisor.name) + ",\nPlease click on the link below to approve the time sheet\n" + \ get_base_url() + "/volunteer_tracker/approve?key=" + str(self.secret_key) from_addr = Configuration.get_or_default( "From Email Address", "*****@*****.**").value send_mail(subject, msg, from_addr, [sendTo]) except: logging.warning( "Unable to send email to volunteer's supervisor! %s" % (self, ), exc_info=True)
def save(self, *args, **kwargs): if not self.id: new = True else: new = False super(ReferralForm, self).save(*args, **kwargs) if new: try: subject = 'New counseling referral for %s.' % (self.student, ) msg = '%s has submitted a counseling referral form for %s. Click this link to view \n%s%s' % \ (self.referred_by, self.student, get_base_url(), reverse('admin:counseling_referralform_change',args=(self.id,)),) from_addr = Configuration.get_or_default( "From Email Address", "*****@*****.**").value to_addr = Configuration.get_or_default( "counseling_referral_notice_email_to", "").value.split(',') if to_addr and to_addr != ['']: send_mail(subject, msg, from_addr, to_addr) except: logging.error('Couldn\'t email counseling referral form.', exc_info=True)
def email_admissions_new_inquiries(): """ Email Admissions team about new online inquiries """ from_email = Configuration.get_or_default("From Email Address").value to_email = Configuration.get_or_default('admissions_notify_email').value if not len(to_email): # don't complain if no one wants this report, just quit return # validate the from address try: validate_email(from_email) except ValidationError: logging.warning('email_admissions_new_inquiries failed because of invalid From Email Address "{}"'.format(from_email), exc_info=True) return # validate the to addresses to_email_list = [] for addr in to_email.split(','): try: validate_email(addr) to_email_list.append(addr) except ValidationError: logging.warning('email_admissions_new_inquiries omitting invalid address "{}" in admissions_notify_email'.format(addr), exc_info=True) subject = "New online inquiries" today = datetime.date.today() new_inquiries = Applicant.objects.filter(date_added=today, from_online_inquiry=True) if new_inquiries: msg = "The following inquiries were submitted today\n" for inquiry in new_inquiries: msg += '\n<a href="{0}{1}">{2} {3}</a>\n'.format( get_base_url(), reverse('admin:admissions_applicant_change', args=(inquiry.id,)), inquiry.fname, inquiry.lname) if Applicant.objects.filter(fname=inquiry.fname, lname=inquiry.lname).count() > 1: msg += "(May be duplicate)\n" send_mail(subject, msg, from_email, to_email_list)