OptionalFee, Parameters, Payback, Payment, Profile,
Student, Training)
from .models.messages import GroupedMessage, StudentGroup
-from .views.crfpa import CorrectorXLSBook, UserXLSBook
+from .views.crfpa import CorrectorXLSBook, UserXLSBook, StudentReadingsXLSBook
from .views.core import get_periods
from django.contrib.admin.helpers import ActionForm
list_display = ['student_name', 'restricted', 'get_trainings', 'platform_only',
'total_payments', 'total_fees', 'balance', 'balance_intermediary']
readonly_fields = ['user', 'balance', 'balance_intermediary']
- actions = ['export_xls', 'write_message', 'add_to_group']
+ actions = ['export_xls_training', 'export_xls_readings', 'write_message', 'add_to_group']
action_form = StudentGroupForm
class Media:
serializers.serialize("json", queryset, stream=response)
return response
- def export_xls(self, request, queryset):
+ def export_xls_training(self, request, queryset):
book = UserXLSBook(students=queryset)
book.write()
response = HttpResponse(content_type="application/vnd.ms-excel")
book.book.save(response)
return response
- export_xls.short_description = "Export vers XLS"
+ def export_xls_readings(self, request, queryset):
+ book = StudentReadingsXLSBook(students=queryset)
+ book.write()
+ response = HttpResponse(content_type="application/vnd.ms-excel")
+ response['Content-Disposition'] = 'attachment; filename=%s.xls' % queryset[0].user.username
+ book.book.save(response)
+ return response
+
+ export_xls_training.short_description = "Export Formation (XLS)"
+ export_xls_readings.short_description = "Export Lectures (XLS)"
def add_to_group(self, request, queryset):
group_name = request.POST['group_name']
validation.save()
return render(self.request, 'quiz/result.html', results)
+
+
+
+class StudentXLSBook:
+
+ def __init__(self, students):
+ self.book = Workbook()
+ if students:
+ self.student = students[0]
+
+ self.sheet_docs = self.book.add_sheet('Documents')
+ self.sheet_media = self.book.add_sheet('Medias')
+
+ def write(self):
+ row = 1
+ for media_read in self.student.user.read.all():
+ self.sheet_media.write(row, 0, str(media_read.media))
+ row += 1
+
+ row = 1
+ for doc_read in self.student.user.private_documents.all():
+ self.sheet_docs.write(row, 0, str(media_read.media))
+ row += 1
+