2025-01-30 13:07:48 +06:00
|
|
|
from django.shortcuts import render, HttpResponse, get_object_or_404
|
2025-01-26 11:22:57 +06:00
|
|
|
from .models import resulation
|
2025-01-30 13:07:48 +06:00
|
|
|
from datetime import datetime
|
|
|
|
import os, uuid
|
|
|
|
import misdghs.settings
|
|
|
|
from django.http import FileResponse
|
2025-01-26 11:22:57 +06:00
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
def Home(request):
|
|
|
|
return render(request,'resulation/home.html')
|
|
|
|
|
2025-01-30 13:07:48 +06:00
|
|
|
def Savepdf(request):
|
|
|
|
if request.method == 'POST':
|
2025-01-26 11:22:57 +06:00
|
|
|
try:
|
2025-01-30 13:07:48 +06:00
|
|
|
# Get text form fields
|
|
|
|
pdftype= request.POST.get('pdftype')
|
2025-01-26 11:22:57 +06:00
|
|
|
org_unit = request.POST.get('org_unit')
|
|
|
|
topic = request.POST.get('topic')
|
|
|
|
tittle = request.POST.get('tittle')
|
|
|
|
m_number = request.POST.get('m_number')
|
|
|
|
m_date = request.POST.get('m_date')
|
|
|
|
m_venue = request.POST.get('m_venue')
|
2025-01-30 13:07:48 +06:00
|
|
|
|
|
|
|
# Get file uploads
|
2025-01-26 11:22:57 +06:00
|
|
|
attendance_file = request.FILES.get('attendance_file')
|
|
|
|
res_con_mou_file = request.FILES.get('res_con_mou_file')
|
2025-01-30 13:07:48 +06:00
|
|
|
|
|
|
|
# Create a new seminar instance with text fields
|
|
|
|
if attendance_file:
|
|
|
|
new_filename = f"attendance_{uuid.uuid4()}.pdf"
|
|
|
|
path1 = os.path.join('media', 'attendance_files', new_filename)
|
|
|
|
with open(path1, 'wb') as destination:
|
|
|
|
for chunk in attendance_file.chunks():
|
|
|
|
destination.write(chunk)
|
|
|
|
|
|
|
|
if res_con_mou_file:
|
|
|
|
new_filename = f"res_con_{uuid.uuid4()}.pdf"
|
|
|
|
path2 = os.path.join('media', 'resolution_files', new_filename)
|
|
|
|
print(path2)
|
|
|
|
with open(path2, 'wb') as destination:
|
|
|
|
for chunk in res_con_mou_file.chunks():
|
|
|
|
destination.write(chunk)
|
|
|
|
seminar = resulation(
|
|
|
|
pdftype=pdftype,
|
2025-01-26 11:22:57 +06:00
|
|
|
org_unit=org_unit,
|
|
|
|
topic=topic,
|
|
|
|
tittle=tittle,
|
|
|
|
m_number=m_number,
|
|
|
|
m_date=m_date,
|
|
|
|
m_venue=m_venue,
|
2025-01-30 13:07:48 +06:00
|
|
|
attendance_file=path1,
|
|
|
|
res_con_mou_file=path2,
|
|
|
|
)
|
|
|
|
seminar.save()
|
|
|
|
print(path1)
|
2025-01-26 11:22:57 +06:00
|
|
|
message = "Data Inserted successfully"
|
2025-01-30 13:07:48 +06:00
|
|
|
# Redirect after a successful save
|
2025-01-26 11:22:57 +06:00
|
|
|
return render(request, "resulation/home.html", {'message': message})
|
2025-01-30 13:07:48 +06:00
|
|
|
|
2025-01-26 11:22:57 +06:00
|
|
|
except Exception as e:
|
2025-01-30 13:07:48 +06:00
|
|
|
# Handle any errors (e.g., invalid file types or sizes)
|
|
|
|
print(f"Error processing form: {str(e)}")
|
|
|
|
return render(request, 'resulation/resulation.html', {'error': str(e)})
|
|
|
|
|
|
|
|
else:
|
|
|
|
# Render the form template
|
2025-01-26 11:22:57 +06:00
|
|
|
return render(request, 'resulation/resulation.html')
|
|
|
|
|
2025-01-30 13:07:48 +06:00
|
|
|
def Viewresulation(request, pk):
|
2025-01-26 11:22:57 +06:00
|
|
|
# Get all records from database
|
|
|
|
pdf_records = resulation.objects.all().order_by('-m_date') # Latest first
|
2025-01-30 13:07:48 +06:00
|
|
|
return render(request, response, 'resulation/viewresulation.html', {'pdf_records': pdf_records})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-26 11:22:57 +06:00
|
|
|
|
|
|
|
def Contract(request):
|
|
|
|
return render(request,'resulation/contract.html')
|
|
|
|
|
|
|
|
def Mou(request):
|
|
|
|
return render(request,'resulation/mou.html')
|