Exemple #1
0
 def child_ribbon_or_not(self):
     if self.age_group in [c.UNDER_6, c.UNDER_13]:
         self.ribbon = add_opt(self.ribbon_ints, c.UNDER_13)
     elif c.UNDER_13 in self.ribbon_ints and self.age_group not in [
             c.UNDER_6, c.UNDER_13
     ]:
         self.ribbon = remove_opt(self.ribbon_ints, c.UNDER_13)
Exemple #2
0
 def unset_volunteering(self):
     self.staffing = False
     self.requested_any_dept = False
     self.requested_depts = []
     self.assigned_depts = []
     self.ribbon = remove_opt(self.ribbon_ints, c.VOLUNTEER_RIBBON)
     if self.badge_type == c.STAFF_BADGE:
         self.badge_type = c.ATTENDEE_BADGE
         self.badge_num = None
     del self.shifts[:]
    def form(self, session, new_app='', message='', **params):
        if new_app and 'attendee_id' in params:
            app = session.marketplace_application(params, ignore_csrf=True)
        else:
            app = session.marketplace_application(params)
        attendee = None

        attendee_attrs = session.query(Attendee.id, Attendee.last_first, Attendee.badge_type, Attendee.badge_num) \
            .filter(Attendee.first_name != '', Attendee.badge_status not in [c.INVALID_STATUS, c.WATCHED_STATUS])

        attendees = [
            (id,
             '{} - {}{}'.format(name.title(), c.BADGES[badge_type],
                                ' #{}'.format(badge_num) if badge_num else ''))
            for id, name, badge_type, badge_num in attendee_attrs
        ]

        if cherrypy.request.method == 'POST':
            if new_app:
                attendee, message = session.attendee_from_marketplace_app(
                    **params)
            else:
                attendee = app.attendee
            message = message or check(app)
            if not message:
                if attendee:
                    if params.get('badge_status', ''):
                        attendee.badge_status = params['badge_status']

                    session.add(attendee)
                    app.attendee = attendee

                    if app.status == c.APPROVED and attendee.group:
                        attendee.group.status = c.CANCELLED
                        attendee.group = None
                        attendee.paid = c.NOT_PAID
                        session.commit()  # Lets us remove the dealer ribbon
                        attendee.ribbon = remove_opt(attendee.ribbon_ints,
                                                     c.DEALER_RIBBON)

                if params.get('save') == 'save_return_to_search':
                    return_to = 'index?'
                else:
                    return_to = 'form?id=' + app.id + '&'
                raise HTTPRedirect(return_to + 'message={}',
                                   'Application updated')
        return {
            'message': message,
            'app': app,
            'attendee': attendee,
            'attendee_id': app.attendee_id or params.get('attendee_id', ''),
            'all_attendees': sorted(attendees, key=lambda tup: tup[1]),
            'new_app': new_app,
        }
    def staffing_badge_and_ribbon_adjustments(self):
        if self.badge_type == c.STAFF_BADGE or c.STAFF_RIBBON in self.ribbon_ints:
            self.ribbon = remove_opt(self.ribbon_ints, c.VOLUNTEER_RIBBON)

        elif self.staffing and self.badge_type != c.STAFF_BADGE \
                and c.STAFF_RIBBON not in self.ribbon_ints and c.VOLUNTEER_RIBBON not in self.ribbon_ints:
            self.ribbon = add_opt(self.ribbon_ints, c.VOLUNTEER_RIBBON)

        if self.badge_type == c.STAFF_BADGE or c.STAFF_RIBBON in self.ribbon_ints:
            self.staffing = True
            if not self.overridden_price and self.paid in [c.NOT_PAID, c.PAID_BY_GROUP]:
                self.paid = c.NEED_NOT_PAY
Exemple #5
0
    def _staffing_adjustments(self):
        if self.is_dept_head:
            self.staffing = True
            if c.SHIFT_CUSTOM_BADGES or \
                    c.STAFF_BADGE not in c.PREASSIGNED_BADGE_TYPES:
                self.badge_type = c.STAFF_BADGE
            if self.paid == c.NOT_PAID:
                self.paid = c.NEED_NOT_PAY
        elif c.VOLUNTEER_RIBBON in self.ribbon_ints and self.is_new:
            self.staffing = True

        if not self.is_new:
            old_ribbon = map(int, self.orig_value_of('ribbon').split(',')) \
                if self.orig_value_of('ribbon') else []
            old_staffing = self.orig_value_of('staffing')

            if self.staffing and not old_staffing or \
                    c.VOLUNTEER_RIBBON in self.ribbon_ints and \
                    c.VOLUNTEER_RIBBON not in old_ribbon:
                self.staffing = True

            elif old_staffing and not self.staffing \
                    or c.VOLUNTEER_RIBBON not in self.ribbon_ints \
                    and c.VOLUNTEER_RIBBON in old_ribbon \
                    and not self.is_dept_head:
                self.unset_volunteering()

        if self.badge_type == c.STAFF_BADGE:
            self.ribbon = remove_opt(self.ribbon_ints, c.VOLUNTEER_RIBBON)

        elif self.staffing and self.badge_type != c.STAFF_BADGE and \
                c.VOLUNTEER_RIBBON not in self.ribbon_ints:
            self.ribbon = add_opt(self.ribbon_ints, c.VOLUNTEER_RIBBON)

        if self.badge_type == c.STAFF_BADGE:
            self.staffing = True
            if not self.overridden_price \
                    and self.paid in [c.NOT_PAID, c.PAID_BY_GROUP]:
                self.paid = c.NEED_NOT_PAY
Exemple #6
0
def _decline_and_convert_dealer_group(session, group, status=c.DECLINED):
    """
    Deletes the waitlisted dealer group and converts all of the group members
    to the appropriate badge type. Unassigned, unpaid badges will be deleted.
    """
    admin_note = 'Converted badge from waitlisted {} "{}".'.format(c.DEALER_REG_TERM, group.name)
    group.status = status

    if not group.is_unpaid:
        group.tables = 0
        for attendee in group.attendees:
            attendee.append_admin_note(admin_note)
            attendee.ribbon = remove_opt(attendee.ribbon_ints, c.DEALER_RIBBON)
        return 'Group {} status removed'.format(c.DEALER_TERM)

    message = ['Group declined']
    emails_failed = 0
    emails_sent = 0
    badges_converted = 0

    for attendee in list(group.attendees):
        if _is_dealer_convertible(attendee):
            attendee.badge_status = c.INVALID_STATUS

            if not attendee.is_unassigned:
                new_attendee = Attendee()
                for attr in c.UNTRANSFERABLE_ATTRS:
                    setattr(new_attendee, attr, getattr(attendee, attr))
                new_attendee.overridden_price = attendee.base_badge_price - c.GROUP_DISCOUNT
                new_attendee.base_badge_price = attendee.base_badge_price
                new_attendee.append_admin_note(admin_note)
                session.add(new_attendee)

                try:
                    send_email.delay(
                        c.MARKETPLACE_EMAIL,
                        new_attendee.email,
                        'Do you still want to come to {}?'.format(c.EVENT_NAME),
                        render('emails/dealers/badge_converted.html', {
                            'attendee': new_attendee,
                            'group': group}, encoding=None),
                        format='html',
                        model=attendee.to_dict('id'))
                    emails_sent += 1
                except Exception:
                    emails_failed += 1

                badges_converted += 1
        else:
            if attendee.paid not in [c.HAS_PAID, c.NEED_NOT_PAY]:
                attendee.paid = c.NOT_PAID

            attendee.append_admin_note(admin_note)
            attendee.ribbon = remove_opt(attendee.ribbon_ints, c.DEALER_RIBBON)

    for count, template in [
            (badges_converted, '{} badge{} converted'),
            (emails_sent, '{} email{} sent'),
            (emails_failed, '{} email{} failed to send')]:

        if count > 0:
            message.append(template.format(count, pluralize(count)))

    return ', '.join(message)
Exemple #7
0
def _decline_and_convert_dealer_group(session, group, delete_when_able=False):
    """
    Deletes the waitlisted dealer group and converts all of the group members
    to the appropriate badge type. Unassigned, unpaid badges will be deleted.
    """
    admin_note = 'Converted badge from waitlisted dealer group "{}".'.format(
        group.name)

    if not group.is_unpaid:
        group.tables = 0
        for attendee in group.attendees:
            attendee.append_admin_note(admin_note)
            attendee.ribbon = remove_opt(attendee.ribbon_ints, c.DEALER_RIBBON)
        return 'Group dealer status removed'

    message = ['Group declined']
    emails_failed = 0
    emails_sent = 0
    badges_converted = 0
    badges_deleted = 0

    group.leader = None
    for attendee in list(group.attendees):
        if (delete_when_able or attendee.is_unassigned
            ) and _is_attendee_disentangled(attendee):
            session.delete(attendee)
            badges_deleted += 1

        else:
            if _is_dealer_convertible(attendee):
                attendee.badge_status = c.NEW_STATUS

                try:
                    send_email.delay(
                        c.REGDESK_EMAIL,
                        attendee.email,
                        'Do you still want to come to {}?'.format(
                            c.EVENT_NAME),
                        render('emails/dealers/badge_converted.html', {
                            'attendee': attendee,
                            'group': group
                        },
                               encoding=None),
                        format='html',
                        model=attendee.to_dict('id'))
                    emails_sent += 1
                except Exception:
                    emails_failed += 1

            badges_converted += 1

            if attendee.paid not in [c.HAS_PAID, c.NEED_NOT_PAY]:
                attendee.paid = c.NOT_PAID

            attendee.append_admin_note(admin_note)
            attendee.ribbon = remove_opt(attendee.ribbon_ints, c.DEALER_RIBBON)
            group.attendees.remove(attendee)

    session.delete(group)

    for count, template in [(badges_converted, '{} badge{} converted'),
                            (emails_sent, '{} email{} sent'),
                            (emails_failed, '{} email{} failed to send'),
                            (badges_deleted, '{} badge{} deleted')]:

        if count > 0:
            message.append(template.format(count, pluralize(count)))

    return ', '.join(message)
Exemple #8
0
 def test_remove_opt_second(self):
     assert str(c.DEALER_RIBBON) == remove_opt(
         Attendee(ribbon=','.join([str(c.VOLUNTEER_RIBBON), str(c.DEALER_RIBBON)])).ribbon_ints, c.VOLUNTEER_RIBBON)
Exemple #9
0
 def test_remove_opt_only(self):
     assert '' == remove_opt(Attendee(ribbon=c.DEALER_RIBBON).ribbon_ints, c.DEALER_RIBBON)
Exemple #10
0
 def test_remove_opt_empty(self):
     assert '' == remove_opt(Attendee().ribbon_ints, c.DEALER_RIBBON)
Exemple #11
0
 def child_to_attendee(self):
     if self.badge_type == c.CHILD_BADGE and self.age_group in [c.UNDER_21, c.OVER_21]:
         self.badge_type = c.ATTENDEE_BADGE
         self.ribbon = remove_opt(self.ribbon_ints, c.UNDER_13)
Exemple #12
0
def _decline_and_convert_dealer_group(session, group, status=c.DECLINED):
    """
    Deletes the waitlisted dealer group and converts all of the group members
    to the appropriate badge type. Unassigned, unpaid badges will be deleted.
    """
    admin_note = 'Converted badge from waitlisted dealer group "{}".'.format(group.name)
    group.status = status

    if not group.is_unpaid:
        group.tables = 0
        for attendee in group.attendees:
            attendee.append_admin_note(admin_note)
            attendee.ribbon = remove_opt(attendee.ribbon_ints, c.DEALER_RIBBON)
        return 'Group dealer status removed'

    message = ['Group declined']
    emails_failed = 0
    emails_sent = 0
    badges_converted = 0

    for attendee in list(group.attendees):
        if _is_dealer_convertible(attendee):
            attendee.badge_status = c.INVALID_STATUS

            if not attendee.is_unassigned:
                new_attendee = Attendee()
                for attr in c.UNTRANSFERABLE_ATTRS:
                    setattr(new_attendee, attr, getattr(attendee, attr))
                new_attendee.overridden_price = attendee.overridden_price
                new_attendee.base_badge_price = attendee.base_badge_price
                new_attendee.append_admin_note(admin_note)
                session.add(new_attendee)

                try:
                    send_email.delay(
                        c.MARKETPLACE_EMAIL,
                        new_attendee.email,
                        'Do you still want to come to {}?'.format(c.EVENT_NAME),
                        render('emails/dealers/badge_converted.html', {
                            'attendee': new_attendee,
                            'group': group}, encoding=None),
                        format='html',
                        model=attendee.to_dict('id'))
                    emails_sent += 1
                except Exception:
                    emails_failed += 1

                badges_converted += 1
        else:
            if attendee.paid not in [c.HAS_PAID, c.NEED_NOT_PAY]:
                attendee.paid = c.NOT_PAID

            attendee.append_admin_note(admin_note)
            attendee.ribbon = remove_opt(attendee.ribbon_ints, c.DEALER_RIBBON)

    for count, template in [
            (badges_converted, '{} badge{} converted'),
            (emails_sent, '{} email{} sent'),
            (emails_failed, '{} email{} failed to send')]:

        if count > 0:
            message.append(template.format(count, pluralize(count)))

    return ', '.join(message)
Exemple #13
0
 def test_remove_opt_second(self):
     assert str(c.DEALER_RIBBON) == remove_opt(
         Attendee(ribbon=','.join([str(c.VOLUNTEER_RIBBON), str(c.DEALER_RIBBON)])).ribbon_ints, c.VOLUNTEER_RIBBON)
Exemple #14
0
 def test_remove_opt_only(self):
     assert '' == remove_opt(Attendee(ribbon=c.DEALER_RIBBON).ribbon_ints, c.DEALER_RIBBON)
Exemple #15
0
 def test_remove_opt_empty(self):
     assert '' == remove_opt(Attendee().ribbon_ints, c.DEALER_RIBBON)
Exemple #16
0
 def child_to_attendee(self):
     if self.badge_type == c.CHILD_BADGE and self.age_group in [
             c.UNDER_21, c.OVER_21
     ]:
         self.badge_type = c.ATTENDEE_BADGE
         self.ribbon = remove_opt(self.ribbon_ints, c.UNDER_13)
Exemple #17
0
 def child_ribbon_or_not(self):
     if self.age_group in [c.UNDER_6, c.UNDER_13]:
         self.ribbon = add_opt(self.ribbon_ints, c.UNDER_13)
     elif c.UNDER_13 in self.ribbon_ints and self.age_group not in [c.UNDER_6, c.UNDER_13]:
         self.ribbon = remove_opt(self.ribbon_ints, c.UNDER_13)