<commit_before>from uber.common import *


def to_sessionized(attendee, group):
    if group.badges:
        return Charge.to_sessionized(group)
    else:
        return Charge.to_sessionized(attendee)


def check_prereg_reqs(attendee):
    if attendee.badge_type == c.PSEUDO_DEALER_BADGE and not attendee.cellphone:
        return 'Your phone number is required'
    elif attendee.amount_extra >= c.SHIRT_LEVEL and attendee.shirt == c.NO_SHIRT:
        return 'Your shirt size is required'


def check_dealer(group):
    if not group.wares:
        return 'You must provide a detailed explanation of what you sell for us to evaluate your submission'
    elif not group.website:
        return "Please enter your business' website address"
    elif not group.description:
        return 'Please provide a brief description of your business'
    elif not group.address:
        return 'Please provide your full address for tax purposes'


def send_banned_email(attendee):
    try:
        send_email(c.REGDESK_EMAIL, c.REGDESK_EMAIL, 'Banned attendee registration',
                   render('emails/reg_workflow/banned_attendee.txt', {'attendee': attendee}), model='n/a')
    except:
        log.error('unable to send banned email about {}', attendee)


def check_post_con(klass):
    def wrapper(func):
        @wraps(func)
        def wrapped(self, *args, **kwargs):
            if c.POST_CON:  # TODO: replace this with a template and make that suitably generic
                return """
                <html><head></head><body style='text-align:center'>
                    <h2 style='color:red'>Hope you had a great {event}!</h2>
                    Preregistration for {event} {year} will open in a few months.
                </body></html>
                """.format(event=EVENT_NAME, year=(1 + int(YEAR)) if YEAR else '')
            else:
                return func(self, *args, **kwargs)
        return wrapped

    for name in dir(klass):
        method = getattr(klass, name)
        if not name.startswith('_') and hasattr(method, '__call__'):
            setattr(klass, name, wrapper(method))
    return klass


@all_renderable()
@check_post_con
class Root:
    @property
    def unpaid_preregs(self):
        return cherrypy.session.setdefault('unpaid_preregs', OrderedDict())

    @property
    def paid_preregs(self):
        return cherrypy.session.setdefault('paid_preregs', [])

    def _get_unsaved(self, id, if_not_found=None):
        """
        if_not_found:  pass in an HTTPRedirect() class to raise if the unsaved attendee is not found.
                       by default we will redirect to the index page
        """
        if id in self.unpaid_preregs:
            target = Charge.from_sessionized(self.unpaid_preregs[id])
            if isinstance(target, Attendee):
                return target, Group()
            else:
                [leader] = [a for a in target.attendees if not a.is_unassigned]
                return leader, target
        else:
            raise HTTPRedirect('index') if if_not_found is None else if_not_found

    def stats(self):
        cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
        return json.dumps({
            'badges_sold': c.BADGES_SOLD,
            'remaining_badges': c.REMAINING_BADGES,

            'server_current_timestamp': int(datetime.utcnow().timestamp()),
            'warn_if_server_browser_time_mismatch': c.WARN_IF_SERVER_BROWSER_TIME_MISMATCH
        })

    def check_prereg(self):
        return json.dumps({'force_refresh': c.AFTER_PREREG_TAKEDOWN or c.BADGES_SOLD >= c.MAX_BADGE_SALES})

    def check_if_preregistered(self, session, message="", **params):
        if 'email' in params:
            attendee = session.query(Attendee).filter(func.lower(Attendee.email) == func.lower(params['email'])).first()
            message = "Thank you! You will receive a confirmation email if you are registered for {}.".format(c.EVENT_NAME_AND_YEAR)
            subject = c.EVENT_NAME_AND_YEAR + ' Registration Confirmation'

            if attendee:
                last_email = session.query(Email)\
                                  .filter(and_(Email.dest == attendee.email, Email.subject == subject))\
                                  .order_by(Email.when.desc()).first()
                if not last_email or last_email.when < (localized_now() - timedelta(days=7)):
                    send_email(c.REGDESK_EMAIL, attendee.email, subject, render('emails/reg_workflow/prereg_check.html', {
                        'attendee': attendee
                    }), model=attendee)
        return {'message': message}

    @check_if_can_reg
    def index(self, message=''):<commit_msg>add laptop "kiosk-mode" landing page this is needed because once laptops are imaged, it's really painful to change their homepage this allows devs to redirect to a different page if needed without having to mess with the laptop config<commit_after>from uber.common import *


def to_sessionized(attendee, group):
    if group.badges:
        return Charge.to_sessionized(group)
    else:
        return Charge.to_sessionized(attendee)


def check_prereg_reqs(attendee):
    if attendee.badge_type == c.PSEUDO_DEALER_BADGE and not attendee.cellphone:
        return 'Your phone number is required'
    elif attendee.amount_extra >= c.SHIRT_LEVEL and attendee.shirt == c.NO_SHIRT:
        return 'Your shirt size is required'


def check_dealer(group):
    if not group.wares:
        return 'You must provide a detailed explanation of what you sell for us to evaluate your submission'
    elif not group.website:
        return "Please enter your business' website address"
    elif not group.description:
        return 'Please provide a brief description of your business'
    elif not group.address:
        return 'Please provide your full address for tax purposes'


def send_banned_email(attendee):
    try:
        send_email(c.REGDESK_EMAIL, c.REGDESK_EMAIL, 'Banned attendee registration',
                   render('emails/reg_workflow/banned_attendee.txt', {'attendee': attendee}), model='n/a')
    except:
        log.error('unable to send banned email about {}', attendee)


def check_post_con(klass):
    def wrapper(func):
        @wraps(func)
        def wrapped(self, *args, **kwargs):
            if c.POST_CON:  # TODO: replace this with a template and make that suitably generic
                return """
                <html><head></head><body style='text-align:center'>
                    <h2 style='color:red'>Hope you had a great {event}!</h2>
                    Preregistration for {event} {year} will open in a few months.
                </body></html>
                """.format(event=EVENT_NAME, year=(1 + int(YEAR)) if YEAR else '')
            else:
                return func(self, *args, **kwargs)
        return wrapped

    for name in dir(klass):
        method = getattr(klass, name)
        if not name.startswith('_') and hasattr(method, '__call__'):
            setattr(klass, name, wrapper(method))
    return klass


@all_renderable()
@check_post_con
class Root:
    @property
    def unpaid_preregs(self):
        return cherrypy.session.setdefault('unpaid_preregs', OrderedDict())

    @property
    def paid_preregs(self):
        return cherrypy.session.setdefault('paid_preregs', [])

    def _get_unsaved(self, id, if_not_found=None):
        """
        if_not_found:  pass in an HTTPRedirect() class to raise if the unsaved attendee is not found.
                       by default we will redirect to the index page
        """
        if id in self.unpaid_preregs:
            target = Charge.from_sessionized(self.unpaid_preregs[id])
            if isinstance(target, Attendee):
                return target, Group()
            else:
                [leader] = [a for a in target.attendees if not a.is_unassigned]
                return leader, target
        else:
            raise HTTPRedirect('index') if if_not_found is None else if_not_found

    def stats(self):
        cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
        return json.dumps({
            'badges_sold': c.BADGES_SOLD,
            'remaining_badges': c.REMAINING_BADGES,

            'server_current_timestamp': int(datetime.utcnow().timestamp()),
            'warn_if_server_browser_time_mismatch': c.WARN_IF_SERVER_BROWSER_TIME_MISMATCH
        })

    def kiosk(self):
        """
        Landing page for kiosk laptops, this should redirect to whichever page we want at-the-door laptop kiosks
        to land on.  The reason this is a redirect is that at-the-door laptops might be imaged and hard to change
        their default landing page.  If sysadmins want to change the landing page, they can do it here.
        """
        raise HTTPRedirect('form')


    def check_prereg(self):
        return json.dumps({'force_refresh': c.AFTER_PREREG_TAKEDOWN or c.BADGES_SOLD >= c.MAX_BADGE_SALES})

    def check_if_preregistered(self, session, message="", **params):
        if 'email' in params:
            attendee = session.query(Attendee).filter(func.lower(Attendee.email) == func.lower(params['email'])).first()
            message = "Thank you! You will receive a confirmation email if you are registered for {}.".format(c.EVENT_NAME_AND_YEAR)
            subject = c.EVENT_NAME_AND_YEAR + ' Registration Confirmation'

            if attendee:
                last_email = session.query(Email)\
                                  .filter(and_(Email.dest == attendee.email, Email.subject == subject))\
                                  .order_by(Email.when.desc()).first()
                if not last_email or last_email.when < (localized_now() - timedelta(days=7)):
                    send_email(c.REGDESK_EMAIL, attendee.email, subject, render('emails/reg_workflow/prereg_check.html', {
                        'attendee': attendee
                    }), model=attendee)
        return {'message': message}

    @check_if_can_reg
    def index(self, message=''):
{'fraction_non_alphanumeric': 0.09814297124600639, 'fraction_numerical': 0.0007987220447284345, 'mean_word_length': 2.4853862212943634, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2962275', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2890, 'n_words': 790}