Example #1
0
    def update(service_id):
        """Update Servicees"""
        service = Service.query.get(service_id)

        if service is None:
            # return error message
            return {"error": "Error when updating an service"}

        form = ServiceForm(obj=request.json, prefix="service")
        form.category_ids.choices = CategoryHandler.list_for_select()

        if form.validate():
            service.name = form.name.data
            service.description = form.description.data
            service.is_active = form.is_active.data
            service.updated = datetime.datetime.now()

            category_ids = form.category_ids.data

            service.set_categoiry_ids(category_ids)

            db.session.commit()

            # upload the image
            ServiceHandler.upload(service, form)

            # success, return new item
            return {"item": service.serialize()}

        # return form errors
        return {"errors": form.errors}
def service_contact():
    form = ServiceForm(request.form)
    if form.validate():
        msg = Message(subject="Service contact form msg from " +
                      form.name.data,
                      sender="*****@*****.**",
                      recipients=["*****@*****.**"],
                      reply_to=form.email.data,
                      html=render_template('service_email.html', **form.data))
        mail.send(msg)
        return "valid data"
    else:
        return json.dumps(form.errors), 400
Example #3
0
    def insert(username):
        """New Service"""
        form = ServiceForm(obj=request.json, prefix="service")
        form.category_ids.choices = CategoryHandler.list_for_select()

        if form.validate():
            name = form.name.data
            description = form.description.data
            is_active = form.is_active.data

            category_ids = form.category_ids.data

            service = Service(
                username=username,
                name=name,
                description=description,
                is_active=is_active,
                updated=datetime.datetime.now(),
                created=datetime.datetime.now()
            )

            db.session.add(service)

            try:
                db.session.commit()

            except:
                db.session.rollback()
                # return error message
                return {"error": "Error when adding an service"}

            # append the categories
            if len(category_ids) > 0:
                service.set_categoiry_ids(category_ids)

                try:
                    db.session.commit()
                except:
                    db.session.rollback()

            ServiceHandler.upload(service, form)

            # success, return new item
            return {"item": service.serialize()}

        # return form errors
        return {"errors": form.errors}
Example #4
0
    def dispatch_request(self):
        self.lock_session()
        form = ServiceForm(request.form)

        if request.method == "GET":
            context = {"form": form}
            return self.render_template(context)
        if request.method == "POST" and form.validate():
            views = {"idp": "idpview", "ldap": "ldapview"}  #, "sp": "spview",}
            for k, v in form.data.iteritems():
                if not v:
                    views[k] = False

            session['data'] = {k: None for k in views.keys()}
            session['next_view'] = {k: v for (k, v) in views.iteritems() if v}
            return self.next_view()
        else:
            flash(lazy_gettext("Selecione pelo menos uma opção."))
            return redirect(url_for(
                "serviceview"))  # TODO: should we call render_template again?