def teacherhandout(self, request, tl, one, two, module, extra, prog, template_file='teacherschedules.html'): # Use the template defined in ProgramPrintables from esp.program.modules.handlers import ProgramPrintables context = {'module': self} pmos = ProgramModuleObj.objects.filter( program=prog, module__handler__icontains='printables') if pmos.count() == 1: pmo = ProgramPrintables(pmos[0]) teacher = ESPUser(request.user) scheditems = [] for cls in teacher.getTaughtClasses().filter( parent_program=self.program): if cls.isAccepted(): for section in cls.sections.all(): scheditems.append({ 'name': teacher.name(), 'teacher': teacher, 'cls': section }) scheditems.sort() context['scheditems'] = scheditems return render_to_response(pmo.baseDir() + template_file, request, context) else: raise ESPError( False ), 'No printables module resolved, so this document cannot be generated. Consult the webmasters.'
def process(self, processoverride=False): """ Process this request...if it's an email, create all the necessary email requests. """ # if we already processed, return if self.processed and not processoverride: return # there's no real thing for this...yet if not self.email_all: return # this is for thread-safeness... self.processed = True self.save() # figure out who we're sending from... if self.sender is not None and len(self.sender.strip()) > 0: send_from = self.sender else: if self.creator is not None: send_from = '%s <%s>' % (ESPUser( self.creator).name(), self.creator.email) else: send_from = 'ESP Web Site <*****@*****.**>' users = self.recipients.getList(ESPUser) try: users = users.distinct() except: pass # go through each user and parse the text...then create the proper # emailrequest and textofemail object for user in users: user = ESPUser(user) newemailrequest = EmailRequest(target=user, msgreq=self) newtxt = TextOfEmail( send_to='%s <%s>' % (user.name(), user.email), send_from=send_from, subject=self.parseSmartText(self.subject, user), msgtext=self.parseSmartText(self.msgtext, user), sent=None) newtxt.save() newemailrequest.textofemail = newtxt newemailrequest.save() print 'Prepared e-mails to send for message request %d: %s' % ( self.id, self.subject)
def load(self, user): user = ESPUser(user) self.fields['user'].initial = user.id self.fields['email'].initial = user.email self.fields['name'].initial = user.name() if user.getLastProfile().contact_user: self.fields['phone'].initial = user.getLastProfile( ).contact_user.phone_cell previous_offers = user.getVolunteerOffers(self.program).order_by('-id') if previous_offers.exists(): self.fields['requests'].initial = previous_offers.values_list( 'request', flat=True) if 'shirt_size' in self.fields: self.fields['shirt_size'].initial = previous_offers[ 0].shirt_size if 'shirt_type' in self.fields: self.fields['shirt_type'].initial = previous_offers[ 0].shirt_type if 'comments' in self.fields: self.fields['comments'].initial = previous_offers[0].comments
class UserAttributeGetter(object): @staticmethod def getFunctions(): """ Enter labels for available fields here; they are sorted alphabetically by key """ labels = { '01_id': 'ID', '02_address': 'Address', '03_fullname': 'Full Name', '04_lastname': 'Last Name', '05_firstname': 'First Name', '06_username': '******', '07_email': 'E-mail', '08_accountdate': 'Created Date', '09_first_regdate': 'Initial Registration Date', '10_last_regdate': 'Most Recent Registration Date', '11_cellphone': 'Cell Phone', '12_textmsg': 'Text Msg?', '13_studentrep': 'Student Rep?', '14_classhours': 'Num Class Hrs', '15_gradyear': 'Grad Year', '16_school': 'School', '17_heard_about': 'Heard about Splash from', '18_transportation': 'Plan to Get to Splash', '19_post_hs': 'Post-HS plans', '20_schoolsystem_id': 'School system ID', '21_tshirt_size': 'T-Shirt Size', } last_label_index = len(labels) for i in range( 3 ): #replace 3 with call to get_max_applications + fix that method key = str(last_label_index + i + 1) + '_class_application_' + str(i + 1) labels[key] = 'Class Application ' + str(i + 1) result = {} for item in dir(UserAttributeGetter): label_map = {} for x in labels.keys(): label_map[x[3:]] = x if item.startswith('get_') and item[4:] in label_map: result[label_map[item[4:]]] = labels[label_map[item[4:]]] return result def __init__(self, user, program): self.user = ESPUser(user) self.program = program self.profile = self.user.getLastProfile() def get(self, attr): attr = attr.lstrip('0123456789_') #if attr = 'classapplication': result = getattr(self, 'get_' + attr)() if result is None: return 'N/A' else: if result is True: return 'Yes' elif result is False: return 'No' else: return result def get_id(self): return self.user.id def get_address(self): if self.profile.contact_user: return self.profile.contact_user.address() def get_fullname(self): return self.user.name() def get_lastname(self): return self.user.last_name def get_firstname(self): return self.user.first_name def get_username(self): return self.user.username def get_email(self): return self.user.email def get_accountdate(self): return self.user.date_joined.strftime("%m/%d/%Y") def get_regdate(self, ordering='startdate'): reg_verb = GetNode('V/Flags/Registration/Enrolled') reg_node_parent = self.program.anchor['Classes'] bits = UserBit.valid_objects().filter( user=self.user, verb=reg_verb).filter(QTree(qsc__below=reg_node_parent)) if bits.exists(): return bits.order_by(ordering).values_list( 'startdate', flat=True)[0].strftime("%Y-%m-%d %H:%M:%S") def get_first_regdate(self): return self.get_regdate(ordering='startdate') def get_last_regdate(self): return self.get_regdate(ordering='-startdate') def get_cellphone(self): if self.profile.contact_user: return self.profile.contact_user.phone_cell def get_textmsg(self): if self.profile.contact_user: return self.profile.contact_user.receive_txt_message def get_studentrep(self): if self.profile.student_info: return self.profile.student_info.studentrep def get_classhours(self): return sum([ x.meeting_times.count() for x in self.user.getEnrolledSections(self.program) ]) def get_school(self): if self.profile.student_info: if self.profile.student_info.k12school: return self.profile.student_info.k12school.name else: return self.profile.student_info.school def get_tshirt_size(self): if self.profile.student_info: return self.profile.student_info.shirt_size elif self.profile.teacher_info: return self.profile.teacher_info.shirt_size else: return None def get_heard_about(self): if self.profile.student_info: return self.profile.student_info.heard_about def get_gradyear(self): if self.profile.student_info: return self.profile.student_info.graduation_year def get_transportation(self): if self.profile.student_info: return self.profile.student_info.transportation def get_post_hs(self): if self.profile.student_info: return self.profile.student_info.post_hs def get_schoolsystem_id(self): if self.profile.student_info: return self.profile.student_info.schoolsystem_id #Replace this with something based on presence and number of application questions for a particular program def get_max_applications(self): return 3 def get_class_application_1(self): responses = self.user.listAppResponses(self.program) if len(responses) > 0: return str(responses[0].question.subject) + ': ' + str( responses[0]) else: return None def get_class_application_2(self): responses = self.user.listAppResponses(self.program) if len(responses) > 1: return str(responses[1].question.subject) + ': ' + str( responses[0]) else: return None def get_class_application_3(self): responses = self.user.listAppResponses(self.program) if len(responses) > 2: return str(responses[2].question.subject) + ': ' + str( responses[0]) else: return None