Ejemplo n.º 1
0
    def __init__(self):
        super(SearchRequestsForm, self).__init__()
        self.agency_ein.choices = get_agency_choices()
        self.agency_ein.choices.insert(0, ('', 'All'))
        if current_user.is_agency:
            self.agency_ein.default = current_user.default_agency_ein
            user_agencies = sorted([(agencies.ein, agencies.name) for agencies in current_user.agencies
                                    if agencies.ein != current_user.default_agency_ein],
                                   key=lambda x: x[1])
            default_agency = current_user.default_agency

            # set default value of agency select field to agency user's primary agency
            self.agency_ein.default = default_agency.ein
            self.agency_ein.choices.insert(1, self.agency_ein.choices.pop(self.agency_ein.choices.index(
                (default_agency.ein, default_agency.name))
            ))

            # set secondary agencies to be below the primary
            for agency in user_agencies:
                self.agency_ein.choices.insert(2, self.agency_ein.choices.pop(self.agency_ein.choices.index(agency)))

            # get choices for agency user select field
            if current_user.is_agency_admin():
                self.agency_user.choices = get_active_users_as_choices(current_user.default_agency.ein)

            if current_user.is_agency_active() and not current_user.is_agency_admin():
                self.agency_user.choices = [
                    ('', 'All'),
                    (current_user.get_id(), 'My Requests')
                ]
                self.agency_user.default = current_user.get_id()

            # process form for default values
            self.process()
Ejemplo n.º 2
0
    def __init__(self):
        super(SearchRequestsForm, self).__init__()
        self.agency_ein.choices = get_agency_choices()
        self.agency_ein.choices.insert(0, ("", "All"))
        if current_user.is_agency:
            self.agency_ein.default = current_user.default_agency_ein
            user_agencies = sorted(
                [(agencies.ein, agencies.name)
                 for agencies in current_user.agencies
                 if agencies.ein != current_user.default_agency_ein],
                key=lambda x: x[1],
            )
            default_agency = current_user.default_agency

            # set default value of agency select field to agency user's primary agency
            self.agency_ein.default = default_agency.ein
            self.agency_ein.choices.insert(
                1,
                self.agency_ein.choices.pop(
                    self.agency_ein.choices.index(
                        (default_agency.ein, default_agency.name))),
            )

            # set secondary agencies to be below the primary
            for agency in user_agencies:
                self.agency_ein.choices.insert(
                    2,
                    self.agency_ein.choices.pop(
                        self.agency_ein.choices.index(agency)),
                )

            # get choices for agency user select field
            if current_user.is_agency_admin():
                self.agency_user.choices = get_active_users_as_choices(
                    current_user.default_agency.ein)

            if current_user.is_agency_active(
            ) and not current_user.is_agency_admin():
                self.agency_user.choices = [
                    ("", "All"),
                    (current_user.get_id(), "My Requests"),
                ]
                self.agency_user.default = current_user.get_id()

            if default_agency.agency_features["custom_request_forms"][
                    "enabled"]:
                self.request_type.choices = [
                    (custom_request_form.form_name,
                     custom_request_form.form_name)
                    for custom_request_form in CustomRequestForms.query.
                    filter_by(agency_ein=default_agency.ein).order_by(
                        asc(CustomRequestForms.category),
                        asc(CustomRequestForms.id)).all()
                ]
                self.request_type.choices.insert(0, ("", "All"))

            # process form for default values
            self.process()
Ejemplo n.º 3
0
    def __init__(self):
        super(SearchRequestsForm, self).__init__()
        self.agency_ein.choices = get_agency_choices()
        self.agency_ein.choices.insert(0, ("", "All"))
        if current_user.is_agency:
            self.agency_ein.default = current_user.default_agency_ein
            user_agencies = sorted(
                [(agencies.ein, agencies.name)
                 for agencies in current_user.agencies
                 if agencies.ein != current_user.default_agency_ein],
                key=lambda x: x[1],
            )
            default_agency = current_user.default_agency

            # set default value of agency select field to agency user's primary agency
            self.agency_ein.default = default_agency.ein
            self.agency_ein.choices.insert(
                1,
                self.agency_ein.choices.pop(
                    self.agency_ein.choices.index(
                        (default_agency.ein, default_agency.name))),
            )

            # set secondary agencies to be below the primary
            for agency in user_agencies:
                self.agency_ein.choices.insert(
                    2,
                    self.agency_ein.choices.pop(
                        self.agency_ein.choices.index(agency)),
                )

            # get choices for agency user select field
            if current_user.is_agency_admin():
                self.agency_user.choices = get_active_users_as_choices(
                    current_user.default_agency.ein)

            if current_user.is_agency_active(
            ) and not current_user.is_agency_admin():
                self.agency_user.choices = [
                    ("", "All"),
                    (current_user.get_id(), "My Requests"),
                ]
                self.agency_user.default = current_user.get_id()

            # process form for default values
            self.process()
Ejemplo n.º 4
0
def get_active_users(agency_ein):
    """
    Retrieve the active users for the specified agency.

    :param agency_ein: Agency EIN (String)

    :return: JSON Object({"active_users": [('', 'All'), ('o8pj0k', 'John Doe')],
                          "is_admin": True}), 200
    """
    if current_user.is_agency_admin(agency_ein):
        return jsonify({"active_users": get_active_users_as_choices(agency_ein), "is_admin": True}), 200

    elif current_user.is_agency_active(agency_ein):
        active_users = [
            ('', 'All'),
            (current_user.get_id(), 'My Requests')
        ]
        return jsonify({"active_users": active_users, "is_admin": False}), 200

    else:
        return jsonify({}), 404
Ejemplo n.º 5
0
def get_active_users(agency_ein):
    """
    Retrieve the active users for the specified agency.

    :param agency_ein: Agency EIN (String)

    :return: JSON Object({"active_users": [('', 'All'), ('o8pj0k', 'John Doe')],
                          "is_admin": True}), 200
    """
    if current_user.is_agency_admin(agency_ein):
        return jsonify({"active_users": get_active_users_as_choices(agency_ein), "is_admin": True}), 200

    elif current_user.is_agency_active(agency_ein):
        active_users = [
            ('', 'All'),
            (current_user.get_id(), 'My Requests')
        ]
        return jsonify({"active_users": active_users, "is_admin": False}), 200

    else:
        return jsonify({}), 404