Ejemplo n.º 1
0
def receiveAddEditProjectForm():
    session = Database.Session()
    P = Database.Project
    p = P()
    Form = createFormContructor(p, [])
    f = Form()

    if f.validates():
        if f.d.project_id == "new":
            p = P()
        else:
            q = session.query(P).filter(P.project_id == int(f.d.project_id))
            p = q.one()
        p.project_name = f.d.project_name
        p.project_status = f.d.project_status
        p.category_id = int(f.d.project_category)
        if p.project_id == None:
            session.add(p)
        session.commit()

        if f.d.project_time_estimate != "":
            p_est = Database.ProjectTimeEst()
            p_est.project_id = p.project_id
            p_est.project_time_estimate = f.d.project_time_estimate
            session.add(p_est)
            session.commit()
    return p.project_id
Ejemplo n.º 2
0
def receiveAddEditTaskForm():
    session = Database.Session()
    T = Database.Task
    t = T()
    Form = createFormContructor(t, [])
    f = Form()

    if f.validates():
        if f.d.task_id == "new":
            t = T()
        else:
            q = session.query(T).filter(T.task_id == int(f.d.task_id))
            t = q.one()
        t.task_name = f.d.task_name
        t.task_status = f.d.task_status
        t.project_id = int(f.d.task_project)
        if t.task_id == None:
            session.add(t)
        session.commit()

        if f.d.task_time_estimate != "":
            t_est = Database.TaskTimeEst()
            t_est.task_id = t.task_id
            t_est.task_time_estimate = f.d.task_time_estimate
            session.add(t_est)
            session.commit()
        return f.d.task_project
Ejemplo n.º 3
0
	def __init__ ( self ):
	    Form.__init__ ( self,
	         Textbox('name', size=30, description="用户名", class_='sl', disabled='disabled'),
	         Textbox('email', EmailValidator, size=30, description="邮箱", class_='sl'),
	         Textbox('signature', regexp(r".{0,100}$", ' 请不要超过100个字符'), size=30, description="签名", class_='sl'),
	         Textbox('outsite_link', LinkValidator, size=30, description="主页", class_='sl'),
	         Button('保存设置', class_='super normal button')
     	)
Ejemplo n.º 4
0
	def __init__ ( self ):
	    Form.__init__ ( self,
	        Textarea ( 'content',
	            Required,
	            rows = 5,
	            cols = 80,
	            description = '',
	            post = '<div class="sep10"></div>',
	            class_ = 'mll'
	        ),
	       Button ( '回复', class_ = 'super normal button' )
	    )
Ejemplo n.º 5
0
    def test_describe_invalid_form_with_valid_form(self):
        # Given
        input1 = Input('input1')
        input2 = Input('input2')
        input3 = Input('input3')
        form = Form(input1, input2, input3)

        # When
        desc = describe_invalid_form(form)

        # Then
        self.assertEquals(dict(), desc)
Ejemplo n.º 6
0
def receiveAddEditCategoryForm():
    session = Database.Session()
    C = Database.Category
    c = C()

    Form = createFormContructor(c, [])
    f = Form()

    if f.validates():
        if f.d.category_id == "new":
            c = C()
        else:
            q = session.query(C).filter(C.category_id == int(f.d.category_id))
            c = q.one()
        c.category_name = f.d.category_name
        c.category_status = f.d.category_status

        if c.category_id == None:
            session.add(c)
        session.commit()

    print f.d.category_id
    return f.d.category_id
Ejemplo n.º 7
0
    def test_describe_invalid_form_with_at_least_one_invalid_input_field(self):
        # Given
        input1 = Input('input1')
        input1.note = 'Required'
        input2 = Input('input2')
        input3 = Input('input3')
        input3.note = 'Invalid: YYYY/MM/DD'
        form = Form(input1, input2, input3)

        # When
        desc = describe_invalid_form(form)

        # Then
        self.assertEquals(
            dict(input1='Required', input3='Invalid: YYYY/MM/DD'), desc)
Ejemplo n.º 8
0
from __future__ import print_function
from web.form import Button, Form, Textbox, net
from infogami.utils import i18n

class BetterButton(Button):
    def render(self):
        label = self.attrs.get('label', self.name)
        safename = net.websafe(self.name)
        x = '<button name="%s"%s>%s</button>' % (safename, self.addatts(), label)
        return x

_ = i18n.strings.get_namespace('/account/preferences')

template_preferences = Form(
    Textbox("path", description=_.template_root),
    BetterButton('save', label=_.save)
)

if __name__ == "__main__":
    print(template_preferences().render())
Ejemplo n.º 9
0
from web.form import Form, Hidden, Textarea, Textbox, Validator

required = Validator("Required", lambda x: x and x.strip())

review_form = Form(Hidden('edition', required), Textbox('title'),
                   Textarea('text', required))
Ejemplo n.º 10
0
from infogami.utils.context import context


class BetterButton(Button):
    def render(self):
        label = self.attrs.get('label', self.name)
        safename = net.websafe(self.name)
        x = f'<button name="{safename}"{self.addatts()}>{label}</button>'
        return x


_ = i18n.strings.get_namespace('/account/login')

login = Form(
    Hidden('redirect'),
    Textbox('username', notnull, description=_.username),
    Password('password', notnull, description=_.password),
    Checkbox('remember', description=_.remember_me),
)

vlogin = regexp(r"^[A-Za-z0-9-_]{3,20}$",
                'must be between 3 and 20 letters and numbers')
vpass = regexp(r".{3,20}", 'must be between 3 and 20 characters')
vemail = regexp(r".*@.*", "must be a valid email address")
not_already_used = Validator(
    'This email is already used',
    lambda email: db.get_user_by_email(context.site, email) is
    None,  # type: ignore
)

_ = i18n.strings.get_namespace('/account/register')
Ejemplo n.º 11
0
	def __init__ ( self ):
	    Form.__init__ ( self,
	        Textbox('name', Required, size=30, description="用户名", class_='sl'),
	        Password('password', Required, size=30, description="密码", class_='sl'),
	        Button('登录', class_='super normal button')
    	)
Ejemplo n.º 12
0
	def __init__ ( self ):
	    Form.__init__ ( self,
			Textarea ( 'title', Required, class_='mle', description='' ),
			Textarea ( 'content', Required, class_='mle tall', description='' ),
			Button   ( '创建', class_ = 'super normal button' )
		)
Ejemplo n.º 13
0
def test_id_escape_issue():
    f = Form(Textbox("x", id="x <unsafe>"))
    assert "<unsafe>" not in f.render()
    assert "<unsafe>" not in f.render_css()
Ejemplo n.º 14
0
def test_id_escape_issue():
    f = Form(Textbox("x", id="x <unsafe>"))
    assert "<unsafe>" not in f.render()
    assert "<unsafe>" not in f.render_css()
Ejemplo n.º 15
0
PointParamExtendedForm = Form(Dropdown('zpoint', [('', '')], description="zpoint"),
                              Textbox('x', size=12),
                              Textbox('y', size=12),
                              Textbox('width', size=12),
                              Textbox('width_new', size=12),
                              Textbox('doubledash', size=12),
                              Textbox('tripledash', size=12),
                              Textbox('leftp', size=12),
                              Textbox('rightp', size=12),
                              Textbox('downp', size=12),
                              Textbox('upp', size=12),
                              Textbox('dir', size=12),
                              Textbox('leftp2', size=12),
                              Textbox('rightp2', size=12),
                              Textbox('downp2', size=12),
                              Textbox('upp2', size=12),
                              Textbox('dir2', size=12),
                              Textbox('tensionand', size=12),
                              Textbox('penshifted', size=12),
                              Textbox('pointshifted', size=12),
                              Textbox('angle', size=12),
                              Textbox('penwidth', size=12),
                              Textbox('overx', size=12),
                              Textbox('overbase', size=12),
                              Textbox('overcap', size=12),
                              Textbox('overasc', size=12),
                              Textbox('overdesc', size=12),

                              Textbox('theta', size=12),
                              Textbox('serif_h_bot', size=12),
                              Textbox('serif_h_top', size=12),
                              Textbox('serif_v_left', size=12),
                              Textbox('serif_v_right', size=12))
Ejemplo n.º 16
0
 def test_id_escape_issue(self):
     f = Form(Textbox("x", id="x <unsafe>"))
     self.assertTrue("<unsafe>" not in f.render())
     self.assertTrue("<unsafe>" not in f.render_css())