コード例 #1
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
コード例 #2
0
ファイル: api.py プロジェクト: umair-gujjar/ihatemoney
 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
コード例 #3
0
ファイル: api.py プロジェクト: rscoates/ihatemoney
 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
コード例 #4
0
ファイル: api.py プロジェクト: aavenel/ihatemoney
 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
コード例 #5
0
ファイル: web.py プロジェクト: cjglover14/ihatemoney-1
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)
コード例 #6
0
ファイル: web.py プロジェクト: Pmtague/ihatemoney
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)
コード例 #7
0
ファイル: web.py プロジェクト: Glandos/ihatemoney
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)
コード例 #8
0
def home():
    project_form = ProjectForm()
    auth_form = AuthenticationForm()
    is_demo_project_activated = current_app.config['ACTIVATE_DEMO_PROJECT']
    is_public_project_creation_allowed = current_app.config['ALLOW_PUBLIC_PROJECT_CREATION']

    return render_template("home.html", project_form=project_form,
                           is_demo_project_activated=is_demo_project_activated,
                           is_public_project_creation_allowed=is_public_project_creation_allowed,
                           auth_form=auth_form, session=session)