<s> from django . shortcuts import render_to_response <EOL> from survey . models import Answer <EOL> from django . db . models import Q <EOL> from django . template . loader import render_to_string <EOL> from django . http import HttpResponse <EOL> from django . utils . cache import add_never_cache_headers <EOL> import json <EOL> from datetime import datetime , timedelta <EOL> def show_paragraph ( max_character = <NUM_LIT:1000> , number_of_columns = <NUM_LIT:100> , number_of_rows = <NUM_LIT:50> , is_required = True ) : <EOL> require_checked = '<STR_LIT>' <EOL> print is_required <EOL> if not is_required : <EOL> require_checked = '<STR_LIT>' <EOL> html = r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % ( max_character , require_checked ) <EOL> return html <EOL> def show_numeric ( max_value = <NUM_LIT:100> , min_value = <NUM_LIT:0> , is_required = True ) : <EOL> require_checked = '<STR_LIT>' <EOL> if not is_required : <EOL> require_checked = '<STR_LIT>' <EOL> html = r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % ( max_value , min_value , require_checked ) <EOL> return html <EOL> def show_checkbox_option ( group_name , description ) : <EOL> html = r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % ( group_name , description ) <EOL> return html <EOL> def show_checkbox ( group_name , values , max_checked = <NUM_LIT:4> , min_checked = <NUM_LIT:0> , is_required = True ) : <EOL> require_checked = '<STR_LIT>' <EOL> if not is_required : <EOL> require_checked = '<STR_LIT>' <EOL> values = values . split ( '<STR_LIT>' ) <EOL> html = r"<STR_LIT>" <EOL> for value in values : <EOL> html += show_checkbox_option ( group_name , value ) <EOL> html += r"<STR_LIT>" <EOL> html += r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % ( max_checked , min_checked , require_checked ) <EOL> return html <EOL> def show_mcq_option ( group_name , description ) : <EOL> html = r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % ( group_name , description ) <EOL> return html <EOL> def show_mcq ( group_name , values , is_required = True ) : <EOL> require_checked = '<STR_LIT>' <EOL> if not is_required : <EOL> require_checked = '<STR_LIT>' <EOL> values = values . split ( '<STR_LIT>' ) <EOL> html = r"<STR_LIT>" <EOL> for value in values : <EOL> html += show_mcq_option ( group_name , value ) <EOL> html += r"<STR_LIT>" <EOL> html += r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % require_checked <EOL> return html <EOL> def show_scale ( max_value = <NUM_LIT:100> , min_value = <NUM_LIT:0> , increment = <NUM_LIT:1> , is_required = True ) : <EOL> require_checked = '<STR_LIT>' <EOL> if not is_required : <EOL> require_checked = '<STR_LIT>' <EOL> html = r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % ( max_value , min_value , increment , require_checked ) <EOL> return html <EOL> def show_text ( max_no_character = <NUM_LIT:255> , is_required = True ) : <EOL> require_checked = '<STR_LIT>' <EOL> if not is_required : <EOL> require_checked = '<STR_LIT>' <EOL> html = r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % ( max_no_character , require_checked ) <EOL> return html <EOL> def show_date ( max_value = "<STR_LIT>" , min_value = "<STR_LIT>" , start_value = "<STR_LIT>" , is_required = True ) : <EOL> require_checked = '<STR_LIT>' <EOL> if not is_required : <EOL> require_checked = '<STR_LIT>' <EOL> now = datetime . now ( ) <EOL> if not max_value : <EOL> max_value = now + timedelta ( days = <NUM_LIT> ) <EOL> if not min_value : <EOL> min_value = now - timedelta ( days = <NUM_LIT> ) <EOL> if not start_value : <EOL> start_value = now <EOL> max_value = max_value . strftime ( "<STR_LIT>" ) <EOL> min_value = min_value . strftime ( "<STR_LIT>" ) <EOL> start_value = start_value . strftime ( "<STR_LIT>" ) <EOL> html = r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" r"<STR_LIT>" % ( start_value , min_value , max_value , start_value , require_checked ) <EOL> return html <EOL> def get_datatables_records ( request , querySet , columnIndexNameMap , jsonTemplatePath = None , * args ) : <EOL> """<STR_LIT>""" <EOL> cols = int ( request . GET . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> iDisplayLength = min ( int ( request . GET . get ( '<STR_LIT>' , <NUM_LIT:10> ) ) , <NUM_LIT:100> ) <EOL> startRecord = int ( request . GET . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> endRecord = startRecord + iDisplayLength <EOL> keys = columnIndexNameMap . keys ( ) <EOL> keys . sort ( ) <EOL> colitems = [ columnIndexNameMap [ key ] for key in keys ] <EOL> sColumns = "<STR_LIT:U+002C>" . join ( map ( str , colitems ) ) <EOL> iSortingCols = int ( request . GET . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> asortingCols = [ ] <EOL> if iSortingCols : <EOL> for sortedColIndex in range ( <NUM_LIT:0> , iSortingCols ) : <EOL> sortedColID = int ( request . GET . get ( '<STR_LIT>' + str ( sortedColIndex ) , <NUM_LIT:0> ) ) <EOL> if request . GET . get ( '<STR_LIT>' . format ( sortedColID ) , '<STR_LIT:false>' ) == '<STR_LIT:true>' : <EOL> sortedColName = columnIndexNameMap [ sortedColID ] <EOL> sortingDirection = request . GET . get ( '<STR_LIT>' + str ( sortedColIndex ) , '<STR_LIT>' ) <EOL> if sortingDirection == '<STR_LIT>' : <EOL> sortedColName = '<STR_LIT:->' + sortedColName <EOL> asortingCols . append ( sortedColName ) <EOL> querySet = querySet . order_by ( * asortingCols ) <EOL> searchableColumns = [ ] <EOL> for col in range ( <NUM_LIT:0> , cols ) : <EOL> if request . GET . get ( '<STR_LIT>' . format ( col ) , False ) == '<STR_LIT:true>' : searchableColumns . append ( columnIndexNameMap [ col ] ) <EOL> customSearch = request . GET . get ( '<STR_LIT>' , '<STR_LIT>' ) . encode ( '<STR_LIT:utf-8>' ) ; <EOL> if customSearch != '<STR_LIT>' : <EOL> outputQ = None <EOL> first = True <EOL> for searchableColumn in searchableColumns : <EOL> kwargz = { searchableColumn + "<STR_LIT>" : customSearch } <EOL> outputQ = outputQ | Q ( ** kwargz ) if outputQ else Q ( ** kwargz ) <EOL> querySet = querySet . filter ( outputQ ) <EOL> outputQ = None <EOL> for col in range ( <NUM_LIT:0> , cols ) : <EOL> if request . GET . get ( '<STR_LIT>' . format ( col ) , False ) > '<STR_LIT>' and request . GET . get ( '<STR_LIT>' . format ( col ) , False ) == '<STR_LIT:true>' : <EOL> kwargz = { columnIndexNameMap [ col ] + "<STR_LIT>" : request . GET [ '<STR_LIT>' . format ( col ) ] } <EOL> outputQ = outputQ & Q ( ** kwargz ) if outputQ else Q ( ** kwargz ) <EOL> if outputQ : querySet = querySet . filter ( outputQ ) <EOL> iTotalRecords = iTotalDisplayRecords = querySet . count ( ) <EOL> querySet = querySet [ startRecord : endRecord ] <EOL> sEcho = int ( request . GET . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> if jsonTemplatePath : <EOL> jstonString = render_to_string ( jsonTemplatePath , locals ( ) ) <EOL> response = HttpResponse ( jstonString , mimetype = "<STR_LIT>" ) <EOL> else : <EOL> aaData = [ ] <EOL> a = querySet . values ( ) <EOL> for row in a : <EOL> rowkeys = row . keys ( ) <EOL> rowvalues = row . values ( ) <EOL> rowlist = [ ] <EOL> for col in range ( <NUM_LIT:0> , len ( colitems ) ) : <EOL> for idx , val in enumerate ( rowkeys ) : <EOL> if val == colitems [ col ] : <EOL> rowlist . append ( str ( rowvalues [ idx ] ) ) <EOL> aaData . append ( rowlist ) <EOL> response_dict = { } <EOL> response_dict . update ( { '<STR_LIT>' : aaData } ) <EOL> response_dict . update ( { '<STR_LIT>' : sEcho , '<STR_LIT>' : iTotalRecords , '<STR_LIT>' : iTotalDisplayRecords , '<STR_LIT>' : sColumns } ) <EOL> response = HttpResponse ( simplejson . dumps ( response_dict ) , mimetype = '<STR_LIT>' ) <EOL> add_never_cache_headers ( response ) <EOL> return response <EOL> def isfloat ( string ) : <EOL> try : <EOL> float ( string ) <EOL> except BaseException as e : <EOL> return False <EOL> return True </s>
