コード例 #1
0
    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
コード例 #2
0
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