Compare commits
18 commits
04636a6408
...
b9ff51fc74
Author | SHA1 | Date | |
---|---|---|---|
b9ff51fc74 | |||
8ca6f2f6e6 | |||
dfb2c5ce96 | |||
dfc3f19429 | |||
7fbf3114a5 | |||
58ce0b6a04 | |||
60fbcee253 | |||
ef7cf4bd2d | |||
3de6248689 | |||
2c68d4a32b | |||
5f28406d95 | |||
c40467f325 | |||
1e4b5a111c | |||
b81ce42242 | |||
d6aff053fe | |||
67cfd61d63 | |||
ed5b7aaca1 | |||
26255fadec |
11 changed files with 123 additions and 36 deletions
|
@ -0,0 +1,52 @@
|
||||||
|
# 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')},
|
||||||
|
),
|
||||||
|
]
|
17
core/inventory/migrations/0006_alter_event_table.py
Normal file
17
core/inventory/migrations/0006_alter_event_table.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# 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,4 +1,4 @@
|
||||||
# Generated by Django 4.2.7 on 2024-11-19 22:02
|
# Generated by Django 4.2.7 on 2024-11-20 01:48
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
@ -7,28 +7,18 @@ import django.db.models.deletion
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('inventory', '0004_alter_event_created_at_alter_item_created_at'),
|
('inventory', '0006_alter_event_table'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RenameField(
|
migrations.RemoveField(
|
||||||
model_name='container',
|
|
||||||
old_name='cid',
|
|
||||||
new_name='id',
|
|
||||||
),
|
|
||||||
migrations.RenameField(
|
|
||||||
model_name='item',
|
model_name='item',
|
||||||
old_name='iid',
|
name='container',
|
||||||
new_name='id',
|
|
||||||
),
|
),
|
||||||
migrations.RenameField(
|
migrations.AlterField(
|
||||||
model_name='item',
|
model_name='item',
|
||||||
old_name='uid',
|
name='event',
|
||||||
new_name='uid_deprecated',
|
field=models.ForeignKey(db_column='eid', on_delete=django.db.models.deletion.CASCADE, to='inventory.event'),
|
||||||
),
|
|
||||||
migrations.AlterUniqueTogether(
|
|
||||||
name='item',
|
|
||||||
unique_together={('uid_deprecated', 'event')},
|
|
||||||
),
|
),
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='ItemPlacement',
|
name='ItemPlacement',
|
||||||
|
@ -39,8 +29,4 @@ class Migration(migrations.Migration):
|
||||||
('item', models.ForeignKey(db_column='iid', on_delete=django.db.models.deletion.CASCADE, related_name='container_history', to='inventory.item')),
|
('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',
|
|
||||||
),
|
|
||||||
]
|
]
|
|
@ -0,0 +1,29 @@
|
||||||
|
# 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,12 +25,10 @@ class Item(SoftDeleteModel):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
uid_deprecated = models.IntegerField()
|
uid_deprecated = models.IntegerField()
|
||||||
description = models.TextField()
|
description = models.TextField()
|
||||||
event = models.ForeignKey('Event', models.CASCADE, db_column='eid')
|
event = models.ForeignKey('Event', models.CASCADE)
|
||||||
# container = models.ForeignKey('Container', models.CASCADE, db_column='cid')
|
|
||||||
returned_at = models.DateTimeField(blank=True, null=True)
|
returned_at = models.DateTimeField(blank=True, null=True)
|
||||||
created_at = models.DateTimeField(null=True, auto_now_add=True)
|
created_at = models.DateTimeField(null=True, auto_now_add=True)
|
||||||
updated_at = models.DateTimeField(blank=True, null=True)
|
updated_at = models.DateTimeField(blank=True, null=True)
|
||||||
#related_issues = models.ManyToManyField('IssueThread', through='ItemRelation')
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def container(self):
|
def container(self):
|
||||||
|
@ -78,13 +76,13 @@ class Container(SoftDeleteModel):
|
||||||
|
|
||||||
class ItemPlacement(models.Model):
|
class ItemPlacement(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
item = models.ForeignKey('Item', models.CASCADE, db_column='iid', related_name='container_history')
|
item = models.ForeignKey('Item', models.CASCADE, related_name='container_history')
|
||||||
container = models.ForeignKey('Container', models.CASCADE, db_column='cid', related_name='item_history')
|
container = models.ForeignKey('Container', models.CASCADE, related_name='item_history')
|
||||||
timestamp = models.DateTimeField(auto_now_add=True)
|
timestamp = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
eid = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
slug = models.CharField(max_length=255, unique=True)
|
slug = models.CharField(max_length=255, unique=True)
|
||||||
start = models.DateTimeField(blank=True, null=True)
|
start = models.DateTimeField(blank=True, null=True)
|
||||||
|
@ -96,3 +94,6 @@ class Event(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '[' + str(self.slug) + ']' + self.name
|
return '[' + str(self.slug) + ']' + self.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
db_table = 'common_event'
|
|
@ -29,8 +29,8 @@ class EventSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Event
|
model = Event
|
||||||
fields = ['eid', 'slug', 'name', 'start', 'end', 'pre_start', 'post_end', 'addresses']
|
fields = ['id', 'slug', 'name', 'start', 'end', 'pre_start', 'post_end', 'addresses']
|
||||||
read_only_fields = ['eid']
|
read_only_fields = ['id']
|
||||||
|
|
||||||
|
|
||||||
# def update(self, instance, validated_data):
|
# def update(self, instance, validated_data):
|
||||||
|
@ -99,6 +99,8 @@ class ItemSerializer(serializers.ModelSerializer):
|
||||||
return internal
|
return internal
|
||||||
|
|
||||||
def validate(self, attrs):
|
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)
|
return super().validate(attrs)
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
|
|
@ -39,7 +39,7 @@ class EventTestCase(TestCase):
|
||||||
def test_update_event(self):
|
def test_update_event(self):
|
||||||
from rest_framework.test import APIClient
|
from rest_framework.test import APIClient
|
||||||
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
||||||
response = APIClient().put(f'/api/2/events/{event.eid}/', {'slug': 'EVENT2', 'name': 'Event 2 new'})
|
response = APIClient().put(f'/api/2/events/{event.id}/', {'slug': 'EVENT2', 'name': 'Event 2 new'})
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json()['slug'], 'EVENT2')
|
self.assertEqual(response.json()['slug'], 'EVENT2')
|
||||||
self.assertEqual(response.json()['name'], 'Event 2 new')
|
self.assertEqual(response.json()['name'], 'Event 2 new')
|
||||||
|
@ -50,7 +50,7 @@ class EventTestCase(TestCase):
|
||||||
def test_update_event(self):
|
def test_update_event(self):
|
||||||
from rest_framework.test import APIClient
|
from rest_framework.test import APIClient
|
||||||
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
||||||
response = APIClient().patch(f'/api/2/events/{event.eid}/', {'addresses': []})#'foo@bar.baz', 'foo1@bar.baz'
|
response = APIClient().patch(f'/api/2/events/{event.id}/', {'addresses': []})#'foo@bar.baz', 'foo1@bar.baz'
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json()['slug'], 'EVENT1')
|
self.assertEqual(response.json()['slug'], 'EVENT1')
|
||||||
self.assertEqual(response.json()['name'], 'Event 1')
|
self.assertEqual(response.json()['name'], 'Event 1')
|
||||||
|
@ -63,7 +63,7 @@ class EventTestCase(TestCase):
|
||||||
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
event = Event.objects.create(slug='EVENT1', name='Event 1')
|
||||||
Event.objects.create(slug='EVENT2', name='Event 2')
|
Event.objects.create(slug='EVENT2', name='Event 2')
|
||||||
self.assertEqual(len(Event.objects.all()), 2)
|
self.assertEqual(len(Event.objects.all()), 2)
|
||||||
response = client.delete(f'/api/2/events/{event.eid}/')
|
response = client.delete(f'/api/2/events/{event.id}/')
|
||||||
self.assertEqual(response.status_code, 204)
|
self.assertEqual(response.status_code, 204)
|
||||||
self.assertEqual(len(Event.objects.all()), 1)
|
self.assertEqual(len(Event.objects.all()), 1)
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ class ItemTestCase(TestCase):
|
||||||
|
|
||||||
def test_update_item(self):
|
def test_update_item(self):
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||||
response = self.client.put(f'/api/2/{self.event.slug}/item/{item.id}/', {'description': '2'},
|
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/', {'description': '2'},
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(response.json(),
|
self.assertEqual(response.json(),
|
||||||
|
@ -105,7 +105,7 @@ class ItemTestCase(TestCase):
|
||||||
def test_update_item_with_file(self):
|
def test_update_item_with_file(self):
|
||||||
import base64
|
import base64
|
||||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||||
response = self.client.put(f'/api/2/{self.event.slug}/item/{item.id}/',
|
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/',
|
||||||
{'description': '2',
|
{'description': '2',
|
||||||
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8')},
|
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8')},
|
||||||
content_type='application/json')
|
content_type='application/json')
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Generated by Django 4.2.7 on 2024-11-19 22:02
|
# Generated by Django 4.2.7 on 2024-11-20 01:48
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
@ -7,7 +7,7 @@ import django.db.models.deletion
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('inventory', '0005_rename_cid_container_id_rename_iid_item_id_and_more'),
|
('inventory', '0007_remove_item_container_alter_item_event_itemplacement'),
|
||||||
('tickets', '0011_train_old_spam'),
|
('tickets', '0011_train_old_spam'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue