2 changed files with 249 additions and 584 deletions
@ -1,613 +1,260 @@ |
|||
""" |
|||
Django management command to seed mock data for hadith transmitters and related models. |
|||
Place this file in: yourapp/management/commands/seed_transmitters.py |
|||
|
|||
Usage: python manage.py seed_transmitters |
|||
python manage.py seed_transmitters --clear |
|||
""" |
|||
|
|||
import json |
|||
import random |
|||
from django.core.management.base import BaseCommand |
|||
from django.utils.text import slugify |
|||
from apps.hadis.models.transmitter import ( |
|||
NarratorLayer, |
|||
Transmitters, |
|||
HadisTransmitter, |
|||
TransmitterOpinion, |
|||
TransmitterOriginalText |
|||
from django.core.exceptions import ObjectDoesNotExist |
|||
# Ensure these imports match your actual app structure |
|||
from apps.hadis.models import ( |
|||
NarratorLayer, |
|||
Transmitters, |
|||
HadisTransmitter, |
|||
TransmitterOpinion, |
|||
TransmitterOriginalText, |
|||
Hadis |
|||
) |
|||
|
|||
|
|||
class Command(BaseCommand): |
|||
help = 'Seed the database with mock hadith transmitter data' |
|||
help = 'Seeds the database with mock Transmitters, Layers, and Chains' |
|||
|
|||
def add_arguments(self, parser): |
|||
parser.add_argument( |
|||
'--clear', |
|||
action='store_true', |
|||
help='Clear existing data before seeding', |
|||
) |
|||
def create_json_field(self, en_text, fa_text, ru_text): |
|||
"""Helper to create your specific JSON format with Russian added""" |
|||
return [ |
|||
{"text": en_text, "language_code": "en"}, |
|||
{"text": fa_text, "language_code": "fa"}, |
|||
{"text": ru_text, "language_code": "ru"} |
|||
] |
|||
|
|||
def handle(self, *args, **options): |
|||
if options['clear']: |
|||
self.stdout.write(self.style.WARNING('Clearing existing transmitter data...')) |
|||
TransmitterOriginalText.objects.all().delete() |
|||
TransmitterOpinion.objects.all().delete() |
|||
HadisTransmitter.objects.all().delete() |
|||
Transmitters.objects.all().delete() |
|||
NarratorLayer.objects.all().delete() |
|||
self.stdout.write(self.style.SUCCESS('Data cleared successfully!')) |
|||
self.stdout.write("--- Starting Transmitters Mock Data Generation (Trilingual) ---") |
|||
|
|||
# Step 1: Create Narrator Layers (Tabaqat) |
|||
self.stdout.write(self.style.SUCCESS('\n📚 Creating Narrator Layers...')) |
|||
# --------------------------------------------------------- |
|||
# 1. Create Narrator Layers (Tabaqat) |
|||
# --------------------------------------------------------- |
|||
self.stdout.write("Creating Narrator Layers...") |
|||
layers_data = [ |
|||
{ |
|||
"name": "Sahaba (Companions)", |
|||
"number": 1, |
|||
"description": "The companions of Prophet Muhammad (PBUH) who heard directly from him." |
|||
}, |
|||
{ |
|||
"name": "Tabi'un (Successors)", |
|||
"number": 2, |
|||
"description": "Narrators who lived after the Prophet's era and heard from the companions." |
|||
}, |
|||
{ |
|||
"name": "Taba' Tabi'in (Followers of Successors)", |
|||
"number": 3, |
|||
"description": "Narrators who heard from the Successors." |
|||
}, |
|||
{ |
|||
"name": "Later Generations", |
|||
"number": 4, |
|||
"description": "Narrators from later Islamic centuries, known for their scholarship." |
|||
}, |
|||
{ |
|||
"name": "Modern Era Scholars", |
|||
"number": 5, |
|||
"description": "Contemporary scholars who have specialized knowledge of hadith narration." |
|||
}, |
|||
(1, "Companions", "صحابه", "Сподвижники", |
|||
"Companions of the Prophet", "یاران پیامبر", "Сподвижники Пророка"), |
|||
(2, "Successors", "تابعین", "Табиины", |
|||
"The generation after Companions", "نسل بعد از صحابه", "Поколение после сподвижников"), |
|||
(3, "Successors of Successors", "تابع تابعین", "Таби ат-Табиин", |
|||
"The third generation", "نسل سوم", "Третье поколение передатчиков"), |
|||
(4, "Students of the Imams", "شاگردان ائمه", "Ученики Имамов", |
|||
"Direct students of the Imams", "شاگردان مستقیم ائمه", "Прямые ученики Имамов"), |
|||
(5, "Minor Narrators", "راویان جزئی", "Малые передатчики", |
|||
"Lesser known narrators", "راویان کمتر شناخته شده", "Малоизвестные передатчики"), |
|||
] |
|||
|
|||
layers = {} |
|||
for layer_data in layers_data: |
|||
created_layers = [] |
|||
for num, en, fa, ru, en_d, fa_d, ru_d in layers_data: |
|||
layer, created = NarratorLayer.objects.get_or_create( |
|||
number=layer_data['number'], |
|||
number=num, |
|||
defaults={ |
|||
'name': layer_data['name'], |
|||
'description': layer_data['description'], |
|||
'slug': slugify(layer_data['name']) |
|||
'name': self.create_json_field(en, fa, ru), |
|||
'description': self.create_json_field(en_d, fa_d, ru_d) |
|||
} |
|||
) |
|||
layers[layer_data['number']] = layer |
|||
status = '✓ Created' if created else '• Updated' |
|||
self.stdout.write(f"{status}: {layer.name} (Layer {layer.number})") |
|||
created_layers.append(layer) |
|||
self.stdout.write(self.style.SUCCESS(f"Verified {len(created_layers)} layers.")) |
|||
|
|||
# Step 2: Create Transmitters (Hadith Narrators) |
|||
self.stdout.write(self.style.SUCCESS('\n👥 Creating Transmitters...')) |
|||
transmitters_data = [ |
|||
{ |
|||
"full_name": "Abu Hurayrah", |
|||
"kunya": "Abu Hurayrah", |
|||
"known_as": "Abd al-Rahman ibn Sakhr", |
|||
"nickname": "Father of the Kitten", |
|||
"origin": "Yamama, Arabia", |
|||
"lived_in": "Medina, Syria", |
|||
"died_in": "Medina", |
|||
"birth_year_hijri": 7, |
|||
"death_year_hijri": 58, |
|||
"age_at_death": 78, |
|||
"generation": 1, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "sunni", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "One of the most prolific hadith narrators, reported 5,374 ahadith.", |
|||
"narrator_layer": 1, |
|||
}, |
|||
{ |
|||
"full_name": "Aisha bint Abu Bakr", |
|||
"kunya": "Umm al-Mu'minin", |
|||
"known_as": "Mother of the Believers", |
|||
"nickname": "Al-Siddiqa", |
|||
"origin": "Medina", |
|||
"lived_in": "Medina", |
|||
"died_in": "Medina", |
|||
"birth_year_hijri": None, |
|||
"death_year_hijri": 58, |
|||
"age_at_death": 66, |
|||
"generation": 1, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "sunni", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "Wife of the Prophet Muhammad (PBUH), a major source of hadith about daily life.", |
|||
"narrator_layer": 1, |
|||
}, |
|||
{ |
|||
"full_name": "Jabir ibn Abdullah al-Ansari", |
|||
"kunya": "Abu Abdullah", |
|||
"known_as": "Jabir", |
|||
"nickname": "Al-Ansari", |
|||
"origin": "Medina", |
|||
"lived_in": "Medina", |
|||
"died_in": "Medina", |
|||
"birth_year_hijri": 10, |
|||
"death_year_hijri": 74, |
|||
"age_at_death": 94, |
|||
"generation": 1, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "sunni", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "One of the long-lived companions, reported numerous ahadith on various topics.", |
|||
"narrator_layer": 1, |
|||
}, |
|||
{ |
|||
"full_name": "Imam Malik ibn Anas", |
|||
"kunya": "Abu Abdullah", |
|||
"known_as": "Malik", |
|||
"nickname": "Imam of Imams", |
|||
"origin": "Medina", |
|||
"lived_in": "Medina", |
|||
"died_in": "Medina", |
|||
"birth_year_hijri": 93, |
|||
"death_year_hijri": 179, |
|||
"age_at_death": 86, |
|||
"generation": 3, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "maliki", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "Founder of the Maliki school of Islamic jurisprudence, compiler of Al-Muwatta.", |
|||
"narrator_layer": 3, |
|||
}, |
|||
{ |
|||
"full_name": "Al-Qasim ibn Muhammad", |
|||
"kunya": "Abu Muhammad", |
|||
"known_as": "Al-Qasim", |
|||
"nickname": "Son of the Rightly Guided", |
|||
"origin": "Medina", |
|||
"lived_in": "Medina", |
|||
"died_in": "Medina", |
|||
"birth_year_hijri": 38, |
|||
"death_year_hijri": 106, |
|||
"age_at_death": 68, |
|||
"generation": 2, |
|||
"reliability": "reliable", |
|||
"madhhab": "sunni", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "Son of Amir al-Mu'minin, known for his knowledge of Islamic jurisprudence.", |
|||
"narrator_layer": 2, |
|||
}, |
|||
{ |
|||
"full_name": "Urwa ibn al-Zubayr", |
|||
"kunya": "Abu Abdullah", |
|||
"known_as": "Urwa", |
|||
"nickname": "The Jurist", |
|||
"origin": "Medina", |
|||
"lived_in": "Medina, Mecca", |
|||
"died_in": "Medina", |
|||
"birth_year_hijri": 23, |
|||
"death_year_hijri": 94, |
|||
"age_at_death": 71, |
|||
"generation": 2, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "sunni", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "Prominent Tabi'un scholar and transmitter of hadith from Aisha.", |
|||
"narrator_layer": 2, |
|||
}, |
|||
{ |
|||
"full_name": "Abdullah ibn Abbas", |
|||
"kunya": "Abu Abbas", |
|||
"known_as": "Ibn Abbas", |
|||
"nickname": "Hibr al-Ummah (The Learned Scholar of the Nation)", |
|||
"origin": "Medina", |
|||
"lived_in": "Medina, Mecca, Basra", |
|||
"died_in": "Taif", |
|||
"birth_year_hijri": 3, |
|||
"death_year_hijri": 68, |
|||
"age_at_death": 71, |
|||
"generation": 1, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "sunni", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "Cousin of the Prophet (PBUH), famous for Quranic exegesis and hadith knowledge.", |
|||
"narrator_layer": 1, |
|||
}, |
|||
{ |
|||
"full_name": "Nafi' (Mawla of Ibn Umar)", |
|||
"kunya": "Abu Abdullah", |
|||
"known_as": "Nafi'", |
|||
"nickname": "The Freed Slave", |
|||
"origin": "Ethiopia", |
|||
"lived_in": "Medina", |
|||
"died_in": "Medina", |
|||
"birth_year_hijri": 25, |
|||
"death_year_hijri": 117, |
|||
"age_at_death": 92, |
|||
"generation": 2, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "sunni", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "Freed slave of Abdullah ibn Umar, transmitted numerous hadith from him.", |
|||
"narrator_layer": 2, |
|||
}, |
|||
{ |
|||
"full_name": "Imam Ahmad ibn Hanbal", |
|||
"kunya": "Abu Abdullah", |
|||
"known_as": "Ahmad", |
|||
"nickname": "Shaykh al-Islam", |
|||
"origin": "Khorasan", |
|||
"lived_in": "Baghdad", |
|||
"died_in": "Baghdad", |
|||
"birth_year_hijri": 164, |
|||
"death_year_hijri": 241, |
|||
"age_at_death": 77, |
|||
"generation": 4, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "hanbali", |
|||
"in_sahih_muslim": False, |
|||
"in_sahih_bukhari": False, |
|||
"description": "Founder of the Hanbali school, compiler of Musnad Ahmad with 40,000+ hadith.", |
|||
"narrator_layer": 3, |
|||
}, |
|||
{ |
|||
"full_name": "Sufyan ibn Uyayna", |
|||
"kunya": "Abu Muhammad", |
|||
"known_as": "Sufyan", |
|||
"nickname": "Amir al-Mu'minin fil-Hadith", |
|||
"origin": "Kufa", |
|||
"lived_in": "Mecca, Kufa", |
|||
"died_in": "Mecca", |
|||
"birth_year_hijri": 107, |
|||
"death_year_hijri": 198, |
|||
"age_at_death": 91, |
|||
"generation": 3, |
|||
"reliability": "very_reliable", |
|||
"madhhab": "shafii", |
|||
"in_sahih_muslim": True, |
|||
"in_sahih_bukhari": True, |
|||
"description": "Great hadith scholar and judge, known for his exceptional memory.", |
|||
"narrator_layer": 3, |
|||
# --------------------------------------------------------- |
|||
# 2. Create Transmitters |
|||
# --------------------------------------------------------- |
|||
self.stdout.write("Creating Transmitters...") |
|||
|
|||
transmitters_list = [ |
|||
{ |
|||
"full_name": ("Zurarah bin Ayan", "زرارة بن اعین", "Зурара ибн Аян"), |
|||
"kunya": ("Abu Ali", "ابو علی", "Абу Али"), |
|||
"origin": ("Kufa", "کوفه", "Куфа"), |
|||
"reliability": Transmitters.ReliabilityLevel.VERY_RELIABLE, |
|||
"madhhab": Transmitters.MadhhabChoices.SHIA, |
|||
"died": 150, |
|||
"layer": 4 |
|||
}, |
|||
{ |
|||
"full_name": ("Muhammad bin Muslim", "محمد بن مسلم", "Мухаммад ибн Муслим"), |
|||
"kunya": ("Abu Ja'far", "ابو جعفر", "Абу Джафар"), |
|||
"origin": ("Kufa", "کوفه", "Куфа"), |
|||
"reliability": Transmitters.ReliabilityLevel.VERY_RELIABLE, |
|||
"madhhab": Transmitters.MadhhabChoices.SHIA, |
|||
"died": 150, |
|||
"layer": 4 |
|||
}, |
|||
{ |
|||
"full_name": ("Abu Basir Al-Asadi", "ابو بصیر الاسدی", "Абу Басир Аль-Асади"), |
|||
"kunya": ("Abu Muhammad", "ابو محمد", "Абу Мухаммад"), |
|||
"origin": ("Kufa", "کوفه", "Куфа"), |
|||
"reliability": Transmitters.ReliabilityLevel.RELIABLE, |
|||
"madhhab": Transmitters.MadhhabChoices.SHIA, |
|||
"died": 150, |
|||
"layer": 4 |
|||
}, |
|||
{ |
|||
"full_name": ("Yunus bin Abd al-Rahman", "یونس بن عبدالرحمن", "Юнус ибн Абд ар-Рахман"), |
|||
"kunya": ("Abu Muhammad", "ابو محمد", "Абу Мухаммад"), |
|||
"origin": ("Baghdad", "بغداد", "Багдад"), |
|||
"reliability": Transmitters.ReliabilityLevel.VERY_RELIABLE, |
|||
"madhhab": Transmitters.MadhhabChoices.SHIA, |
|||
"died": 208, |
|||
"layer": 3 |
|||
}, |
|||
{ |
|||
"full_name": ("Hammad bin Isa", "حماد بن عیسی", "Хаммад ибн Иса"), |
|||
"kunya": ("Abu Amin", "ابو امین", "Абу Амин"), |
|||
"origin": ("Basra", "بصره", "Басра"), |
|||
"reliability": Transmitters.ReliabilityLevel.RELIABLE, |
|||
"madhhab": Transmitters.MadhhabChoices.SHIA, |
|||
"died": 209, |
|||
"layer": 3 |
|||
}, |
|||
{ |
|||
"full_name": ("Ibrahim bin Hashim", "ابراهیم بن هاشم", "Ибрагим ибн Хашим"), |
|||
"kunya": ("Abu Ishaq", "ابو اسحاق", "Абу Исхак"), |
|||
"origin": ("Qom", "قم", "Кум"), |
|||
"reliability": Transmitters.ReliabilityLevel.ACCEPTABLE, |
|||
"madhhab": Transmitters.MadhhabChoices.SHIA, |
|||
"died": 250, |
|||
"layer": 2 |
|||
}, |
|||
{ |
|||
"full_name": ("Sahl bin Ziyad", "سهل بن زیاد", "Сахль ибн Зияд"), |
|||
"kunya": ("Abu Sa'id", "ابو سعید", "Абу Саид"), |
|||
"origin": ("Rayy", "ری", "Рей"), |
|||
"reliability": Transmitters.ReliabilityLevel.WEAK, |
|||
"madhhab": Transmitters.MadhhabChoices.SHIA, |
|||
"died": 255, |
|||
"layer": 2 |
|||
}, |
|||
{ |
|||
"full_name": ("Jabir bin Hayyan", "جابر بن حیان", "Джабир ибн Хайян"), |
|||
"kunya": ("Abu Musa", "ابو موسی", "Абу Муса"), |
|||
"origin": ("Tus", "توس", "Тус"), |
|||
"reliability": Transmitters.ReliabilityLevel.UNKNOWN, |
|||
"madhhab": Transmitters.MadhhabChoices.OTHER, |
|||
"died": 195, |
|||
"layer": 3 |
|||
}, |
|||
] |
|||
|
|||
transmitters = {} |
|||
for trans_data in transmitters_data: |
|||
narrator_layer_num = trans_data.pop('narrator_layer') |
|||
narrator_layer = layers.get(narrator_layer_num) |
|||
|
|||
transmitter, created = Transmitters.objects.get_or_create( |
|||
full_name=trans_data['full_name'], |
|||
defaults=trans_data |
|||
) |
|||
transmitters[trans_data['full_name']] = transmitter |
|||
status = '✓ Created' if created else '• Updated' |
|||
self.stdout.write(f"{status}: {transmitter.full_name}") |
|||
created_transmitters = [] |
|||
|
|||
# Step 3: Create Transmitter Opinions |
|||
self.stdout.write(self.style.SUCCESS('\n💬 Creating Transmitter Opinions...')) |
|||
opinions_data = [ |
|||
{ |
|||
"transmitter_name": "Abu Hurayrah", |
|||
"scholar_name": "Imam al-Bukhari", |
|||
"opinion_text": "Abu Hurayrah is one of the most reliable narrators with a perfect memory and integrity.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Abu Hurayrah", |
|||
"scholar_name": "Imam Muslim", |
|||
"opinion_text": "His narrations are authentic and widely accepted in the Islamic jurisprudence.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Aisha bint Abu Bakr", |
|||
"scholar_name": "Imam al-Bukhari", |
|||
"opinion_text": "The Mother of the Believers is the most reliable source for hadith about the Prophet's household.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Jabir ibn Abdullah al-Ansari", |
|||
"scholar_name": "Ibn Hajar al-Asqalani", |
|||
"opinion_text": "His longevity allowed him to transmit from many companions and successors.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Imam Malik ibn Anas", |
|||
"scholar_name": "Imam ash-Shafi'i", |
|||
"opinion_text": "Malik is among the most knowledgeable of the Medinese scholars in jurisprudence.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Imam Malik ibn Anas", |
|||
"scholar_name": "Imam Ahmad ibn Hanbal", |
|||
"opinion_text": "Malik's narrations form the basis of sound Islamic jurisprudence.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Al-Qasim ibn Muhammad", |
|||
"scholar_name": "Ibn Hajar al-Asqalani", |
|||
"opinion_text": "Al-Qasim is a trustworthy narrator from the Tabi'un generation with reliable traditions.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Urwa ibn al-Zubayr", |
|||
"scholar_name": "Imam al-Bukhari", |
|||
"opinion_text": "Urwa is among the most knowledgeable about the traditions of the Prophet's household.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Abdullah ibn Abbas", |
|||
"scholar_name": "Imam at-Tirmidhi", |
|||
"opinion_text": "Ibn Abbas has exceptional knowledge in Quranic interpretation and hadith narration.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Nafi' (Mawla of Ibn Umar)", |
|||
"scholar_name": "Imam Muslim", |
|||
"opinion_text": "Nafi' is one of the most reliable freed slaves who transmitted authentic traditions.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Imam Ahmad ibn Hanbal", |
|||
"scholar_name": "Ibn Hajar al-Asqalani", |
|||
"opinion_text": "Ahmad ibn Hanbal's knowledge of hadith is unparalleled in his era.", |
|||
"status": "confirmed" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Sufyan ibn Uyayna", |
|||
"scholar_name": "Imam al-Bukhari", |
|||
"opinion_text": "Sufyan is a highly reliable hadith scholar with exceptional memory.", |
|||
"status": "confirmed" |
|||
}, |
|||
] |
|||
for t_data in transmitters_list: |
|||
# Check if exists by simple slug check (EN name) |
|||
en_name = t_data["full_name"][0] |
|||
# Replace spaces with dash for rough slug matching |
|||
slug_guess = en_name.lower().replace(' ', '-') |
|||
|
|||
existing = Transmitters.objects.filter(slug__startswith=slug_guess) |
|||
|
|||
if existing.exists(): |
|||
self.stdout.write(f"Skipping {en_name}, likely exists.") |
|||
created_transmitters.append(existing.first()) |
|||
continue |
|||
|
|||
for opinion_data in opinions_data: |
|||
transmitter_name = opinion_data.pop('transmitter_name') |
|||
transmitter = transmitters.get(transmitter_name) |
|||
if transmitter: |
|||
opinion, created = TransmitterOpinion.objects.get_or_create( |
|||
transmitter=transmitter, |
|||
scholar_name=opinion_data['scholar_name'], |
|||
defaults=opinion_data |
|||
transmitter = Transmitters( |
|||
full_name=self.create_json_field(*t_data["full_name"]), |
|||
kunya=self.create_json_field(*t_data["kunya"]), |
|||
origin=self.create_json_field(*t_data["origin"]), |
|||
lived_in=self.create_json_field(*t_data["origin"]), |
|||
died_in=self.create_json_field("Unknown", "نامشخص", "Неизвестно"), |
|||
reliability=t_data["reliability"], |
|||
madhhab=t_data["madhhab"], |
|||
death_year_hijri=t_data["died"], |
|||
description=self.create_json_field( |
|||
f"A narrator from {t_data['origin'][0]}", |
|||
f"راوی اهل {t_data['origin'][1]}", |
|||
f"Передатчик из города {t_data['origin'][2]}" |
|||
) |
|||
if created: |
|||
self.stdout.write( |
|||
self.style.SUCCESS( |
|||
f"✓ Opinion added: {opinion_data['scholar_name']} on {transmitter_name}" |
|||
) |
|||
) |
|||
|
|||
# Step 4: Create Original Texts |
|||
self.stdout.write(self.style.SUCCESS('\n📜 Creating Transmitter Original Texts...')) |
|||
original_texts_data = [ |
|||
{ |
|||
"transmitter_name": "Abu Hurayrah", |
|||
"title": "His Narration on Zakat", |
|||
"text": "حدثنا أبو هريرة قال: قال رسول الله صلى الله عليه وسلم: من آمن بالله واليوم الآخر فليؤد الزكاة", |
|||
"translation": [ |
|||
{"language_code": "en", "text": "Abu Hurayrah narrated: The Messenger of Allah (PBUH) said: Whoever believes in Allah and the Last Day, let him pay the Zakat (alms)."}, |
|||
{"language_code": "ar", "text": "أبو هريرة: من آمن بالله واليوم الآخر فليؤد الزكاة"} |
|||
], |
|||
"share_link": "https://hadith.example.com/abu-hurayrah/zakat-1" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Aisha bint Abu Bakr", |
|||
"title": "Her Account of the Prophet's Night Prayer", |
|||
"text": "قالت عائشة: كان النبي صلى الله عليه وسلم يقوم الليل فيصلي ثلاث عشرة ركعة", |
|||
"translation": [ |
|||
{"language_code": "en", "text": "Aisha said: The Prophet (PBUH) used to pray at night thirteen rak'ahs."}, |
|||
{"language_code": "ar", "text": "عائشة: كان النبي يقوم الليل بثلاث عشرة ركعة"} |
|||
], |
|||
"share_link": "https://hadith.example.com/aisha/night-prayer-1" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Jabir ibn Abdullah al-Ansari", |
|||
"title": "The Farewell Hajj Narration", |
|||
"text": "قال جابر: خرجنا مع رسول الله صلى الله عليه وسلم في حجة الوداع", |
|||
"translation": [ |
|||
{"language_code": "en", "text": "Jabir narrated: We went out with the Messenger of Allah (PBUH) for the Farewell Hajj."}, |
|||
{"language_code": "ar", "text": "جابر: خرجنا مع رسول الله في حجة الوداع"} |
|||
], |
|||
"share_link": "https://hadith.example.com/jabir/farewell-hajj-1" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Imam Malik ibn Anas", |
|||
"title": "Narration on Purity and Prayer", |
|||
"text": "قال مالك: الطهارة شرط من شروط الصلاة", |
|||
"translation": [ |
|||
{"language_code": "en", "text": "Malik said: Purification is a condition for the validity of prayer."}, |
|||
{"language_code": "ar", "text": "مالك: الطهارة من شروط صحة الصلاة"} |
|||
], |
|||
"share_link": "https://hadith.example.com/malik/purity-1" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Abdullah ibn Abbas", |
|||
"title": "His Commentary on Divine Justice", |
|||
"text": "قال ابن عباس: إن الله تعالى عدل لا يظلم أحدا", |
|||
"translation": [ |
|||
{"language_code": "en", "text": "Ibn Abbas said: Truly Allah is Just and does not oppress anyone."}, |
|||
{"language_code": "ar", "text": "ابن عباس: الله عدل لا يظلم أحدا"} |
|||
], |
|||
"share_link": "https://hadith.example.com/ibn-abbas/justice-1" |
|||
}, |
|||
{ |
|||
"transmitter_name": "Sufyan ibn Uyayna", |
|||
"title": "Teaching on Knowledge Seeking", |
|||
"text": "قال سفيان بن عيينة: طلب العلم فريضة على كل مسلم", |
|||
"translation": [ |
|||
{"language_code": "en", "text": "Sufyan ibn Uyayna said: Seeking knowledge is an obligation for every Muslim."}, |
|||
{"language_code": "ar", "text": "سفيان: طلب العلم فريضة على كل مسلم"} |
|||
], |
|||
"share_link": "https://hadith.example.com/sufyan/knowledge-1" |
|||
}, |
|||
] |
|||
) |
|||
transmitter.save() |
|||
created_transmitters.append(transmitter) |
|||
self.stdout.write(self.style.SUCCESS(f"Created transmitter: {en_name}")) |
|||
|
|||
for text_data in original_texts_data: |
|||
transmitter_name = text_data.pop('transmitter_name') |
|||
transmitter = transmitters.get(transmitter_name) |
|||
if transmitter: |
|||
original_text, created = TransmitterOriginalText.objects.get_or_create( |
|||
transmitter=transmitter, |
|||
title=text_data['title'], |
|||
defaults=text_data |
|||
# --------------------------------------------------------- |
|||
# 3. Create Opinions |
|||
# --------------------------------------------------------- |
|||
self.stdout.write("Adding Opinions...") |
|||
if created_transmitters: |
|||
t_target = created_transmitters[0] # Zurarah |
|||
TransmitterOpinion.objects.create( |
|||
transmitter=t_target, |
|||
scholar_name=self.create_json_field("Al-Najashi", "النجاشی", "Аль-Наджаши"), |
|||
opinion_text=self.create_json_field( |
|||
"He is the master of our companions and their teacher.", |
|||
"او بزرگ اصحاب ما و استاد آنان است.", |
|||
"Он — господин наших сподвижников и их учитель." |
|||
), |
|||
status=TransmitterOpinion.OpinionStatus.CONFIRMED |
|||
) |
|||
|
|||
t_weak = next((t for t in created_transmitters if t.reliability == 'weak'), None) |
|||
if t_weak: |
|||
TransmitterOpinion.objects.create( |
|||
transmitter=t_weak, |
|||
scholar_name=self.create_json_field("Ibn al-Ghadairi", "ابن الغضائری", "Ибн аль-Гадаири"), |
|||
opinion_text=self.create_json_field( |
|||
"Weak in hadith, extremist in belief.", |
|||
"ضعیف در حدیث، غالی در مذهب.", |
|||
"Слаб в хадисах, экстремист в убеждениях." |
|||
), |
|||
status=TransmitterOpinion.OpinionStatus.REJECTED |
|||
) |
|||
if created: |
|||
self.stdout.write( |
|||
self.style.SUCCESS( |
|||
f"✓ Original text added: {text_data['title']} by {transmitter_name}" |
|||
) |
|||
) |
|||
|
|||
# Step 5: Create Hadis Transmitters (Chain of narration) |
|||
self.stdout.write(self.style.SUCCESS('\n⛓️ Creating Hadis Transmitters (Chains)...')) |
|||
# --------------------------------------------------------- |
|||
# 4. Create Original Texts |
|||
# --------------------------------------------------------- |
|||
self.stdout.write("Adding Original Texts...") |
|||
if created_transmitters: |
|||
t_author = created_transmitters[1] # Muhammad bin Muslim |
|||
TransmitterOriginalText.objects.create( |
|||
transmitter=t_author, |
|||
title=self.create_json_field( |
|||
"Book of Four Hundred Problems", |
|||
"کتاب چهارصد مسئله", |
|||
"Книга четырехсот вопросов" |
|||
), |
|||
text=self.create_json_field( |
|||
"Content of the book regarding jurisprudence...", |
|||
"محتوای کتاب در مورد فقه...", |
|||
"Содержание книги по исламскому праву..." |
|||
), |
|||
translation=self.create_json_field( |
|||
"English Translation...", |
|||
"ترجمه فارسی...", |
|||
"Русский перевод..." |
|||
), |
|||
) |
|||
|
|||
# --------------------------------------------------------- |
|||
# 5. Link Transmitters to Hadis |
|||
# --------------------------------------------------------- |
|||
self.stdout.write("Linking Transmitters to Hadis (1877-1888)...") |
|||
|
|||
# Sample hadis IDs to use (you can have any ID from 1800 to 1852) |
|||
hadis_ids = list(range(1800, 1853)) |
|||
target_hadis_ids = range(1877, 1889) |
|||
|
|||
# Create chains for different hadis |
|||
chains_data = [ |
|||
{ |
|||
"hadis_id": hadis_ids[0], |
|||
"chain": [ |
|||
{"transmitter_name": "Abu Hurayrah", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Imam Malik ibn Anas", "order": 2, "layer": 3, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[1], |
|||
"chain": [ |
|||
{"transmitter_name": "Aisha bint Abu Bakr", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Urwa ibn al-Zubayr", "order": 2, "layer": 2, "status": "reliable"}, |
|||
{"transmitter_name": "Imam Malik ibn Anas", "order": 3, "layer": 3, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[2], |
|||
"chain": [ |
|||
{"transmitter_name": "Jabir ibn Abdullah al-Ansari", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Al-Qasim ibn Muhammad", "order": 2, "layer": 2, "status": "reliable"}, |
|||
{"transmitter_name": "Sufyan ibn Uyayna", "order": 3, "layer": 3, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[3], |
|||
"chain": [ |
|||
{"transmitter_name": "Abdullah ibn Abbas", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Nafi' (Mawla of Ibn Umar)", "order": 2, "layer": 2, "status": "reliable"}, |
|||
{"transmitter_name": "Imam Ahmad ibn Hanbal", "order": 3, "layer": 3, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[4], |
|||
"chain": [ |
|||
{"transmitter_name": "Abu Hurayrah", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Sufyan ibn Uyayna", "order": 2, "layer": 3, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[5], |
|||
"chain": [ |
|||
{"transmitter_name": "Aisha bint Abu Bakr", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Al-Qasim ibn Muhammad", "order": 2, "layer": 2, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[6], |
|||
"chain": [ |
|||
{"transmitter_name": "Jabir ibn Abdullah al-Ansari", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Nafi' (Mawla of Ibn Umar)", "order": 2, "layer": 2, "status": "reliable"}, |
|||
{"transmitter_name": "Imam Malik ibn Anas", "order": 3, "layer": 3, "status": "reliable"}, |
|||
{"transmitter_name": "Sufyan ibn Uyayna", "order": 4, "layer": 3, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[7], |
|||
"chain": [ |
|||
{"transmitter_name": "Abdullah ibn Abbas", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Urwa ibn al-Zubayr", "order": 2, "layer": 2, "status": "reliable"}, |
|||
{"transmitter_name": "Imam Ahmad ibn Hanbal", "order": 3, "layer": 3, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[8], |
|||
"chain": [ |
|||
{"transmitter_name": "Abu Hurayrah", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Al-Qasim ibn Muhammad", "order": 2, "layer": 2, "status": "reliable"}, |
|||
{"transmitter_name": "Imam Malik ibn Anas", "order": 3, "layer": 3, "status": "reliable"}, |
|||
{"transmitter_name": "Sufyan ibn Uyayna", "order": 4, "layer": 3, "status": "reliable"}, |
|||
] |
|||
}, |
|||
{ |
|||
"hadis_id": hadis_ids[9], |
|||
"chain": [ |
|||
{"transmitter_name": "Aisha bint Abu Bakr", "order": 1, "layer": 1, "status": "reliable"}, |
|||
{"transmitter_name": "Nafi' (Mawla of Ibn Umar)", "order": 2, "layer": 2, "status": "reliable"}, |
|||
] |
|||
}, |
|||
] |
|||
for hadis_id in target_hadis_ids: |
|||
try: |
|||
hadis_obj = Hadis.objects.get(id=hadis_id) |
|||
except ObjectDoesNotExist: |
|||
self.stdout.write(self.style.WARNING(f"Hadis ID {hadis_id} not found. Skipping.")) |
|||
continue |
|||
|
|||
HadisTransmitter.objects.filter(hadis=hadis_obj).delete() |
|||
|
|||
hadis_transmitter_count = 0 |
|||
for chain_data in chains_data: |
|||
hadis_id = chain_data['hadis_id'] |
|||
chain = chain_data['chain'] |
|||
# Create a random chain of 3 transmitters |
|||
chain_length = 3 |
|||
chain_narrators = random.sample(created_transmitters, min(len(created_transmitters), chain_length)) |
|||
|
|||
for item in chain: |
|||
transmitter = transmitters.get(item['transmitter_name']) |
|||
layer = layers.get(item['layer']) |
|||
for index, narrator in enumerate(chain_narrators): |
|||
layer_obj = NarratorLayer.objects.get(number=5-index) if index < 5 else None |
|||
|
|||
if transmitter and layer: |
|||
hadis_trans, created = HadisTransmitter.objects.get_or_create( |
|||
hadis_id=hadis_id, |
|||
transmitter=transmitter, |
|||
order=item['order'], |
|||
defaults={ |
|||
'narrator_layer': layer, |
|||
'status': item['status'], |
|||
'is_gap': False |
|||
} |
|||
) |
|||
if created: |
|||
hadis_transmitter_count += 1 |
|||
self.stdout.write( |
|||
self.style.SUCCESS( |
|||
f"✓ Chain link: Hadis {hadis_id} <- {item['transmitter_name']} (Order {item['order']})" |
|||
) |
|||
) |
|||
|
|||
self.stdout.write( |
|||
self.style.SUCCESS( |
|||
f'\n✓ Successfully seeded transmitter data!' |
|||
) |
|||
) |
|||
self._print_summary(transmitters, hadis_transmitter_count) |
|||
|
|||
def _print_summary(self, transmitters, hadis_transmitter_count): |
|||
"""Print a summary of created data""" |
|||
self.stdout.write("\n" + "="*70) |
|||
self.stdout.write(self.style.SUCCESS("TRANSMITTER DATABASE SUMMARY")) |
|||
self.stdout.write("="*70) |
|||
|
|||
layers_count = NarratorLayer.objects.count() |
|||
transmitters_count = Transmitters.objects.count() |
|||
opinions_count = TransmitterOpinion.objects.count() |
|||
original_texts_count = TransmitterOriginalText.objects.count() |
|||
HadisTransmitter.objects.create( |
|||
hadis=hadis_obj, |
|||
transmitter=narrator, |
|||
narrator_layer=layer_obj, |
|||
order=index + 1, |
|||
status=HadisTransmitter.ReliabilityStatus.RELIABLE, |
|||
is_gap=False |
|||
) |
|||
|
|||
self.stdout.write(f"Created chain for Hadis {hadis_id} with {len(chain_narrators)} transmitters.") |
|||
|
|||
self.stdout.write(f"📚 Narrator Layers: {layers_count}") |
|||
self.stdout.write(f"👥 Total Transmitters: {transmitters_count}") |
|||
self.stdout.write(f"💬 Transmitter Opinions: {opinions_count}") |
|||
self.stdout.write(f"📜 Original Texts: {original_texts_count}") |
|||
self.stdout.write(f"⛓️ Hadis Transmitter Chains: {hadis_transmitter_count}") |
|||
|
|||
self.stdout.write("\n" + "="*70) |
|||
self.stdout.write(self.style.WARNING("Notable Transmitters Created:")) |
|||
self.stdout.write("="*70) |
|||
for name in list(transmitters.keys())[:5]: |
|||
self.stdout.write(f" • {name}") |
|||
self.stdout.write(f" ... and {max(0, len(transmitters) - 5)} more") |
|||
self.stdout.write("="*70 + "\n") |
|||
self.stdout.write(self.style.SUCCESS("--- Mock Data Generation Complete ---")) |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue