Example #1
0
def upload(resolution_id):
    resolution_row = database.get_or_404('resolution', resolution_id)
    resolution_schema = schema.ResolutionSchema.from_flat(resolution_row)
    session = database.get_session()

    doc = flask.request.files["file"]
    lang = flask.request.form.get('lang')

    if lang not in ('E', 'F', 'S'):
        flask.abort(400)

    db_file = session.get_db_file()

    if doc.filename:
        resolution_schema['filename'][lang].set(doc.filename)
        resolution_schema['doc_id'][lang].set(db_file.id)

        if resolution_schema.validate():
            db_file.save_from(doc)
            resolution_row.update(resolution_schema.flatten())
            session.save(resolution_row)
            session.commit()
            flask.flash('Document saved', 'success')

    return flask.redirect(
        flask.url_for('resolution.view', resolution_id=resolution_id))
Example #2
0
def change_password(token=None):
    if not token and not flask.session.get("logged_in_email"):
        return flask.redirect("/login")

    if flask.request.method == "POST":
        form_data = flask.request.form.to_dict()

        new_pass = form_data["new_pass"]
        check_pass = form_data["check_pass"]

        if token:
            staff_member = database.find("staff", token=token)
            staff_member = staff_member.next()

        else:
            old_pass = form_data["old_pass"]

            email = flask.session["logged_in_email"]
            staff_member = database.find("staff", email=email)
            staff_member = staff_member.next()

            try:
                assert sugar.check_hash(old_pass, staff_member["password"])
            except AssertionError:
                flask.flash("Wrong password.", "error")
                return

        try:
            assert sugar.check_hash(new_pass, sugar.make_hash(check_pass))
        except AssertionError:
            flask.flash("New passwords do not match.", "error")
            return {"token": token}

        try:
            assert new_pass != u""
        except AssertionError:
            flask.flash("Please enter a new password.", "error")
        else:
            session = database.get_session()

            staff_row = database.get_or_404("staff", id=staff_member.id)
            staff_schema = StaffSchema.from_flat(staff_row)

            staff_schema["password"].set(sugar.make_hash(new_pass))

            if staff_schema.validate():
                staff_row.update(staff_schema.flatten())
                session.save(staff_row)
                session.commit()

                flask.flash("Password changed sucessfuly.", "success")

                if token:
                    login_url = flask.url_for("auth.login", next=flask.url_for("meeting.home"))
                    return flask.redirect(login_url)

    return {"token": token}
Example #3
0
def reset_password():
    email_to_reset_password = flask.request.form.get("email", "")

    if flask.request.method == "POST":
        try:
            staff_member = [i for i in database.find("staff", email=email_to_reset_password)]
            assert len(staff_member) == 1
            staff_member = staff_member[0]
        except AssertionError:
            flask.flash(u"Your email does not exist in our database.", "error")
        else:
            auth_token = sugar.generate_token(email_to_reset_password)

            session = database.get_session()

            staff_row = database.get_or_404("staff", id=staff_member.id)
            staff_schema = StaffSchema.from_flat(staff_row)

            staff_schema["token"].set(auth_token)

            if staff_schema.validate():
                staff_row.update(staff_schema.flatten())
                session.save(staff_row)
                session.commit()

            app = flask.current_app
            mail = Mail(app)

            settings_url = app.config.get("HOSTNAME")
            mail_msg_link = "%s/%s/change-password" % (settings_url, auth_token)

            msg_subject = "Reset your Cites password"
            msg_sender = app.config.get("DEFAULT_MAIL_SENDER")
            msg_recipients = [email_to_reset_password]
            msg_body = str(
                "Forgot your password?\n\nCites received a request "
                "to reset the password for your account.\n"
                "If you want to reset your "
                "password, click on the link below (or copy and "
                "paste the URL into your browser):\n\n%s\n\nThis "
                "link takes you to a secure page where you can "
                "change your password.\nIf you don't want to "
                "reset your password, please ignore this "
                "message. Your password will not be reset."
                "\n\nThe Cites Team" % (mail_msg_link)
            )

            msg = Message(msg_subject, sender=msg_sender, recipients=msg_recipients, body=msg_body)

            mail.send(msg)

            flash_message = str(
                "We've sent password reset instructions to your "
                "email address. Please also check your email's "
                "spam filter."
            )
            flask.flash(flash_message, "success")
Example #4
0
def delete_document(resolution_id, doc_id, lang):
    resolution_row = database.get_or_404('resolution', resolution_id)
    resolution_row['doc_id_%s' % lang] = ''
    resolution_row['filename_%s' % lang] = ''

    session = database.get_session()
    session.del_db_file(doc_id)
    session.save(resolution_row)
    session.commit()
    return flask.jsonify({'status': 'success'})
Example #5
0
def edit(resolution_id=None):
    if resolution_id is None:
        resolution_row = None
    else:
        resolution_row = database.get_or_404('resolution', resolution_id)

    meetings = [schema.Meeting.from_flat(m) for m in database.get_all('meeting')]
    session = database.get_session()

    if flask.request.method == "POST":
        form_data = dict(schema.ResolutionSchema.from_defaults().flatten())
        form_data.update(flask.request.form.to_dict())

        resolution_schema = schema.ResolutionSchema()
        resolution_schema.set_meetings(meetings)
        resolution_schema.set_flat(form_data)

        if resolution_schema.validate():
            if resolution_row is None:
                resolution_row = database.new('resolution')
            resolution_row.update(resolution_schema.flatten())
            session.save(resolution_row)
            session.commit()
            flask.flash('Resolution saved', 'success')
            if resolution_id:
                url = flask.url_for('resolution.view',
                                    resolution_id=resolution_id)
            else:
                url = flask.url_for('resolution.home')
            return flask.redirect(url)
        else:
            flask.flash(u"Errors in person information", "error")
    else:
        resolution_schema = schema.ResolutionSchema()
        resolution_schema.set_meetings(meetings)

        if resolution_row:
            resolution_schema.set_flat(resolution_row)
        else:
            resolution_schema = resolution_schema.from_defaults()
            resolution_schema.set_meetings(meetings)

    return {
        'mk': sugar.MarkupGenerator(
            flask.current_app.jinja_env.get_template('widgets/widgets_edit.html')
        ),
        'resolution_id': resolution_id,
        'resolution_schema': resolution_schema,
    }
Example #6
0
def delete(resolution_id):
    resolution_row = database.get_or_404('resolution', resolution_id)
    session = database.get_session()

    if resolution_row['doc_id_E']:
        session.del_db_file(int(resolution_row['doc_id_E']))

    if resolution_row['doc_id_F']:
        session.del_db_file(int(resolution_row['doc_id_F']))

    if resolution_row['doc_id_S']:
        session.del_db_file(int(resolution_row['doc_id_S']))

    session['resolution'].delete(resolution_id)
    session.commit()
    return flask.jsonify({'status': 'success'})
Example #7
0
def view(resolution_id):
    resolution_row = database.get_or_404('resolution', resolution_id)
    meetings = [schema.Meeting.from_flat(m) for m in database.get_all('meeting')]

    resolution_schema = schema.ResolutionSchema()
    resolution_schema.set_meetings(meetings)
    resolution_schema.set_flat(resolution_row)
    resolution = resolution_schema.value

    return {
        'mk': sugar.MarkupGenerator(
            flask.current_app.jinja_env.get_template("widgets/widgets_view.html")
        ),
        'resolution_schema': resolution_schema,
        'resolution_id': resolution_id,
        'resolution': resolution,
    }
Example #8
0
def insert_category(meeting_id, file_name):
    import os
    import json
    from cites.schema import MeetingSchema

    meeting_row = database.get_or_404("meeting", id=str(meeting_id))
    meeting_schema = MeetingSchema.from_flat(meeting_row)
    member_schema = meeting_schema["categories"].member_schema
    data = json.load(open(os.path.join(os.path.dirname(__file__), file_name), "rb"))
    new_category_schema = member_schema(data)
    if new_category_schema.validate():
        meeting_schema["categories"].insert(0, new_category_schema)

    if meeting_schema.validate():
        session = database.get_session()
        meeting_row.update(meeting_schema.flatten())
        session.save(meeting_row)
        session.commit()
Example #9
0
def edit(country_id=None):
    app = flask.current_app
    session = database.get_session()
    if country_id:
        country_row = database.get_or_404("country", country_id)
        country = Country.from_flat(country_row)
    else:
        country_row = database.new("country")
        country = None

    if flask.request.method == "POST":
        form_data = dict(CountrySchema.from_defaults().flatten())
        form_data.update(flask.request.form.to_dict())

        country_schema = CountrySchema.from_flat(form_data)

        if country_schema.validate():
            if country_row is None:
                country_row = database.new('country')
            country_row.update(country_schema.flatten())
            session.save(country_row)
            session.commit()
            flask.flash('Country saved.', 'success')
            view_url = flask.url_for("country.home")
            return flask.redirect(view_url)
        else:
            flask.flash(u"Errors in country information", "error")
    else:
        if country_row is None:
            country_schema = CountrySchema()
        else:
            country_schema = CountrySchema.from_flat(country_row)

    return {
        "mk": sugar.MarkupGenerator(
            app.jinja_env.get_template("widgets/widgets_edit.html")
        ),
        "country_schema": country_schema,
        "country": country,
    }
Example #10
0
 def get_or_404(cls, country_id):
     return cls.from_flat(database.get_or_404("country", country_id))
Example #11
0
 def get_or_404(cls, meeting_id):
     return cls.from_flat(database.get_or_404("meeting", meeting_id))
Example #12
0
 def get_or_404(cls, mail_log_id):
     return cls.from_flat(database.get_or_404("mail_log", mail_log_id))
Example #13
0
 def get_or_404(cls, resolution_id):
     return cls.from_flat(database.get_or_404('resolution', resolution_id))
Example #14
0
 def has_photo(self):
     assert self.id is not None
     person_row = database.get_or_404("person", self.id)
     return bool(person_row.get("photo", ""))
Example #15
0
 def get_or_404(cls, person_id):
     return cls.from_flat(database.get_or_404("person", person_id))
Example #16
0
 def get_or_404(cls, link_id):
     return cls.from_flat(database.get_or_404("link", link_id))
Example #17
0
 def get_or_404(cls, staff_id):
     return cls.from_flat(database.get_or_404("staff", staff_id))
Example #18
0
 def get_or_404(cls, document_id):
     return cls.from_flat(database.get_or_404("document", document_id))
Example #19
0
 def has_photo(self):
     assert self.id is not None
     staff_row = database.get_or_404("staff", self.id)
     return bool(staff_row.get("photo", ""))