mirror of
https://github.com/OpenBankProject/API-Manager.git
synced 2026-02-06 16:46:57 +00:00
Added pagination for the users list page
No longer load all users with "/users/all" to filter usernames and email Load the all entitlements with the "/entitlements" api instead of traversing all the users Set default value for the call limits inputs
This commit is contained in:
parent
53f84db2a9
commit
8220547ecd
@ -19,6 +19,7 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
|
||||
@ -29,6 +30,7 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
per_day_call_limit = forms.IntegerField(
|
||||
@ -38,6 +40,7 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
per_week_call_limit = forms.IntegerField(
|
||||
@ -47,6 +50,7 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
|
||||
@ -57,5 +61,6 @@ class ApiConsumersForm(forms.Form):
|
||||
'class': 'form-control',
|
||||
}
|
||||
),
|
||||
initial=-1,
|
||||
required=False,
|
||||
)
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
<form class="form-inline" method="get">
|
||||
<div class="form-group">
|
||||
<label for="offset">Offset:</label>
|
||||
<input type="number" class="form-control" name="offset" id="offset" placeholder="0" value="{{ offset }}">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="limit">Limit:</label>
|
||||
<input type="number" class="form-control" name="limit" id="limit" placeholder="50" value="{{ limit }}">
|
||||
</div>
|
||||
<button type="submit" class="btn btn-default">Get user list</button>
|
||||
</form>
|
||||
@ -28,6 +28,15 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
|
||||
<h2>Pagination</h2>
|
||||
{% include "users/includes/filter_pagination.html" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Statistics</h2>
|
||||
<ul id="statistics">
|
||||
<li>Total number of users: {{ statistics.users_num }}
|
||||
|
||||
@ -49,20 +49,19 @@ class IndexView(LoginRequiredMixin, TemplateView):
|
||||
template_name = "users/index.html"
|
||||
|
||||
def get_users_rolenames(self, context):
|
||||
users = []
|
||||
|
||||
api = API(self.request.session.get('obp'))
|
||||
try:
|
||||
urlpath = '/users'
|
||||
users = api.get(urlpath)
|
||||
urlpath = '/entitlements'
|
||||
entitlements = api.get(urlpath)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return [], []
|
||||
|
||||
role_names = []
|
||||
try:
|
||||
for user in users['users']:
|
||||
for entitlement in user['entitlements']['list']:
|
||||
role_names.append(entitlement['role_name'])
|
||||
for entitlement in entitlements['list']:
|
||||
role_names.append(entitlement['role_name'])
|
||||
# fail gracefully in case API provides new structure
|
||||
except KeyError as err:
|
||||
messages.error(self.request, 'KeyError: {}'.format(err))
|
||||
@ -70,23 +69,42 @@ class IndexView(LoginRequiredMixin, TemplateView):
|
||||
|
||||
role_names = list(set(role_names))
|
||||
role_names.sort()
|
||||
users = FilterRoleName(context, self.request.GET)\
|
||||
.apply(users['users'])
|
||||
users = FilterEmail(context, self.request.GET)\
|
||||
.apply(users)
|
||||
users = FilterUsername(context, self.request.GET)\
|
||||
.apply(users)
|
||||
return users, role_names
|
||||
|
||||
return role_names
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(IndexView, self).get_context_data(**kwargs)
|
||||
users, role_names = self.get_users_rolenames(context)
|
||||
|
||||
api = API(self.request.session.get('obp'))
|
||||
limit = self.request.GET.get('limit', 50)
|
||||
offset = self.request.GET.get('offset', 0)
|
||||
email = self.request.GET.get('email')
|
||||
username = self.request.GET.get('username')
|
||||
|
||||
if email:
|
||||
urlpath = '/users/email/{}/terminator'.format(email)
|
||||
elif username:
|
||||
urlpath = '/users/username/{}'.format(username)
|
||||
else:
|
||||
urlpath = '/users?limit={}&offset={}'.format(limit, offset)
|
||||
|
||||
try:
|
||||
users = api.get(urlpath)
|
||||
except APIError as err:
|
||||
messages.error(self.request, err)
|
||||
return [], []
|
||||
|
||||
role_names = self.get_users_rolenames(context)
|
||||
users = FilterRoleName(context, self.request.GET) \
|
||||
.apply([users] if username else users['users'])
|
||||
context.update({
|
||||
'role_names': role_names,
|
||||
'statistics': {
|
||||
'users_num': len(users),
|
||||
},
|
||||
'users': users,
|
||||
'limit': limit,
|
||||
'offset': offset
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
@ -8,5 +8,4 @@ gunicorn==19.6.0
|
||||
matplotlib
|
||||
django-bootstrap-datepicker-plus
|
||||
django-mathfilters
|
||||
django-bootstrap3
|
||||
django-bootstrap-datepicker-plus
|
||||
django-bootstrap3
|
||||
Loading…
Reference in New Issue
Block a user