コード例 #1
0
def activity_new():
    if request.method == "GET":

        today = datetime.datetime.now().date().isoformat()
        return render_template("activity_edit.html",
                    # Specify some defaults
                    activity = {
                        "flow_type": "10",
                        "aid_type": "C01",
                        "collaboration_type": "1",
                        "finance_type": "110",
                        "tied_status": "5",
                        "start_date": today,
                        "end_date": today,
                        "recipient_country_code": current_user.recipient_country_code,
                    },
                    loggedinuser=current_user,
                    codelists = codelists.get_codelists(),
                    users = quser.user()
                              )

    elif request.method == "POST":
        # Create new activity
        data = request.form.to_dict()
        data["user_id"] = current_user.id
        a = qactivity.create_activity(data)
        if a:
            flash("Successfully added your activity", "success")
        else:
            flash("An error occurred and your activity couldn't be added", "danger")
        return redirect(url_for('activity_edit', activity_id=a.id))
コード例 #2
0
ファイル: users.py プロジェクト: markbrough/maedi-projects
def users_edit(user_id):
    if request.method=="GET":
        user = quser.user(user_id)
        return render_template("user.html",
                 user = user,
                 loggedinuser=current_user,
                 codelists = codelists.get_codelists())
    elif request.method == "POST":
        data = request.form.to_dict()
        data["id"] = user_id
        if quser.updateUser(data):
            flash(gettext(u"Successfully updated user!"), "success")
        else:
            flash(gettext(u"Sorry, couldn't update that user!"), "danger")
        return redirect(url_for("users"))
コード例 #3
0
def activity_edit(activity_id):
    activity = qactivity.get_activity(activity_id)
    locations = qlocation.get_locations_country(
                                    activity.recipient_country_code)
    return render_template("activity_edit.html",
                activity = activity,
                loggedinuser=current_user,
                codelists = codelists.get_codelists(),
                locations = locations,
                api_locations_url ="/api/locations/%s/" % activity.recipient_country_code,
                api_activity_locations_url = "/api/activity_locations/%s/" % activity_id,
                api_activity_finances_url = "/api/activity_finances/%s/" % activity_id,
                api_update_activity_finances_url = "/api/activity_finances/%s/update_finances/" % activity_id,
                users = quser.user()
          )
コード例 #4
0
def load_user(id):
    return quser.user(id)
コード例 #5
0
def user_permissions_edit(user_id):
    def _append_organisation(uo, organisations):
        uo["organisations"] = dict(
            map(lambda o: (o.id, o.as_dict()), organisations))
        if uo["organisations"].get(uo["organisation_id"]):
            uo["organisations"].get(
                uo["organisation_id"])["selected"] = " selected"
        uo["organisations"] = list(uo["organisations"].values())
        select_options = {True: " selected", False: ""}
        uo["permission_values"] = [{
            "name":
            "View projects",
            "value":
            "view",
            "selected":
            select_options[bool(uo["permission_value"] == "view")]
        }, {
            "name":
            "Edit projects",
            "value":
            "edit",
            "selected":
            select_options[bool(uo["permission_value"] == "edit")]
        }]
        return uo

    if not current_user.administrator:
        flash("You must be an administrator to edit users.", "danger")
        return redirect(url_for("activities.dashboard"))
    if request.method == "GET":
        user = quser.user(user_id)
        user_organisations = list(
            map(
                lambda uo: (_append_organisation(
                    uo.as_dict(), qorganisations.get_organisations())),
                user.organisations))
        return jsonify(permissions=user_organisations)
    elif request.method == "POST":
        data = request.form.to_dict()
        data["user_id"] = user_id
        if data["action"] == "add":
            op = quser.addOrganisationPermission(data)
            if not op: return "False"
            return jsonify({
                "id":
                op.id,
                "organisations":
                list(
                    map(lambda o: o.as_dict(),
                        qorganisations.get_organisations())),
                "permission_values": [{
                    "selected": " selected",
                    "name": "View projects",
                    "value": "view"
                }, {
                    "selected": "",
                    "name": "Edit projects",
                    "value": "edit"
                }],
            })
        elif data["action"] == "delete":
            op = quser.deleteOrganisationPermission(data)
            if not op:
                return False
            return "ok"
        elif data["action"] == "edit":
            op = quser.updateOrganisationPermission(data)
            if not op:
                return False
            return "ok"
        return "error, unknown action"
コード例 #6
0
ファイル: users.py プロジェクト: markbrough/maedi-projects
def users():
    users = quser.user()
    return render_template("users.html",
             users = users,
             loggedinuser=current_user)
コード例 #7
0
ファイル: users.py プロジェクト: markbrough/maedi-projects
def load_user(id):
    return quser.user(id)
コード例 #8
0
ファイル: users.py プロジェクト: markbrough/maedi-projects
def users():
    users = quser.user()
    return render_template("users.html",
                           users=users,
                           loggedinuser=current_user)
コード例 #9
0
def activity_new():
    if request.method == "GET":
        today = datetime.datetime.now().date().isoformat()
        return render_template("activity_edit.html",
            # Specify some defaults
            activity = {
                "flow_type": "10",
                "aid_type": "C01",
                "collaboration_type": "1",
                "finance_type": "110",
                "activity_status": "2",
                "tied_status": "5",
                "start_date": today,
                "end_date": today,
                "recipient_country_code": current_user.recipient_country_code,
                "domestic_external": current_user.permissions_dict.get("domestic_external_edit"),
                "organisations": [ # Here we use the role as the ID so it gets submitted but this is a bad hack
                    {"role": 1, "id": 1, "organisation": { "id": ""}},
                    {"role": 4, "id": 4, "organisation": { "id": ""}}
                ],
                "classification_data": {
                    "mtef-sector": {
                        "name": "MTEF Sector",
                        "code": "mtef-sector",
                        "id": "mtef-sector",
                        "entries": [
                            {""}
                        ]
                    },
                    "aft-pillar": {
                        "name": "AfT Pillar",
                        "code": "aft-pillar",
                        "id": "aft-pillar",
                        "entries": [
                            {""}
                        ]
                    },
                    "aligned-ministry-agency": {
                        "name": "Aligned Ministry/Agency",
                        "code": "aligned-ministry-agency",
                        "id": "aligned-ministry-agency",
                        "entries": [
                            {""}
                        ]
                    },
                    "sdg-goals": {
                        "name": "SDG Goals",
                        "code": "sdg-goals",
                        "id": "sdg-goals",
                        "entries": [
                            {""}
                        ]
                    },
                    "papd-pillar": {
                        "name": "PAPD Pillar",
                        "code": "papd-pillar",
                        "id": "papd-pillar",
                        "entries": [
                            {""}
                        ]
                    }
                },
            },
            loggedinuser=current_user,
            organisations = qorganisations.get_organisations(),
            codelists = codelists.get_codelists(),
            users = quser.user()
            )

    elif request.method == "POST":
        # Create new activity
        data = request.form.to_dict()
        data["user_id"] = current_user.id
        a = qactivity.create_activity(data)
        if a:
            flash("Successfully added your activity", "success")
        else:
            flash("An error occurred and your activity couldn't be added", "danger")
        return redirect(url_for('activities.activity_edit', activity_id=a.id))