Example #1
0
File: web.py Project: 3kwa/tnc
    def index(self, **form):

        if cherrypy.request.method == "GET":
            return serve_template('index.html', form=forms.render_submission())

        if cherrypy.request.method == "POST":
            try:
                values = forms.validate_submission(form)
            except forms.Invalid, e:
                return serve_template('index.html',
                                      form=forms.render_submission(
                                          defaults=e.value,
                                          errors=e.unpack_errors()))
            else:
                save_submission(values)
                raise cherrypy.HTTPRedirect("thankyou")
Example #2
0
File: web.py Project: 3kwa/tnc
            publish_project(id_)
            return 'OK'
        elif action == 'unpublish':
            unpublish(id_)
            return 'OK'
        else:
            raise cherrypy.HTTPError(501)

    @cherrypy.expose
    def publish(self):
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return publish_json()

    @cherrypy.expose
    def submission(self, **form):
        try:
            values = forms.validate_submission(form)
            errors = {}
        except forms.Invalid, e:
            values = e.value
            errors = e.unpack_errors()
        else:
            models.save_submission(values)
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return json.dumps({'values' : values, 'errors' : errors})

current_dir = os.path.dirname(os.path.abspath(__file__))
config_file = os.path.join(current_dir, 'web.conf')

cherrypy.quickstart(App(), '/tnc', config=config_file)