def __call__(self): output = {} T = current.T request = current.request response = current.response s3 = response.s3 # Check logged in and permissions auth = current.auth settings = current.deployment_settings roles = current.session.s3.roles system_roles = auth.get_system_roles() AUTHENTICATED = system_roles.AUTHENTICATED # Login/Registration forms self_registration = current.deployment_settings.get_security_self_registration( ) registered = False login_form = None login_div = None register_form = None register_div = None # Contact Form request_email = settings.get_frontpage("request_email") if request_email: from gluon.dal import Field from gluon.validators import IS_NOT_EMPTY from gluon.sqlhtml import SQLFORM fields = [ Field( "name", label="Your name", requires=IS_NOT_EMPTY(), ), Field( "address", label="Your e-mail address", requires=IS_NOT_EMPTY(), ), Field( "subject", label="Subject", requires=IS_NOT_EMPTY(), ), Field( "message", "text", label="Message", requires=IS_NOT_EMPTY(), ), ] from s3 import s3_mark_required labels, required = s3_mark_required(fields) s3.has_required = required response.form_label_separator = "" contact_form = SQLFORM.factory( formstyle=settings.get_ui_formstyle(), submit_button=T("Submit"), labels=labels, separator="", table_name="contact", # Dummy table name _id="mailform", *fields) if contact_form.accepts(request.post_vars, current.session, formname="contact_form", keepvalues=False, hideerror=False): # Processs Contact Form form_vars = contact_form.vars sender = "%s <%s>" % (form_vars.name, form_vars.address) result = current.msg.send_email( to=request_email, sender=sender, subject=form_vars.subject, message=form_vars.message, reply_to=form_vars.address, ) if result: response.confirmation = "Thank you for your message - we'll be in touch shortly" if s3.cdn: if s3.debug: s3.scripts.append( "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js" ) else: s3.scripts.append( "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" ) else: if s3.debug: s3.scripts.append("/%s/static/scripts/jquery.validate.js" % request.application) else: s3.scripts.append( "/%s/static/scripts/jquery.validate.min.js" % request.application) validation_script = ''' $('#mailform').validate({ errorClass:'req', rules:{ name:{ required:true }, address: { required:true, email:true }, subject:{ required:true }, message:{ required:true } }, messages:{ name:"Enter your name", subject:"Enter a subject", message:"Enter a message", address:{ required:"Please enter a valid email address", email:"Please enter a valid email address" } }, errorPlacement:function(error,element){ error.appendTo(element.parents('div.controls')) }, submitHandler:function(form){ form.submit() } })''' s3.jquery_ready.append(validation_script) else: contact_form = "" if AUTHENTICATED not in roles: login_buttons = DIV(A(T("Login"), _id="show-login", _class="tiny secondary button"), _id="login-buttons") script = ''' $('#show-mailform').click(function(e){ e.preventDefault() $('#intro').slideDown(400, function() { $('#login_box').hide() }); }) $('#show-login').click(function(e){ e.preventDefault() $('#login_form').show() $('#register_form').hide() $('#login_box').show() $('#intro').slideUp() })''' s3.jquery_ready.append(script) # This user isn't yet logged-in if request.cookies.has_key("registered"): # This browser has logged-in before registered = True if self_registration is True: # Provide a Registration box on front page login_buttons.append( A(T("Register"), _id="show-register", _class="tiny secondary button", _style="margin-left:5px")) script = ''' $('#show-register').click(function(e){ e.preventDefault() $('#login_form').hide() $('#register_form').show() $('#login_box').show() $('#intro').slideUp() })''' s3.jquery_ready.append(script) register_form = auth.register() register_div = DIV(H3(T("Register")), P(XML(T("If you would like to help, then please %(sign_up_now)s") % \ dict(sign_up_now=B(T("sign-up now")))))) register_script = ''' $('#register-btn').click(function(e){ e.preventDefault() $('#register_form').show() $('#login_form').hide() }) $('#login-btn').click(function(e){ e.preventDefault() $('#register_form').hide() $('#login_form').show() })''' s3.jquery_ready.append(register_script) # Provide a login box on front page auth.messages.submit_button = T("Login") login_form = auth.login(inline=True) login_div = DIV(H3(T("Login")), P(XML(T("Registered users can %(login)s to access the system") % \ dict(login=B(T("login")))))) else: login_buttons = "" output["login_buttons"] = login_buttons output["self_registration"] = self_registration output["registered"] = registered output["login_div"] = login_div output["login_form"] = login_form output["register_div"] = register_div output["register_form"] = register_form output["contact_form"] = contact_form # Slick slider if s3.debug: s3.scripts.append("/%s/static/scripts/slick.js" % request.application) else: s3.scripts.append("/%s/static/scripts/slick.min.js" % request.application) script = ''' $(document).ready(function(){ $('#title-image').slick({ autoplay:true, autoplaySpeed:5000, speed:1000, fade:true, cssEase:'linear' }); });''' s3.jquery_ready.append(script) self._view(TEMPLATE, "index.html") return output
def __call__(self): output = {} T = current.T request = current.request response = current.response s3 = response.s3 # Check logged in and permissions auth = current.auth settings = current.deployment_settings roles = current.session.s3.roles system_roles = auth.get_system_roles() AUTHENTICATED = system_roles.AUTHENTICATED # Login/Registration forms self_registration = current.deployment_settings.get_security_registration_visible() registered = False login_form = None login_div = None register_form = None register_div = None # Contact Form request_email = settings.get_frontpage("request_email") if request_email: from s3dal import Field from gluon.validators import IS_NOT_EMPTY from gluon.sqlhtml import SQLFORM fields = [Field("name", label="Your name", requires=IS_NOT_EMPTY(), ), Field("address", label="Your e-mail address", requires=IS_NOT_EMPTY(), ), Field("subject", label="Subject", requires=IS_NOT_EMPTY(), ), Field("message", "text", label="Message", requires=IS_NOT_EMPTY(), ), ] from s3 import s3_mark_required labels, required = s3_mark_required(fields) s3.has_required = required response.form_label_separator = "" contact_form = SQLFORM.factory(formstyle = settings.get_ui_formstyle(), submit_button = T("Submit"), labels = labels, separator = "", table_name = "contact", # Dummy table name _id="mailform", *fields ) if contact_form.accepts(request.post_vars, current.session, formname="contact_form", keepvalues=False, hideerror=False): # Processs Contact Form form_vars = contact_form.vars sender = "%s <%s>" % (form_vars.name, form_vars.address) result = current.msg.send_email(to=request_email, sender=sender, subject=form_vars.subject, message=form_vars.message, reply_to=form_vars.address, ) if result: response.confirmation = "Thank you for your message - we'll be in touch shortly" if s3.cdn: if s3.debug: s3.scripts.append("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js") else: s3.scripts.append("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js") else: if s3.debug: s3.scripts.append("/%s/static/scripts/jquery.validate.js" % request.application) else: s3.scripts.append("/%s/static/scripts/jquery.validate.min.js" % request.application) validation_script = ''' $('#mailform').validate({ errorClass:'req', rules:{ name:{ required:true }, address: { required:true, email:true }, subject:{ required:true }, message:{ required:true } }, messages:{ name:"Enter your name", subject:"Enter a subject", message:"Enter a message", address:{ required:"Please enter a valid email address", email:"Please enter a valid email address" } }, errorPlacement:function(error,element){ error.appendTo(element.parents('div.controls')) }, submitHandler:function(form){ form.submit() } })''' s3.jquery_ready.append(validation_script) else: contact_form = "" if AUTHENTICATED not in roles: login_buttons = DIV(A(T("Login"), _id="show-login", _class="tiny secondary button"), _id="login-buttons" ) script = ''' $('#show-mailform').click(function(e){ e.preventDefault() $('#intro').slideDown(400, function() { $('#login_box').hide() }); }) $('#show-login').click(function(e){ e.preventDefault() $('#login_form').show() $('#register_form').hide() $('#login_box').show() $('#intro').slideUp() })''' s3.jquery_ready.append(script) # This user isn't yet logged-in if request.cookies.has_key("registered"): # This browser has logged-in before registered = True if self_registration is True: # Provide a Registration box on front page login_buttons.append(A(T("Register"), _id="show-register", _class="tiny secondary button", _style="margin-left:5px")) script = ''' $('#show-register').click(function(e){ e.preventDefault() $('#login_form').hide() $('#register_form').show() $('#login_box').show() $('#intro').slideUp() })''' s3.jquery_ready.append(script) register_form = auth.register() register_div = DIV(H3(T("Register")), P(XML(T("If you would like to help, then please %(sign_up_now)s") % \ dict(sign_up_now=B(T("sign-up now")))))) register_script = ''' $('#register-btn').click(function(e){ e.preventDefault() $('#register_form').show() $('#login_form').hide() }) $('#login-btn').click(function(e){ e.preventDefault() $('#register_form').hide() $('#login_form').show() })''' s3.jquery_ready.append(register_script) # Provide a login box on front page auth.messages.submit_button = T("Login") login_form = auth.login(inline=True) login_div = DIV(H3(T("Login")), P(XML(T("Registered users can %(login)s to access the system") % \ dict(login=B(T("login")))))) else: login_buttons = "" output["login_buttons"] = login_buttons output["self_registration"] = self_registration output["registered"] = registered output["login_div"] = login_div output["login_form"] = login_form output["register_div"] = register_div output["register_form"] = register_form output["contact_form"] = contact_form # Slick slider if s3.debug: s3.scripts.append("/%s/static/scripts/slick.js" % request.application) else: s3.scripts.append("/%s/static/scripts/slick.min.js" % request.application) script = ''' $(document).ready(function(){ $('#title-image').slick({ autoplay:true, autoplaySpeed:5000, speed:1000, fade:true, cssEase:'linear' }); });''' s3.jquery_ready.append(script) self._view(TEMPLATE, "index.html") return output
def __call__(self): request = current.request response = current.response from gluon import Field, SQLFORM, IS_NOT_EMPTY, IS_EMAIL, IS_IN_SET, IS_EMPTY_OR from s3 import s3_mark_required, S3StringWidget T = current.T formstyle = current.deployment_settings.get_ui_formstyle() fields = [Field("address", label = T("Your e-mail address"), requires = IS_EMAIL(), widget = lambda *args, **kwargs: \ S3StringWidget(placeholder="*****@*****.**")(_type="email", *args, **kwargs), ), Field("subject", label = T("Subject"), requires = IS_EMPTY_OR(IS_IN_SET(("Solution Development", "Workshop / Training", "SAHANA Deployment / Support", "Other / General Inquiry", ), zero = "What can we do for you?", sort = False, )), ), Field("message", "text", label = T("Message"), requires = IS_NOT_EMPTY(), ), ] labels, required = s3_mark_required(fields) response.form_label_separator = "" form = SQLFORM.factory( formstyle=formstyle, labels=labels, submit_button=T("Send Message"), _id="mailform", *fields, ) if form.accepts( request.post_vars, current.session, formname="default/index/contact", #onvalidation = onvalidation, keepvalues=False, hideerror=False, ): form_vars = form.vars subject = "Request on AidIQ website" if form_vars.subject: subject = "%s: %s" % (subject, form_vars.subject) result = current.msg.send_email( to=current.deployment_settings.get_mail_approver(), subject=form_vars.subject, message=form_vars.message, reply_to=form_vars.address, ) if result: response.confirmation = "Thank you for your message - we'll be in touch shortly" appname = request.application s3 = response.s3 sappend = s3.scripts.append if s3.cdn: if s3.debug: sappend( "//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js" ) else: sappend( "//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js" ) else: if s3.debug: sappend("/%s/static/scripts/jquery.validate.js" % appname) else: sappend("/%s/static/scripts/jquery.validate.min.js" % appname) sappend("/%s/static/themes/AidIQ/js/contact.js" % appname) response.title = "Contact Us | AidIQ.com" self._view(THEME, "contact.html") return { "form": DIV(form, _class="form-container"), }
def __call__(self): auth = current.auth # Redirect if already logged-in if auth.s3_logged_in(): redirect(URL(c="default", f="index")) auth_settings = auth.settings auth_messages = auth.messages self.customise_auth_messages() T = current.T db = current.db s3db = current.s3db request = current.request response = current.response session = current.session settings = current.deployment_settings utable = auth_settings.table_user # Page title and intro text title = T("Volunteer Registration") # Form Fields formfields, required_fields, subheadings = self.formfields() # Generate labels (and mark required fields in the process) labels, has_required = s3_mark_required( formfields, mark_required=required_fields, ) response.s3.has_required = has_required labels["skill_id"] = DIV( labels["skill_id"], DIV( "(%s)" % T("Select all that apply"), _class="sub-label", ), ) # Form buttons REGISTER = T("Register") buttons = [ INPUT( _type="submit", _value=REGISTER, ), # TODO cancel-button? ] # Construct the form response.form_label_separator = "" form = SQLFORM.factory(table_name=utable._tablename, record=None, hidden={"_next": request.vars._next}, labels=labels, separator="", showid=False, submit_button=REGISTER, delete_label=auth_messages.delete_label, formstyle=settings.get_ui_formstyle(), buttons=buttons, *formfields) # Identify form for CSS & JS Validation form.add_class("auth_register") # Add Subheadings if subheadings: for pos, heading in subheadings[::-1]: form[0].insert(pos, DIV(heading, _class="subheading")) # Inject client-side Validation auth.s3_register_validation() # Set default registration key, so new users are prevented # from logging in until approved key = str(uuid4()) code = uuid4().hex[-6:].upper() utable.registration_key.default = self.keyhash(key, code) if form.accepts( request.vars, session, formname="register", onvalidation=auth_settings.register_onvalidation, ): formvars = form.vars # Add default organisation organisation_id = formvars.get("organisation_id") if not organisation_id: formvars[ "organisation_id"] = settings.get_org_default_organisation # Add HR type link_user_to = formvars.get("link_user_to") if link_user_to is None: formvars["link_user_to"] = ["volunteer"] # Create the user record user_id = utable.insert( **utable._filter_fields(formvars, id=False)) formvars.id = user_id # Save temporary user fields in s3db.auth_user_temp temptable = s3db.auth_user_temp record = {"user_id": user_id} mobile = formvars.mobile_phone if mobile: record["mobile"] = mobile record["consent"] = formvars.consent # Store Custom fields custom = {#"date_of_birth": formvars.date_of_birth, "home_phone": formvars.home_phone, #"office_phone": formvars.office_phone, "location_id": formvars.location_id, "addr_street": formvars.addr_street, "addr_postcode": formvars.addr_postcode, "occupation_type_ids": formvars.occupation_type_ids, "occupation": formvars.occupation, #"start_date": formvars.start_date, #"end_date": formvars.end_date, "hours_per_week": formvars.hours_per_week, "schedule": formvars.schedule, "skill_id": formvars.skill_id, "comments": formvars.comments, } for datefield in ("date_of_birth", "start_date", "end_date"): value = formvars.get(datefield) if value: value = value.isoformat() custom[datefield] = value record["custom"] = json.dumps(custom) temptable.insert(**record) # Post-process the new user record users = db(utable.id > 0).select(utable.id, limitby=(0, 2)) if len(users) == 1: # 1st user to register doesn't need verification/approval auth.s3_approve_user(form.vars) session.confirmation = auth_messages.registration_successful # 1st user gets Admin rights admin_group_id = 1 auth.add_membership(admin_group_id, users.first().id) # Log them in if "language" not in form.vars: # Was missing from login form form.vars.language = T.accepted_language user = Storage(utable._filter_fields(form.vars, id=True)) auth.login_user(user) # Send welcome email auth.s3_send_welcome_email(form.vars) # Where to go next? register_next = request.vars._next or auth_settings.register_next else: # Request User Verify their Email # System Details for Verification Email verify_url = URL( c="default", f="index", args=["verify_email", key], scheme="https" if request.is_https else "http", ) system = { "system_name": settings.get_system_name(), "url": verify_url, #"url": "%s/default/index/verify_email/%s" % (response.s3.base_url, key), "code": code, } # Try to send the Verification Email if not auth_settings.mailer or \ not auth_settings.mailer.settings.server or \ not auth_settings.mailer.send(to = form.vars.email, subject = auth_messages.verify_email_subject % system, message = auth_messages.verify_email % system, ): response.error = auth_messages.email_verification_failed # Custom View self._view(THEME, "register.html") return { "title": title, "form": form, } # Redirect to Verification Info page register_next = URL( c="default", f="message", args=["verify_email_sent"], vars={"email": form.vars.email}, ) # Log action auth.log_event(auth_messages.register_log, form.vars) # Redirect redirect(register_next) elif form.errors: response.error = T( "There are errors in the form, please check your input") # Custom View self._view(THEME, "register.html") return { "title": title, "form": form, }
def __call__(self): output = {} T = current.T request = current.request response = current.response s3 = response.s3 # Check logged in and permissions auth = current.auth settings = current.deployment_settings roles = current.session.s3.roles system_roles = auth.get_system_roles() AUTHENTICATED = system_roles.AUTHENTICATED # Login/Registration forms self_registration = settings.get_security_registration_visible() registered = False login_form = None login_div = None register_form = None register_div = None # Project Links project_links = DIV(_class="title-links hide-for-small") project_description = settings.get_frontpage("project_description") if project_description: project_links.append( A( ICON("link"), T("Project Description"), _class="action-lnk", _href=project_description, _target="_blank", )) project_links.append( A( ICON("link"), T("User Manual"), _class="action-lnk", _href=URL( c="default", f="index", args=["docs"], vars={"name": "UserManual"}, ), _target="_blank", )) mailing_list = settings.get_frontpage("mailing_list") if mailing_list: project_links.append( A( ICON("link"), T("Mailing List"), _class="action-lnk", _href=mailing_list, _target="_blank", )) # Contact Form request_email = settings.get_frontpage("request_email") if request_email: from s3dal import Field from gluon.validators import IS_NOT_EMPTY from gluon.sqlhtml import SQLFORM fields = [ Field( "name", label="Your name", requires=IS_NOT_EMPTY(), ), Field( "address", label="Your e-mail address", requires=IS_NOT_EMPTY(), ), Field( "subject", label="Subject", requires=IS_NOT_EMPTY(), ), Field( "message", "text", label="Message", requires=IS_NOT_EMPTY(), ), ] from s3 import s3_mark_required labels, required = s3_mark_required(fields) s3.has_required = required response.form_label_separator = "" contact_form = SQLFORM.factory( formstyle=settings.get_ui_formstyle(), submit_button=T("Submit"), labels=labels, separator="", table_name="contact", # Dummy table name _id="mailform", *fields) if contact_form.accepts(request.post_vars, current.session, formname="contact_form", keepvalues=False, hideerror=False): # Processs Contact Form form_vars = contact_form.vars sender = "%s <%s>" % (form_vars.name, form_vars.address) result = current.msg.send_email( to=request_email, sender=sender, subject=form_vars.subject, message=form_vars.message, reply_to=form_vars.address, ) if result: response.confirmation = "Thank you for your message - we'll be in touch shortly" if s3.cdn: if s3.debug: s3.scripts.append( "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js" ) else: s3.scripts.append( "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" ) else: if s3.debug: s3.scripts.append("/%s/static/scripts/jquery.validate.js" % request.application) else: s3.scripts.append( "/%s/static/scripts/jquery.validate.min.js" % request.application) validation_script = ''' $('#mailform').validate({ errorClass:'req', rules:{ name:{ required:true }, address: { required:true, email:true }, subject:{ required:true }, message:{ required:true } }, messages:{ name:"Enter your name", subject:"Enter a subject", message:"Enter a message", address:{ required:"Please enter a valid email address", email:"Please enter a valid email address" } }, errorPlacement:function(error,element){ error.appendTo(element.parents('div.controls')) }, submitHandler:function(form){ form.submit() } })''' s3.jquery_ready.append(validation_script) else: contact_form = "" if AUTHENTICATED not in roles: login_buttons = DIV(A(T("Login"), _id="show-login", _class="tiny secondary button"), _id="login-buttons") script = ''' $('#show-mailform').click(function(e){ e.preventDefault() $('#login_box').fadeOut(function(){$('#intro').fadeIn()}) }) $('#show-login').click(function(e){ e.preventDefault() $('#login_form').show() $('#register_form').hide() $('#intro').fadeOut(function(){$('#login_box').fadeIn()}) })''' s3.jquery_ready.append(script) # This user isn't yet logged-in if request.cookies.has_key("registered"): # This browser has logged-in before registered = True if self_registration is True: # Provide a Registration box on front page login_buttons.append( A(T("Register"), _id="show-register", _class="tiny secondary button", _style="margin-left:5px")) script = ''' $('#show-register').click(function(e){ e.preventDefault() $('#login_form').hide() $('#register_form').show() $('#intro').fadeOut(function(){$('#login_box').fadeIn()}) })''' s3.jquery_ready.append(script) register_form = auth.register() register_div = DIV(H3(T("Register")), P(XML(T("If you would like to help, then please %(sign_up_now)s") % \ dict(sign_up_now=B(T("sign-up now")))))) register_script = ''' $('#register-btn').click(function(e){ e.preventDefault() $('#login_form').fadeOut(function(){$('#register_form').fadeIn()}) }) $('#login-btn').click(function(e){ e.preventDefault() $('#register_form').fadeOut(function(){$('#login_form').fadeIn()}) })''' s3.jquery_ready.append(register_script) # Provide a login box on front page auth.messages.submit_button = T("Login") login_form = auth.login(inline=True) login_div = DIV(H3(T("Login")), P(XML(T("Registered users can %(login)s to access the system") % \ dict(login=B(T("login")))))) else: login_buttons = "" # Create output dict output = { "login_buttons": login_buttons, "self_registration": self_registration, "registered": registered, "login_div": login_div, "login_form": login_form, "register_div": register_div, "register_form": register_form, "contact_form": contact_form, "project_links": project_links, } # Count records (@todo: provide total/updated counters?) s3db = current.s3db db = current.db # Organisations table = s3db.org_organisation query = (table.deleted != True) count = table.id.count() row = db(query).select(count).first() output["total_organisations"] = row[count] # Service Locations (@todo) #table = s3db.org_service_location #query = (table.deleted != True) #count = table.id.count() #row = db(query).select(count).first() output["total_services"] = 0 #row[count] # Needs lists table = s3db.req_organisation_needs query = (table.deleted != True) count = table.id.count() row = db(query).select(count).first() output["total_needs"] = row[count] # Frontpage Feed Control if settings.frontpage.rss: s3.external_stylesheets.append( "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css" ) s3.scripts.append( "http://www.google.com/jsapi?key=notsupplied-wizard") s3.scripts.append( "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" ) counter = 0 feeds = "" for feed in settings.frontpage.rss: counter += 1 feeds = "".join((feeds, "{title:'%s',\n" % feed["title"], "url:'%s'}" % feed["url"])) # Don't add a trailing comma for old IEs if counter != len(settings.frontpage.rss): feeds += ",\n" # feedCycleTime: milliseconds before feed is reloaded (5 minutes) feed_control = "".join((''' function LoadDynamicFeedControl(){ var feeds=[ ''', feeds, ''' ] var options={ feedCycleTime:300000, numResults:5, stacked:true, horizontal:false, title:"''', str(T("News")), '''" } new GFdynamicFeedControl(feeds,'feed-control',options) } google.load('feeds','1') google.setOnLoadCallback(LoadDynamicFeedControl)''')) s3.js_global.append(feed_control) s3.stylesheets.append("../themes/RW/homepage.css") self._view(TEMPLATE, "index.html") return output
def register(self, r, **attr): """ Register a test result @param r: the S3Request instance @param attr: controller attributes """ if r.http not in ("GET", "POST"): r.error(405, current.ERROR.BAD_METHOD) if not r.interactive: r.error(415, current.ERROR.BAD_FORMAT) T = current.T db = current.db s3db = current.s3db auth = current.auth request = current.request response = current.response s3 = response.s3 settings = current.deployment_settings # Page title and intro text title = T("Register Test Result") # Get intro text from CMS ctable = s3db.cms_post ltable = s3db.cms_post_module join = ltable.on((ltable.post_id == ctable.id) & \ (ltable.module == "disease") & \ (ltable.resource == "case_diagnostics") & \ (ltable.deleted == False)) query = (ctable.name == "TestResultRegistrationIntro") & \ (ctable.deleted == False) row = db(query).select( ctable.body, join=join, cache=s3db.cache, limitby=(0, 1), ).first() intro = row.body if row else None # Instantiate Consent Tracker consent = s3db.auth_Consent( processing_types=["CWA_ANONYMOUS", "CWA_PERSONAL"]) table = s3db.disease_case_diagnostics # Configure disease_id field = table.disease_id if field.writable: default_disease = None offset = 1 else: default_disease = field.default field.readable = False offset = 0 # Probe date is mandatory field = table.probe_date requires = field.requires if isinstance(requires, IS_EMPTY_OR): field.requires = requires.other # Configure device_id field = table.device_id field.readable = field.writable = True dtable = s3db.disease_testing_device query = (dtable.device_class == "RAT") & \ (dtable.approved == True) & \ (dtable.available == True) if default_disease: query = (dtable.disease_id == default_disease) & query field.requires = IS_ONE_OF( db(query), "disease_testing_device.id", field.represent, ) cwa_options = ( ("NO", T("Do not report")), ("ANONYMOUS", T("Issue anonymous contact tracing code")), ("PERSONAL", T("Issue personal test certificate")), ) formfields = [ # -- Test Result -- table.site_id, table.disease_id, table.probe_date, table.device_id, table.result, # -- Report to CWA -- Field( "report_to_cwa", "string", requires=IS_IN_SET(cwa_options, sort=False, zero=""), default="NO", label=T("Report test result to %(system)s") % CWA, ), Field( "last_name", label=T("Last Name"), ), Field( "first_name", label=T("First Name"), ), s3_date( "date_of_birth", label=T("Date of Birth"), month_selector=True, ), Field( "dcc_option", "boolean", default=False, label=T("Provide Digital %(title)s Certificate") % {"title": "COVID-19 Test"}, ), Field( "consent", label="", widget=consent.widget, ), ] # Required fields required_fields = [] # Subheadings subheadings = ( (0, T("Test Result")), (4 + offset, CWA["system"]), ) # Generate labels (and mark required fields in the process) labels, has_required = s3_mark_required( formfields, mark_required=required_fields, ) s3.has_required = has_required # Form buttons REGISTER = T("Submit") buttons = [ INPUT( _type="submit", _value=REGISTER, ), ] # Construct the form response.form_label_separator = "" form = SQLFORM.factory(table_name="test_result", record=None, hidden={"_next": request.vars._next}, labels=labels, separator="", showid=False, submit_button=REGISTER, delete_label=auth.messages.delete_label, formstyle=settings.get_ui_formstyle(), buttons=buttons, *formfields) # Identify form for CSS & JS Validation form.add_class("result-register") # Add Subheadings if subheadings: for pos, heading in subheadings[::-1]: form[0].insert(pos, DIV(heading, _class="subheading")) # Inject scripts script = "/%s/static/themes/RLP/js/testresult.js" % r.application if script not in s3.scripts: s3.scripts.append(script) s3.jquery_ready.append("S3EnableNavigateAwayConfirm()") if form.accepts( request.vars, current.session, formname="register", onvalidation=self.validate, ): formvars = form.vars # Create disease_case_diagnostics record testresult = { "result": formvars.get("result"), } if "site_id" in formvars: testresult["site_id"] = formvars["site_id"] if "disease_id" in formvars: testresult["disease_id"] = formvars["disease_id"] if "probe_date" in formvars: testresult["probe_date"] = formvars["probe_date"] if "device_id" in formvars: testresult["device_id"] = formvars["device_id"] record_id = table.insert(**testresult) if not record_id: raise RuntimeError("Could not create testresult record") testresult["id"] = record_id # Set record owner auth = current.auth auth.s3_set_record_owner(table, record_id) auth.s3_make_session_owner(table, record_id) # Onaccept s3db.onaccept(table, testresult, method="create") response.confirmation = T("Test Result registered") report_to_cwa = formvars.get("report_to_cwa") if report_to_cwa == "NO": # Do not report to CWA, just forward to read view self.next = r.url(id=record_id, method="read") else: # Report to CWA and show test certificate dcc_option = False if report_to_cwa == "ANONYMOUS": processing_type = "CWA_ANONYMOUS" cwa_report = CWAReport(record_id) elif report_to_cwa == "PERSONAL": dcc_option = formvars.get("dcc_option") processing_type = "CWA_PERSONAL" cwa_report = CWAReport( record_id, anonymous=False, first_name=formvars.get("first_name"), last_name=formvars.get("last_name"), dob=formvars.get("date_of_birth"), dcc=dcc_option, ) else: processing_type = cwa_report = None if cwa_report: # Register consent if processing_type: cwa_report.register_consent( processing_type, formvars.get("consent"), ) # Send to CWA success = cwa_report.send() if success: response.information = T( "Result reported to %(system)s") % CWA retry = False else: response.error = T("Report to %(system)s failed") % CWA retry = True # Store DCC data if dcc_option: cwa_data = cwa_report.data from .dcc import DCC try: hcert = DCC.from_result( cwa_data.get("hash"), record_id, cwa_data.get("fn"), cwa_data.get("ln"), cwa_data.get("dob"), ) except ValueError as e: hcert = None response.warning = str(e) if hcert: hcert.save() else: # Remove DCC flag if hcert could not be generated cwa_report.dcc = False S3CustomController._view("RLPPTM", "certificate.html") # Title field = table.disease_id if cwa_report.disease_id and field.represent: disease = field.represent(cwa_report.disease_id) title = "%s %s" % (disease, T("Test Result")) else: title = T("Test Result") return { "title": title, "intro": None, # TODO "form": cwa_report.formatted(retry=retry), } else: response.information = T( "Result not reported to %(system)s") % CWA self.next = r.url(id=record_id, method="read") return None elif form.errors: current.response.error = T( "There are errors in the form, please check your input") # Custom View S3CustomController._view("RLPPTM", "testresult.html") return { "title": title, "intro": intro, "form": form, }
def __call__(self): output = {} T = current.T request = current.request response = current.response s3 = response.s3 # Check logged in and permissions auth = current.auth settings = current.deployment_settings roles = current.session.s3.roles system_roles = auth.get_system_roles() AUTHENTICATED = system_roles.AUTHENTICATED # Login/Registration forms self_registration = settings.get_security_registration_visible() registered = False login_form = None login_div = None register_form = None register_div = None # Project Links project_links = DIV(_class="title-links hide-for-small") project_description = settings.get_frontpage("project_description") if project_description: project_links.append(A(ICON("link"), T("Project Description"), _class = "action-lnk", _href = project_description, _target = "_blank", )) project_links.append(A(ICON("link"), T("User Manual"), _class = "action-lnk", _href = URL(c="default", f="index", args = ["docs"], vars = {"name": "UserManual"}, ), _target = "_blank", )) mailing_list = settings.get_frontpage("mailing_list") if mailing_list: project_links.append(A(ICON("link"), T("Mailing List"), _class = "action-lnk", _href = mailing_list, _target = "_blank", )) # Contact Form request_email = settings.get_frontpage("request_email") if request_email: from gluon import IS_NOT_EMPTY, SQLFORM from s3dal import Field fields = [Field("name", label="Your name", requires=IS_NOT_EMPTY(), ), Field("address", label="Your e-mail address", requires=IS_NOT_EMPTY(), ), Field("subject", label="Subject", requires=IS_NOT_EMPTY(), ), Field("message", "text", label="Message", requires=IS_NOT_EMPTY(), ), ] from s3 import s3_mark_required labels, required = s3_mark_required(fields) s3.has_required = required response.form_label_separator = "" contact_form = SQLFORM.factory(formstyle = settings.get_ui_formstyle(), submit_button = T("Submit"), labels = labels, separator = "", table_name = "contact", # Dummy table name _id = "mailform", *fields ) if contact_form.accepts(request.post_vars, current.session, formname="contact_form", keepvalues=False, hideerror=False): # Processs Contact Form form_vars = contact_form.vars sender = "%s <%s>" % (form_vars.name, form_vars.address) result = current.msg.send_email(to=request_email, sender=sender, subject=form_vars.subject, message=form_vars.message, reply_to=form_vars.address, ) if result: response.confirmation = "Thank you for your message - we'll be in touch shortly" if s3.cdn: if s3.debug: s3.scripts.append("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js") else: s3.scripts.append("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js") else: if s3.debug: s3.scripts.append("/%s/static/scripts/jquery.validate.js" % request.application) else: s3.scripts.append("/%s/static/scripts/jquery.validate.min.js" % request.application) validation_script = ''' $('#mailform').validate({ errorClass:'req', rules:{ name:{ required:true }, address: { required:true, email:true }, subject:{ required:true }, message:{ required:true } }, messages:{ name:"Enter your name", subject:"Enter a subject", message:"Enter a message", address:{ required:"Please enter a valid email address", email:"Please enter a valid email address" } }, errorPlacement:function(error,element){ error.appendTo(element.parents('div.controls')) }, submitHandler:function(form){ form.submit() } })''' s3.jquery_ready.append(validation_script) else: contact_form = "" if AUTHENTICATED not in roles: login_buttons = DIV(A(T("Login"), _id="show-login", _class="tiny secondary button"), _id="login-buttons" ) script = ''' $('#show-mailform').click(function(e){ e.preventDefault() $('#login_box').fadeOut(function(){$('#intro').fadeIn()}) }) $('#show-login').click(function(e){ e.preventDefault() $('#login_form').show() $('#register_form').hide() $('#intro').fadeOut(function(){$('#login_box').fadeIn()}) })''' s3.jquery_ready.append(script) # This user isn't yet logged-in if request.cookies.has_key("registered"): # This browser has logged-in before registered = True if self_registration is True: # Provide a Registration box on front page login_buttons.append(A(T("Register"), _id="show-register", _class="tiny secondary button", _style="margin-left:5px")) script = ''' $('#show-register').click(function(e){ e.preventDefault() $('#login_form').hide() $('#register_form').show() $('#intro').fadeOut(function(){$('#login_box').fadeIn()}) })''' s3.jquery_ready.append(script) register_form = auth.register() register_div = DIV(H3(T("Register")), P(XML(T("If you would like to help, then please %(sign_up_now)s") % \ dict(sign_up_now=B(T("sign-up now")))))) register_script = ''' $('#register-btn').click(function(e){ e.preventDefault() $('#login_form').fadeOut(function(){$('#register_form').fadeIn()}) }) $('#login-btn').click(function(e){ e.preventDefault() $('#register_form').fadeOut(function(){$('#login_form').fadeIn()}) })''' s3.jquery_ready.append(register_script) # Provide a login box on front page auth.messages.submit_button = T("Login") login_form = auth.login(inline=True) login_div = DIV(H3(T("Login")), P(XML(T("Registered users can %(login)s to access the system") % \ dict(login=B(T("login")))))) else: login_buttons = "" # Create output dict output = {"login_buttons": login_buttons, "self_registration": self_registration, "registered": registered, "login_div": login_div, "login_form": login_form, "register_div": register_div, "register_form": register_form, "contact_form": contact_form, "project_links": project_links, } # Count records (@todo: provide total/updated counters?) s3db = current.s3db db = current.db # Organisations table = s3db.org_organisation query = (table.deleted != True) count = table.id.count() row = db(query).select(count).first() output["total_organisations"] = row[count] # Service Locations (@todo) #table = s3db.org_service_location #query = (table.deleted != True) #count = table.id.count() #row = db(query).select(count).first() output["total_services"] = 0 #row[count] # Needs lists table = s3db.req_organisation_needs query = (table.deleted != True) count = table.id.count() row = db(query).select(count).first() output["total_needs"] = row[count] # Frontpage Feed Control if settings.frontpage.rss: s3.external_stylesheets.append("http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css") s3.scripts.append("http://www.google.com/jsapi?key=notsupplied-wizard") s3.scripts.append("http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js") counter = 0 feeds = "" for feed in settings.frontpage.rss: counter += 1 feeds = "".join((feeds, "{title:'%s',\n" % feed["title"], "url:'%s'}" % feed["url"])) # Don't add a trailing comma for old IEs if counter != len(settings.frontpage.rss): feeds += ",\n" # feedCycleTime: milliseconds before feed is reloaded (5 minutes) feed_control = "".join((''' function LoadDynamicFeedControl(){ var feeds=[ ''', feeds, ''' ] var options={ feedCycleTime:300000, numResults:5, stacked:true, horizontal:false, title:"''', str(T("News")), '''" } new GFdynamicFeedControl(feeds,'feed-control',options) } google.load('feeds','1') google.setOnLoadCallback(LoadDynamicFeedControl)''')) s3.js_global.append(feed_control) s3.stylesheets.append("../themes/RW/homepage.css") self._view(THEME, "index.html") return output
def __call__(self): request = current.request response = current.response if request.env.request_method == "POST": # Processs Form vars = request.post_vars result = current.msg.send_email( to=current.deployment_settings.get_mail_approver(), subject=vars.subject, message=vars.message, reply_to=vars.address, ) if result: response.confirmation = "Thankyou for your message - we'll be in touch shortly" from gluon import Field, SQLFORM from s3 import s3_mark_required, S3StringWidget T = current.T formstyle = current.deployment_settings.get_ui_formstyle() fields = [Field("name", label = T("Your name"), required = True, ), Field("address", label = T("Your e-mail address"), required = True, #widget = S3StringWidget(placeholder="*****@*****.**"), ), Field("subject", label = T("Subject"), required = True, ), Field("message", "text", label = T("Message"), required = True, ), ] labels, required = s3_mark_required(fields) response.form_label_separator = "" form = SQLFORM.factory(formstyle = formstyle, labels = labels, submit_button = T("Send Message"), *fields) form["_id"] = "mailform" form = DIV( H4("Contact Us", _style="background-color:#f7f8f9;padding:0.1rem 0.3rem"), P("You can leave a message using the contact form below."), form, _class="form-container", ) appname = request.application s3 = response.s3 sappend = s3.scripts.append if s3.cdn: if s3.debug: sappend("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js") else: sappend("http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js") else: if s3.debug: sappend("/%s/static/scripts/jquery.validate.js" % appname) else: sappend("/%s/static/scripts/jquery.validate.min.js" % appname) if s3.debug: sappend("/%s/static/themes/AidIQ/js/contact.js" % appname) else: sappend("/%s/static/themes/AidIQ/js/contact.min.js" % appname) response.title = "Contact | AidIQ.com" self._view(THEME, "contact.html") return dict(form=form)
def invite(self, r, **attr): """ Prepare and process invitation form @param r: the S3Request instance @param attr: controller attributes """ T = current.T db = current.db s3db = current.s3db response = current.response request = current.request session = current.session settings = current.deployment_settings auth = current.auth auth_settings = auth.settings auth_messages = auth.messages output = { "title": T("Invite Organisation"), } # Get all accounts that are linked to this org utable = auth_settings.table_user oltable = s3db.org_organisation_user pltable = s3db.pr_person_user organisation_id = r.record.id join = oltable.on((oltable.user_id == utable.id) & \ (oltable.deleted == False)) left = pltable.on((pltable.user_id == utable.id) & \ (pltable.deleted == False)) query = (oltable.organisation_id == organisation_id) rows = db(query).select( utable.id, utable.first_name, utable.last_name, utable.email, utable.registration_key, pltable.pe_id, join=join, left=left, ) active, disabled, invited = [], [], [] for row in rows: user = row[utable] person_link = row.pr_person_user if person_link.pe_id: if user.registration_key: disabled.append(user) else: active.append(user) else: invited.append(user) if active or disabled: response.error = T( "There are already user accounts registered for this organization" ) from gluon import UL, LI, H4, DIV from s3 import s3_format_fullname fullname = lambda user: s3_format_fullname( fname=user.first_name, lname=user.last_name, truncate=False, ) account_list = DIV(_class="org-account-list") if active: account_list.append(H4(T("Active Accounts"))) accounts = UL() for user in active: accounts.append( LI("%s <%s>" % (fullname(user), user.email))) account_list.append(accounts) if disabled: account_list.append(H4(T("Disabled Accounts"))) accounts = UL() for user in disabled: accounts.append( LI("%s <%s>" % (fullname(user), user.email))) account_list.append(accounts) output["item"] = account_list response.view = self._view(r, "display.html") return output account = invited[0] if invited else None # Look up existing invite-account email = None if account: email = account.email else: ctable = s3db.pr_contact query = (ctable.pe_id == r.record.pe_id) & \ (ctable.contact_method == "EMAIL") & \ (ctable.deleted == False) contact = db(query).select( ctable.value, orderby=ctable.priority, limitby=(0, 1), ).first() if contact: email = contact.value # Form Fields dbset = db(utable.id != account.id) if account else db formfields = [ Field("email", default=email, requires=[ IS_EMAIL(error_message=auth_messages.invalid_email), IS_LOWER(), IS_NOT_IN_DB( dbset, "%s.email" % utable._tablename, error_message=auth_messages.duplicate_email, ), ]), ] # Generate labels (and mark required fields in the process) labels, has_required = s3_mark_required(formfields, ) response.s3.has_required = has_required # Form buttons SEND_INVITATION = T("Send New Invitation") if account else T( "Send Invitation") buttons = [ INPUT( _type="submit", _value=SEND_INVITATION, ), # TODO cancel-button? ] # Construct the form response.form_label_separator = "" form = SQLFORM.factory( table_name="invite", record=None, hidden={"_next": request.vars._next}, labels=labels, separator="", showid=False, submit_button=SEND_INVITATION, #delete_label = auth_messages.delete_label, formstyle=settings.get_ui_formstyle(), buttons=buttons, *formfields) # Identify form for CSS & JS Validation form.add_class("send_invitation") if form.accepts( request.vars, session, formname="invite", #onvalidation = auth_settings.register_onvalidation, ): error = self.invite_account(r.record, form.vars.email, account=account) if error: response.error = T( "Could not send invitation (%(reason)s)") % { "reason": error } else: response.confirmation = T("Invitation sent") else: if account: response.warning = T( "This organisation has been invited before!") output["form"] = form response.view = self._view(r, "update.html") return output
def __call__(self): request = current.request response = current.response if request.env.request_method == "POST": # Processs Form vars = request.post_vars result = current.msg.send_email( to=current.deployment_settings.get_mail_approver(), subject=vars.subject, message=vars.message, reply_to=vars.address, ) if result: response.confirmation = "Thankyou for your message - we'll be in touch shortly" from gluon import Field, SQLFORM from s3 import s3_mark_required, S3StringWidget T = current.T formstyle = current.deployment_settings.get_ui_formstyle() fields = [ Field( "name", label=T("Your name"), required=True, ), Field( "address", label=T("Your e-mail address"), required=True, #widget = S3StringWidget(placeholder="*****@*****.**"), ), Field( "subject", label=T("Subject"), required=True, ), Field( "message", "text", label=T("Message"), required=True, ), ] labels, required = s3_mark_required(fields) response.form_label_separator = "" form = SQLFORM.factory(formstyle=formstyle, labels=labels, submit_button=T("Send Message"), *fields) form["_id"] = "mailform" form = DIV( H4("Contact Us", _style="background-color:#f7f8f9;padding:0.1rem 0.3rem"), P("You can leave a message using the contact form below."), form, _class="form-container", ) appname = request.application s3 = response.s3 sappend = s3.scripts.append if s3.cdn: if s3.debug: sappend( "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js" ) else: sappend( "http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js" ) else: if s3.debug: sappend("/%s/static/scripts/jquery.validate.js" % appname) else: sappend("/%s/static/scripts/jquery.validate.min.js" % appname) if s3.debug: sappend("/%s/static/themes/AidIQ/js/contact.js" % appname) else: sappend("/%s/static/themes/AidIQ/js/contact.min.js" % appname) response.title = "Contact | AidIQ.com" self._view(THEME, "contact.html") return dict(form=form)