Compare commits
	
		
			3 commits
		
	
	
		
			master
			...
			export_sez
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						64bd360716 | ||
| 
							 | 
						350041c587 | ||
| 
							 | 
						3a8d5b2207 | 
					 2 changed files with 41 additions and 0 deletions
				
			
		| 
						 | 
					@ -22,4 +22,9 @@ urlpatterns = [
 | 
				
			||||||
		org_required(views.SeznamListView.as_view()),
 | 
							org_required(views.SeznamListView.as_view()),
 | 
				
			||||||
		name='seznam-list'
 | 
							name='seznam-list'
 | 
				
			||||||
	),
 | 
						),
 | 
				
			||||||
 | 
						path(
 | 
				
			||||||
 | 
							'prednasky/seznam_export/<int:seznam>/',
 | 
				
			||||||
 | 
							org_required(views.exportSeznamuPrednasekNeHodnoceni),
 | 
				
			||||||
 | 
							name='seznam_export_csv'
 | 
				
			||||||
 | 
						),
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -114,4 +114,40 @@ def SeznamExportView(request, seznam):
 | 
				
			||||||
		content_type="text/plain"
 | 
							content_type="text/plain"
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def exportSeznamuPrednasekNeHodnoceni(req, seznam):
 | 
				
			||||||
 | 
						# UGLY CODE. Jen byla potřeba pro garanta přednášek tabulka, tak vznikla :-P
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						seznam = get_object_or_404(Seznam, id=seznam)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						from django.http import HttpResponse
 | 
				
			||||||
 | 
						import csv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# Kód jsem zkopíroval přímo z tutoriálu
 | 
				
			||||||
 | 
						# https://docs.djangoproject.com/en/4.0/howto/outputting-csv/
 | 
				
			||||||
 | 
						# Jo, je to špatná verze djanga. whatever.
 | 
				
			||||||
 | 
						response = HttpResponse(
 | 
				
			||||||
 | 
							content_type='text/csv',
 | 
				
			||||||
 | 
							headers={'Content-Disposition': 'attachment; filename="seznam.csv"'},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						writer = csv.writer(response)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						attrs = (
 | 
				
			||||||
 | 
							'id',
 | 
				
			||||||
 | 
							'org',
 | 
				
			||||||
 | 
							'nazev',
 | 
				
			||||||
 | 
							'anotace',
 | 
				
			||||||
 | 
							'klicova',
 | 
				
			||||||
 | 
							'obor',
 | 
				
			||||||
 | 
							'obtiznost',
 | 
				
			||||||
 | 
							'popis',
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
						# Hlavička
 | 
				
			||||||
 | 
						writer.writerow(attrs)
 | 
				
			||||||
 | 
						# Tělo
 | 
				
			||||||
 | 
						for predn in Prednaska.objects.filter(seznamy=seznam):
 | 
				
			||||||
 | 
							row = [getattr(predn, attr) for attr in attrs]
 | 
				
			||||||
 | 
							writer.writerow(row)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue