Compare commits
17 commits
b9ff51fc74
...
04636a6408
Author | SHA1 | Date | |
---|---|---|---|
04636a6408 | |||
d842c2af72 | |||
b2323f2c48 | |||
6657c54e4a | |||
a42911af3f | |||
da9634ba15 | |||
0b24f3d964 | |||
972ad7a1d8 | |||
30cdb07ee3 | |||
0b53987800 | |||
6339ffd480 | |||
8087463727 | |||
1c99604e73 | |||
9f288fec82 | |||
e4a7f89a6e | |||
191dfe6c9e | |||
ca6629b380 |
11 changed files with 37 additions and 124 deletions
0
core/files/tests/v1/__init__.py
Normal file
0
core/files/tests/v1/__init__.py
Normal file
|
@ -1,52 +0,0 @@
|
|||
# Generated by Django 4.2.7 on 2024-11-19 22:56
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0004_alter_event_created_at_alter_item_created_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='container',
|
||||
old_name='cid',
|
||||
new_name='id',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='event',
|
||||
old_name='eid',
|
||||
new_name='id',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='item',
|
||||
old_name='iid',
|
||||
new_name='id',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='item',
|
||||
old_name='uid',
|
||||
new_name='uid_deprecated',
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='item',
|
||||
unique_together=set(),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='item',
|
||||
name='container',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='inventory.container'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='item',
|
||||
name='event',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='inventory.event'),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='item',
|
||||
unique_together={('uid_deprecated', 'event')},
|
||||
),
|
||||
]
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.7 on 2024-11-20 01:48
|
||||
# Generated by Django 4.2.7 on 2024-11-19 22:02
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -7,18 +7,28 @@ import django.db.models.deletion
|
|||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0006_alter_event_table'),
|
||||
('inventory', '0004_alter_event_created_at_alter_item_created_at'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='item',
|
||||
name='container',
|
||||
migrations.RenameField(
|
||||
model_name='container',
|
||||
old_name='cid',
|
||||
new_name='id',
|
||||
),
|
||||
migrations.AlterField(
|
||||
migrations.RenameField(
|
||||
model_name='item',
|
||||
name='event',
|
||||
field=models.ForeignKey(db_column='eid', on_delete=django.db.models.deletion.CASCADE, to='inventory.event'),
|
||||
old_name='iid',
|
||||
new_name='id',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='item',
|
||||
old_name='uid',
|
||||
new_name='uid_deprecated',
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='item',
|
||||
unique_together={('uid_deprecated', 'event')},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ItemPlacement',
|
||||
|
@ -29,4 +39,8 @@ class Migration(migrations.Migration):
|
|||
('item', models.ForeignKey(db_column='iid', on_delete=django.db.models.deletion.CASCADE, related_name='container_history', to='inventory.item')),
|
||||
],
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='item',
|
||||
name='container',
|
||||
),
|
||||
]
|
|
@ -1,17 +0,0 @@
|
|||
# Generated by Django 4.2.7 on 2024-11-20 01:39
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0005_rename_cid_container_id_rename_eid_event_id_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelTable(
|
||||
name='event',
|
||||
table='common_event',
|
||||
),
|
||||
]
|
|
@ -1,29 +0,0 @@
|
|||
# Generated by Django 4.2.7 on 2024-11-20 01:52
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0007_remove_item_container_alter_item_event_itemplacement'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='item',
|
||||
name='event',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='inventory.event'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='itemplacement',
|
||||
name='container',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='item_history', to='inventory.container'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='itemplacement',
|
||||
name='item',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='container_history', to='inventory.item'),
|
||||
),
|
||||
]
|
|
@ -25,10 +25,12 @@ class Item(SoftDeleteModel):
|
|||
id = models.AutoField(primary_key=True)
|
||||
uid_deprecated = models.IntegerField()
|
||||
description = models.TextField()
|
||||
event = models.ForeignKey('Event', models.CASCADE)
|
||||
event = models.ForeignKey('Event', models.CASCADE, db_column='eid')
|
||||
# container = models.ForeignKey('Container', models.CASCADE, db_column='cid')
|
||||
returned_at = models.DateTimeField(blank=True, null=True)
|
||||
created_at = models.DateTimeField(null=True, auto_now_add=True)
|
||||
updated_at = models.DateTimeField(blank=True, null=True)
|
||||
#related_issues = models.ManyToManyField('IssueThread', through='ItemRelation')
|
||||
|
||||
@property
|
||||
def container(self):
|
||||
|
@ -76,13 +78,13 @@ class Container(SoftDeleteModel):
|
|||
|
||||
class ItemPlacement(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
item = models.ForeignKey('Item', models.CASCADE, related_name='container_history')
|
||||
container = models.ForeignKey('Container', models.CASCADE, related_name='item_history')
|
||||
item = models.ForeignKey('Item', models.CASCADE, db_column='iid', related_name='container_history')
|
||||
container = models.ForeignKey('Container', models.CASCADE, db_column='cid', related_name='item_history')
|
||||
timestamp = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class Event(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
eid = models.AutoField(primary_key=True)
|
||||
name = models.CharField(max_length=255)
|
||||
slug = models.CharField(max_length=255, unique=True)
|
||||
start = models.DateTimeField(blank=True, null=True)
|
||||
|
@ -94,6 +96,3 @@ class Event(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return '[' + str(self.slug) + ']' + self.name
|
||||
|
||||
class Meta:
|
||||
db_table = 'common_event'
|
|
@ -29,8 +29,8 @@ class EventSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = Event
|
||||
fields = ['id', 'slug', 'name', 'start', 'end', 'pre_start', 'post_end', 'addresses']
|
||||
read_only_fields = ['id']
|
||||
fields = ['eid', 'slug', 'name', 'start', 'end', 'pre_start', 'post_end', 'addresses']
|
||||
read_only_fields = ['eid']
|
||||
|
||||
|
||||
# def update(self, instance, validated_data):
|
||||
|
@ -99,8 +99,6 @@ class ItemSerializer(serializers.ModelSerializer):
|
|||
return internal
|
||||
|
||||
def validate(self, attrs):
|
||||
if not 'container' in attrs and not self.partial:
|
||||
raise serializers.ValidationError("This field cannot be empty.")
|
||||
return super().validate(attrs)
|
||||
|
||||
def create(self, validated_data):
|
||||
|
|
0
core/inventory/tests/v1/__init__.py
Normal file
0
core/inventory/tests/v1/__init__.py
Normal file
|
@ -39,7 +39,7 @@ class EventTestCase(TestCase):
|
|||
def test_update_event(self):
|
||||
from rest_framework.test import APIClient
|
||||
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
||||
response = APIClient().put(f'/api/2/events/{event.id}/', {'slug': 'EVENT2', 'name': 'Event 2 new'})
|
||||
response = APIClient().put(f'/api/2/events/{event.eid}/', {'slug': 'EVENT2', 'name': 'Event 2 new'})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json()['slug'], 'EVENT2')
|
||||
self.assertEqual(response.json()['name'], 'Event 2 new')
|
||||
|
@ -50,7 +50,7 @@ class EventTestCase(TestCase):
|
|||
def test_update_event(self):
|
||||
from rest_framework.test import APIClient
|
||||
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
||||
response = APIClient().patch(f'/api/2/events/{event.id}/', {'addresses': []})#'foo@bar.baz', 'foo1@bar.baz'
|
||||
response = APIClient().patch(f'/api/2/events/{event.eid}/', {'addresses': []})#'foo@bar.baz', 'foo1@bar.baz'
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json()['slug'], 'EVENT1')
|
||||
self.assertEqual(response.json()['name'], 'Event 1')
|
||||
|
@ -63,7 +63,7 @@ class EventTestCase(TestCase):
|
|||
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
||||
Event.objects.create(slug='EVENT2', name='Event 2')
|
||||
self.assertEqual(len(Event.objects.all()), 2)
|
||||
response = client.delete(f'/api/2/events/{event.id}/')
|
||||
response = client.delete(f'/api/2/events/{event.eid}/')
|
||||
self.assertEqual(response.status_code, 204)
|
||||
self.assertEqual(len(Event.objects.all()), 1)
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ class ItemTestCase(TestCase):
|
|||
|
||||
def test_update_item(self):
|
||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/', {'description': '2'},
|
||||
response = self.client.put(f'/api/2/{self.event.slug}/item/{item.id}/', {'description': '2'},
|
||||
content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.json(),
|
||||
|
@ -105,7 +105,7 @@ class ItemTestCase(TestCase):
|
|||
def test_update_item_with_file(self):
|
||||
import base64
|
||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/',
|
||||
response = self.client.put(f'/api/2/{self.event.slug}/item/{item.id}/',
|
||||
{'description': '2',
|
||||
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8')},
|
||||
content_type='application/json')
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.7 on 2024-11-20 01:48
|
||||
# Generated by Django 4.2.7 on 2024-11-19 22:02
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -7,7 +7,7 @@ import django.db.models.deletion
|
|||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0007_remove_item_container_alter_item_event_itemplacement'),
|
||||
('inventory', '0005_rename_cid_container_id_rename_iid_item_id_and_more'),
|
||||
('tickets', '0011_train_old_spam'),
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in a new issue