aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-02-06 14:21:17 +0300
committerFrederick Muriuki Muriithi2023-02-06 14:21:17 +0300
commitc236eded0a4316a7a3e61d4af9b745860d70e2d2 (patch)
treed043235b1787af2d094d30b403d6b62bd91fefeb
parent19fb26a1021bb5f213de109258a389559d1bc0e1 (diff)
downloadgenenetwork2-c236eded0a4316a7a3e61d4af9b745860d70e2d2.tar.gz
oauth2: resources: View resource. Handle creation error/success
* Handle the resource creation success or error in a better way than simply dropping the user to a plaintext/json results page. * Enable viewing a particular resource's details.
-rw-r--r--wqflask/wqflask/oauth2/resources.py18
-rw-r--r--wqflask/wqflask/templates/oauth2/resources.html4
-rw-r--r--wqflask/wqflask/templates/oauth2/view-resource.html47
3 files changed, 62 insertions, 7 deletions
diff --git a/wqflask/wqflask/oauth2/resources.py b/wqflask/wqflask/oauth2/resources.py
index 28a5a362..db23fc75 100644
--- a/wqflask/wqflask/oauth2/resources.py
+++ b/wqflask/wqflask/oauth2/resources.py
@@ -1,6 +1,6 @@
import uuid
-from flask import request, Blueprint, render_template
+from flask import flash, request, url_for, redirect, Blueprint, render_template
from .checks import require_oauth2
from .client import oauth2_get, oauth2_post
@@ -36,11 +36,13 @@ def create_resource():
from flask import jsonify
def __perr__(error):
- print(f"ERROR: {process_error(error)}")
- return jsonify(process_error(error))
+ err = process_error(error)
+ print(f"THE ERROR: {err}")
+ flash(f"{err['error']}: {err['error_message']}", "alert-danger")
+ return redirect(url_for("oauth2.resource.user_resources"))
def __psuc__(succ):
- print(f"SUCCESS: {succ.json()}")
- return jsonify(succ.json())
+ flash("Resource created successfully", "alert-success")
+ return redirect(url_for("oauth2.resource.user_resources"))
return oauth2_post(
"oauth2/resource/create", data=request.form).either(
__perr__, __psuc__)
@@ -52,7 +54,11 @@ def view_resource(resource_id: uuid.UUID):
# Display the resource's details
# Provide edit/delete options
# Metadata edit maybe?
- return "WOULD DISPLAY THE GIVEN RESOURCE'S DETAILS"
+ return oauth2_get(f"oauth2/resource/view/{resource_id}").either(
+ lambda err: render_template("oauth2/view-resource.html",
+ resource=None, error=process_error(err)),
+ lambda resource: render_template(
+ "oauth2/view-resource.html", resource=resource, error=None))
@resources.route("/edit/<uuid:resource_id>", methods=["GET"])
@require_oauth2
diff --git a/wqflask/wqflask/templates/oauth2/resources.html b/wqflask/wqflask/templates/oauth2/resources.html
index 19730f6b..08233921 100644
--- a/wqflask/wqflask/templates/oauth2/resources.html
+++ b/wqflask/wqflask/templates/oauth2/resources.html
@@ -30,7 +30,9 @@
{%for resource in resources %}
<tr>
<td>
- <a href="url_for('oauth2.resources.view', resource_id=resource.resource_id)"
+ <a href="{{url_for(
+ 'oauth2.resource.view_resource',
+ resource_id=resource.resource_id)}}"
title="View resource {{resource.resource_name}}">
{{resource.resource_name}}
</a>
diff --git a/wqflask/wqflask/templates/oauth2/view-resource.html b/wqflask/wqflask/templates/oauth2/view-resource.html
new file mode 100644
index 00000000..0ebd7f7a
--- /dev/null
+++ b/wqflask/wqflask/templates/oauth2/view-resource.html
@@ -0,0 +1,47 @@
+{%extends "base.html"%}
+{%from "oauth2/profile_nav.html" import profile_nav%}
+{%block title%}View User{%endblock%}
+{%block content%}
+<div class="container" style="min-width: 1250px;">
+ {{profile_nav("resources")}}
+ <h3>Resources</h3>
+
+ {{flash_me()}}
+
+ <div class="container-fluid">
+
+ <div class="row">
+ {%if error %}
+ <span class="glyphicon glyphicon-exclamation-sign text-danger">
+ </span>
+ &nbsp;
+ <strong class="text-danger">{{error.error}}</strong>
+ {{error.error_description}}
+ {%else%}
+ <table class="table">
+ <caption>Resource: {{resource.resource_name}}</caption>
+ <thead>
+ <tr>
+ <th>Name</th>
+ <th>Category</th>
+ <th>Group</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <tr>
+ <td>{{resource.resource_name}}</td>
+ <td>{{resource.resource_category.resource_category_description}}</td>
+ <td>{{resource.group.group_name}}</td>
+ </tr>
+ </tbody>
+ </table>
+
+ <p>List the resource's data here...</p>
+ {%endif%}
+ </div>
+
+ </div>
+
+</div>
+{%endblock%}