Esempio n. 1
0
    def _edit(self, id):
        """UPDATE PERSON"""
        # We need to recheck auth in here so we can pass in the id
        if not h.auth.authorized(
                h.auth.Or(h.auth.is_same_zookeepr_user(id),
                          h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()

        c.person = Person.find_by_id(id)

        for key in self.form_result['person']:
            setattr(c.person, key, self.form_result['person'][key])

        for sn in self.form_result['social_network']:
            network = SocialNetwork.find_by_name(sn['name'])
            if sn['account_name']:
                c.person.social_networks[network] = sn['account_name']
            elif network in c.person.social_networks:
                del c.person.social_networks[network]

        # update the objects with the validated form data
        meta.Session.commit()

        redirect_to(action='view', id=id)
Esempio n. 2
0
    def index(self):
        c.DAYS_OPEN = DAYS_OPEN
        c.open_date = lca_info.lca_info['date']
        days_open = (datetime.date.today() - c.open_date.date()).days
        photo_db = PhotoCompEntry.read_db()
        photos = [
            photo for days in photo_db.values() for entries in days
            for photo in entries if photo is not None and photo.day < days_open
        ]
        c.no_photos = not photos
        day_filter = request.GET.get('day', 'All')
        if day_filter and day_filter != 'All':
            photos = [p for p in photos if str(p.day) == day_filter]
        person_filter = request.GET.get('person', 'All')
        if person_filter and person_filter != 'All':
            photos = [p for p in photos if str(p.person_id) == person_filter]
        submitted = request.GET.get('s', None)
        randomise = not submitted or 'randomise' in request.GET
        if randomise:
            random.shuffle(photos)
        else:
            photos.sort(key=lambda p: (p.day, p.person_id, p.entry_id))
        person_map = {}
        for photo in photos:
            photo.write_scaled()
            person_map[photo.person_id] = None
        c.all_person = []
        for person_id in person_map:
            person = Person.find_by_id(person_id)
            person_map[person_id] = person
            c.all_person.append(person)
        c.all_person.sort(key=lambda person:
                          (person.firstname + " " + person.lastname).lower())
        c.photos = photos

        def photo_title(photo):
            return "%s %s, %s entry %s, %s" % (
                person_map[photo.person_id].firstname,
                person_map[photo.person_id].lastname,
                (c.open_date + datetime.timedelta(photo.day)).strftime('%A'),
                ENTRY_NAMES[photo.entry_id],
                photo.image_name,
            )

        c.photo_title = photo_title
        field_values = {
            'day': day_filter,
            'person': person_filter,
        }
        if randomise:
            field_values['randomise'] = '1'
        if submitted == 'Full Screen' and photos:
            html = render('/photocomp/index-fullscreen.mako')
        else:
            html = render('/photocomp/index.mako')
        return htmlfill.render(html, field_values)
Esempio n. 3
0
    def view(self, id):
        # We need to recheck auth in here so we can pass in the id
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_user(id), h.auth.has_reviewer_role, h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()

        c.registration_status = h.config['app_conf'].get('registration_status')
        c.person = Person.find_by_id(id)

        return render('person/view.mako')
Esempio n. 4
0
    def index(self):
        c.DAYS_OPEN = DAYS_OPEN
        c.open_date = lca_info.lca_info['date']
        days_open = (datetime.date.today() - c.open_date.date()).days
        photo_db = PhotoCompEntry.read_db()
        photos = [
            photo
            for days in photo_db.values()
            for entries in days
            for photo in entries
            if photo is not None and photo.day < days_open]
        c.no_photos = not photos
        day_filter = request.GET.get('day', 'All')
        if day_filter and day_filter != 'All':
            photos = [p for p in photos if str(p.day) == day_filter]
        person_filter = request.GET.get('person', 'All')
        if person_filter and person_filter != 'All':
            photos = [p for p in photos if str(p.person_id) == person_filter]
        submitted = request.GET.get('s', None)
        randomise = not submitted or 'randomise' in request.GET
        if randomise:
            random.shuffle(photos)
        else:
            photos.sort(key=lambda p: (p.day, p.person_id, p.entry_id))
        person_map = {}
        for photo in photos:
            photo.write_scaled()
            person_map[photo.person_id] = None
        c.all_person = []
        for person_id in person_map:
            person = Person.find_by_id(person_id)
            person_map[person_id] = person
            c.all_person.append(person)
        c.all_person.sort(key=lambda person: (person.firstname + " " + person.lastname).lower())
        c.photos = photos
        def photo_title(photo):
            return "%s %s, %s entry %s, %s" % (
                person_map[photo.person_id].firstname,
                person_map[photo.person_id].lastname,
                (c.open_date + datetime.timedelta(photo.day)).strftime('%A'),
                ENTRY_NAMES[photo.entry_id],
                photo.image_name,)
        c.photo_title = photo_title
        field_values = {
            'day':      day_filter,
            'person':   person_filter,
        }
        if randomise:
            field_values['randomise'] = '1'
	if submitted == 'Full Screen' and photos:
            html = render('/photocomp/index-fullscreen.mako')
        else:
            html = render('/photocomp/index.mako')
        return htmlfill.render(html, field_values)
Esempio n. 5
0
    def view(self, id):
        # We need to recheck auth in here so we can pass in the id
        if not h.auth.authorized(
                h.auth.Or(h.auth.is_same_zookeepr_user(id),
                          h.auth.has_reviewer_role,
                          h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()

        c.registration_status = h.config['app_conf'].get('registration_status')
        c.person = Person.find_by_id(id)

        return render('person/view.mako')
Esempio n. 6
0
    def edit(self, id):
        # We need to recheck auth in here so we can pass in the id
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_user(id), h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()
        c.form = 'edit'
        c.person = Person.find_by_id(id)
        c.social_networks = SocialNetwork.find_all()
        c.person.fetch_social_networks()

        defaults = h.object_to_defaults(c.person, 'person')
        defaults['person.email_address2'] = c.person.email_address

        form = render('/person/edit.mako')
        return htmlfill.render(form, defaults)
Esempio n. 7
0
    def edit(self, id):
        # We need to recheck auth in here so we can pass in the id
        if not h.auth.authorized(
                h.auth.Or(h.auth.is_same_zookeepr_user(id),
                          h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()
        c.form = 'edit'
        c.person = Person.find_by_id(id)
        c.social_networks = SocialNetwork.find_all()
        c.person.fetch_social_networks()

        defaults = h.object_to_defaults(c.person, 'person')
        defaults['person.email_address2'] = c.person.email_address

        form = render('/person/edit.mako')
        return htmlfill.render(form, defaults)
Esempio n. 8
0
    def _edit(self, id):
        """UPDATE PERSON"""
        # We need to recheck auth in here so we can pass in the id
        if not h.auth.authorized(h.auth.Or(h.auth.is_same_zookeepr_user(id), h.auth.has_organiser_role)):
            # Raise a no_auth error
            h.auth.no_role()

        c.person = Person.find_by_id(id)

        for key in self.form_result['person']:
            setattr(c.person, key, self.form_result['person'][key])

        for sn in self.form_result['social_network']:
           network = SocialNetwork.find_by_name(sn['name'])
           if sn['account_name']:
               c.person.social_networks[network] = sn['account_name']
           elif network in c.person.social_networks:
               del c.person.social_networks[network]

        # update the objects with the validated form data
        meta.Session.commit()

        redirect_to(action='view', id=id)
Esempio n. 9
0
    def _roles(self, id):
        """ Lists and changes the person's roles. """

        c.person = Person.find_by_id(id)
        c.roles = Role.find_all()

        role = self.form_result['role']
        action = self.form_result['action']

        role = Role.find_by_name(name=role)

        if action == 'Revoke' and role in c.person.roles:
            c.person.roles.remove(role)
            h.flash('Role ' + role.name + ' Revoked')
        elif action == 'Grant' and role not in c.person.roles:
            c.person.roles.append(role)
            h.flash('Role ' + role.name + ' Granted')
        else:
            h.flash("Nothing to do")

        meta.Session.commit()

        return render('person/roles.mako')
Esempio n. 10
0
    def _roles(self, id):
        """ Lists and changes the person's roles. """

        c.person = Person.find_by_id(id)
        c.roles = Role.find_all()

        role = self.form_result['role']
        action = self.form_result['action']

        role = Role.find_by_name(name=role)

        if action == 'Revoke' and role in c.person.roles:
            c.person.roles.remove(role)
            h.flash('Role ' + role.name + ' Revoked')
        elif action == 'Grant' and role not in c.person.roles:
            c.person.roles.append(role)
            h.flash('Role ' + role.name + ' Granted')
        else:
            h.flash("Nothing to do")

        meta.Session.commit()

        return render('person/roles.mako')
Esempio n. 11
0
    def roles(self, id):

        c.person = Person.find_by_id(id)
        c.roles = Role.find_all()
        return render('person/roles.mako')
Esempio n. 12
0
 def reprint(self, id):
     c.person = Person.find_by_id(id)
     c.person.badge_printed = False
     meta.Session.commit()
     redirect_to(action='view', id=id)
Esempio n. 13
0
 def _to_python(self, value, state):
     return Person.find_by_id(int(value))
Esempio n. 14
0
 def reprint(self, id):
     c.person = Person.find_by_id(id)
     c.person.badge_printed = False
     meta.Session.commit()
     redirect_to(action='view', id=id)
Esempio n. 15
0
 def _to_python(self, value, state):
     return Person.find_by_id(int(value))
Esempio n. 16
0
 def _to_python(self, value, state):
     person = Person.find_by_id(int(value), abort_404=False)
     if person is None:
         raise Invalid("Unknown person ID.", value, state)
     else:
         return person
Esempio n. 17
0
    def roles(self, id):

        c.person = Person.find_by_id(id)
        c.roles = Role.find_all()
        return render('person/roles.mako')
Esempio n. 18
0
 def _to_python(self, value, state):
     person = Person.find_by_id(int(value), abort_404=False)
     if person is None:
         raise Invalid("Unknown person ID.", value, state)
     else:
         return person