diff --git a/helpdesk/horilla_faq_data.json b/helpdesk/horilla_faq_data.json new file mode 100644 index 000000000..dc119e522 --- /dev/null +++ b/helpdesk/horilla_faq_data.json @@ -0,0 +1,56 @@ +{ + "FAQ_CATEGORY": [ + { + "title": "Leave", + "description": "FAQs related to leave are shown here" + }, + { + "title": "Attendance", + "description": "FAQs related to attendance are shown here" + }, + { + "title": "Employee", + "description": "FAQs related to employee are shown here" + }, + { + "title": "Base", + "description": "FAQs related to base are shown here" + }, + { + "title": "Recruitment", + "description": "FAQs related to recruitment are shown here" + } + ], + "FAQS": [ + { + "category": "Leave", + "question": "How to create a leave request?", + "answer": "Click on My Leave Request > Select Leave Type > Fill out the form" + }, + { + "category": "Attendance", + "question": "How to export work records?", + "answer": "Click on Work Records inside Attendance, filter the data and click on Export button" + }, + { + "category": "Base", + "question": "How to create a shift request?", + "answer": "go to employee --> shift request --> create --> Fill out the form" + }, + { + "category": "Recruitment", + "question": "How to add stage managers to an existing stage?", + "answer": "recruitment --> stage 3 dot --> edit --> managers" + }, + { + "category": "Recruitment", + "question": "What is recruitment pipeline?", + "answer": "All the details about the recruitment, stage, and candidate can be controlled from here." + }, + { + "category": "Employee", + "question": "How to create an Employee?", + "answer": "employee --> create --> Fill out the form" + } + ] +} \ No newline at end of file diff --git a/helpdesk/management/commands/__init__.py b/helpdesk/management/commands/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/helpdesk/management/commands/create_faqs.py b/helpdesk/management/commands/create_faqs.py new file mode 100644 index 000000000..ed5280616 --- /dev/null +++ b/helpdesk/management/commands/create_faqs.py @@ -0,0 +1,58 @@ +import json +from django.core.management.base import BaseCommand +from helpdesk.models import FAQCategory, FAQ + +class Command(BaseCommand): + help = 'Create FAQ categories and FAQs from a JSON file' + + def add_arguments(self, parser): + parser.add_argument( + 'file_path', type=str, help='The path to the JSON file containing FAQ categories and FAQs' + ) + + def handle(self, *args, **kwargs): + file_path = kwargs['file_path'] + + try: + with open(file_path, 'r') as file: + data_dict = json.load(file) + + faq_categories = data_dict.get('FAQ_CATEGORY', []) + faqs = data_dict.get('FAQS', []) + + for category_data in faq_categories: + title = category_data.get('title') + description = category_data.get('description') + category, created = FAQCategory.objects.get_or_create( + title=title, defaults={'description': description} + ) + if not created: + category.description = description + category.save() + + for faq_data in faqs: + category_title = faq_data.get('category') + question = faq_data.get('question') + answer = faq_data.get('answer') + + try: + category = FAQCategory.objects.get(title=category_title) + except FAQCategory.DoesNotExist: + self.stdout.write(self.style.ERROR(f'Category "{category_title}" does not exist. Skipping FAQ: {question}')) + continue + + FAQ.objects.get_or_create( + question=question, + defaults={ + 'answer': answer, + 'category': category, + } + ) + self.stdout.write(self.style.SUCCESS('Successfully created FAQs and FAQ categories.')) + + except FileNotFoundError: + self.stdout.write(self.style.ERROR(f'File not found: {file_path}')) + except json.JSONDecodeError as e: + self.stdout.write(self.style.ERROR(f'Invalid JSON format: {e}')) + except Exception as e: + self.stdout.write(self.style.ERROR(f'Error: {e}'))