Repository: OpenEnergyPlatform/oeplatform

Issue:
[OPR] Prompt the reviewer to suggest a badge and finish review.
## Description of the issue

Once all fields have the state accepted, a new html div should pop up/made visible and prompt for a suggested badge by the reviewer. 

## Ideas of solution

- Implement javaScript function that checks if all fields are accepted 
- Show input fields to the reviewer 
  - suggest a badge to the best knowledge of the reviewer 
  - in the future the badge will be calculated from the review automatically
  - reviewer selects an option (one of): bronze, silver, gold, platinum

## Workflow checklist
- [ ] I am aware of the workflow in [CONTRIBUTING.md](https://github.com/OpenEnergyPlatform/oeplatform/blob/develop/CONTRIBUTING.md)



Discussion:

Resolving patch:
diff --git a/dataedit/helper.py b/dataedit/helper.py
--- a/dataedit/helper.py
+++ b/dataedit/helper.py
@@ -52,18 +52,22 @@ def process_review_data(review_data, metadata, categories):
             if latest_field_review:
                 state = latest_field_review.get('state')
                 reviewer_suggestion = latest_field_review.get('reviewerSuggestion')
+                reviewer_suggestion_comment = latest_field_review.get("comment")
             else:
                 state = None
                 reviewer_suggestion = None
+                reviewer_suggestion_comment = None
         else:
             state = field_review.get('state')
             reviewer_suggestion = field_review.get('reviewerSuggestion')
+            reviewer_suggestion_comment = field_review.get("comment")
 
-        if reviewer_suggestion is not None:
+        if reviewer_suggestion is not None and reviewer_suggestion_comment is not None:
             for category in categories:
                 for item in metadata[category]:
                     if item['field'] == field_key:
                         item['reviewer_suggestion'] = reviewer_suggestion
+                        item['suggestion_comment'] = reviewer_suggestion_comment
                         break
         state_dict[field_key] = state
 
diff --git a/dataedit/models.py b/dataedit/models.py
--- a/dataedit/models.py
+++ b/dataedit/models.py
@@ -187,6 +187,10 @@ def update(self, *args, **kwargs):
             elif review_type == "submit":
                 current_pm.status = ReviewDataStatus.SUBMITTED.value
                 current_pm.set_next_reviewer()
+            elif review_type == "finished":
+                self.is_finished = True
+                self.date_finished = timezone.now()
+                current_pm.status = ReviewDataStatus.FINISHED.value
             
             # update peere review manager related to this peer review entry
             current_pm.save()
diff --git a/dataedit/views.py b/dataedit/views.py
--- a/dataedit/views.py
+++ b/dataedit/views.py
@@ -1072,9 +1072,11 @@ def iter_oem_key_order(metadata: dict):
             latest_review = reviews.last()
             opr_manager.update_open_since(opr=latest_review)
             current_reviewer = opr_manager.load(latest_review).current_reviewer
-            opr_context.update({"opr_id": latest_review.id, "opr_current_reviewer": current_reviewer})
+            opr_context.update({"opr_id": latest_review.id, "opr_current_reviewer": current_reviewer, "is_finished": latest_review.is_finished})
         else:
             opr_context.update({"opr_id": None, "opr_current_reviewer": None})
+
+        print(opr_context)
         
         #########################################################################
         context_dict = {
@@ -1987,6 +1989,7 @@ def get(self, request, schema, table, review_id=None):
             "can_add": can_add,
             "url_peer_review": url_peer_review,
             "url_table": reverse("view", kwargs={"schema": schema, "table": table}),
+            "topic": schema,
             "table": table,
         }
 
@@ -2050,7 +2053,6 @@ def post(self, request, schema, table, review_id=None):
                     merged_review_data = merge_field_reviews(current_json=current_review_data, new_json=review_datamodel)
 
                     # Set new review values and update existing review
-                    active_peer_review.is_finished = review_finished
                     active_peer_review.review = merged_review_data
                     active_peer_review.reviewer = request.user
                     active_peer_review.contributor = contributor
@@ -2093,8 +2095,9 @@ def get(self, request, schema, table, review_id):
              "url_table": reverse(
                  "view", kwargs={"schema": schema, "table": table}
              ),
-             "table": table,
-             }),
+            "topic": schema,
+            "table": table,
+            }),
             "table": table,
             "meta": metadata,
             "json_schema": json_schema,


Test patch: