Browse Source

Enhance HadisStatus model with color palette and properties

- Added a COLOR_PALETTE dictionary to the HadisStatus model for color management.
- Introduced properties to retrieve main and light color codes based on the selected color.
- Updated HadisStatusSerializer to include read-only fields for main and light color codes.
- Enabled the population of books in the entrypoint script by uncommenting the relevant command.
master
Mohsen Taba 4 months ago
parent
commit
8ed4aee4a0
  1. 24
      apps/hadis/models/hadis.py
  2. 4
      apps/hadis/serializers/hadis.py
  3. 2
      entrypoint.sh

24
apps/hadis/models/hadis.py

@ -171,6 +171,16 @@ class HadisStatus(models.Model):
ORANGE = 'orange', _('Orange')
PURPLE = 'purple', _('Purple')
GRAY = 'gray', _('Gray')
COLOR_PALETTE = {
'red': {'main': '#E74C3C', 'light': '#FADBD8'},
'green': {'main': '#27AE60', 'light': '#D5F5E3'},
'blue': {'main': '#2980B9', 'light': '#D4E6F1'},
'yellow': {'main': '#F1C40F', 'light': '#FCF3CF'},
'orange': {'main': '#E67E22', 'light': '#FAE5D3'},
'purple': {'main': '#8E44AD', 'light': '#EBDEF0'},
'gray': {'main': '#7F8C8D', 'light': '#E5E8E8'},
}
title = models.JSONField(default = list , verbose_name=_('Title'))
slug= models.SlugField(max_length=255, verbose_name=_('slug'), blank=True,unique = True)
@ -178,6 +188,20 @@ class HadisStatus(models.Model):
order = models.IntegerField(default=0, verbose_name=_('order'))
description = models.JSONField(default = list , verbose_name=_('Description'))
@property
def color_hashes(self):
"""Returns the dictionary of hash codes based on the selected color"""
return self.COLOR_PALETTE.get(self.color, {'main': '#000000', 'light': '#FFFFFF'})
# Helper for specific fields if you need them flat
@property
def main_color_code(self):
return self.color_hashes['main']
@property
def light_color_code(self):
return self.color_hashes['light']
def save(self, *args, **kwargs):
if not self.slug or (isinstance(self.slug, str) and self.slug.strip() == ''):
# Try to get text from title field with robust error handling

4
apps/hadis/serializers/hadis.py

@ -247,9 +247,11 @@ class HadisStatusSerializer(serializers.ModelSerializer):
"""Serializer for HadisStatus"""
title = LocalizedField()
description = LocalizedField()
main_color_code = serializers.ReadOnlyField()
light_color_code = serializers.ReadOnlyField()
class Meta:
model = HadisStatus
fields = ['id', 'title', 'color', 'description']
fields = ['id', 'title', 'color', 'main_color_code', 'light_color_code', 'description']
class HadisTagSerializer(serializers.ModelSerializer):

2
entrypoint.sh

@ -10,7 +10,7 @@ python manage.py collectstatic --noinput
# python manage.py seed_russian_data
# python manage.py hadisreferences
# python manage.py seed_complete_hadis_data
# python manage.py populate_books
python manage.py populate_books
# python manage.py populate_book_reference
# python manage.py populate_refrence_images
# python manage.py populate_article

Loading…
Cancel
Save