Commit 394320e2 authored by DwyxE's avatar DwyxE

error again i give up !

parent 72d2568a
# Generated by Django 4.2 on 2023-04-04 09:34 # Generated by Django 4.2 on 2023-04-04 10:24
from django.db import migrations, models from django.db import migrations, models
import django.db.models.deletion import django.db.models.deletion
...@@ -50,7 +50,7 @@ class Migration(migrations.Migration): ...@@ -50,7 +50,7 @@ class Migration(migrations.Migration):
migrations.CreateModel( migrations.CreateModel(
name='SummaryReport', name='SummaryReport',
fields=[ fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('sr_no', models.AutoField(primary_key=True, serialize=False)),
('prod_score', models.IntegerField()), ('prod_score', models.IntegerField()),
('date', models.DateField()), ('date', models.DateField()),
('totalworkhrs', models.DurationField()), ('totalworkhrs', models.DurationField()),
......
...@@ -93,6 +93,8 @@ class History(models.Model): ...@@ -93,6 +93,8 @@ class History(models.Model):
# totalworkhrs = models.DurationField() # totalworkhrs = models.DurationField()
class SummaryReport(models.Model): class SummaryReport(models.Model):
sr_no = models.AutoField(primary_key=True)
employee_name = models.CharField(max_length=255)
prod_score = models.IntegerField() prod_score = models.IntegerField()
date = models.DateField() date = models.DateField()
totalworkhrs = models.DurationField() totalworkhrs = models.DurationField()
......
<table> <table>
<thead> <thead>
<tr> <tr>
<th>SR No</th>
<th>Employee Name</th>
<th>Date</th> <th>Date</th>
<th>Prod Score</th> <th>Prod Score</th>
<th>Total Work Hrs</th> <th>Total Work Hrs</th>
...@@ -10,6 +12,8 @@ ...@@ -10,6 +12,8 @@
<tbody> <tbody>
{% for row in csv_data %} {% for row in csv_data %}
<tr> <tr>
<td>{{ row.sr_no}}</td>
<td>{{ row.employee_name}}</td>
<td>{{ row.date}}</td> <td>{{ row.date}}</td>
<td>{{ row.productivity_score }}</td> <td>{{ row.productivity_score }}</td>
<td>{{ row.totalworkhrs }}</td> <td>{{ row.totalworkhrs }}</td>
......
...@@ -64,6 +64,49 @@ def loginpage(request): ...@@ -64,6 +64,49 @@ def loginpage(request):
else: else:
return render(request, 'EmployeeProdDB/loginpage.html') return render(request, 'EmployeeProdDB/loginpage.html')
def upload_csv(request):
if request.method == 'POST':
csv_file = request.FILES['csv_file']
if not csv_file.name.endswith('.csv'):
messages.error(request, 'This is not a CSV file')
else:
# read the data from the uploaded file
csv_data = csv.reader(
(line.decode('utf-8') for line in csv_file),
delimiter=',',
quotechar='"'
)
#Loop through data rows
for i, row in enumerate(csv_data):
# Check if this row is the start of a new report
if row[0] == 'PRODUCTIVITY REPORT':
# Reset variables for the new report
sr_no = row[1]
employee_name= None
prod_score = None
date = None
totalworkhrs = None
# Check if this is the fifth row after the start of the report
elif i == 4 and employee_name is None:
employee_name = row[0]
# Check if this row contains a date and "Total Duration:" and "Productivity %"
if len(row) > 2 and "/" in row[0] and "Total Duration:" in row and "Productivity %" in row:
date = datetime.strptime(row[0], '%m/%d/%Y').date()
totalworkhrs = timedelta(hours=float(row[row.index("Total Duration:") + 2]))
prod_score = int(row[row.index("Productivity %") + 2])
summary_pr = SummaryReport.objects.create(sr_no=sr_no, employee_name=employee_name, prod_score=prod_score, date=date, totalworkhrs=totalworkhrs)
summary_pr.save()
return redirect('home')
return render(request, 'EmployeeProdDB/upload_csv.html')
def upload_csv(request): def upload_csv(request):
if request.method == 'POST': if request.method == 'POST':
csv_file = request.FILES['csv_file'] csv_file = request.FILES['csv_file']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment