steambird/boecie/views.py
def form_valid(self, form: Form) -> HttpResponse:
        """
        Validates if the form submitted contains valid options, returns a download for
        those options.

        :param form: Django Form object
        :return: Django HttpResponse object
        """

        form = form.cleaned_data

        period = Period[form.get('period')]

        result = io.StringIO()

        writer = csv.writer(result, delimiter=';', quotechar='"')
        writer.writerow('groep;vak;standaardvak;isbn;prognose;schoolBetaalt;verplicht;huurkoop;'
                        'vanprijs;korting;opmerking'.split(';'))

        if int(form.get('option')) < 4:
            for study in Study.objects.filter(type='bachelor'):
                courses = [c for c in Course.objects.with_all_periods().filter(
                    coursestudy__study_year=int(form.get('option')),
                    calendar_year=form.get('year', Config.get_system_value('year')))
                           if c.falls_in(period)]

                for course in courses:
                    for msp in MSP.objects.filter(course=course):
                        if msp.resolved():
                            for book in msp.mspline_set.last().materials.all():
                                if isinstance(book, Book):
                                    writer.writerow(
                                        [
                                            study,
                                            'Module {year}.{period} - {name}'.format(
                                                year=form.get('option'),
                                                period=course.period[1],
                                                name=course.name
                                            ),
                                            '',
                                            book.ISBN,
                                            '',
                                            'n',
                                            'verplicht' if msp.mandatory else 'aanbevolen',
                                            'koop'
                                            '',
                                            '',
                                            ''
                                        ]
                                    )

        elif int(form.get('option')) == 4:
            for study in Study.objects.filter(type='master'):
                courses = [c for c in Course.objects.filter(
                    calendar_year=form.get('year', datetime.date.today().year)
                ) if c.falls_in(period)]

                for course in courses:
                    for msp in MSP.objects.filter(course=course):
                        if msp.resolved():
                            for book in msp.mspline_set.last().materials.all():
                                if isinstance(book, Book):
                                    writer.writerow(
                                        [
                                            study,
                                            '{name}'.format(
                                                name=course.name
                                            ),
                                            '',
                                            book.ISBN,
                                            '',
                                            'n',
                                            'verplicht' if msp.mandatory else 'aanbevolen',
                                            'koop'
                                            '',
                                            '',
                                            ''
                                        ]
                                    )
        elif int(form.get('option')) == 5:
            for study in Study.objects.filter('premaster'):
                courses = [c for c in Course.objects.filter(
                    calendar_year=form.get('year', datetime.date.today().year)
                ) if c.falls_in(period)]

                for course in courses:
                    for msp in MSP.objects.filter(course=course):
                        if msp.resolved():
                            for book in msp.mspline_set.last().materials.all():
                                if isinstance(book, Book):
                                    writer.writerow(
                                        [
                                            study,
                                            '{name}'.format(
                                                name=course.name
                                            ),
                                            '',
                                            book.ISBN,
                                            '',
                                            'n',
                                            'verplicht' if msp.mandatory else 'aanbevolen',
                                            'koop'
                                            '',
                                            '',
                                            ''
                                        ]
                                    )
        response = HttpResponse(result.getvalue(), content_type="text/csv")
        response['Content-Disposition'] = 'attachment; filename="{}.csv"'.format('foobarbaz')
        return response

        Validates if the form submitted contains valid options, returns a download for
        those options.

        :param form: Django Form object
        :return: Django HttpResponse object
        
Validates if the form submitted contains valid options, returns a download for
those options.
Validates if the form submitted contains valid options returns a download for those options .
def form_valid(self, form: Form) -> HttpResponse:
        form = form.cleaned_data
        period = Period[form.get('period')]
        result = io.StringIO()
        writer = csv.writer(result, delimiter=';', quotechar='"')
        writer.writerow('groep;vak;standaardvak;isbn;prognose;schoolBetaalt;verplicht;huurkoop;'
                        'vanprijs;korting;opmerking'.split(';'))
        if int(form.get('option')) < 4:
            for study in Study.objects.filter(type='bachelor'):
                courses = [c for c in Course.objects.with_all_periods().filter(
                    coursestudy__study_year=int(form.get('option')),
                    calendar_year=form.get('year', Config.get_system_value('year')))
                           if c.falls_in(period)]
                for course in courses:
                    for msp in MSP.objects.filter(course=course):
                        if msp.resolved():
                            for book in msp.mspline_set.last().materials.all():
                                if isinstance(book, Book):
                                    writer.writerow(
                                        [
                                            study,
                                            'Module {year}.{period} - {name}'.format(
                                                year=form.get('option'),
                                                period=course.period[1],
                                                name=course.name
                                            ),
                                            '',
                                            book.ISBN,
                                            '',
                                            'n',
                                            'verplicht' if msp.mandatory else 'aanbevolen',
                                            'koop'
                                            '',
                                            '',
                                            ''
                                        ]
                                    )
        elif int(form.get('option')) == 4:
            for study in Study.objects.filter(type='master'):
                courses = [c for c in Course.objects.filter(
                    calendar_year=form.get('year', datetime.date.today().year)
                ) if c.falls_in(period)]
                for course in courses:
                    for msp in MSP.objects.filter(course=course):
                        if msp.resolved():
                            for book in msp.mspline_set.last().materials.all():
                                if isinstance(book, Book):
                                    writer.writerow(
                                        [
                                            study,
                                            '{name}'.format(
                                                name=course.name
                                            ),
                                            '',
                                            book.ISBN,
                                            '',
                                            'n',
                                            'verplicht' if msp.mandatory else 'aanbevolen',
                                            'koop'
                                            '',
                                            '',
                                            ''
                                        ]
                                    )
        elif int(form.get('option')) == 5:
            for study in Study.objects.filter('premaster'):
                courses = [c for c in Course.objects.filter(
                    calendar_year=form.get('year', datetime.date.today().year)
                ) if c.falls_in(period)]
                for course in courses:
                    for msp in MSP.objects.filter(course=course):
                        if msp.resolved():
                            for book in msp.mspline_set.last().materials.all():
                                if isinstance(book, Book):
                                    writer.writerow(
                                        [
                                            study,
                                            '{name}'.format(
                                                name=course.name
                                            ),
                                            '',
                                            book.ISBN,
                                            '',
                                            'n',
                                            'verplicht' if msp.mandatory else 'aanbevolen',
                                            'koop'
                                            '',
                                            '',
                                            ''
                                        ]
                                    )
        response = HttpResponse(result.getvalue(), content_type="text/csv")
        response['Content-Disposition'] = 'attachment; filename="{}.csv"'.format('foobarbaz')
        return response
def form_valid ( self , form : Form ) -> HttpResponse : form = form . cleaned_data period = Period [ form . get ( 'period' ) ] result = io . StringIO ( ) writer = csv . writer ( result , delimiter = ';' , quotechar = '"' ) writer . writerow ( 'groep;vak;standaardvak;isbn;prognose;schoolBetaalt;verplicht;huurkoop;' 'vanprijs;korting;opmerking' . split ( ';' ) ) if int ( form . get ( 'option' ) ) < 4 : for study in Study . objects . filter ( type = 'bachelor' ) : courses = [ c for c in Course . objects . with_all_periods ( ) . filter ( coursestudy__study_year = int ( form . get ( 'option' ) ) , calendar_year = form . get ( 'year' , Config . get_system_value ( 'year' ) ) ) if c . falls_in ( period ) ] for course in courses : for msp in MSP . objects . filter ( course = course ) : if msp . resolved ( ) : for book in msp . mspline_set . last ( ) . materials . all ( ) : if isinstance ( book , Book ) : writer . writerow ( [ study , 'Module {year}.{period} - {name}' . format ( year = form . get ( 'option' ) , period = course . period [ 1 ] , name = course . name ) , '' , book . ISBN , '' , 'n' , 'verplicht' if msp . mandatory else 'aanbevolen' , 'koop' '' , '' , '' ] ) elif int ( form . get ( 'option' ) ) == 4 : for study in Study . objects . filter ( type = 'master' ) : courses = [ c for c in Course . objects . filter ( calendar_year = form . get ( 'year' , datetime . date . today ( ) . year ) ) if c . falls_in ( period ) ] for course in courses : for msp in MSP . objects . filter ( course = course ) : if msp . resolved ( ) : for book in msp . mspline_set . last ( ) . materials . all ( ) : if isinstance ( book , Book ) : writer . writerow ( [ study , '{name}' . format ( name = course . name ) , '' , book . ISBN , '' , 'n' , 'verplicht' if msp . mandatory else 'aanbevolen' , 'koop' '' , '' , '' ] ) elif int ( form . get ( 'option' ) ) == 5 : for study in Study . objects . filter ( 'premaster' ) : courses = [ c for c in Course . objects . filter ( calendar_year = form . get ( 'year' , datetime . date . today ( ) . year ) ) if c . falls_in ( period ) ] for course in courses : for msp in MSP . objects . filter ( course = course ) : if msp . resolved ( ) : for book in msp . mspline_set . last ( ) . materials . all ( ) : if isinstance ( book , Book ) : writer . writerow ( [ study , '{name}' . format ( name = course . name ) , '' , book . ISBN , '' , 'n' , 'verplicht' if msp . mandatory else 'aanbevolen' , 'koop' '' , '' , '' ] ) response = HttpResponse ( result . getvalue ( ) , content_type = "text/csv" ) response [ 'Content-Disposition' ] = 'attachment; filename="{}.csv"' . format ( 'foobarbaz' ) return response
Validates if the form submitted contains valid options, returns a download for
those options.
Validates if the form submitted contains valid options returns a download for those options .
"""
        Validates if the form submitted contains valid options, returns a download for
        those options.

        :param form: Django Form object
        :return: Django HttpResponse object
        """
Django HttpResponse object
Django HttpResponse object
self
form
Form
Django Form object
Django Form object