def get_classcards(self, auth_user_id=None, public_only=True): """ :param public_only: Defines whether or not to show only public classcards, True by default False means all cards are returned Returns classcards for school """ from .tools import OsTools db = current.db os_tools = OsTools() allow_trial_for_existing_customers = os_tools.get_sys_property( 'shop_allow_trial_cards_for_existing_customers') query = (db.school_classcards.Archived == False) if public_only: query &= (db.school_classcards.PublicCard == True) if auth_user_id and allow_trial_for_existing_customers != 'on': from .os_customer import Customer customer = Customer(auth_user_id) existing_customer = customer.get_has_or_had_subscription_or_classcard( ) if existing_customer: query &= (db.school_classcards.Trialcard == False) return db(query).select(db.school_classcards.ALL, orderby=db.school_classcards.Trialcard | db.school_classcards.Name)
def _get_formatted_button_apply_accent_color(self, a): from .tools import OsTools os_tools = OsTools() color = os_tools.get_sys_property( 'shop_branding_secondary_accent_color') if color: a['_style'] = 'color: %s;' % (color) else: a['_class'] = '' return a
def _get_enddate(self, startdate): """ :return: """ from openstudio.tools import OsTools tools = OsTools() enddate = tools.calculate_validity_enddate( self.row.Startdate, self.school_membership.Validity, self.school_membership.ValidityUnit) return enddate
def _get_formatted_display_widget_header(self, name, price): from .tools import OsTools os_tools = OsTools() bg_color = os_tools.get_sys_property( 'shop_branding_primary_accent_bg_color') fg_color = os_tools.get_sys_property( 'shop_branding_primary_accent_fg_color') header = DIV(H3(name, _class="widget-user-username"), H4(price, _class="widget-user-desc"), _class="widget-user-header") if bg_color and fg_color: header['_style'] = 'background: %s; color: %s;' % (bg_color, fg_color) return header
def _render_email_template_teacher_sub_requests_daily_summary( self, template_content, auth_user_id): """ :param template_content: :param auth_user_id: :return: """ from openstudio.os_class import Class from openstudio.os_teacher import Teacher from openstudio.tools import OsTools from openstudio.os_classes_otcs import ClassesOTCs db = current.db T = current.T os_tools = OsTools() cotcs = ClassesOTCs() teacher = Teacher(auth_user_id) DATE_FORMAT = current.DATE_FORMAT TIME_FORMAT = current.TIME_FORMAT error = False error_msg = '' date_from = current.TODAY_LOCAL + datetime.timedelta(days=1) date_until = date_from + datetime.timedelta(days=45) # G get list of allowed class types query = (db.teachers_classtypes.auth_user_id == auth_user_id) classtype_rows = db(query).select(db.teachers_classtypes.ALL) ct_ids = [] for row in classtype_rows: ct_ids.append(int(row.school_classtypes_id)) open_classes_for_teacher = 0 open_classes = '' description = '' if ct_ids: sys_hostname = os_tools.get_sys_property('sys_hostname') description = XML( template_content.format(teacher_name=teacher.get_first_name(), link_employee_portal=URL( 'ep', 'index', scheme='https', host=sys_hostname))) open_classes = TABLE( THEAD( TR( TH(T("Date"), _align="left"), TH(T("Time"), _align="left"), TH(T("Location"), _align="left"), TH(T("Class"), _align="left"), # TH(), )), _cellspacing="0", _cellpadding='5px', _width='100%', border="0") # Get Open classes in the next 45 days rows = cotcs.get_sub_teacher_rows(date_from, date_until, school_classtypes_ids=ct_ids, only_open=True) for i, row in enumerate(rows): repr_row = list(rows[i:i + 1].render())[0] date = row.classes_otc.ClassDate clsID = row.classes.id cls = Class(clsID, date) regular_teachers = cls.get_regular_teacher_ids() if regular_teachers['auth_teacher_id'] == auth_user_id: continue open_classes.append( TR( TD(repr_row.classes_otc.ClassDate, _align="left"), TD(repr_row.classes.Starttime, _align="left"), TD(repr_row.classes.school_locations_id, _align="left"), TD(repr_row.classes.school_classtypes_id, _align="left"), # TD('Actions here?'), )) open_classes_for_teacher += 1 if not open_classes_for_teacher: error = True error_msg = T( "No upcoming classes with subs required found for this teacher" ) return dict(content=open_classes, description=description, error=error, error_msg=error_msg)
def get_memberships_formatted(self, per_row=3, public_only=True, link_type='shop'): """ :param public: boolean, defines whether to show only public or all memberships :return: list of school_memberships formatted for shop """ from openstudio.tools import OsTools from openstudio.os_school_membership import SchoolMembership os_gui = current.globalenv['os_gui'] T = current.T os_tools = OsTools() if per_row == 3: card_class = 'col-md-4' elif per_row == 4: card_class = 'col-md-3' else: raise ValueError('Incompatible value: per_row has to be 3 or 4') rows = self.get_memberships(public_only=public_only) memberships = DIV() display_row = DIV(_class='row') row_item = 0 for i, row in enumerate(rows): repr_row = list(rows[i:i + 1].render())[0] sm = SchoolMembership(row.id) name = max_string_length(row.Name, 33) validity = os_tools.format_validity(row.Validity, row.ValidityUnit) membership_content = TABLE( TR(TD(T('Validity')), TD(validity)), TR(TD(T('Price')), TD(sm.get_price_on_date(datetime.date.today()))), TR(TD(T('Description')), TD(row.Description or '')), _class='table') panel_class = 'box-primary' footer_content = '' if link_type == 'shop': footer_content = self._get_memberships_formatted_button_to_cart( row.id) membership = DIV(os_gui.get_box_table( name, membership_content, panel_class, show_footer=True, footer_content=footer_content), _class=card_class) display_row.append(membership) row_item += 1 if row_item == per_row or i == (len(rows) - 1): memberships.append(display_row) display_row = DIV(_class='row') row_item = 0 return memberships
def get_memberships_formatted(self, per_row=3, public_only=True, link_type='shop'): """ :param public: boolean, defines whether to show only public or all memberships :return: list of school_memberships formatted for shop """ from openstudio.tools import OsTools from openstudio.os_school_membership import SchoolMembership os_gui = current.globalenv['os_gui'] T = current.T os_tools = OsTools() TODAY_LOCAL = current.TODAY_LOCAL if per_row == 3: card_class = 'col-md-4' elif per_row == 4: card_class = 'col-md-3' else: raise ValueError('Incompatible value: per_row has to be 3 or 4') rows = self.get_memberships(public_only=public_only) memberships = DIV() display_row = DIV(_class='row') row_item = 0 for i, row in enumerate(rows): repr_row = list(rows[i:i + 1].render())[0] sm = SchoolMembership(row.id) name = max_string_length(row.Name, 33) validity = os_tools.format_validity(row.Validity, row.ValidityUnit) membership = DIV(DIV( DIV( self._get_formatted_display_widget_header( name, repr_row.Price)), DIV(DIV(repr_row.Description, _class='col-md-12'), _class='box-body'), DIV( DIV(DIV(DIV(H5(validity, _class="description-header"), SPAN(T("Validity"), _class="description-text"), _class="description-block"), _class="col-sm-6 border-right"), DIV(DIV(H5( self._get_memberships_formatted_button_to_cart( row.id), _class="description-header"), SPAN(T(""), _class="description-text"), _class="description-block"), _class="col-sm-6"), _class="row"), _class="box-footer", ), _class="box box-widget widget-user"), _class=card_class) display_row.append(membership) row_item += 1 if row_item == per_row or i == (len(rows) - 1): memberships.append(display_row) display_row = DIV(_class='row') row_item = 0 return memberships
def user(): """ exposes: http://..../[app]/default/user/login http://..../[app]/default/user/logout http://..../[app]/default/user/register http://..../[app]/default/user/profile http://..../[app]/default/user/retrieve_password http://..../[app]/default/user/change_password http://..../[app]/default/user/manage_users (requires membership in use @auth.requires_login() @auth.requires_membership('group name') @auth.requires_permission('read','table name',record_id) to decorate functions that need access control """ # If saml2 is enabled, use that one if configuration.get('auth.saml2_auth'): return saml_user() # check if someone is looking for profile if 'profile' in request.args: redirect(URL('profile', 'index')) # Send styles email messages from auth osmail = OsMail() auth.messages.verify_email = osmail.render_email_template( 'sys_verify_email', return_html=True)['html_message'] # auth.messages.reset_password = '******' auth.messages.reset_password = osmail.render_email_template( 'sys_reset_password', return_html=True)['html_message'] # Log registration accepted terms (if any) auth.settings.register_onaccept.append(user_register_log_acceptance) auth.settings.login_onaccept.append(user_set_last_login) # Fetch reCAPTCHA settings recaptcha_enabled = get_sys_property('recaptcha_enabled') recaptcha_site_key = get_sys_property('recaptcha_site_key') recaptcha_secret_key = get_sys_property('recaptcha_secret_key') use_recaptcha = False if recaptcha_enabled == "on" and recaptcha_site_key and recaptcha_secret_key: use_recaptcha = True ## Create auth form if session.show_location: # check if we need a requirement for the school_locations_id field for customers loc_query = (db.school_locations.AllowAPI == True) db.auth_user.school_locations_id.requires = IS_IN_DB( db(loc_query), 'school_locations.id', '%(Name)s', error_message=T('Please select a location'), zero=T('Please select a location...')) if get_sys_property('registration_requires_mobile') == "on": db.auth_user.mobile.requires = IS_LENGTH( minsize=8, error_message=T("Please enter a valid phone number")) # actually create auth form # Set nicer error messages for name fields db.auth_user.first_name.requires = IS_NOT_EMPTY( error_message=T("Please enter your first name")) db.auth_user.last_name.requires = IS_NOT_EMPTY( error_message=T("Please enter your last name")) form = '' form_login = '' login_link = '' login_title = '' login_message = '' form_register = '' register_link = '' register_title = '' reset_passwd = '' _next = request.vars['_next'] or "" self_checkin = '' error_msg = '' try: organization = ORGANIZATIONS[ORGANIZATIONS['default']] company_name = B(organization['Name']) has_terms = True if organization['TermsConditionsURL'] else False has_privacy_notice = True if organization['PrivacyNoticeURL'] else False except: company_name = '' organization = False has_terms = False has_privacy_notice = False if 'register' in request.args: # Enforce strong passwords db.auth_user.password.requires.insert(0, IS_STRONG()) recaptcha2 = "" if use_recaptcha: auth.settings.captcha = Recaptcha2( request, recaptcha_site_key, recaptcha_secret_key, error_message=T("Please verify you're not a robot")) form = auth() recaptcha2 = DIV( BR(), Recaptcha2( request, recaptcha_site_key, recaptcha_secret_key, error_message=T("Please verify you're not a robot")), DIV( DIV(form.errors.get('captcha', ''), _class="error"), _class="error-wrapper", ), ) else: form = auth() register_title = T("Create your account") login_title = T("Already have an account?") login_link = A(T("Click here to log in"), _href=URL(args='login', vars=request.vars)) login_message = DIV( B("Can't register?"), BR(), T("In case you can't register because your email address already has an account, click" ), ' ', A(T("here"), _href=URL(args='request_reset_password')), ' ', T("to request a new password."), BR(), BR(), ) response.view = 'default/user_login.html' user_registration_set_visible_fields() first_name = form.element('#auth_user_first_name') first_name['_placeholder'] = T("First name...") last_name = form.element('#auth_user_last_name') last_name['_placeholder'] = T("Last name...") email = form.element('#auth_user_email') email['_placeholder'] = T("Email...") password = form.element('#auth_user_password') password['_placeholder'] = T("Password...") password2 = form.element('#auth_user_password_two') password2['_placeholder'] = T("Repeat Password...") submit = form.element('input[type=submit]') submit['_value'] = T('Create account') location = '' if session.show_location: location = DIV(LABEL(form.custom.label.school_locations_id), form.custom.widget.school_locations_id, _class='form-group') phone = '' if get_sys_property('registration_requires_mobile') == "on": mobile = form.element('#auth_user_mobile') mobile['_placeholder'] = T("Phone...") phone = DIV(LABEL(T("Phone")), form.custom.widget.mobile, _class='form-group') accept_ul = UL(_id='accept_ul') accept_ul.append( LI(T('Confirm that the data above is true and complete'))) if organization: if organization['TermsConditionsURL']: accept_ul.append( SPAN( T('Agree to the'), ' ', A(T('Terms and conditions'), _href=organization['TermsConditionsURL'], _target="_blank"))) if organization['PrivacyNoticeURL']: accept_ul.append( SPAN( T('Accept the'), ' ', A(T('Privacy notice'), _href=organization['PrivacyNoticeURL'], _target="_blank"))) form = DIV( form.custom.begin, DIV(LABEL(form.custom.label.first_name), form.custom.widget.first_name, _class='form-group'), DIV(LABEL(form.custom.label.last_name), form.custom.widget.last_name, _class='form-group'), DIV(LABEL(form.custom.label.email), form.custom.widget.email, _class='form-group'), phone, DIV(LABEL(form.custom.label.password), form.custom.widget.password, _class='form-group'), DIV(LABEL(form.custom.label.password_two), form.custom.widget.password_two, _class='form-group'), location, SPAN(T('By creating an account I'), _class='bold'), accept_ul, recaptcha2, BR(), A(T('Cancel'), _href=URL(args='login'), _class='btn btn-default', _title=T('Back to login')), DIV(form.custom.submit, _class='pull-right'), form.custom.end) form_register = form # set logo logo_login = user_get_logo_login() if 'logout' in request.args or 'not_authorized' in request.args or 'verify_email' in request.args: form = auth() if 'login' in request.args: form = auth() response.view = 'default/user_login.html' login_title = T("Log in") register_title = T("Create your account") auth.messages.login_button = T('Sign In') email = form.element('#auth_user_email') email['_placeholder'] = T("Email...") password = form.element('#auth_user_password') password['_placeholder'] = T("Password...") submit = form.element('input[type=submit]') submit['_value'] = T('Sign In') form = DIV( form.custom.begin, DIV(form.custom.widget.email, SPAN( _class='glyphicon glyphicon-envelope form-control-feedback' ), _class='form-group has-feedback'), DIV(form.custom.widget.password, SPAN(_class='glyphicon glyphicon-lock form-control-feedback'), _class='form-group has-feedback'), LABEL(form.custom.widget.remember_me, ' ', form.custom.label.remember_me, _id='label_remember'), DIV(form.custom.submit, _class='pull-right'), form.custom.end, ) if not 'request_reset_password' in auth.settings.actions_disabled: reset_passwd = A(T('Lost password?'), _href=URL(args='request_reset_password')) if not 'register' in auth.settings.actions_disabled: form_register = SPAN( T("Are you new here and would you like to create an account?"), BR(), T("Please click the button below to get started."), BR(), ) register_link = A(T("Create your account"), _href=URL(args='register', vars=request.vars), _class='btn btn-primary btn-create_your_account') form_login = form if 'request_reset_password' in request.args: recaptcha2 = "" if use_recaptcha: auth.settings.captcha = Recaptcha2( request, recaptcha_site_key, recaptcha_secret_key, error_message=T("Please verify you're not a robot")) form = auth() recaptcha2 = DIV( BR(), Recaptcha2( request, recaptcha_site_key, recaptcha_secret_key, error_message=T("Please verify you're not a robot")), DIV( DIV(form.errors.get('captcha', ''), _class="error"), _class="error-wrapper", ), ) else: form = auth() response.view = 'default/user_login.html' cancel = A(T("Cancel"), _href=URL('/user', args='login'), _class='btn btn-default') form = DIV(form.custom.begin, DIV(form.custom.widget.email, _class='form-group'), recaptcha2, BR(), DIV(form.custom.submit, _class='pull-right'), cancel, form.custom.end) form_login = form login_title = T("Reset password") register_title = T("Info") register_link = SPAN( T("After entering your email address and clicking the Reset password button" ), ' ', T("you should receive an email with a link to reset your password within a few minutes." ), ' ', T("In case you don't receive an email, please check your spam folder." ), BR(), BR(), A(T("Click here to log in"), _href=URL(args="login"))) # set email placeholder if 'login' in request.args or 'request_reset_password' in request.args: email = form.element('#auth_user_email') email['_placeholder'] = T("Email...") if 'reset_password' in request.args: # Enforce strong passwords db.auth_user.password.requires.insert(0, IS_STRONG()) recaptcha2 = "" if use_recaptcha: auth.settings.captcha = Recaptcha2( request, recaptcha_site_key, recaptcha_secret_key, error_message=T("Please verify you're not a robot")) form = auth() recaptcha2 = DIV( BR(), Recaptcha2( request, recaptcha_site_key, recaptcha_secret_key, error_message=T("Please verify you're not a robot")), DIV( DIV(form.errors.get('captcha', ''), _class="error"), _class="error-wrapper", ), ) else: form = auth() response.view = 'default/user_login.html' passwd = form.element('#no_table_new_password') passwd['_placeholder'] = T("New password...") passwd2 = form.element('#no_table_new_password2') passwd2['_placeholder'] = T("Repeat new password...") form = DIV( form.custom.begin, os_gui.get_form_group(form.custom.label.new_password, form.custom.widget.new_password), os_gui.get_form_group(form.custom.label.new_password2, form.custom.widget.new_password2), recaptcha2, BR(), form.custom.submit, form.custom.end) form_login = form login_title = T("Reset password") register_title = T("Info") register_link = SPAN( T("After setting a new password, you will be logged in automatically." ), ' ', T("Please use your new password for future logins."), BR(), BR(), A(T("Click here to log in"), _href=URL(args="login"))) if 'request_reset_password' in request.args or \ 'reset_password' in request.args: submit = form.element('input[type=submit]') submit['_value'] = T('Reset password') if 'change_password' in request.args: # Enforce strong passwords db.auth_user.password.requires.insert(0, IS_STRONG()) form = auth() response.view = 'default/user_login.html' response.title = T('Change password') oldpwd = form.element('#no_table_old_password') oldpwd['_placeholder'] = T('Old password...') passwd = form.element('#no_table_new_password') passwd['_placeholder'] = T("New password...") passwd2 = form.element('#no_table_new_password2') passwd2['_placeholder'] = T("Repeat password...") cancel = A(T('Cancel'), _href=URL('profile', 'index'), _class='btn btn-default') form = DIV( form.custom.begin, os_gui.get_form_group(form.custom.label.old_password, form.custom.widget.old_password), os_gui.get_form_group(form.custom.label.new_password, form.custom.widget.new_password), os_gui.get_form_group(form.custom.label.new_password2, form.custom.widget.new_password2), DIV(form.custom.submit, _class='pull-right'), cancel, form.custom.end) form_login = form login_title = T("Change password") if "/shop/subscription" in _next: os_tools = OsTools() login_message_subscription = os_tools.get_sys_property( "shop_login_message_subscription") or "" if login_message_subscription: company_name = SPAN(company_name, BR(), BR(), XML(login_message_subscription), _class='center') if "/shop/classcard" in _next: os_tools = OsTools() login_message_classcard = os_tools.get_sys_property( "shop_login_message_classcard") or "" if login_message_classcard: company_name = SPAN(company_name, BR(), BR(), XML(login_message_classcard), _class='center') return dict(form=form, form_login=form_login, form_register=form_register, content=form, error_msg=error_msg, reset_passwd=reset_passwd, register_link=register_link, register_title=register_title, login_link=login_link, login_title=login_title, login_message=login_message, self_checkin=self_checkin, company_name=company_name, has_organization=True if organization else False, has_terms=has_terms, has_privacy_notice=has_privacy_notice, logo_login=logo_login)