Compare commits

..

18 commits

Author SHA1 Message Date
b9ff51fc74 stash
All checks were successful
/ test (push) Successful in 55s
2024-11-20 02:53:12 +01:00
8ca6f2f6e6 stash 2024-11-20 02:45:52 +01:00
dfb2c5ce96 save raw_mails as file 2024-11-20 02:45:52 +01:00
dfc3f19429 stash 2024-11-20 02:45:52 +01:00
7fbf3114a5 stash 2024-11-20 02:45:52 +01:00
58ce0b6a04 stash 2024-11-20 02:45:52 +01:00
60fbcee253 stash 2024-11-20 02:45:52 +01:00
ef7cf4bd2d stash 2024-11-20 02:45:52 +01:00
3de6248689 stash 2024-11-20 02:45:44 +01:00
2c68d4a32b stash 2024-11-20 02:44:06 +01:00
5f28406d95 stash 2024-11-20 02:44:06 +01:00
c40467f325 stash 2024-11-20 02:44:06 +01:00
1e4b5a111c stash 2024-11-20 02:44:06 +01:00
b81ce42242 stash 2024-11-20 02:44:06 +01:00
d6aff053fe stash 2024-11-20 02:44:06 +01:00
67cfd61d63 stash 2024-11-20 02:44:06 +01:00
ed5b7aaca1 stash 2024-11-20 02:44:06 +01:00
26255fadec drop v1 API and rename id columns
All checks were successful
/ test (push) Successful in 51s
2024-11-20 02:39:49 +01:00
11 changed files with 123 additions and 36 deletions

View file

@ -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')},
),
]

View 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',
),
]

View file

@ -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
import django.db.models.deletion
@ -7,28 +7,18 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('inventory', '0004_alter_event_created_at_alter_item_created_at'),
('inventory', '0006_alter_event_table'),
]
operations = [
migrations.RenameField(
model_name='container',
old_name='cid',
new_name='id',
),
migrations.RenameField(
migrations.RemoveField(
model_name='item',
old_name='iid',
new_name='id',
name='container',
),
migrations.RenameField(
migrations.AlterField(
model_name='item',
old_name='uid',
new_name='uid_deprecated',
),
migrations.AlterUniqueTogether(
name='item',
unique_together={('uid_deprecated', 'event')},
name='event',
field=models.ForeignKey(db_column='eid', on_delete=django.db.models.deletion.CASCADE, to='inventory.event'),
),
migrations.CreateModel(
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')),
],
),
migrations.RemoveField(
model_name='item',
name='container',
),
]

View file

@ -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'),
),
]

View file

@ -25,12 +25,10 @@ class Item(SoftDeleteModel):
id = models.AutoField(primary_key=True)
uid_deprecated = models.IntegerField()
description = models.TextField()
event = models.ForeignKey('Event', models.CASCADE, db_column='eid')
# container = models.ForeignKey('Container', models.CASCADE, db_column='cid')
event = models.ForeignKey('Event', models.CASCADE)
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):
@ -78,13 +76,13 @@ class Container(SoftDeleteModel):
class ItemPlacement(models.Model):
id = models.AutoField(primary_key=True)
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')
item = models.ForeignKey('Item', models.CASCADE, related_name='container_history')
container = models.ForeignKey('Container', models.CASCADE, related_name='item_history')
timestamp = models.DateTimeField(auto_now_add=True)
class Event(models.Model):
eid = models.AutoField(primary_key=True)
id = 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)
@ -96,3 +94,6 @@ class Event(models.Model):
def __str__(self):
return '[' + str(self.slug) + ']' + self.name
class Meta:
db_table = 'common_event'

View file

@ -29,8 +29,8 @@ class EventSerializer(serializers.ModelSerializer):
class Meta:
model = Event
fields = ['eid', 'slug', 'name', 'start', 'end', 'pre_start', 'post_end', 'addresses']
read_only_fields = ['eid']
fields = ['id', 'slug', 'name', 'start', 'end', 'pre_start', 'post_end', 'addresses']
read_only_fields = ['id']
# def update(self, instance, validated_data):
@ -99,6 +99,8 @@ 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):

View 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.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.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.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.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.eid}/')
response = client.delete(f'/api/2/events/{event.id}/')
self.assertEqual(response.status_code, 204)
self.assertEqual(len(Event.objects.all()), 1)

View file

@ -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.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')
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.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',
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8')},
content_type='application/json')

View file

@ -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
import django.db.models.deletion
@ -7,7 +7,7 @@ import django.db.models.deletion
class Migration(migrations.Migration):
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'),
]