Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cms/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,12 @@ nav {
font-style: normal;
}

a {
color: var(--bloodorange);
}

a:hover {
color: var(--jasmine-rice);
color: var(--tomato);
}

button {
Expand Down Expand Up @@ -1549,14 +1553,22 @@ div.breadcrumbs a {
}
#branding .items-end {
gap: 8px;
align-items: center;
padding: 8px;
}
#branding h1 {
font-size: 1.4rem;
}
#main {
padding: 8px;
}
}

@media (max-width: 767px) {
#header, #content, #footer {
padding: 0px !important;
}
body.login {
padding: 0 !important;
}
}
6 changes: 1 addition & 5 deletions cms/templates/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" dir="{{ LANGUAGE_BIDI|yesno:'rtl,ltr,auto' }}">
<head>
<title>{% block title %}{% endblock %}</title>
<title>{% block title %}hord{% endblock %}</title>
<link rel="stylesheet" href="{% block stylesheet %}{% static "admin/css/base.css" %}{% endblock %}">
{% block dark-mode-vars %}
<link rel="stylesheet" href="{% static "admin/css/dark_mode.css" %}">
<script src="{% static "admin/js/theme.js" %}"></script>
{% endblock %}
{% if not is_popup and is_nav_sidebar_enabled %}
<link rel="stylesheet" href="{% static "admin/css/nav_sidebar.css" %}">
{% endif %}
Expand Down
8 changes: 8 additions & 0 deletions cms/templates/admin/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@

<div id="content-main">

{% if user.is_anonymous %}
<p>
{% blocktranslate trimmed %}
Testing. Signups will open soon!
{% endblocktranslate %}
</p>
{% endif %}

{% if user.is_authenticated %}
<p class="errornote">
{% blocktranslate trimmed %}
Expand Down
2 changes: 2 additions & 0 deletions core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class UserAdmin(BaseUserAdmin):
'is_active',
'is_staff',
'is_superuser',
'groups',
)
}
),
Expand All @@ -33,6 +34,7 @@ class UserAdmin(BaseUserAdmin):
'is_active',
'is_staff',
'is_superuser',
'groups',

),
}),
Expand Down
57 changes: 57 additions & 0 deletions core/management/commands/create_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from django.core.management.base import BaseCommand
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
from core.models import User
from inventory.models import InventoryItem, Product, QuantitativeUnit
from recipes.models import Recipe

class Command(BaseCommand):
help = 'Create user groups and set permissions for Administrator, Moderator, and Contributor'

content_type = ContentType.objects.get_for_model(InventoryItem)
inventory_item_permission = Permission.objects.filter(content_type=content_type)
print([perm.codename for perm in inventory_item_permission])

def handle(self, *args, **kwargs):
groups_permissions = {
'Administrator': ['add_user', 'change_user', 'delete_user', 'view_user', 'add_inventoryitem', 'change_inventoryitem', 'delete_inventoryitem', 'view_inventoryitem', 'add_product', 'change_product', 'delete_product', 'view_product', 'add_recipe', 'change_recipe', 'delete_recipe', 'view_recipe', 'add_quantitativeunit', 'change_quantitativeunit', 'delete_quantitativeunit', 'view_quantitativeunit'],
'Moderator': ['view_user', 'add_inventoryitem', 'change_inventoryitem', 'delete_inventoryitem', 'view_inventoryitem', 'add_product', 'change_product', 'delete_product', 'view_product', 'add_recipe', 'change_recipe', 'delete_recipe', 'view_recipe', 'add_quantitativeunit', 'change_quantitativeunit', 'delete_quantitativeunit', 'view_quantitativeunit'],
'Contributor': ['add_inventoryitem', 'change_inventoryitem', 'delete_inventoryitem', 'view_inventoryitem', 'add_product', 'change_product', 'delete_product', 'view_product', 'add_recipe', 'change_recipe', 'delete_recipe', 'view_recipe', 'add_quantitativeunit', 'change_quantitativeunit', 'delete_quantitativeunit', 'view_quantitativeunit']
}

model_content_types = {
'user': ContentType.objects.get_for_model(User),
'inventoryitem': ContentType.objects.get_for_model(InventoryItem),
'product': ContentType.objects.get_for_model(Product),
'quantitativeunit': ContentType.objects.get_for_model(QuantitativeUnit),
'recipe': ContentType.objects.get_for_model(Recipe),
}

for group_name, permissions_list in groups_permissions.items():
# Create the group
group, created = Group.objects.get_or_create(name=group_name)
if created:
self.stdout.write(f'Group "{group_name}" created')
else:
self.stdout.write(f'Group "{group_name}" already exists')

# Set permissions
for perm_codename in permissions_list:
# Determine model and content type
model_name = perm_codename.split('_')[1]
content_type = model_content_types.get(model_name)

if not content_type:
self.stdout.write(f'No content type found for model "{model_name}"')
continue

try:
# Fetch the permission based on the codename and content type
permission = Permission.objects.get(codename=perm_codename, content_type=content_type)
group.permissions.add(permission)
except Permission.DoesNotExist:
self.stdout.write(f'Permission "{perm_codename}" not found for group "{group_name}"')

self.stdout.write(f'Permissions set for group "{group_name}"')

self.stdout.write(self.style.SUCCESS('Groups and permissions setup complete.'))
1 change: 1 addition & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ python manage.py makemigrations
python manage.py migrate
python manage.py migrate --fake contenttypes
python manage.py spectacular
python manage.py create_groups
gunicorn --config gunicorn_config.py cms.wsgi:application

exec "$@"