From 2bf39216ec52a806598279a9eb937accadeb08dc Mon Sep 17 00:00:00 2001 From: lombardofr Date: Wed, 18 Jul 2018 17:02:16 +0200 Subject: [PATCH] ui fix Change-Id: I73d09df0e5851c08dc5eb2a588446d4c3eac8573 Signed-off-by: lombardofr --- lib/osm/osmclient/clientv2.py | 20 +++++++ .../template/project/modal/project_edit.html | 32 +++++++++++ .../{new_project.html => project_new.html} | 0 .../template/project/projectlist.html | 30 ++++++++--- projecthandler/urls/project.py | 5 +- projecthandler/views.py | 21 +++++++- userhandler/templates/modal/user_edit.html | 53 +++++++++++++++++++ userhandler/templates/user_list.html | 18 +++++-- 8 files changed, 164 insertions(+), 15 deletions(-) create mode 100644 projecthandler/template/project/modal/project_edit.html rename projecthandler/template/project/modal/{new_project.html => project_new.html} (100%) create mode 100644 userhandler/templates/modal/user_edit.html diff --git a/lib/osm/osmclient/clientv2.py b/lib/osm/osmclient/clientv2.py index 5e4f390..47c8e67 100644 --- a/lib/osm/osmclient/clientv2.py +++ b/lib/osm/osmclient/clientv2.py @@ -180,6 +180,26 @@ class Client(object): result['data'] = Util.json_loads_byteified(r.text) return result + def project_edit(self, token, id, project_data): + + result = {'error': True, 'data': ''} + headers = {"Content-Type": "application/json", "accept": "application/json", + 'Authorization': 'Bearer {}'.format(token['id'])} + + _url = "{0}/admin/v1/projects/{1}".format(self._base_path, id) + + try: + r = requests.put(_url, json=project_data, verify=False, headers=headers) + except Exception as e: + log.exception(e) + result['data'] = str(e) + return result + print r.status_code + if r.status_code == requests.codes.no_content: + result['error'] = False + result['data'] = Util.json_loads_byteified(r.text) + return result + def project_delete(self, token, id): result = {'error': True, 'data': ''} headers = {"Content-Type": "application/yaml", "accept": "application/json", diff --git a/projecthandler/template/project/modal/project_edit.html b/projecthandler/template/project/modal/project_edit.html new file mode 100644 index 0000000..27a9ee6 --- /dev/null +++ b/projecthandler/template/project/modal/project_edit.html @@ -0,0 +1,32 @@ + \ No newline at end of file diff --git a/projecthandler/template/project/modal/new_project.html b/projecthandler/template/project/modal/project_new.html similarity index 100% rename from projecthandler/template/project/modal/new_project.html rename to projecthandler/template/project/modal/project_new.html diff --git a/projecthandler/template/project/projectlist.html b/projecthandler/template/project/projectlist.html index 85abb59..ed8b583 100644 --- a/projecthandler/template/project/projectlist.html +++ b/projecthandler/template/project/projectlist.html @@ -47,9 +47,7 @@ Modification Date Creation Date - - - + Actions @@ -63,8 +61,22 @@ {{ p|get_sub:"_admin,modified"|get_date}} {{ p|get_sub:"_admin,created"|get_date}} - Delete - + +
+ + +
+ {% endfor %} @@ -74,7 +86,8 @@ -{% include "modal/new_project.html" %} +{% include "modal/project_new.html" %} +{% include "modal/project_edit.html" %} {% endblock %} {% block resource_block %} @@ -84,6 +97,11 @@ $('#modal_new_project').modal('show'); } + function editProject(url){ + $("#formEditProject").attr("action", url); + $('#modal_edit_project').modal('show'); + } + function deleteProject(url) { bootbox.confirm("Are you sure want to delete?", function (result) { if (result) { diff --git a/projecthandler/urls/project.py b/projecthandler/urls/project.py index e0395c8..9d653b6 100644 --- a/projecthandler/urls/project.py +++ b/projecthandler/urls/project.py @@ -21,8 +21,9 @@ urlpatterns = [ url(r'^$', views.open_project, name='open_project'), url(r'^list/', views.user_projects, name='projects_list'), url(r'^new/', views.create_new_project, name='new_project'), - url(r'^delete$', views.delete_project, name='delete_project'), - url(r'^switch/(?P\w+)', views.switch_project, name='switch_project'), + url(r'^(?P\w+)/delete$', views.delete_project, name='delete_project'), + url(r'^(?P\w+)/switch', views.switch_project, name='switch_project'), + url(r'^(?P\w+)/edit', views.edit_project, name='edit_project'), url(r'^descriptors/(?P\w+)/list$', views.show_descriptors, name='list_descriptors'), url(r'^descriptors/(?P\w+)/(?P[-\w]+)(/$)', views.edit_descriptor, name='edit_descriptor'), diff --git a/projecthandler/views.py b/projecthandler/views.py index 0f0cf6c..0f4248a 100644 --- a/projecthandler/views.py +++ b/projecthandler/views.py @@ -281,9 +281,9 @@ def open_project(request): @login_required -def delete_project(request): +def delete_project(request, project_id): user = osmutils.get_user(request) - project_id = user.project_id + client = Client() result = client.project_delete(user.get_token(), project_id) if isinstance(result, dict) and 'error' in result and result['error']: @@ -301,6 +301,23 @@ def switch_project(request, project_id): return redirect('projects:open_project') +@login_required +def edit_project(request, project_id): + if request.method == 'POST': + user = osmutils.get_user(request) + client = Client() + project_dict = request.POST.dict() + keys = ["name"] + project_data = dict(filter(lambda i: i[0] in keys and len(i[1]) > 0, project_dict.items())) + result = client.project_edit(user.get_token(), project_id, project_data) + if isinstance(result, dict) and 'error' in result and result['error']: + print result + return __response_handler(request, result['data'], url=None, + status=result['data']['status'] if 'status' in result['data'] else 500) + else: + return __response_handler(request, {}, url=None, status=200) + + @login_required def show_descriptors(request, descriptor_type=None): user = osmutils.get_user(request) diff --git a/userhandler/templates/modal/user_edit.html b/userhandler/templates/modal/user_edit.html new file mode 100644 index 0000000..b278e22 --- /dev/null +++ b/userhandler/templates/modal/user_edit.html @@ -0,0 +1,53 @@ + diff --git a/userhandler/templates/user_list.html b/userhandler/templates/user_list.html index 03ae70f..f8fa6ac 100644 --- a/userhandler/templates/user_list.html +++ b/userhandler/templates/user_list.html @@ -65,12 +65,20 @@ {{ s|get_sub:"_admin,created"|get_date}} -
- -
+
+ + +
-- 2.25.1