Compare commits

..

17 commits

Author SHA1 Message Date
04636a6408 stash
All checks were successful
/ test (push) Successful in 57s
2024-11-19 23:03:55 +01:00
d842c2af72 stash 2024-11-18 03:30:57 +01:00
b2323f2c48 save raw_mails as file 2024-11-18 03:30:46 +01:00
6657c54e4a stash 2024-11-18 03:30:46 +01:00
a42911af3f stash 2024-11-18 03:30:36 +01:00
da9634ba15 stash 2024-11-18 03:30:01 +01:00
0b24f3d964 stash 2024-11-18 03:29:56 +01:00
972ad7a1d8 stash 2024-11-18 03:29:36 +01:00
30cdb07ee3 stash 2024-11-18 03:28:31 +01:00
0b53987800 stash 2024-11-18 03:28:31 +01:00
6339ffd480 stash 2024-11-18 03:28:31 +01:00
8087463727 stash 2024-11-18 03:28:31 +01:00
1c99604e73 stash 2024-11-18 03:28:25 +01:00
9f288fec82 stash 2024-11-18 03:27:55 +01:00
e4a7f89a6e stash 2024-11-18 03:27:55 +01:00
191dfe6c9e stash 2024-11-18 03:27:55 +01:00
ca6629b380 stash 2024-11-18 03:27:49 +01:00
11 changed files with 37 additions and 124 deletions

View file

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

View file

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

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

View file

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

View file

@ -25,10 +25,12 @@ 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) 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) 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):
@ -76,13 +78,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, related_name='container_history') item = models.ForeignKey('Item', models.CASCADE, db_column='iid', related_name='container_history')
container = models.ForeignKey('Container', models.CASCADE, related_name='item_history') container = models.ForeignKey('Container', models.CASCADE, db_column='cid', 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):
id = models.AutoField(primary_key=True) eid = 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)
@ -94,6 +96,3 @@ 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'

View file

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

View file

View file

@ -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.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.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.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.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.id}/') response = client.delete(f'/api/2/events/{event.eid}/')
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)

View file

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

View file

@ -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 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', '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'), ('tickets', '0011_train_old_spam'),
] ]