コード例 #1
0
ファイル: subscribe.py プロジェクト: Project78/Project78
    def post(self):
        session = get_current_session()
        '''A guardian is already logged in'''
        if self.isAuthenticatedGuardian():
            self.redirectToSubscriptionPage(self)
            return
        
        '''A visitor is not authenticated as a guardian, so move on'''
        session.clear()
        notifications = []
        templVal = {
            'notifications': notifications
        }
        
        '''The guardian-id and/or passphrase are/is empty'''
        if not (self.request.get('guardian-id') and self.request.get('passphrase')):
            notifications.append('Vul uw voogdnummer in en de sleutel die u ontvangen heeft.')
            self.showLoginPage(templVal)
            return

        guardian = Guardian.get_by_key_name(self.request.get('guardian-id'))
        passphrase = self.request.get('passphrase')
        
        '''A gardian with the given keyname does not exists'''
        if not guardian:
            notifications.append('Vul een bestaand voogdnummer in.')
            self.showLoginPage(templVal)
            return

        '''A combination of the gardian and the passphrase does not exists.'''
        subscriptionDetailsList = SubscriptionDetails.gql("WHERE guardian = :1 AND passphrase = :2", guardian, passphrase).fetch(1,0)
        if not subscriptionDetailsList:
            notifications.append('Vul een geldige combinatie van voogdnummer en sleutel in.')
            self.showLoginPage(templVal)
            return
        
        subscriptionDetails = subscriptionDetailsList[0]
        
        '''The guardian has already made a subscription for the concerning event'''
        if subscriptionDetails.requested:
            notifications.append('U kunt geen verzoeken meer indienen.')
            path = os.path.join(os.path.dirname(__file__), '../templates/notification.html')
            self.response.out.write(template.render(path, templVal))
            return
        
        '''Everything is ok, so login and go to the subscription page!'''
        event = subscriptionDetails.event
        session['guardian'] = guardian
        session['event'] = event
        self.redirectToSubscriptionPage(self)
コード例 #2
0
ファイル: subscribe.py プロジェクト: Project78/Project78
    def get(self, eventId, guardianId):
        '''The visitor is not an authenticated guardian'''
        if not SubscriptionLoginHandler.isAuthenticatedGuardian():
            self.redirect('/inschrijven/')
            return
        
        '''The guardian is not authorized to see the page with the given eventId/guardianId'''
        if not self.isAuthorized(eventId, guardianId):
            SubscriptionLoginHandler.redirectToSubscriptionPage(self)
            return
        
        '''The guardian is an authorized guardian, so show the form'''    
        event = Event.get_by_id(int(eventId))
        days = Day.gql("WHERE event = :1", event).fetch(999)
        guardian = Guardian.get_by_key_name(guardianId)
        notifications = []
        templVal = {
            'notifications': notifications
        }
        subscriptionDetailsList = SubscriptionDetails.gql("WHERE event = :1 AND guardian = :2", event, guardian).fetch(1, 0)
        if not subscriptionDetailsList:
            notifications.append('Pagina niet gevonden.')
            self.showError(templVal)
            return    
        subscriptionDetails = subscriptionDetailsList[0]
        if subscriptionDetails and subscriptionDetails.requested:
            notifications.append('U kunt geen verzoeken meer indienen.')
            self.showError(templVal)
            return            
        
        students = Student.gql("WHERE guardian = :1", guardian).fetch(999, 0)
        students_subjects = self.getStudentsSubjects(students) 

        if event and guardian and students and days:
            templVal = {
                'event': event,
                'days': days,
                'guardian': guardian,
                'students': students_subjects
            }
            path = os.path.join(os.path.dirname(__file__), '../templates/subscription/subscription.html')
            self.response.out.write(template.render(path, templVal))
コード例 #3
0
ファイル: subscribe.py プロジェクト: Project78/Project78
    def post(self, eventId, guardianId):
        '''The visitor is not an authenticated guardian'''
        if not SubscriptionLoginHandler.isAuthenticatedGuardian():
            self.redirect('/inschrijven/')
            return
        
        '''The guardian is not authorized to the given'''
        if not self.isAuthorized(eventId, guardianId):
            SubscriptionLoginHandler.redirectToSubscriptionPage(self)
            return
        
        event = Event.get_by_id(int(eventId))
        days = Day.gql("WHERE event = :1", event).fetch(999)
        guardian = Guardian.get_by_key_name(guardianId)
        students = Student.gql("WHERE guardian = :1", guardian).fetch(999, 0)
        students_subjects = self.getStudentsSubjects(students)
        notifications = []
        templVal = {
            'event': event,
            'days': days,
            'guardian': guardian,
            'students': students_subjects,
            'notifications': notifications
        }
           
        if not (event and days and guardian and students):
            notifications.append('U probeert een onmogelijke bewerking uit te voeren.')
            self.showError(templVal)
            return
        
        subscriptionDetailsList = SubscriptionDetails.gql("WHERE event = :1 AND guardian = :2", event, guardian).fetch(1, 0)
        if not subscriptionDetailsList:
            notifications.append('Pagina niet gevonden.')
            self.showError(templVal)
            return           
        subscriptionDetails = subscriptionDetailsList[0]
        if subscriptionDetails and subscriptionDetails.requested:
            notifications.append('U kunt geen verzoeken meer indienen.')
            self.showError(templVal)
            return
        
        studentKeys = [str(k.replace('subject_', '')) for k in self.request.arguments() if re.match("subject_.+", k)]
        requests = []
        dayPrefs = []
        
        for s in students[:]:
            if str(s.key().name()) not in studentKeys:
                students.remove(s)
                
        if not students:
            notifications.append('U kunt geen verzoek indienen als u geen enkel vak geselecteerd heeft. ')
        
        for student in students[:]:
            subjectCodes = [c for c in self.request.get_all("subject_" + str(student.key().name()))]
            subjects = Subject.get_by_key_name(subjectCodes)
            if len(subjectCodes) > 3:
                notifications.append('U kunt maximaal 3 vakken per leerling bespreken.')
            if len(subjectCodes) != len(subjects):
                notifications.append('U probeert een onmogelijke bewerking uit te voeren.')
                
            for subject in subjects:
                combination = Combination.gql("WHERE class_id = :1 AND subject = :2", student.class_id, subject).fetch(1,0)[0]
                if not combination:
                    notifications.append('U probeert een onmogelijke bewerking uit te voeren.')
                    self.showError(templVal)
                    return
                request = Request()
                request.event = event
                request.guardian = guardian
                request.student = student
                request.combination = combination
                requests.append(request)

        '''Process timepreference'''
        timePref = TimePreference()
        timePref.event = event
        timePref.guardian = guardian
        timePref.preference = 0
        if not (self.request.get('time_pref') and (int(self.request.get('time_pref')) in [0,1,2])):
            notifications.append('U moet een voorkeur voor tijd aangeven.')
        else:            
            timePref.preference = int(self.request.get('time_pref'))
        
        '''Check if dates from the form match the dates from the event '''
        dayKeys = [long(k.replace('date_', '')) for k in self.request.arguments() if re.match("date_.+", k)]
        dayKeysFromStore= [day.key().id() for day in days]
        daysOk = True
        for dayKey in dayKeys:
            if dayKey not in dayKeysFromStore:
                daysOk = False
                notifications.append('U probeert een onmogelijke bewerking uit te voeren.')
                self.showError(templVal)
                return

        '''Check if the daypreference are correct filled in'''    
        dayPrefsList = [int(self.request.get(k)) for k in self.request.arguments() if re.match("date_.+", k)]
        dayPrefsList.sort()
        dayPrefsOk = True
        if dayPrefsList != [1,2,3]:
            dayPrefsOk = False
            notifications.append('U moet een eerste, een tweede en een derde voorkeur aangeven')

        '''Process daypreferences'''
        if daysOk and dayPrefsOk:
            for day in days:
                dayPref = DayPreference()
                dayPref.day = day
                dayPref.guardian = guardian
                dayPref.rank = int(self.request.get("date_" + str(day.key().id())))
                dayPrefs.append(dayPref)
        
        if notifications:
            path = os.path.join(os.path.dirname(__file__), '../templates/subscription/subscription.html')
            self.response.out.write(template.render(path, templVal))
            return
        
        '''Store the requests'''
        for request in requests:
            request.put()
        for dayPref in dayPrefs:
            dayPref.put()
        timePref.put()
        subscriptionDetails.requested = True
        subscriptionDetails.put()
        
        SubscriptionLogoutHandler.logoutGuardian()
        path = os.path.join(os.path.dirname(__file__), '../templates/subscription/subscription-success.html')
        self.response.out.write(template.render(path, templVal))
        return        
コード例 #4
0
ファイル: administration.py プロジェクト: Project78/Project78
    def get(self, arg):
        event = Event.get_by_id(int(arg))
        notifications = []
        if not event:
            notifications.append("De bewerking kon niet worden voltooid omdat het event niet bestaat.")
            events = Event.all()
            path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-list.html')
            template_values = {'events': events, 'logoutlink': users.create_logout_url("/") , 'notifications': notifications }
            self.response.out.write(template.render(path, template_values))
            return
        
        requests = event.requests.fetch(9999)
        guardians_keys = []
        
        for request in requests:
            if request.guardian.key().name() not in guardians_keys:
                guardians_keys.append(request.guardian.key().name())
        
        if not guardians_keys:
            notifications.append("Er zijn geen voogden met verzoeken")
            events = Event.all()
            path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-list.html')
            template_values = {'events': events, 'logoutlink': users.create_logout_url("/") , 'notifications': notifications }
            self.response.out.write(template.render(path, template_values))
            return
            
        for guardian_num, guardian_key in enumerate(guardians_keys):
            guardian = Guardian.get_by_key_name(guardian_key)
            guardian_requests = Request.gql("WHERE guardian = :1 AND event = :2", guardian, event).fetch(999)
            guardian_appointments = [guardian_request.appointment.get() for guardian_request in guardian_requests if guardian_request.appointment.get()]
            day_ids = [appointment.day.key().id() for appointment in guardian_appointments if appointment]
            day_ids = list(set(day_ids))

            if not guardian_appointments:
                continue

            mail = Email()
            message = 'Beste ' + guardian.title
            if not guardian.preposition == '':
                message += ' ' + guardian.preposition
            message += ' ' + guardian.lastname + ',\n\n'
            message += 'Er zijn afspraken ingepland voor de ouderavond(en) van het ' + event.event_name + ". "
            message += 'Hieronder vind u de afspraken die voor u zijn gemaakt:\n\n'

            for day_id in day_ids:
                day = Day.get_by_id(day_id)
                message += 'Op ' + str(day.date.day) + ' ' + AdministrationInviteGuardiansHandler.getMonthText(self, day.date.month) + ' '  + str(day.date.year) + ':\n' 
                for appointment in guardian_appointments:
                    if appointment.day.key().id() == day_id:
                        student = appointment.request.student
                        m = event.talk_time * appointment.slot
                        d = timedelta(minutes=m)
                        time = day.date + d
                        message += 'Tijd: ' + str(time.hour) + ':' + str(time.minute) + '\n'
                        message += 'Tafel: ' + str(appointment.table) + '\n'
                        message += 'Leerling: ' + student.firstname + ' ' + student.preposition + ' ' + student.lastname + '\n'
                        message += 'Vak: ' + appointment.request.combination.subject.name + '\n'
                        message += 'Docent: ' + appointment.request.combination.teacher.name + '\n'
                        message += 'Docentcode: ' + appointment.request.combination.teacher.key().name() + '\n\n'
                    
#            mail.sendMail(guardian.email, 'Afspraken ouderavond(en) ' + event.event_name, message)
            if guardian_num == 0:
                print message
        return
コード例 #5
0
ファイル: administration.py プロジェクト: Project78/Project78
    def post(self, arg):
        event = Event.get_by_id(int(arg))
        notifications = []
        appointments = []
        
        template_values = {
            'event': event,
            'appointments': appointments,
            'notifications': notifications, 
            'logoutlink': users.create_logout_url("/") 
        }
        
        if not event: 
            notifications.append("Er is geen ouderavondreeks gevonden met het nummer " + str(arg))
            path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-appointments.html')
            self.response.out.write(template.render(path, template_values))
            return
        
        code = self.request.POST['search-code']
        method = self.request.POST['search-on']
        
        if not code:
            notifications.append("Er dient een docentcode of voogdnummer ingevoerd te worden.")
        if not method:
            notifications.append("Er dient aangegeven te worden of er op docent of voogd gezocht wordt.")
        if not (code and method):
            path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-appointments.html')
            self.response.out.write(template.render(path, template_values))
            return
        
        if method == 'guardian':
            guardian = Guardian.get_by_key_name(code)
            if not guardian:
                notifications.append("Er is geen voogd gevonden met het voogdnummer " + str(code))
                path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-appointments.html')
                self.response.out.write(template.render(path, template_values))
                return
            
            requests = guardian.all_requests.filter('event', event).fetch(999)
            for request in requests: 
                if request.appointment.get():
                    appointments.append(request.appointment.get()) 
            
            if not appointments:
                notifications.append("Er zijn geen afspraken gevonden voor de voogd met het voogdnummer " + str(code))
                path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-appointments.html')
                self.response.out.write(template.render(path, template_values))
                return
            
#            days = []
#            for appointment in appointments:
#                found = False
#                for day in days:
#                    if day.key().id() == appointment.day.key().id():
#                        found = True
#                        break
#                if not found:
#                    days.append(appointment.day)
#            
#            days_appointments = []
#            for day in days:
#                appointments_in_day = []
#                for appointment in appointments:
#                    if appointment.day.key().id() == day.key().id():
#                        appointments_in_day.append(appointment)
#                
#                days_appointments.append([day, appointments_in_day])
#            
#            days_tables_appointments = []
#            for day_appointments in days_appointments:
#                tables = []
#                for appointment in day_appointments[1]:
#                    if appointment.table not in tables:
#                        tables.append(int(appointment.table))
#                
#                day_tables = []
#                for table in tables:
#                    table_appointments = []
#                    for appointment in day_appointments[1]:
#                        if int(appointment.table) == table:
#                            table_appointments.append(appointment)
#                    day_tables.append([table, table_appointments])
#                days_tables_appointments.append([day_appointments[0], day_tables])
#                
#            day_tables_slots = []
#            for day_tables_appointments in days_tables_appointments:
#                for table_appointments in day_tables_appointments[1]:
#                    table_slots = []
#                    for slot in range(1, day_tables_appointments[0].talks+1):
#                        added = False
#                        for appointment in table_appointments[1]:
#                            if(int(appointment.slot) == slot):
#                                added = True
#                                table_slots.append(appointment)
#                        if not added:
#                            table_slots.append(1)
#                    day_tables_slots.append([day_tables_appointments[0], [table_appointments[0], table_slots]])
        elif method == 'teacher':
            teacher = Teacher.get_by_key_name(code.upper())
            if not teacher:
                notifications.append('Er is geen docent gevonden met de opgegeven docentcode.')
            if teacher:
                subjects = teacher.subjects.fetch(999)
                requests = []
                for subject in subjects:
                    reqs = subject.requests.fetch(999)
                    for req in reqs:
                        requests.append(req)
                appointments = [request.appointment.get() for request in requests if request.appointment.get()]
                if not appointments:
                    notifications.append("Er zijn geen afspraken gevonden voor de docent met docentcode " + str(code))
                    
        path = os.path.join(os.path.dirname(__file__), '../templates/administration/event-appointments.html')
        self.response.out.write(template.render(path, template_values))