Merge branch 'develop' into feature/shopping-ui
# Conflicts: # cookbook/serializer.py
This commit is contained in:
85
.github/workflows/ci.yml
vendored
85
.github/workflows/ci.yml
vendored
@ -10,31 +10,80 @@ jobs:
|
|||||||
max-parallel: 4
|
max-parallel: 4
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ['3.10']
|
python-version: ['3.10']
|
||||||
|
node-version: ['18']
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v3
|
||||||
- name: Set up Python 3.10
|
- uses: awalsh128/cache-apt-pkgs-action@v1.3.1
|
||||||
|
with:
|
||||||
|
packages: libsasl2-dev python3-dev libldap2-dev libssl-dev
|
||||||
|
version: 1.0
|
||||||
|
|
||||||
|
# Setup python & dependencies
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.10'
|
python-version: ${{ matrix.python-version }}
|
||||||
# Build Vue frontend
|
cache: 'pip'
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
- name: Install Python Dependencies
|
||||||
node-version: '18'
|
|
||||||
- name: Install Vue dependencies
|
|
||||||
working-directory: ./vue
|
|
||||||
run: yarn install
|
|
||||||
- name: Build Vue dependencies
|
|
||||||
working-directory: ./vue
|
|
||||||
run: yarn build
|
|
||||||
- name: Install Django dependencies
|
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get -y update
|
|
||||||
sudo apt-get install -y libsasl2-dev python3-dev libldap2-dev libssl-dev
|
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
- name: Cache StaticFiles
|
||||||
|
uses: actions/cache@v3
|
||||||
|
id: django_cache
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
./cookbook/static
|
||||||
|
./vue/webpack-stats.json
|
||||||
|
./staticfiles
|
||||||
|
key: |
|
||||||
|
${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.node-version }}-collectstatic-${{ hashFiles('**/*.css', '**/*.js', 'vue/src/*') }}
|
||||||
|
|
||||||
|
# Build Vue frontend & Dependencies
|
||||||
|
- name: Set up Node ${{ matrix.node-version }}
|
||||||
|
if: steps.django_cache.outputs.cache-hit != 'true'
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
cache: 'yarn'
|
||||||
|
cache-dependency-path: ./vue/yarn.lock
|
||||||
|
|
||||||
|
- name: Install Vue dependencies
|
||||||
|
if: steps.django_cache.outputs.cache-hit != 'true'
|
||||||
|
working-directory: ./vue
|
||||||
|
run: yarn install
|
||||||
|
|
||||||
|
- name: Build Vue dependencies
|
||||||
|
if: steps.django_cache.outputs.cache-hit != 'true'
|
||||||
|
working-directory: ./vue
|
||||||
|
run: yarn build
|
||||||
|
|
||||||
|
- name: Compile Django StatisFiles
|
||||||
|
if: steps.django_cache.outputs.cache-hit != 'true'
|
||||||
|
run: |
|
||||||
python3 manage.py collectstatic --noinput
|
python3 manage.py collectstatic --noinput
|
||||||
python3 manage.py collectstatic_js_reverse
|
python3 manage.py collectstatic_js_reverse
|
||||||
|
|
||||||
|
- uses: actions/cache/save@v3
|
||||||
|
if: steps.django_cache.outputs.cache-hit != 'true'
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
./cookbook/static
|
||||||
|
./vue/webpack-stats.json
|
||||||
|
./staticfiles
|
||||||
|
key: |
|
||||||
|
${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.node-version }}-collectstatic-${{ hashFiles('**/*.css', '**/*.js', 'vue/src/*') }}
|
||||||
|
|
||||||
- name: Django Testing project
|
- name: Django Testing project
|
||||||
run: |
|
run: pytest --junitxml=junit/test-results-${{ matrix.python-version }}.xml
|
||||||
pytest
|
|
||||||
|
- name: Publish Test Results
|
||||||
|
uses: EnricoMi/publish-unit-test-result-action@v2
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
comment_mode: off
|
||||||
|
files: |
|
||||||
|
junit/test-results-${{ matrix.python-version }}.xml
|
||||||
|
@ -315,8 +315,8 @@ admin.site.register(MealPlan, MealPlanAdmin)
|
|||||||
|
|
||||||
|
|
||||||
class MealTypeAdmin(admin.ModelAdmin):
|
class MealTypeAdmin(admin.ModelAdmin):
|
||||||
list_display = ('name', 'created_by', 'order')
|
list_display = ('name', 'space', 'created_by', 'order')
|
||||||
search_fields = ('name', 'created_by__username')
|
search_fields = ('name', 'space', 'created_by__username')
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(MealType, MealTypeAdmin)
|
admin.site.register(MealType, MealTypeAdmin)
|
||||||
|
25
cookbook/management/commands/seed_basic_data.py
Normal file
25
cookbook/management/commands/seed_basic_data.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.contrib.postgres.search import SearchVector
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.utils import translation
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django_scopes import scopes_disabled
|
||||||
|
|
||||||
|
from cookbook.managers import DICTIONARY
|
||||||
|
from cookbook.models import Recipe, Step, Space
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
help = 'Seeds some basic data (space, account, food)'
|
||||||
|
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
with scopes_disabled():
|
||||||
|
user = User.objects.get_or_create(username='test')[0]
|
||||||
|
user.set_password('test')
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
space = Space.objects.get_or_create(
|
||||||
|
name='Test Space',
|
||||||
|
created_by=user
|
||||||
|
)[0]
|
@ -13,22 +13,22 @@ def migrate_icons(apps, schema_editor):
|
|||||||
PropertyType = apps.get_model('cookbook', 'PropertyType')
|
PropertyType = apps.get_model('cookbook', 'PropertyType')
|
||||||
RecipeBook = apps.get_model('cookbook', 'RecipeBook')
|
RecipeBook = apps.get_model('cookbook', 'RecipeBook')
|
||||||
|
|
||||||
duplicate_meal_types = MealType.objects.values('name').annotate(name_count=Count('name')).exclude(name_count=1).all()
|
duplicate_meal_types = MealType.objects.values('space_id', 'name').annotate(name_count=Count('name')).exclude(name_count=1).all()
|
||||||
if len(duplicate_meal_types) > 0:
|
if len(duplicate_meal_types) > 0:
|
||||||
raise RuntimeError(f'Duplicate MealTypes found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
|
raise RuntimeError(f'Duplicate MealTypes found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
|
||||||
MealType.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
|
MealType.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
|
||||||
|
|
||||||
duplicate_meal_types = Keyword.objects.values('name').annotate(name_count=Count('name')).exclude(name_count=1).all()
|
duplicate_meal_types = Keyword.objects.values('space_id', 'name').annotate(name_count=Count('name')).exclude(name_count=1).all()
|
||||||
if len(duplicate_meal_types) > 0:
|
if len(duplicate_meal_types) > 0:
|
||||||
raise RuntimeError(f'Duplicate Keyword found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
|
raise RuntimeError(f'Duplicate Keyword found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
|
||||||
Keyword.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
|
Keyword.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
|
||||||
|
|
||||||
duplicate_meal_types = PropertyType.objects.values('name').annotate(name_count=Count('name')).exclude(name_count=1).all()
|
duplicate_meal_types = PropertyType.objects.values('space_id', 'name').annotate(name_count=Count('name')).exclude(name_count=1).all()
|
||||||
if len(duplicate_meal_types) > 0:
|
if len(duplicate_meal_types) > 0:
|
||||||
raise RuntimeError(f'Duplicate PropertyType found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
|
raise RuntimeError(f'Duplicate PropertyType found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
|
||||||
PropertyType.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
|
PropertyType.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
|
||||||
|
|
||||||
duplicate_meal_types = RecipeBook.objects.values('name').annotate(name_count=Count('name')).exclude(name_count=1).all()
|
duplicate_meal_types = RecipeBook.objects.values('space_id', 'name').annotate(name_count=Count('name')).exclude(name_count=1).all()
|
||||||
if len(duplicate_meal_types) > 0:
|
if len(duplicate_meal_types) > 0:
|
||||||
raise RuntimeError(f'Duplicate RecipeBook found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
|
raise RuntimeError(f'Duplicate RecipeBook found, please remove/rename them and run migrations again/restart the container. {duplicate_meal_types}')
|
||||||
RecipeBook.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
|
RecipeBook.objects.update(name=Concat(F('icon'), Value(' '), F('name')))
|
||||||
@ -40,7 +40,7 @@ class Migration(migrations.Migration):
|
|||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RunPython( migrate_icons),
|
migrations.RunPython(migrate_icons),
|
||||||
migrations.AlterModelOptions(
|
migrations.AlterModelOptions(
|
||||||
name='propertytype',
|
name='propertytype',
|
||||||
options={'ordering': ('order',)},
|
options={'ordering': ('order',)},
|
||||||
|
@ -353,8 +353,7 @@ class MealTypeSerializer(SpacedModelSerializer, WritableNestedModelSerializer):
|
|||||||
validated_data['name'] = validated_data['name'].strip()
|
validated_data['name'] = validated_data['name'].strip()
|
||||||
space = validated_data.pop('space', self.context['request'].space)
|
space = validated_data.pop('space', self.context['request'].space)
|
||||||
validated_data['created_by'] = self.context['request'].user
|
validated_data['created_by'] = self.context['request'].user
|
||||||
obj, created = MealType.objects.get_or_create(name__iexact=validated_data['name'], space=space,
|
obj, created = MealType.objects.get_or_create(name__iexact=validated_data['name'], space=space, created_by=self.context['request'].user, defaults=validated_data)
|
||||||
defaults=validated_data)
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -2,7 +2,7 @@ version: "2.4"
|
|||||||
services:
|
services:
|
||||||
db_recipes:
|
db_recipes:
|
||||||
restart: always
|
restart: always
|
||||||
image: postgres:15-alpine
|
image: postgres:16-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- ${POSTGRES_DATA_DIR:-./postgresql}:/var/lib/postgresql/data
|
- ${POSTGRES_DATA_DIR:-./postgresql}:/var/lib/postgresql/data
|
||||||
env_file:
|
env_file:
|
||||||
|
@ -2,7 +2,7 @@ version: "3"
|
|||||||
services:
|
services:
|
||||||
db_recipes:
|
db_recipes:
|
||||||
restart: always
|
restart: always
|
||||||
image: postgres:15-alpine
|
image: postgres:16-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- ./postgresql:/var/lib/postgresql/data
|
- ./postgresql:/var/lib/postgresql/data
|
||||||
env_file:
|
env_file:
|
||||||
|
@ -2,7 +2,7 @@ version: "3"
|
|||||||
services:
|
services:
|
||||||
db_recipes:
|
db_recipes:
|
||||||
restart: always
|
restart: always
|
||||||
image: postgres:15-alpine
|
image: postgres:16-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- ./postgresql:/var/lib/postgresql/data
|
- ./postgresql:/var/lib/postgresql/data
|
||||||
env_file:
|
env_file:
|
||||||
|
@ -2,7 +2,7 @@ version: "3"
|
|||||||
services:
|
services:
|
||||||
db_recipes:
|
db_recipes:
|
||||||
restart: always
|
restart: always
|
||||||
image: postgres:15-alpine
|
image: postgres:16-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- ./postgresql:/var/lib/postgresql/data
|
- ./postgresql:/var/lib/postgresql/data
|
||||||
env_file:
|
env_file:
|
||||||
|
@ -69,7 +69,7 @@ services:
|
|||||||
db_recipes:
|
db_recipes:
|
||||||
restart: always
|
restart: always
|
||||||
container_name: db_recipes
|
container_name: db_recipes
|
||||||
image: postgres:15-alpine
|
image: postgres:16-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- ./recipes/db:/var/lib/postgresql/data
|
- ./recipes/db:/var/lib/postgresql/data
|
||||||
env_file:
|
env_file:
|
||||||
|
@ -81,7 +81,7 @@ version: "3"
|
|||||||
services:
|
services:
|
||||||
db_recipes:
|
db_recipes:
|
||||||
restart: always
|
restart: always
|
||||||
image: postgres:15-alpine
|
image: postgres:16-alpine
|
||||||
volumes:
|
volumes:
|
||||||
- ./postgresql:/var/lib/postgresql/data
|
- ./postgresql:/var/lib/postgresql/data
|
||||||
env_file:
|
env_file:
|
||||||
|
Reference in New Issue
Block a user