Beispiel #1
0
    def test_library_include_errors(self):
        # render not included
        self.assertEqual(ptah.render_includes(self.request), '')

        # include unknown
        ptah.include(self.request, 'test-lib-test')
        self.assertEqual(ptah.render_includes(self.request), '')
Beispiel #2
0
    def test_library_include_errors(self):
        # render not included
        self.assertEqual(ptah.render_includes(self.request), '')

        # include unknown
        ptah.include(self.request, 'test-lib-test')
        self.assertEqual(ptah.render_includes(self.request), '')
Beispiel #3
0
    def test_library_include_recursive(self):
        ptah.library(
            'test-lib1-r', path='http://ptah.org/style1.css', type='css')

        ptah.library(
            'test-lib2-r', path='http://ptah.org/style2.css', type='css',
            require='test-lib1-r')

        ptah.library(
            'test-lib3-r', path='http://ptah.org/style3.css', type='css',
            require=('test-lib1-r', 'test-lib2-r'))

        ptah.library(
            'test-lib4-r', path='http://ptah.org/style4.css', type='css',
            require=('test-lib1-r', 'test-lib2-r'))
        self.init_ptah()

        ptah.include(self.request, 'test-lib3-r')
        ptah.include(self.request, 'test-lib4-r')

        self.assertEqual(
            ptah.render_includes(self.request),
"""<link type="text/css" rel="stylesheet" href="http://ptah.org/style1.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style2.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style3.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style4.css" />""")
Beispiel #4
0
    def test_library_include_recursive(self):
        ptah.library('test-lib1-r',
                     path='http://ptah.org/style1.css',
                     type='css')

        ptah.library('test-lib2-r',
                     path='http://ptah.org/style2.css',
                     type='css',
                     require='test-lib1-r')

        ptah.library('test-lib3-r',
                     path='http://ptah.org/style3.css',
                     type='css',
                     require=('test-lib1-r', 'test-lib2-r'))

        ptah.library('test-lib4-r',
                     path='http://ptah.org/style4.css',
                     type='css',
                     require=('test-lib1-r', 'test-lib2-r'))
        self.init_ptah()

        ptah.include(self.request, 'test-lib3-r')
        ptah.include(self.request, 'test-lib4-r')

        self.assertEqual(
            ptah.render_includes(self.request),
            """<link type="text/css" rel="stylesheet" href="http://ptah.org/style1.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style2.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style3.css" />
<link type="text/css" rel="stylesheet" href="http://ptah.org/style4.css" />""")
Beispiel #5
0
def edit_category(context, request):
    categoryform = form.Form(context,request)
    categoryform.fields = models.Category.__type__.fieldset

    def backAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return
        form.context.name = data['name']
        form.message('Category has been updated.')

    categoryform.label = u'Edit category'
    categoryform.buttons.add_action('Update', action=updateAction)
    categoryform.buttons.add_action('Back', action=backAction)
    categoryform.content = {'name':context.name}

    result = categoryform.update()
    if isinstance(result, HTTPFound):
        return result

    rendered_form = categoryform.render()

    ptah.include(request, 'bootstrap')
    rendered_includes = ptah.render_includes(request)

    api = TemplateAPI(request)

    return {'api': api,
            'rendered_form': rendered_form,
            'rendered_includes': rendered_includes,
            'rendered_messages': ptah.render_messages(request)}
Beispiel #6
0
    def test_library_include(self):
        ptah.library('test-lib2', path='http://ptah.org/style.css', type='css')
        self.init_ptah()

        ptah.include(self.request, 'test-lib2')
        self.assertEqual(
            ptah.render_includes(self.request),
            '<link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" />'
        )
Beispiel #7
0
    def test_library_include(self):
        ptah.library(
            'test-lib2', path='http://ptah.org/style.css', type='css')
        self.init_ptah()

        ptah.include(self.request, 'test-lib2')
        self.assertEqual(
            ptah.render_includes(self.request),
            '<link type="text/css" rel="stylesheet" href="http://ptah.org/style.css" />')
Beispiel #8
0
    def test_library_include_resource(self):
        self.config.add_static_view('tests30', 'ptah.tests:static/dir1')
        ptah.library('test-lib-30',
                     path='ptah.tests:static/dir1/style.css',
                     type='css')
        self.init_ptah()

        ptah.include(self.request, 'test-lib-30')

        self.assertEqual(
            ptah.render_includes(self.request),
            '<link type="text/css" rel="stylesheet" href="http://example.com/tests30/style.css" />'
        )
Beispiel #9
0
    def test_library_include_resource(self):
        self.config.add_static_view('tests30', 'ptah.tests:static/dir1')
        ptah.library(
            'test-lib-30',
            path='ptah.tests:static/dir1/style.css',
            type='css')
        self.init_ptah()

        ptah.include(self.request, 'test-lib-30')

        self.assertEqual(
            ptah.render_includes(self.request),
            '<link type="text/css" rel="stylesheet" href="http://example.com/tests30/style.css" />')
Beispiel #10
0
def add_post(context, request):
    postform = form.Form(context,request)
    postform.fields = models.Post.__type__.fieldset

    def cancelAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return

        now = datetime.utcnow()
        user = ptah.auth_service.get_current_principal().name
        post = models.Post(creator = user,
                           title = data['title'],
                           tags = data['tags'],
                           category = data['category'],
                           text = data['text'],
                           discussion = data['discussion'],
                           modified = now,
                           created = now)
        ptah.get_session().add(post)

        form.message('Post has been created.')
        return HTTPFound(location='/')

    postform.label = u'Add post'
    postform.buttons.add_action('Add', action=updateAction)
    postform.buttons.add_action('Cancel', action=cancelAction)

    result = postform.update() # prepare form for rendering
    if isinstance(result, HTTPFound):
        return result

    rendered_form = postform.render()

    ptah.include(request, 'bootstrap')
    rendered_includes = ptah.render_includes(request)

    api = TemplateAPI(request)

    return {'api': api,
            'rendered_form': rendered_form,
            'rendered_includes': rendered_includes,
            'rendered_messages': ptah.render_messages(request)}
Beispiel #11
0
def edit_post(context, request):
    postform = form.Form(context,request)
    postform.fields = models.Post.__type__.fieldset

    def backAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return
        user = ptah.auth_service.get_current_principal().name
        form.context.creator = user
        form.context.title = data['title']
        form.context.tags = data['tags']
        form.context.category = data['category']
        form.context.text = data['text']
        form.context.discussion = data['discussion']
        form.context.modified = datetime.utcnow()
        form.message('Post has been updated.')

    postform.label = u'Edit Post'
    postform.buttons.add_action('Update', action=updateAction)
    postform.buttons.add_action('Back', action=backAction)
    postform.content = {'title':context.title,
                        'tags':context.tags,
                        'category':context.category,
                        'text':context.text,
                        'discussion':context.discussion}

    result = postform.update()
    if isinstance(result, HTTPFound):
        return result

    rendered_form = postform.render()

    ptah.include(request, 'bootstrap')
    rendered_includes = ptah.render_includes(request)

    api = TemplateAPI(request)

    return {'api': api,
            'rendered_form': rendered_form,
            'rendered_includes': rendered_includes,
            'rendered_messages': ptah.render_messages(request)}
Beispiel #12
0
def edit_blog(context, request):
    configform = form.Form(context,request)
    configform.fields = models.Blog.__type__.fieldset

    def backAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return
        form.context.name = data['name']
        form.context.title = data['title']
        form.context.tagline = data['tagline']
        form.context.discussion = data['discussion']
        form.context.disqus = data['disqus']
        form.message('Blog has been updated.')

    configform.label = u'Blog Configuration'
    configform.buttons.add_action('Update', action=updateAction)
    configform.buttons.add_action('Back', action=backAction)
    configform.content = {'name':context.name,
                        'title':context.title,
                        'tagline':context.tagline,
                        'discussion':context.discussion,
                        'disqus':context.disqus}

    result = configform.update()
    if isinstance(result, HTTPFound):
        return result

    rendered_form = configform.render()

    ptah.include(request, 'bootstrap')
    rendered_includes = ptah.render_includes(request)

    api = TemplateAPI(request)

    return {'api': api,
            'rendered_form': rendered_form,
            'rendered_includes': rendered_includes,
            'rendered_messages': ptah.render_messages(request)}
Beispiel #13
0
def add_object(context, request):
    rackobform = form.Form(context, request)
    rackobform.fields = models.RackObject.__type__.fieldset

    def cancelAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return

        obj = models.RackObject(title=data['title'],
                                label=data['label'],
                                objtype=data['objtype'])
        ptah.get_session().add(obj)

        form.message('RackObject has been created.')
        return HTTPFound(location='/')

    rackobform.label = u'Add object'
    rackobform.buttons.add_action('Add', action=updateAction)
    rackobform.buttons.add_action('Cancel', action=cancelAction)

    result = rackobform.update()  # prepare form for rendering
    if isinstance(result, HTTPFound):
        return result

    rendered_form = rackobform.render()

    ptah.include(request, 'bootstrap')
    rendered_includes = ptah.render_includes(request)

    return {
        'objects': ptah.get_session().query(models.RackObject),
        'rendered_form': rendered_form,
        'rendered_includes': rendered_includes,
        'rendered_messages': ptah.render_messages(request)
    }
Beispiel #14
0
def add_link(context, request):
    linkform = form.Form(context,request)
    linkform.fields = models.Link.__type__.fieldset

    def cancelAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return

        link = models.Link(title = data['title'],
                           href = data['href'],
                           color = data['color'])
        ptah.get_session().add(link)

        form.message('Link has been created.')
        return HTTPFound(location='/')

    linkform.label = u'Add link'
    linkform.buttons.add_action('Add', action=updateAction)
    linkform.buttons.add_action('Cancel', action=cancelAction)

    result = linkform.update() # prepare form for rendering
    if isinstance(result, HTTPFound):
        return result

    rendered_form = linkform.render()

    ptah.include(request, 'bootstrap')
    rendered_includes = ptah.render_includes(request)

    return {'links': ptah.get_session().query(models.Link),
            'rendered_form': rendered_form,
            'rendered_includes': rendered_includes,
            'rendered_messages': ptah.render_messages(request)}
Beispiel #15
0
def add_category(context, request):
    categoryform = form.Form(context,request)
    categoryform.fields = models.Category.__type__.fieldset

    def cancelAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return

        category = models.Category(name = data['name'])
        ptah.get_session().add(category)

        form.message('Category has been created.')
        return HTTPFound(location='/')

    categoryform.label = u'Add category'
    categoryform.buttons.add_action('Add', action=updateAction)
    categoryform.buttons.add_action('Cancel', action=cancelAction)

    result = categoryform.update() # prepare form for rendering
    if isinstance(result, HTTPFound):
        return result

    rendered_form = categoryform.render()

    ptah.include(request, 'bootstrap')
    rendered_includes = ptah.render_includes(request)

    api = TemplateAPI(request)

    return {'api': api,
            'rendered_form': rendered_form,
            'rendered_includes': rendered_includes,
            'rendered_messages': ptah.render_messages(request)}
Beispiel #16
0
def edit_link(context, request):
    linkform = form.Form(context,request)
    linkform.fields = models.Link.__type__.fieldset

    def backAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()
        if errors:
            form.message(errors, 'form-error')
            return
        form.context.title = data['title']
        form.context.href = data['href']
        form.context.color = data['color']
        form.message('Link has been updated.')

    linkform.label = u'Edit link'
    linkform.buttons.add_action('Update', action=updateAction)
    linkform.buttons.add_action('Back', action=backAction)
    linkform.content = {'title':context.title,
                        'href':context.href,
                        'color':context.color}

    result = linkform.update() # prepare form for rendering
    if isinstance(result, HTTPFound):
        return result

    rendered_form = linkform.render()

    ptah.include(request, 'bootstrap')
    rendered_includes = ptah.render_includes(request)

    return {'links': ptah.get_session().query(models.Link),
            'rendered_form': rendered_form,
            'rendered_includes': rendered_includes,
            'rendered_messages': ptah.render_messages(request)}
Beispiel #17
0
 def __call__(self):
     return {'rendered_includes': ptah.render_includes(self.request),
             'rendered_messages': ptah.render_messages(self.request)}
Beispiel #18
0
def contact_us(context, request):
    contactform = form.Form(context, request)
    contactform.fields = form.Fieldset(

        form.TextField(
            'fullname',
            title = u'First & Last Name'),

        form.TextField(
            'phone',
            title = u'Telephone number',
            description=u'Please provide telephone number',
            validator = Telephone()),

        form.TextField(
            'email',
            title = u'Your email',
            description = u'Please provide email address.',
            validator = form.Email()),

        form.TextAreaField(
            'subject',
            title = u'How can we help?',
            missing = u''), # field use this value is request doesnt contain
                            # field value, effectively field is required
                            # if `missing` is not specified
        )

    # form actions
    def cancelAction(form):
        return HTTPFound(location='/')

    def updateAction(form):
        data, errors = form.extract()

        if errors:
            form.message(errors, 'form-error')
            return

        # form.context is ...
        form.context.fullname = data['fullname']
        form.context.phone = data['phone']
        form.context.email = data['email']
        form.context.subject = data['subject']

        # You would add any logic/database updates/insert here.
        # You would probably also redirect.

        log.info('The form was updated successfully')
        form.message('The form was updated successfully')

    contactform.label = u'Contact us'
    contactform.buttons.add_action('Update', action=updateAction)
    contactform.buttons.add_action('Cancel', action=cancelAction)

    # form default values
    contactform.content = {}

    # prepare form
    result = contactform.update()
    if isinstance(result, HTTPFound):
        return result

    # render form into HTML
    rendered_form = contactform.render()

    # query for links to populate links box
    links = ptah.get_session().query(models.Link)

    #include library dependencies
    ptah.include(request, 'bootstrap')

    # render all the included libraries into html
    rendered_includes = ptah.render_includes(request)

    # render messages
    rendered_messages = ptah.render_messages(request)

    return {'links': links,
            'rendered_form': rendered_form,
            'rendered_messages': rendered_messages,
            'rendered_includes': rendered_includes}
Beispiel #19
0
 def __call__(self):
     request = self.request
     self.rendered_includes = ptah.render_includes(request)
     self.rendered_messages = ptah.render_messages(request)
     return {}