Esempio n. 1
0
def CONFIRM_BOX(request,
                session,
                title="Delete Record",
                label="Are you sure you want to delete this record?",
                content="",
                func_yes=lambda v: v,
                func_no=lambda v: v):
    form = FORM(
        DIV(
            P(LABEL(label), _class="centered"),
            P(BUTTON("Yes", _type="submit", _name="yes", _value="yes"),
              _class="centered"),
            P(BUTTON("No", _type="submit", _name="no", _value="no"),
              _class="centered"),
        ))

    html = DIV(
        H2(title),
        DIV(DIV(form, P(content), _id="padding"), _id="user_action"),
    )

    if form.accepts(request.vars, session):
        if request.vars.yes == "yes":
            func_yes()
        else:
            func_no()
    elif form.errors:
        response.flash = "There were errors with the form"

    return html
Esempio n. 2
0
    def widget(cls, field, value, **attributes):
        """
        Generates a Bootstrap Radio Button
        """

        if isinstance(value, (list, tuple)):
            value = str(value[0])
        else:
            value = str(value)

        attr = cls._attributes(field, {}, **attributes)
        attr['_class'] = add_class(attr.get('_class'), 'web2py_radiowidget')

        requires = field.requires
        if not isinstance(requires, (list, tuple)):
            requires = [requires]
        if requires:
            if hasattr(requires[0], 'options'):
                options = requires[0].options()
            else:
                raise SyntaxError('widget cannot determine options of %s' %
                                  field)
        options = [(k, v) for k, v in options if str(v)]
        opts = []
        cols = attributes.get('cols', 1)
        totals = len(options)
        mods = totals % cols
        rows = totals / cols
        if mods:
            rows += 1

        for r_index in range(rows):
            tds = []
            for k, v in options[r_index * cols:(r_index + 1) * cols]:
                checked = {'_checked': 'checked'} if k == value else {}
                tds.append(
                    LABEL(INPUT(_type='radio',
                                _id='%s%s' % (field.name, k),
                                _name=field.name,
                                requires=attr.get('requires', None),
                                hideerror=True,
                                _value=k,
                                value=value,
                                **checked),
                          v,
                          _for='%s%s' % (field.name, k)))
            opts.append(DIV(tds, _class='radio'))

        if opts:
            opts[-1][0][0]['hideerror'] = False
        return DIV(*opts, **attr)
Esempio n. 3
0
def myradiowidget(field, value, **attributes):
    """
    <div class="control-group">
            <label for="inlineCheckboxes" class="control-label">Inline checkboxes</label>
            <div class="controls">
              <label class="checkbox inline">
                <input type="checkbox" value="option1" id="inlineCheckbox1"> 1
              </label>
              <label class="checkbox inline">
                <input type="checkbox" value="option2" id="inlineCheckbox2"> 2
              </label>
              <label class="checkbox inline">
                <input type="checkbox" value="option3" id="inlineCheckbox3"> 3
              </label>
            </div>
          </div>
    """
    _id = "%s_%s" % (field._tablename, field.name)

    requires = field.requires
    if not isinstance(requires, (list, tuple)):
        requires = [requires]
    if requires:
        if hasattr(requires[0], 'options'):
            options = requires[0].options()
        else:
            raise SyntaxError, 'widget cannot determine options of %s' \
                % field
    options = [(k, v) for k, v in options if str(v)]
    labels_and_inputs = []
    for i, a in options:
        checked = {'_checked': 'checked'} if i == value else {}
        labels_and_inputs.extend([
            LABEL(a,
                  INPUT(_type="radio",
                        _name=field.name,
                        _value=i,
                        _id="%s%s" % (_id, i),
                        **checked),
                  _class="radio%s" % (attributes.get('type', ' inline')))
        ])

    return TAG[''](*labels_and_inputs)
Esempio n. 4
0
 def test_LABEL(self):
     self.assertEqual(
         LABEL('<>', _a='1', _b='2').xml(),
         b'<label a="1" b="2">&lt;&gt;</label>')
Esempio n. 5
0
    def rdrt_member_profile_header(r):
        """ Custom profile header to allow update of RDRT roster status """

        record = r.record
        if not record:
            return ""

        person_id = record.person_id
        from s3 import s3_fullname, s3_avatar_represent
        name = s3_fullname(person_id)

        table = r.table

        # Organisation
        comments = table.organisation_id.represent(record.organisation_id)

        from s3 import s3_unicode
        from gluon.html import A, DIV, H2, LABEL, P, SPAN

        # Add job title if present
        job_title_id = record.job_title_id
        if job_title_id:
            comments = (SPAN("%s, " % \
                             s3_unicode(table.job_title_id.represent(job_title_id))),
                             comments)

        # Determine the current roster membership status (active/inactive)
        atable = current.s3db.deploy_application
        status = atable.active
        query = atable.human_resource_id == r.id
        row = current.db(query).select(atable.id,
                                       atable.active,
                                       limitby=(0, 1)).first()
        if row:
            active = 1 if row.active else 0
            status_id = row.id
            roster_status = status.represent(row.active)
        else:
            active = None
            status_id = None
            roster_status = current.messages.UNKNOWN_OPT

        if status_id and \
           current.auth.s3_has_permission("update",
                                          "deploy_application",
                                          record_id=status_id):
            # Make inline-editable
            roster_status = A(roster_status,
                              data = {"status": active},
                              _id = "rdrt-roster-status",
                              _title = T("Click to edit"),
                              )
            s3 = current.response.s3
            script = "/%s/static/themes/IFRC/js/rdrt.js" % r.application
            if script not in s3.scripts:
                s3.scripts.append(script)
            script = '''$.rdrtStatus('%(url)s','%(active)s','%(inactive)s','%(submit)s')'''
            from gluon import URL
            options = {"url": URL(c="deploy", f="application",
                                  args=["%s.s3json" % status_id]),
                       "active": status.represent(True),
                       "inactive": status.represent(False),
                       "submit": T("Save"),
                       }
            s3.jquery_ready.append(script % options)
        else:
            # Read-only
            roster_status = SPAN(roster_status)

        # Render profile header
        return DIV(A(s3_avatar_represent(person_id,
                                         tablename="pr_person",
                                         _class="media-object",
                                         ),
                     _class="pull-left",
                     ),
                   H2(name),
                   P(comments),
                   DIV(LABEL(status.label + ": "), roster_status),
                   _class="profile-header",
                   )
Esempio n. 6
0
from gluon.sql import Field
from gluon.sqlhtml import SQLFORM
from gluon.html import INPUT, FORM, LABEL, P, BR, SELECT, OPTION, A, CENTER, BODY, TEXTAREA, OBJECT, TAG
from gluon.validators import IS_NOT_EMPTY, IS_EXPR
from gluon.storage import Storage
from gluon import current

# web2py SQLFORM expects T in current (thread-local data) to translate messages
current.T = lambda x: x

if __name__ == '__main__':
    app = wx.App(False)
    w = gui.HtmlWindow(None, title="test html", visible=False, resizable=True)
    if '--login' in sys.argv:
        form = FORM(
            LABEL("Username", _width="25%"),
            INPUT(_type='text',
                  _name='username',
                  requires=IS_NOT_EMPTY(),
                  _width="75%"), LABEL("Password", _width="25%"),
            INPUT(_type='password',
                  _name='password',
                  requires=IS_NOT_EMPTY(),
                  _width="75%"), LABEL("Options:", _width="25%"),
            INPUT(_type='checkbox', _name='rememberme', _width="10%"),
            LABEL("Remember me", _width="65%"), LABEL("", _width="25%"),
            INPUT(_type='checkbox', _name='superuser', _width="10%"),
            LABEL("Log in as root", _width="65%"),
            CENTER(
                INPUT(_type='submit', _name='login', _value="Login"),
                BR(),