From 52473cdafcc8ff6adc681f14e358708f74fc31ac Mon Sep 17 00:00:00 2001 From: masterking008 Date: Tue, 22 Oct 2024 14:59:00 +0530 Subject: [PATCH 1/3] frontend --- .../management/commands/upload_projects.py | 45 ++++++++++++++++++- socfrontend/src/components/Navbar.js | 2 +- socfrontend/src/pages/Home.jsx | 17 +++---- socfrontend/src/pages/Login.jsx | 41 ++++++++++++++--- 4 files changed, 86 insertions(+), 19 deletions(-) diff --git a/socbackend/projects/management/commands/upload_projects.py b/socbackend/projects/management/commands/upload_projects.py index 89bc9db..967129e 100644 --- a/socbackend/projects/management/commands/upload_projects.py +++ b/socbackend/projects/management/commands/upload_projects.py @@ -1,3 +1,46 @@ # Write your functions for uploading the projects from csv file.. -# Use projects.csv \ No newline at end of file +# Use projects.csv +import csv +from django.core.management.base import BaseCommand +from projects.models import Project # Assuming you have a Project model +from django.db import IntegrityError + +class Command(BaseCommand): + help = 'Upload projects from a CSV file' + + def add_arguments(self, parser): + # Argument for the CSV file path + parser.add_argument('csv_file', type=str, help='Path to the CSV file') + + def handle(self, *args, **kwargs): + csv_file = kwargs['csv_file'] + + # Open the CSV file + with open(csv_file, newline='', encoding='utf-8') as file: + reader = csv.DictReader(file) + + for row in reader: + try: + # Replace 'name', 'description' with your actual field names + project, created = Project.objects.update_or_create( + name=row['name'], + defaults={ + 'description': row['description'], + 'start_date': row['start_date'], # Adjust field names as per your model + 'end_date': row['end_date'], + } + ) + + if created: + self.stdout.write(self.style.SUCCESS(f"Project '{project.name}' created successfully.")) + else: + self.stdout.write(self.style.SUCCESS(f"Project '{project.name}' updated successfully.")) + + except KeyError as e: + self.stdout.write(self.style.ERROR(f"Missing field in CSV: {e}")) + except IntegrityError as e: + self.stdout.write(self.style.ERROR(f"Database error: {e}")) + except Exception as e: + self.stdout.write(self.style.ERROR(f"An error occurred: {e}")) + diff --git a/socfrontend/src/components/Navbar.js b/socfrontend/src/components/Navbar.js index fdd959a..dc73149 100644 --- a/socfrontend/src/components/Navbar.js +++ b/socfrontend/src/components/Navbar.js @@ -15,7 +15,7 @@ export default function Navbar(props) { return (