Repository: OpenEnergyPlatform/oeplatform

Issue:
[OPR] Bug related to the review history on profile/reviews page 
## Description of the issue

On the profile -> reviews page, an error is raised if there are reviews present, but no active review is available. 
This error is raised while creating the review history.


## Ideas of solution

Only remove the latest review from the history of all reviews related to one specific table.

## Context and Environment
* Version used: 
* Operating system: 
* Environment setup and (python) version: 

## 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
@@ -53,14 +53,17 @@ def process_review_data(review_data, metadata, categories):
                 state = latest_field_review.get("state")
                 reviewer_suggestion = latest_field_review.get("reviewerSuggestion")
                 reviewer_suggestion_comment = latest_field_review.get("comment")
+                newValue = latest_field_review.get("newValue")
             else:
                 state = None
                 reviewer_suggestion = None
                 reviewer_suggestion_comment = None
+                newValue = None
         else:
             state = field_review.get("state")
             reviewer_suggestion = field_review.get("reviewerSuggestion")
             reviewer_suggestion_comment = field_review.get("comment")
+            newValue = field_review.get("newValue")
 
         if reviewer_suggestion is not None and reviewer_suggestion_comment is not None:
             for category in categories:
@@ -69,6 +72,15 @@ def process_review_data(review_data, metadata, categories):
                         item["reviewer_suggestion"] = reviewer_suggestion
                         item["suggestion_comment"] = reviewer_suggestion_comment
                         break
+
+        if newValue is not None:
+            for category in categories:
+                for item in metadata[category]:
+                    if item['field'] == field_key:
+                        item['newValue'] = newValue
+                        break
+
         state_dict[field_key] = state
 
     return state_dict
+
diff --git a/dataedit/views.py b/dataedit/views.py
--- a/dataedit/views.py
+++ b/dataedit/views.py
@@ -1934,6 +1934,7 @@ def sort_in_category(self, schema, table):
                     {
                     "field": "id",
                     "value": "http: //127.0.0.1:8000/dataedit/view/model_draft/test2",
+                    "newValue": "",
                     "reviewer_suggestion": "",
                     "suggestion_comment": ""
                     }
@@ -2199,7 +2200,6 @@ def get(self, request, schema, table, review_id):
         state_dict = process_review_data(
             review_data=review_data, metadata=metadata, categories=categories
         )
-
         context_meta = {
             "config": json.dumps(
                 {
diff --git a/login/views.py b/login/views.py
--- a/login/views.py
+++ b/login/views.py
@@ -87,7 +87,12 @@ def get(self, request, user_id):
                 PeerReviewManager.filter_latest_open_opr_by_reviewer(reviewer_user=user)
             )
 
-            # review_history = peer_review_reviews.exclude(pk=active_peer_review_revewier.pk)  # noqa
+            if active_peer_review_revewier is not None:
+                review_history = peer_review_reviews.exclude(pk=active_peer_review_revewier.pk)  # noqa
+            else:
+                # Handle the case when active_peer_review_revewier is None.
+                # Maybe set review_history to some default value or just leave it as None.
+                review_history = None
 
             # Context da for the "All reviews" section on the profile page
             reviewed_context.update(
@@ -141,8 +146,6 @@ def get(self, request, user_id):
         # get contributor pov reviews
         ##################################################################
         reviewed_contributions_context = {}
-
-        # all peer reviews related to the contributor user
         peer_review_contributions = PeerReviewManager.filter_opr_by_contributor(
             contributor_user=user
         )
@@ -158,12 +161,15 @@ def get(self, request, user_id):
                     contributor_user=user
                 )
             )
+            if active_peer_review_contributor is not None:
+                reviewed_contribution_history = peer_review_contributions.exclude(
+                    pk=active_peer_review_contributor.pk
+                )
+            else:
+                # Handle the case when active_peer_review_contributor is None.
+                # Maybe set reviewed_contribution_history to some default value or just leave it as None.
+                reviewed_contribution_history = None
 
-            reviewed_contribution_history = peer_review_contributions.exclude(
-                pk=active_peer_review_contributor.pk
-            )
-
-            # Context da for the "All reviews" section on the profile page
             reviewed_contributions_context = {
                 # mainly used to check if review exists
                 "latest": latest_reviewed_contribution,


Test patch: