Skip to content

Commit 486e05d

Browse files
committed
fix: hide used or expired items that were shared from filter + dashboard
1 parent faf22e9 commit 486e05d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

myapp/templates/update_preferences.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<div class="card">
1919
<div class="card-body">
2020
<h6 class="card-title">{% trans "Configure Display Preferences" %}</h6>
21-
<p>{% trans "Select which fields should be visible in your inventory view." %}</p>
21+
<p>{% trans "Select which fields should be visible in your inventory/sharing view." %}</p>
2222

2323
<form method="POST" action="">
2424
{% csrf_token %}

myapp/views.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def dashboard(request):
7777

7878
# Count the number of items shared by the user
7979
shared_items_count_by_you = ItemShare.objects.filter(shared_by=user).values('item').distinct().count()
80-
shared_items_count_with_you = ItemShare.objects.filter(shared_with_user=user).values('item').distinct().count()
80+
shared_items_count_with_you = ItemShare.objects.filter(
81+
shared_with_user=user,
82+
item__is_used=False,
83+
item__expiry_date__gte=now().date()
84+
).exclude(item__user=user).values('item').distinct().count()
8185

8286
# Get threshold days from environment variable or default to 30
8387
threshold_days = int(os.getenv('EXPIRY_THRESHOLD_DAYS', 30))
@@ -117,7 +121,11 @@ def show_items(request):
117121
if filter_value == 'shared_by_me':
118122
items = Item.objects.filter(shared_with__shared_by=user).distinct()
119123
elif filter_value == 'shared_with_me':
120-
items = Item.objects.filter(shared_with__shared_with_user=user).exclude(user=user).distinct()
124+
items = Item.objects.filter(
125+
shared_with__shared_with_user=user,
126+
is_used=False,
127+
expiry_date__gte=now().date() # Only not expired
128+
).exclude(user=user).distinct()
121129
elif filter_value == 'soon_expiring':
122130
threshold_days = int(os.getenv('EXPIRY_THRESHOLD_DAYS', 30))
123131
soon_expiry_date = now() + timedelta(days=threshold_days)

0 commit comments

Comments
 (0)