diff --git a/apps/hadis/models/category.py b/apps/hadis/models/category.py index 53686d4..cdb28f8 100644 --- a/apps/hadis/models/category.py +++ b/apps/hadis/models/category.py @@ -3,6 +3,7 @@ from django.utils.translation import gettext_lazy as _ from django.core.exceptions import ValidationError from mptt.models import MPTTModel, TreeForeignKey from django.utils.text import slugify +from django.conf import settings class HadisSect(models.Model): @@ -149,6 +150,18 @@ class HadisCategory(MPTTModel): self.slug = base_slug super().save(*args, **kwargs) + @property + def share_link(self): + if self.slug: + return f"{settings.DOVODI_DOMAIN}/arguments/category/{self.slug}" + return None + + @property + def xmind_share_link(self): + if self.slug and self.xmind_file: + return f"{settings.DOVODI_DOMAIN}/xmind/{self.slug}" + return None + class Meta: diff --git a/apps/hadis/models/hadis.py b/apps/hadis/models/hadis.py index 0824db6..69eff04 100644 --- a/apps/hadis/models/hadis.py +++ b/apps/hadis/models/hadis.py @@ -326,8 +326,7 @@ class Hadis(models.Model): # Generate/update share_link before saving if self.slug: - category_slug = self.category.slug if self.category and self.category.slug else 'uncategorized' - self.share_link = f"{settings.DOVODI_DOMAIN}/arguments/hadith/{category_slug}/{self.slug}" + self.share_link = f"{settings.DOVODI_DOMAIN}/arguments/hadith/{self.slug}" # Reset embedded_in if text or translation changes if self.pk: @@ -538,8 +537,7 @@ class HadisCorrection(models.Model): # Generate/update share_link before saving if self.slug and self.hadis and self.hadis.slug: - category_slug = self.hadis.category.slug if self.hadis.category and self.hadis.category.slug else 'uncategorized' - self.share_link = f"{settings.DOVODI_DOMAIN}/arguments/hadith/{category_slug}/{self.hadis.slug}/corrections/{self.slug}" + self.share_link = f"{settings.DOVODI_DOMAIN}/arguments/hadith/{self.hadis.slug}/corrections/{self.slug}" # Reset embedded_in if text or translation changes if self.pk: diff --git a/apps/hadis/serializers/category.py b/apps/hadis/serializers/category.py index c73798e..38cdb13 100644 --- a/apps/hadis/serializers/category.py +++ b/apps/hadis/serializers/category.py @@ -120,7 +120,7 @@ class HadisCategorySelectSerializer(serializers.ModelSerializer): class Meta: model = HadisCategory fields = ['id', 'title', 'source_type','slug', 'sect_id', - 'sect_type','description','children_count','has_hadis','hadis_count'] + 'sect_type','description','children_count','has_hadis','hadis_count', 'share_link', 'xmind_share_link'] def get_has_hadis(self, obj): """Check if category can have hadis (no active children) and has hadis""" @@ -167,7 +167,7 @@ class HadisCategorySelectSourceSerializer(serializers.ModelSerializer): class Meta: model = HadisCategory fields = ['id', 'title', 'source_type','slug', 'sect_id', - 'sect_type','description','children_count','has_hadis','hadis_count'] + 'sect_type','description','children_count','has_hadis','hadis_count', 'share_link', 'xmind_share_link'] def get_has_hadis(self, obj): """Check if category can have hadis (no active children) and has hadis""" @@ -209,7 +209,7 @@ class CategorySerializer(serializers.ModelSerializer): model = HadisCategory fields = ['id', 'title', 'sect_id', 'sect_type','source_type', 'description','slug', - 'children_count','has_hadis','hadis_count'] + 'children_count','has_hadis','hadis_count', 'share_link', 'xmind_share_link'] def get_children_count(self, obj): # """Get count of active children categories that have children or hadis""" diff --git a/apps/hadis/serializers/hadis.py b/apps/hadis/serializers/hadis.py index a7f672a..9a8f4ae 100644 --- a/apps/hadis/serializers/hadis.py +++ b/apps/hadis/serializers/hadis.py @@ -88,6 +88,7 @@ class HadisSyncSerializer(serializers.ModelSerializer): for a in authors ], 'description': book.description if book else None, + 'share_link': book.share_link if book else None, }) for img in reference.images.all(): @@ -579,10 +580,11 @@ class HadisReferenceSerializer(serializers.ModelSerializer): book_title = serializers.SerializerMethodField() book_authors = serializers.SerializerMethodField() book_description = serializers.SerializerMethodField() + share_link = serializers.CharField(source='book_reference.share_link', read_only=True) class Meta: model = HadisReference fields = [ - 'id', 'book_title', 'book_description','book_authors' + 'id', 'book_title', 'book_description','book_authors','share_link' ] # def get_type_name(self, obj):