Example #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
Example #2
0
 def post(self):
     form = ProjectForm(meta={"csrf": False})
     if form.validate() and current_app.config.get("ALLOW_PUBLIC_PROJECT_CREATION"):
         project = form.save()
         db.session.add(project)
         db.session.commit()
         return project.id, 201
     return form.errors, 400
Example #3
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
Example #4
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
Example #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)
Example #6
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])
            success = send_email(msg)
            if success:
                flash(_("A reminder email has just been sent to you"),
                      category="success")
            else:
                # Display the error as a simple "info" alert, because it's
                # not critical and doesn't prevent using the project.
                flash(
                    _("We tried to send you an reminder email, but there was an error. "
                      "You can still use the project normally."),
                    category="info",
                )
            # 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)
Example #7
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)