Beispiel #1
0
 def post(self):
     form = ProjectForm(meta={'csrf': False})
     if form.validate():
         project = form.save()
         db.session.add(project)
         db.session.commit()
         return project.id, 201
     return form.errors, 400
Beispiel #2
0
 def add(self):
     form = ProjectForm(meta={'csrf': False})
     if form.validate():
         project = form.save()
         db.session.add(project)
         db.session.commit()
         return 201, project.id
     return 400, form.errors
Beispiel #3
0
def create_project():
    form = ProjectForm()
    if request.method == "GET" and 'project_id' in request.values:
        form.name.data = request.values['project_id']

    if request.method == "POST":
        # At first, we don't want the user to bother with the identifier
        # so it will automatically be missing because not displayed into
        # the form
        # Thus we fill it with the same value as the filled name,
        # the validation will take care of the slug
        if not form.id.data:
            form.id.data = form.name.data
        if form.validate():
            # save the object in the db
            project = form.save()
            db.session.add(project)
            db.session.commit()

            # create the session object (authenticate)
            session[project.id] = True
            session.update()

            # send reminder email
            g.project = project

            message_title = _(
                "You have just created '%(project)s' "
                "to share your expenses",
                project=g.project.name)

            message_body = render_template("reminder_mail.%s.j2" %
                                           get_locale().language)

            msg = Message(message_title,
                          body=message_body,
                          recipients=[project.contact_email])
            try:
                current_app.mail.send(msg)
            except SMTPRecipientsRefused:
                msg_compl = 'Problem sending mail. '
                # TODO: destroy the project and cancel instead?
            else:
                msg_compl = ''

            # redirect the user to the next step (invite)
            flash(
                _("%(msg_compl)sThe project identifier is %(project)s",
                  msg_compl=msg_compl,
                  project=project.id))
            return redirect(url_for(".list_bills", project_id=project.id))

    return render_template("create_project.html", form=form)
Beispiel #4
0
def create_project():
    form = ProjectForm()
    if request.method == "GET" and "project_id" in request.values:
        form.name.data = request.values["project_id"]

    if request.method == "POST":
        # At first, we don't want the user to bother with the identifier
        # so it will automatically be missing because not displayed into
        # the form
        # Thus we fill it with the same value as the filled name,
        # the validation will take care of the slug
        if not form.id.data:
            form.id.data = form.name.data
        if form.validate():
            # save the object in the db
            project = form.save()
            db.session.add(project)
            db.session.commit()

            # create the session object (authenticate)
            session[project.id] = True
            session.update()

            # send reminder email
            g.project = project

            message_title = _(
                "You have just created '%(project)s' "
                "to share your expenses",
                project=g.project.name,
            )

            message_body = render_localized_template("reminder_mail")

            msg = Message(message_title,
                          body=message_body,
                          recipients=[project.contact_email])
            try:
                current_app.mail.send(msg)
            except SMTPRecipientsRefused:
                flash(_("Error while sending reminder email"),
                      category="danger")

            # redirect the user to the next step (invite)
            flash(
                _("The project identifier is %(project)s", project=project.id))
            return redirect(url_for(".list_bills", project_id=project.id))

    return render_template("create_project.html", form=form)
Beispiel #5
0
def create_project():
    form = ProjectForm()
    if request.method == "GET" and 'project_id' in request.values:
        form.name.data = request.values['project_id']

    if request.method == "POST":
        # At first, we don't want the user to bother with the identifier
        # so it will automatically be missing because not displayed into
        # the form
        # Thus we fill it with the same value as the filled name,
        # the validation will take care of the slug
        if not form.id.data:
            form.id.data = form.name.data
        if form.validate():
            # save the object in the db
            project = form.save()
            db.session.add(project)
            db.session.commit()

            # create the session object (authenticate)
            session[project.id] = True
            session.update()

            # send reminder email
            g.project = project

            message_title = _("You have just created '%(project)s' "
                              "to share your expenses", project=g.project.name)

            message_body = render_template("reminder_mail.%s.j2" %
                                           get_locale().language)

            msg = Message(message_title,
                          body=message_body,
                          recipients=[project.contact_email])
            try:
                current_app.mail.send(msg)
            except SMTPRecipientsRefused:
                msg_compl = 'Problem sending mail. '
                # TODO: destroy the project and cancel instead?
            else:
                msg_compl = ''

            # redirect the user to the next step (invite)
            flash(_("%(msg_compl)sThe project identifier is %(project)s",
                    msg_compl=msg_compl, project=project.id))
            return redirect(url_for(".list_bills", project_id=project.id))

    return render_template("create_project.html", form=form)