Bump Django version to 2.1 (wip)

parent 38a5f55e
Pipeline #6441 failed with stage
in 29 seconds
......@@ -76,6 +76,12 @@ class BugReportSerializer(serializers.ModelSerializer):
return b
def save(self, **kwargs):
# Include default for read_only `author` and `bar` fields
kwargs["author"] = self.fields["author"].get_default()
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class BugReportViewSet(viewsets.ModelViewSet):
queryset = BugReport.objects.all()
......
......@@ -16,7 +16,7 @@ class BugreportTests(APITestCase):
self.bar, _ = Bar.objects.get_or_create(id='natationjone')
self.user, _ = User.objects.get_or_create(username='bob')
self.create_data = {'message': 'test', 'data': 'error'}
self.create_data = {'message': 'test', 'data': 'error', 'author': self.user.id}
def test_create_bugreport(self):
......@@ -37,9 +37,8 @@ class BugreportTests(APITestCase):
self.client.force_authenticate(user=self.user)
response = self.client.post('/bugreport/?bar=natationjone', self.create_data)
self.assertEqual(response.status_code, 201)
self.assertEqual(m.call_args[0][0], 'bars_bugtracker.add_bugreport')
bugreport = BugReport.objects.get(id=response.data.get('id'))
self.assertEqual(bugreport.bar, self.bar)
self.assertEqual(bugreport.author, self.user)
self.assertEqual(bugreport.message, self.create_data.get('message'))
self.assertEqual(m.call_args[0][0], 'bars_bugtracker.add_bugreport')
bugreport = BugReport.objects.get(id=response.data.get('id'))
self.assertEqual(bugreport.bar, self.bar)
self.assertEqual(bugreport.author, self.user)
self.assertEqual(bugreport.message, self.create_data.get('message'))
# Generated by Django 2.1.14 on 2019-11-24 19:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('bars_core', '0021_auto_20160117_2034'),
]
operations = [
migrations.AlterField(
model_name='role',
name='name',
field=models.CharField(choices=[('barmanager', 'barmanager'), ('stockmanager', 'stockmanager'), ('appromanager', 'appromanager'), ('newsmanager', 'newsmanager'), ('staff', 'staff'), ('agios_daemon', 'agios_daemon'), ('policeman', 'policeman'), ('admin', 'admin'), ('customer', 'customer'), ('itemcreator', 'itemcreator'), ('usermanager', 'usermanager'), ('itemmanager', 'itemmanager'), ('accountmanager', 'accountmanager'), ('inventorymanager', 'inventorymanager'), ('usercreator', 'usercreator'), ('treasurer', 'treasurer')], max_length=127),
),
]
......@@ -46,6 +46,11 @@ class AccountSerializer(serializers.ModelSerializer):
_type = VirtualField("Account")
bar = serializers.PrimaryKeyRelatedField(read_only=True, default=CurrentBarCreateOnlyDefault())
def save(self, **kwargs):
# Include default for read_only `bar` field
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class AccountViewSet(viewsets.ModelViewSet):
queryset = Account.objects.all()
......
......@@ -46,6 +46,11 @@ class RoleSerializer(serializers.ModelSerializer):
bar = serializers.PrimaryKeyRelatedField(read_only=True, default=CurrentBarCreateOnlyDefault())
perms = serializers.ListField(child=serializers.CharField(max_length=127), read_only=True, source='get_permissions')
def save(self, **kwargs):
# Include default for read_only `bar` field
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class RoleViewSet(viewsets.ModelViewSet):
queryset = Role.objects.all()
......
......@@ -329,7 +329,6 @@ class AccountTests(APITestCase):
self.assertEqual(reload(self.account).deleted, self.account.deleted)
class RoleTests(APITestCase):
@classmethod
def setUpTestData(self):
......
......@@ -4,7 +4,7 @@ ALLOWED_HOSTS = [ "*" ]
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'chocapix',
'HOST': 'localhost',
'USER': 'chocapix',
......
......@@ -146,6 +146,11 @@ class BuyItemPriceSerializer(serializers.ModelSerializer):
return buyitemprice
def save(self, **kwargs):
# Include default for read_only `bar` field
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class BuyItemPriceViewSet(viewsets.ModelViewSet):
queryset = BuyItemPrice.objects.all()
......
......@@ -106,6 +106,11 @@ class SellItemSerializer(serializers.ModelSerializer):
unit_factor = serializers.FloatField(write_only=True, default=1)
oldest_inventory = serializers.DateTimeField(read_only=True, source='calc_oldest_inventory')
def save(self, **kwargs):
# Include default for read_only `bar` field
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class MergeSellItemSerializer(serializers.Serializer):
sellitem = serializers.PrimaryKeyRelatedField(queryset=SellItem.objects.all())
......
......@@ -101,6 +101,11 @@ class StockItemSerializer(serializers.ModelSerializer):
raise ValidationError("'sell_to_buy' field has to be nonnegative")
return value
def save(self, **kwargs):
# Include default for read_only `bar` field
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class StockItemViewSet(viewsets.ModelViewSet):
queryset = StockItem.objects.all()
......
......@@ -39,6 +39,11 @@ class SuggestedItemSerializer(serializers.ModelSerializer):
si.voters_list.add(self.context.get('request').user)
return si
def save(self, **kwargs):
# Include default for read_only `bar`
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class SuggestedItemViewSet(viewsets.ModelViewSet):
queryset = SuggestedItem.objects.all()
......
......@@ -98,6 +98,12 @@ class MenuSerializer(serializers.ModelSerializer):
Menu.objects.filter(pk=instance.id).update(**data)
return Menu.objects.prefetch_related('items').get(pk=instance.id)
def save(self, **kwargs):
# Include default for read_only `user` and `bar` fields
kwargs["user"] = self.fields["user"].get_default()
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class MenuViewSet(viewsets.ModelViewSet):
queryset = Menu.objects.all()
......
......@@ -35,6 +35,12 @@ class NewsSerializer(serializers.ModelSerializer):
bar = serializers.PrimaryKeyRelatedField(read_only=True, default=CurrentBarCreateOnlyDefault())
author = serializers.PrimaryKeyRelatedField(read_only=True, default=CurrentUserCreateOnlyDefault())
def save(self, **kwargs):
# Include default for read_only `author` and `bar` fields
kwargs["author"] = self.fields["author"].get_default()
kwargs["bar"] = self.fields["bar"].get_default()
return super().save(**kwargs)
class NewsFilterBackend(filters.BaseFilterBackend):
......
# Generated by Django 2.1.14 on 2019-11-24 19:08
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('bars_transactions', '0003_transaction_moneyflow'),
]
operations = [
migrations.AlterField(
model_name='transaction',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL),
),
]
......@@ -18,7 +18,7 @@ dependencies:
- django-filter==2.0.*
- django-permission==1.0.4
# - django-rest-swagger==0.3.10
- django==2.0.*
- django==2.1.*
- djangorestframework-composed-permissions==0.2.1
- djangorestframework-jwt==1.8.0
- djangorestframework==3.7.*
- djangorestframework==3.9.*
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment