Example #1
0
    def display_user_list(self, users, user):
        page = context.page
        request = context.request

        page.title = "User List"
        page.heading = "User List"
        page.add_block(NavBlock(force_pager=True))

        headers = []
        tds = [
            HTML.th("ID", width="16"),
            HTML.th("Av.", width="16", title="Avatar"),
            HTML.th("Username"),
            HTML.th("Join Date"),
            HTML.th("Ps.", width="16", title="Post Count"),
            HTML.th("Cs.", width="16", title="Comment Count"),
        ]
        if user.can("view_user_email"):
            tds.append(HTML.th("Email Address"))
        tds.append(HTML.th("Action"))
        headers.append(HTML.tr(*tds))

        tds = [
            "",  # HTML.input(name="page", type="hidden", value=request.args.get("page", "1")),
            tags.checkbox("avatar", checked=request.args.get("avatar")),
            tags.text("username", value=request.args.get("username")),
            "",
            tags.checkbox("posts", value="1", checked=request.args.get("posts")),
            tags.checkbox("comments", value="1", checked=request.args.get("comments")),
        ]
        if user.can("view_user_email"):
            tds.append(tags.text("email", value=request.args.get("email")))
        tds.append(tags.submit(name="submit", value="Search"))
        headers.append(HTML.tr(HTML.form(*[HTML.td(x) for x in tds], action="#", method="GET")))

        rows = []
        for duser in users:
            assert isinstance(duser, User)
            tds = [
                duser.id,
                duser.get_avatar_html(16),
                HTML.a(duser.username, href=make_link("user/"+duser.username)),
                str(duser.join_date)[:16],
                HTML.a(duser.post_count, href=make_link("post/list/uploaded_by_id=%d/1" % duser.id)),
                duser.comment_count,
            ]
            if user.can("view_user_email"):
                tds.append(duser.email)
            tds.append("")
            rows.append(HTML.tr(*[HTML.td(x) for x in tds]))

        page.add_block(Block(
            "Users",
            HTML.table(HTML.thead(*headers), HTML.tbody(*rows), class_="zebra")
        ))
Example #2
0
 def test_text_field(self):
     eq_(
         text("title", ""),
         u'<input id="title" name="title" type="text" value="" />'
     )
     eq_(
         text("title", None),
         u'<input id="title" name="title" type="text" />'
     )
     eq_(
         text("title", "Hello!"),
         u'<input id="title" name="title" type="text" value="Hello!" />'
     )
Example #3
0
 def test_multiple_id_bug(self):
     # Don't set multiple id attributes for 'id_' argument.
     eq_(
         text("spam", "pizza", id="eggs"),
         u'<input id="eggs" name="spam" type="text" value="pizza" />')
     eq_(
         text("spam", "pizza", id_="eggs"),
         u'<input id="eggs" name="spam" type="text" value="pizza" />')
     eq_(
         select("spam", [1, 2], [2], id="eggs"),
         u'<select id="eggs" name="spam">\n<option selected="selected" value="2">2</option>\n</select>')
     eq_(
         select("spam", [1, 2], [2], id_="eggs"),
         u'<select id="eggs" name="spam">\n<option selected="selected" value="2">2</option>\n</select>')
Example #4
0
 def text(
         self, name, value=None, id=None,
         cols=10, inner_cols=None, errors=True, **attrs):
     """
     Outputs text input.
     """
     id = id or name
     if name in self.form.schema.fields:
         validator = self.form.schema.fields[name]
         if (
                 isinstance(validator, validators.FancyValidator) and
                 validator.not_empty and
                 not 'required' in attrs):
             attrs['required'] = 'required'
         if (
                 isinstance(validator, validators.String) and
                 validator.max is not None and
                 not 'maxlength' in attrs):
             attrs['maxlength'] = validator.max
     if inner_cols:
         attrs = css_add_class(attrs, 'small-%d' % inner_cols)
     result = tags.text(name, self.value(name, value), id, **attrs)
     if cols:
         return self.column(name, result, cols, inner_cols, errors)
     else:
         return result
 def url(self, name, value=None, id=None, **attrs):
     kw = {'type': 'text', 'maxlength': 150, 'class_': 'url'}
     kw.update(attrs)
     value = self.value(name, value)
     if value and value.startswith('http://'):
         value = value[len('http://'):]
     return literal(u'http://') + tags.text(name, value, id, **kw)
Example #6
0
 def text(self,
          name,
          value=None,
          id=None,
          cols=10,
          inner_cols=None,
          errors=True,
          **attrs):
     """
     Outputs text input.
     """
     id = id or name
     if name in self.form.schema.fields:
         validator = self.form.schema.fields[name]
         if (isinstance(validator, validators.FancyValidator)
                 and validator.not_empty and not 'required' in attrs):
             attrs['required'] = 'required'
         if (isinstance(validator, validators.String)
                 and validator.max is not None
                 and not 'maxlength' in attrs):
             attrs['maxlength'] = validator.max
     if inner_cols:
         attrs = css_add_class(attrs, 'small-%d' % inner_cols)
     result = tags.text(name, self.value(name, value), id, **attrs)
     if cols:
         return self.column(name, result, cols, inner_cols, errors)
     else:
         return result
Example #7
0
 def text(self, name, value=None, id=None, **attrs):
     """
     Outputs text input.
     """
     id = id or name
     val = self.value(name, value)
     return tags.text(self.prefix + name, val, id, **attrs) + self.getErrorTag(name)
 def url(self, name, value=None, id=None, **attrs):
     kw = {'type': 'text', 'maxlength': 150, 'class_': 'url'}
     kw.update(attrs)
     value = self.value(name, value)
     if value and value.startswith('http://'):
         value = value[len('http://'):]
     return literal(u'http://') + tags.text(name, value, id, **kw)
Example #9
0
def date_field(name, value=None, data_options=None, **kwargs):
    id = gen_id()
    format = get_date_format()
    
    # this hack is need for datebox correct working
    format = format.replace('yy', 'yyyy')

    _data_options = """
        editable:false,
        formatter:function(date){return dt_formatter(date, %s);},
        parser:function(s){return dt_parser(s, %s);}
        """ % (
       json.dumps(format),
       json.dumps(format)
    )
    if data_options:
        _data_options += ",%s" % data_options
    if value:
        value = format_date(value, format)
    html = tags.text(
        name, value, class_="easyui-datebox text w10",
        id=id, data_options=_data_options, **kwargs
    )
    return html + HTML.literal("""
        <script type="text/javascript">
            add_datebox_clear_btn("#%s");
        </script>
    """) % id
Example #10
0
 def date(self, name, value=None, id=None, **attrs):
     """
     Outputs date text input.
     """
     id = id or name
     val = self.value(name, value)
     if isinstance(val, datetime):
         val = val.strftime('%d-%m-%Y')
     return tags.text(self.prefix + name, val, id, **attrs) + self.getErrorTag(name)
 def text(self, name, value=None, id=None, **attrs):
     """
     Outputs text input.
     """
     return tags.text(
         name, 
         self.value(name, value), 
         self._get_id(id, name), 
         **attrs
     )
    def colour(self, name, value=None, id=None, **attrs):
        kw = {'maxlength': 50, 'size': 20, 'class_': 'colour'}
        kw.update(attrs)
        kw['size'] = min((kw['maxlength'], kw['size']))

        id = id or name

        value = self.value(name, value)
        if value and value[0] == '#':
            value = value[1:]

        return literal('#') + tags.text(name, value, id, **kw)
Example #13
0
	def date(self, name, value=None, id=None, **attrs):
		kw = {'maxlength': 200, 'size': const.DATE_TEXT_SIZE}
		kw.update(attrs)
		kw['size'] = min((kw['maxlength'], kw['size']))

		kw['class_'] = self._fix_class(attrs, 'DatePicker')
		kw['id'] = self._fix_id(id or name)

		value = self.value(name, value)
		value = format_date(value, self.form.request)

		return tags.text(name, value, **kw)
    def colour(self, name, value=None, id=None, **attrs):
        kw = {'maxlength': 50, 'size': 20, 'class_': 'colour'}
        kw.update(attrs)
        kw['size'] = min((kw['maxlength'], kw['size']))

        id = id or name

        value = self.value(name, value)
        if value and value[0] == '#':
            value = value[1:]

        return literal('#') + tags.text(name, value, id, **kw)
Example #15
0
 def __call__(self):
     if self._show_toolbar:
         toolbar = self._render_toolbar()
     else:
         toolbar = None
     return HTML(
        tags.text(
            self._name, self._value, id=self._id,
            class_="easyui-combogrid text w20",
            data_options=self._render_data_options(),
            **self._html_attrs
        ),
        toolbar if toolbar else ''
     )
    def date(self, name, value=None, id=None, date_format=None, **attrs):
        """
        Outputs text input with an optionally formatted datetime.
        """
        value = self.value(name, value)
        if isinstance(value, datetime.date) and date_format:
            value = value.strftime(date_format)

        return tags.text(
            name,
            value,
            self._get_id(id, name),
            **attrs
        )
Example #17
0
def text_field(name, value=None, **options):
    """
    Creates a standard text field.

    ``value`` is a string, the content of the text field

    Options:

    * ``disabled`` - If set to True, the user will not be able to use this input.
    * ``size`` - The number of visible characters that will fit in the input.
    * ``maxlength`` - The maximum number of characters that the browser will allow the user to enter.

    Remaining keyword options will be standard HTML options for the tag.
    """
    _update_fa(options, name)
    return text(name, value=value, **options)
Example #18
0
def text_field(name, value=None, **options):
    """
    Creates a standard text field.

    ``value`` is a string, the content of the text field

    Options:

    * ``disabled`` - If set to True, the user will not be able to use this input.
    * ``size`` - The number of visible characters that will fit in the input.
    * ``maxlength`` - The maximum number of characters that the browser will allow the user to enter.

    Remaining keyword options will be standard HTML options for the tag.
    """
    _update_fa(options, name)
    return text(name, value=value, **options)
Example #19
0
 def display_login_block(self):
     page = context.page
     table = HTML.table(
         HTML.tr(
             HTML.th("Username"),
             HTML.td(tags.text("username")),
         ),
         HTML.tr(
             HTML.th("Password"),
             HTML.td(tags.password("password")),
         ),
         HTML.tr(
             HTML.td(tags.submit(name="submit", value="Log In"), colspan=2)
         ),
         HTML.tr(
             HTML.td(HTML.small(HTML.a("Create Account", href=make_link("user_admin/create"))), colspan=2)
         ),
         # class_="form",
     )
     form = HTML.form(table, action=make_link("user_admin/login"), method="POST")
     page.add_block(Block("Login", form, self._user_block_location(), 90))
Example #20
0
def navigations_combotree_field(
    name, position_id, value=None, data_options=None, **kwargs
):
    _data_options = """
        url: '/navigations/list',
        onBeforeLoad: function(node, param){
            param.position_id = %s;
            param.sort = 'sort_order';
            param.order = 'asc';
    """ % position_id
    if value:
        _data_options += """
            if(!node){
                param.id = %s;
                param.with_chain = true;
            }
        """ % value

    _data_options += """
        }
    """
    if value:
        _data_options += """,
            onLoadSuccess: function(node, data){
                if(!node){
                    var n = $(this).tree('find', %s);
                    $(this).tree('expandTo', n.target);
                    $(this).tree('scrollTo', n.target);
                }
            }
        """ % value
    if data_options:
        _data_options += ',%s' % data_options

    return tags.text(
        name, value, class_="easyui-combotree text w20",
        data_options=_data_options, **kwargs
    )
Example #21
0
def services_types_combobox_field(name, value=None):
    ids = map(
        lambda x: str(x.id), get_resources_types_by_interface(IServiceType)
    )
    data_options = """
        url: '/resources_types/list',
        valueField: 'id',
        textField: 'humanize',
        editable: false,
        onBeforeLoad: function(param){
            param.sort = 'humanize';
            param.rows = 0;
            param.page = 1;
            param.id = %s
        },
        loadFilter: function(data){
            return data.rows;
        }
    """ % json.dumps(','.join(ids))
    return tags.text(
        name, value, class_="easyui-combobox text w20",
        data_options=data_options
    )
Example #22
0
def _combotree_field(
    name, value, url, sort, order='asc', data_options=None, **kwargs
):
    _data_options = """
        url: '%(url)s',
        onBeforeLoad: function(node, param){
            param.sort = '%(sort)s';
            param.order = '%(order)s';
    """ % {'url': url, 'sort': sort, 'order': order}
    if value:
        _data_options += """
            if(!node){
                param.id = %s;
                param.with_chain = true;
            }
        """ % value

    _data_options += """
        }
    """
    if value:
        _data_options += """,
            onLoadSuccess: function(node, data){
                if(!node){
                    var n = $(this).tree('find', %s);
                    $(this).tree('expandTo', n.target);
                    $(this).tree('scrollTo', n.target);
                }
            }
        """ % value
    if data_options:
        _data_options += ',%s' % data_options

    return tags.text(
        name, value, class_="easyui-combotree text w20",
        data_options=_data_options, **kwargs
    )
Example #23
0
def datetime_field(name, value=None, data_options=None, **kwargs):
    id = gen_id()
    _data_options = """
        editable:false,
        showSeconds:false,
        formatter:function(date){return dt_formatter(date, %s);},
        parser:function(s){return dt_parser(s, %s);}
        """ % (
            json.dumps(get_datetime_format()),
            json.dumps(get_datetime_format())
        )
    if data_options:
        _data_options += ",%s" % data_options
    if value:
        value = format_datetime(value)
    html = tags.text(
        name, value, class_="easyui-datetimebox text w10",
        id=id, data_options=_data_options, **kwargs
    )
    return html + HTML.literal("""
        <script type="text/javascript">
            add_datetimebox_clear_btn("#%s");
        </script>
    """) % id
Example #24
0
 def text(self, name, value=None, id=None, **attrs):
     """
     Outputs text input.
     """
     id = id or name
     return tags.text(name, self.value(name, value), id, **attrs)
Example #25
0
 def test_text_field_class_string(self):
     eq_(
         text("title", "Hello!", class_="admin"),
         u'<input class="admin" id="title" name="title" type="text" value="Hello!" />'
     )
Example #26
0
def reset(name, value=None, id=NotGiven, **attrs):
    return tags.text(name, value, id, type="reset", **attrs)
Example #27
0
 def text(self, name, value=None, id=None, **attrs):
     """
     Outputs text input.
     """
     return tags.text(name, self.value(name, value), self._get_id(id, name),
                      **attrs)
Example #28
0
def reset(name, value=None, id=NotGiven, **attrs):
    return tags.text(name, value, id, type="reset", **attrs)
Example #29
0
 def text(self, name, value=None, id=None, **attrs):
     return tags.text(name,
                      self.value(name, value),
                      self._id(id, name),
                      **attrs)