download working well

This commit is contained in:
sofordar 2025-02-02 12:26:20 +06:00
parent d1f41dcd38
commit a0ef3cff8d
26 changed files with 9 additions and 6 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -13,8 +13,7 @@ urlpatterns = [
path('viewresulation/', resulation.views.Viewresulation, name='viewresulation'), path('viewresulation/', resulation.views.Viewresulation, name='viewresulation'),
path('deed/', resulation.views.Contract, name='deed'), path('deed/', resulation.views.Contract, name='deed'),
path('mou/', resulation.views.Mou, name='mou'), path('mou/', resulation.views.Mou, name='mou'),
re_path('downloads/<int:attendance_id>/<str:filename>', resulation.views.file_download, name='file-download'), path('<str:type>/<str:filename>', resulation.views.file_download, name='file-download'),
path('rcm/downloads/<int:attendance_id>/<str:filename>', resulation.views.file_download, name='file-download'),
path('rcm/', resulation.views.file_download, name='download_file'), path('rcm/', resulation.views.file_download, name='download_file'),
] ]

View File

@ -77,9 +77,13 @@ def Viewresulation(request):
return render(request, 'resulation/viewresulation.html', {'pdf_records': pdf_records}) return render(request, 'resulation/viewresulation.html', {'pdf_records': pdf_records})
def file_download(request, attendance_id, filename): def file_download(request, type, filename):
# Construct the full path to the file # Construct the full path to the file
file_path = os.path.join(settings.MEDIA_ROOT, 'attendance_files', filename) if type== 'attendance':
file_path = os.path.join(settings.MEDIA_ROOT, 'attendance_files', filename)
if type=='resolution':
file_path = os.path.join(settings.MEDIA_ROOT, 'resolution_files', filename)
# Use sendfile to stream the file directly # Use sendfile to stream the file directly
return FileResponse(open(file_path, 'rb'), content_type='application/pdf') return FileResponse(open(file_path, 'rb'), content_type='application/pdf')

View File

@ -35,11 +35,11 @@
<td>{{ record.m_date|date:"d M Y" }}</td> <td>{{ record.m_date|date:"d M Y" }}</td>
<td>{{ record.m_venue }}</td> <td>{{ record.m_venue }}</td>
<td> <td>
<a href="{% url 'file-download' attendance_id=record.eid filename=record.attendance_file %}">Download</a> <a href="{% url 'file-download' type="attendance" filename=record.attendance_file %}">Download</a>
</td> </td>
<td> <td>
{% if record.res_con_mou_file %} {% if record.res_con_mou_file %}
<a href="{{ record.res_con_mou_file.url }}">Download</a> <a href="{% url 'file-download' type="resolution" filename=record.res_con_mou_file %}">Download</a>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>