Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
sab-LC committed Oct 18, 2023
1 parent 8f66723 commit 4e4db8e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
4 changes: 4 additions & 0 deletions institutions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def is_user_in_institution(self, user):
else:
return False

def get_distinct_creators(self):
project_creators = self.institution_created_project.filter(institution=self).distinct("project__project_creator")
return [element.project.project_creator for element in project_creators]

def __str__(self):
return str(self.institution_name)

Expand Down
3 changes: 3 additions & 0 deletions researchers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Researcher(models.Model):
orcid_auth_token = models.TextField(null=True, blank=True)
date_connected = models.DateTimeField(auto_now_add=True, null=True)

def get_projects(self):
return self.researcher_created_project.filter(researcher=self).exists()

def __str__(self):
return str(self.user)

Expand Down
17 changes: 7 additions & 10 deletions templates/partials/infocards/_community-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,18 @@
href="{% url 'select-label' community.id %}"
>View account</a>
{% if approved_label %}
{% for collaborator in community.get_collaborator %}
{% if request.user == collaborator %}
<a class="primary-btn action-btn" href="{% url 'community-projects' community.id %}">View account</a>
{% endif %}
{% endfor %}
{% if request.user in community.get_collaborator or request.user == community.community_creator %}
<a class="primary-btn action-btn" href="{% url 'community-projects' community.id %}">View account</a>
{% endif %}
{% else %}
<a class="primary-btn action-btn" href="{% url 'select-label' community.id %}">View account</a>
{% endif %}
{% endif %}

{% for viewer in community.get_viewers %}
{% if request.user == viewer and approved_label %}
<a class="primary-btn action-btn" href="{% url 'select-label' community.id %}">View account</a>
{% endif %}
{% endfor %}
{% if request.user in community.get_viewers and approved_label %}
<a class="primary-btn action-btn" href="{% url 'select-label' community.id %}">View account</a>
{% endif %}

</div>
</div>

Expand Down
17 changes: 17 additions & 0 deletions templates/partials/infocards/_institution-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,27 @@
{% endif %}
{% endif %}
{% if '/dashboard/' in request.path %}
<a
{% if institution_projects %}
{% if request.user in institution.get_distinct_creators %}
<a
class="primary-btn action-btn"
href="{% url 'institution-projects' institution.id %}"
>View account</a>
{% else %}
<a
class="primary-btn action-btn"
href="{% url 'institution-notices' institution.id %}"
>View account</a>
{% endif %}

{% else %}
<a
class="primary-btn action-btn"
href="{% url 'institution-notices' institution.id %}"
>View account</a>
>View account</a>
{% endif %}
{% endif %}
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions templates/partials/infocards/_researcher-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,17 @@
{% endif %}
{% endif %}
{% if '/dashboard/' in request.path %}
{% if researcher.get_projects %}
<a
class="primary-btn action-btn"
href="{% url 'researcher-projects' researcher.id %}"
>View account</a>
{% else %}
<a
class="primary-btn action-btn"
href="{% url 'researcher-notices' researcher.id %}"
>View account</a>
{% endif %}
{% endif %}
</div>
</div>
Expand Down

0 comments on commit 4e4db8e

Please sign in to comment.