hide private items from friends in search
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
93335b2776
commit
f4894d3a8c
4 changed files with 38 additions and 11 deletions
|
@ -24,7 +24,8 @@ def inventory_items(identity):
|
|||
for friend in identity.friends.all():
|
||||
if friend_user := friend.user.get():
|
||||
for item in friend_user.inventory_items.all():
|
||||
yield item
|
||||
if item.availability_policy != 'private':
|
||||
yield item
|
||||
|
||||
|
||||
class InventoryItemViewSet(viewsets.ModelViewSet):
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.2.2 on 2024-02-20 15:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('toolshed', '0004_storagelocation_inventoryitem_storage_location'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='inventoryitem',
|
||||
name='availability_policy',
|
||||
field=models.CharField(choices=[('sell', 'Sell'), ('rent', 'Rent'), ('lend', 'Lend'), ('share', 'Share'), ('private', 'Private')], default='private', max_length=20),
|
||||
),
|
||||
]
|
|
@ -50,12 +50,20 @@ class Tag(models.Model):
|
|||
|
||||
|
||||
class InventoryItem(SoftDeleteModel):
|
||||
AVAILABILITY_POLICY_CHOICES = (
|
||||
('sell', 'Sell'),
|
||||
('rent', 'Rent'),
|
||||
('lend', 'Lend'),
|
||||
('share', 'Share'),
|
||||
('private', 'Private'),
|
||||
)
|
||||
|
||||
published = models.BooleanField(default=False)
|
||||
name = models.CharField(max_length=255, null=True, blank=True)
|
||||
description = models.TextField(null=True, blank=True)
|
||||
category = models.ForeignKey(Category, on_delete=models.CASCADE, null=True, blank=True,
|
||||
related_name='inventory_items')
|
||||
availability_policy = models.CharField(max_length=255, default="private")
|
||||
availability_policy = models.CharField(max_length=20, choices=AVAILABILITY_POLICY_CHOICES, default='private')
|
||||
owned_quantity = models.IntegerField(default=1, validators=[MinValueValidator(0)])
|
||||
owner = models.ForeignKey(ToolshedUser, on_delete=models.CASCADE, related_name='inventory_items')
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
|
|
@ -38,7 +38,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
|
||||
def test_post_new_item(self):
|
||||
reply = client.post('/api/inventory_items/', self.f['local_user1'], {
|
||||
'availability_policy': 'friends',
|
||||
'availability_policy': 'rent',
|
||||
'category': 'cat2',
|
||||
'name': 'test3',
|
||||
'description': 'test',
|
||||
|
@ -50,7 +50,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
self.assertEqual(reply.status_code, 201)
|
||||
self.assertEqual(InventoryItem.objects.count(), 3)
|
||||
item = InventoryItem.objects.get(name='test3')
|
||||
self.assertEqual(item.availability_policy, 'friends')
|
||||
self.assertEqual(item.availability_policy, 'rent')
|
||||
self.assertEqual(item.category, Category.objects.get(name='cat2'))
|
||||
self.assertEqual(item.name, 'test3')
|
||||
self.assertEqual(item.description, 'test')
|
||||
|
@ -61,7 +61,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
|
||||
def test_post_new_item2(self):
|
||||
reply = client.post('/api/inventory_items/', self.f['local_user1'], {
|
||||
'availability_policy': 'friends',
|
||||
'availability_policy': 'share',
|
||||
'name': 'test3',
|
||||
'description': 'test',
|
||||
'owned_quantity': 1,
|
||||
|
@ -70,7 +70,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
self.assertEqual(reply.status_code, 201)
|
||||
self.assertEqual(InventoryItem.objects.count(), 3)
|
||||
item = InventoryItem.objects.get(name='test3')
|
||||
self.assertEqual(item.availability_policy, 'friends')
|
||||
self.assertEqual(item.availability_policy, 'share')
|
||||
self.assertEqual(item.category, None)
|
||||
self.assertEqual(item.name, 'test3')
|
||||
self.assertEqual(item.description, 'test')
|
||||
|
@ -80,7 +80,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
|
||||
def test_post_new_item_empty(self):
|
||||
reply = client.post('/api/inventory_items/', self.f['local_user1'], {
|
||||
'availability_policy': 'friends',
|
||||
'availability_policy': 'rent',
|
||||
'owned_quantity': 1,
|
||||
'image': '',
|
||||
})
|
||||
|
@ -89,7 +89,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
|
||||
def test_post_new_item3(self):
|
||||
reply = client.post('/api/inventory_items/', self.f['local_user1'], {
|
||||
'availability_policy': 'friends',
|
||||
'availability_policy': 'private',
|
||||
'name': 'test3',
|
||||
'description': 'test',
|
||||
'owned_quantity': 1,
|
||||
|
@ -99,7 +99,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
self.assertEqual(reply.status_code, 201)
|
||||
self.assertEqual(InventoryItem.objects.count(), 3)
|
||||
item = InventoryItem.objects.get(name='test3')
|
||||
self.assertEqual(item.availability_policy, 'friends')
|
||||
self.assertEqual(item.availability_policy, 'private')
|
||||
self.assertEqual(item.category, None)
|
||||
self.assertEqual(item.name, 'test3')
|
||||
self.assertEqual(item.description, 'test')
|
||||
|
@ -109,7 +109,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
|
||||
def test_put_item(self):
|
||||
reply = client.put('/api/inventory_items/1/', self.f['local_user1'], {
|
||||
'availability_policy': 'friends',
|
||||
'availability_policy': 'sell',
|
||||
'name': 'test4',
|
||||
'description': 'new description',
|
||||
'owned_quantity': 100,
|
||||
|
@ -121,7 +121,7 @@ class InventoryApiTestCase(UserTestMixin, InventoryTestMixin, ToolshedTestCase):
|
|||
self.assertEqual(reply.status_code, 200)
|
||||
self.assertEqual(InventoryItem.objects.count(), 2)
|
||||
item = InventoryItem.objects.get(id=1)
|
||||
self.assertEqual(item.availability_policy, 'friends')
|
||||
self.assertEqual(item.availability_policy, 'sell')
|
||||
self.assertEqual(item.category, None)
|
||||
self.assertEqual(item.name, 'test4')
|
||||
self.assertEqual(item.description, 'new description')
|
||||
|
|
Loading…
Reference in a new issue