Browse Source
feat: add management command to refresh share links and script to validate link consistency
master
feat: add management command to refresh share links and script to validate link consistency
master
2 changed files with 119 additions and 7 deletions
@ -0,0 +1,97 @@ |
|||
#!/usr/bin/env python |
|||
import os |
|||
import sys |
|||
import django |
|||
from django.conf import settings |
|||
|
|||
# Setup Django |
|||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base') |
|||
django.setup() |
|||
|
|||
from apps.hadis.models import Hadis, HadisCategory, Transmitters, BookReference, TransmitterOriginalText |
|||
from apps.article.models import Article |
|||
from apps.podcast.models import Podcast |
|||
from apps.video.models import Video |
|||
from apps.library.models import Book |
|||
|
|||
def check_link(name, link, expected_pattern): |
|||
if not link: |
|||
print(f"❌ {name}: Link is missing") |
|||
return False |
|||
|
|||
# Simple pattern check (standard doesn't specify exact origin, but backend uses settings.DOVODI_DOMAIN) |
|||
origin = settings.DOVODI_DOMAIN |
|||
expected = expected_pattern.format(origin=origin) |
|||
|
|||
if link.startswith(expected): |
|||
print(f"✅ {name}: {link}") |
|||
return True |
|||
else: |
|||
print(f"❌ {name}: Got {link}, expected pattern starting with {expected}") |
|||
return False |
|||
|
|||
def main(): |
|||
print("🧪 Validating Standardized Share Links") |
|||
print("=" * 60) |
|||
|
|||
success = True |
|||
|
|||
# 1. Hadith |
|||
h = Hadis.objects.filter(slug__isnull=False).first() |
|||
if h: |
|||
if not check_link("Hadith", h.share_link, "{origin}/arguments/hadith/"): |
|||
success = False |
|||
|
|||
# 2. Category |
|||
c = HadisCategory.objects.filter(slug__isnull=False).first() |
|||
if c: |
|||
if not check_link("Category", c.share_link, "{origin}/arguments/category/"): |
|||
success = False |
|||
if c.xmind_file: |
|||
if not check_link("Mind Map", c.xmind_share_link, "{origin}/xmind/"): |
|||
success = False |
|||
|
|||
# 3. Narrator (Transmitters) |
|||
t = Transmitters.objects.filter(slug__isnull=False).first() |
|||
if t: |
|||
if not check_link("Narrator", t.share_link, "{origin}/arguments/narrators/"): |
|||
success = False |
|||
|
|||
# 4. Source (BookReference) |
|||
br = BookReference.objects.filter(slug__isnull=False).first() |
|||
if br: |
|||
if not check_link("Source", br.share_link, "{origin}/arguments/sources/"): |
|||
success = False |
|||
|
|||
# 5. Article |
|||
a = Article.objects.filter(slug__isnull=False).first() |
|||
if a: |
|||
if not check_link("Article", a.share_link, "{origin}/articles/"): |
|||
success = False |
|||
|
|||
# 6. Podcast |
|||
p = Podcast.objects.filter(slug__isnull=False).first() |
|||
if p: |
|||
if not check_link("Podcast", p.share_link, "{origin}/podcast/"): |
|||
success = False |
|||
|
|||
# 7. Video |
|||
v = Video.objects.filter(slug__isnull=False).first() |
|||
if v: |
|||
if not check_link("Video", v.share_link, "{origin}/videos/"): |
|||
success = False |
|||
|
|||
# 8. Library Book |
|||
lb = Book.objects.filter(slug__isnull=False).first() |
|||
if lb: |
|||
if not check_link("Library Book", lb.share_link, "{origin}/library/"): |
|||
success = False |
|||
|
|||
print("=" * 60) |
|||
if success: |
|||
print("🎉 ALL CHECKS PASSED!") |
|||
else: |
|||
print("⚠️ SOME CHECKS FAILED. Please review the output above.") |
|||
|
|||
if __name__ == "__main__": |
|||
main() |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue