Skip to content

Commit

Permalink
Merge 8b354da into 1d25531
Browse files Browse the repository at this point in the history
  • Loading branch information
MyPyDavid committed Jul 21, 2023
2 parents 1d25531 + 8b354da commit 63478d5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
20 changes: 17 additions & 3 deletions rdmo/projects/filters.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
from django_filters import CharFilter, FilterSet
from django_filters import CharFilter, FilterSet, ModelChoiceFilter
from rest_framework.filters import BaseFilterBackend

from rdmo.questions.models import Catalog

from .models import Project


def catalogs_for_user(request):
if request is None:
return Catalog.objects.none()

catalogs = Catalog.objects.filter_current_site() \
.filter_group(request.user) \
.filter_availability(request.user)
return catalogs


class ProjectFilter(FilterSet):
title = CharFilter(field_name='title', lookup_expr='icontains')

catalog = ModelChoiceFilter(queryset=catalogs_for_user)
class Meta:
model = Project
fields = ('title', )
fields = ('title', 'catalog')




class SnapshotFilterBackend(BaseFilterBackend):
Expand Down
21 changes: 20 additions & 1 deletion rdmo/projects/templates/projects/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ <h2>{% trans 'Filter projects' %}</h2>
{% endblocktrans %}
</small>
</p>
{{ request.GET.catalog|floatformat }}<br>
{% for catalog in filter.filters.catalog.extra.queryset %}
{{ catalog.id }} {% if catalog == request.GET.catalog %}selected{% endif %}<br>
{% comment %} TODO fix, the select is not work properly atm {% endcomment %}
{% endfor %}
<label for="id_catalog"></label>
<select name="catalog" id="id_catalog" class="form-control">
<option value="">{% trans 'Search project catalog' %}</option>
{% for catalog in filter.filters.catalog.extra.queryset %}
<option value="{{ catalog.id }}" {% if catalog.id|floatformat == request.GET.catalog|floatformat %}selected{% endif %}>
{{ catalog.title }}
</option>
{% endfor %}
</select>
<button type="submit" class="btn btn-primary">search</button>
</form>

<h2>{% trans 'Import existing project' %}</h2>
Expand Down Expand Up @@ -122,7 +137,8 @@ <h1>{% trans 'My Projects' %}</h1>
<table class="table projects-table" id="projects-table">
<thead>
<tr>
<th style="width: 60%;">{% trans 'Name' %}</th>
<th style="width: 50%;">{% trans 'Name' %}</th>
<th style="width: 10%;">{% trans 'Catalog' %}</th>
<th style="width: 10%;">{% trans 'Role' %}</th>
<th style="width: 23%;">{% trans 'Last changed' %}</th>
<th style="width: 7%;"></th>
Expand All @@ -137,6 +153,9 @@ <h1>{% trans 'My Projects' %}</h1>
<strong>{{ project.title }}</strong>
</a>
</td>
<td>
{{ project.catalog.title }}
</td>
<td>
{{ project.role|projects_role }}
</td>
Expand Down

0 comments on commit 63478d5

Please sign in to comment.