1313 clean_input , prep_ranges , parse_bool , parse_ints , parse_galgrp ,
1414 SearchArray , TextBox , TextBoxNoEg , YesNoBox , ParityBox , CountBox ,
1515 StatsDisplay , totaler , proportioners , prop_int_pretty , Downloader ,
16- sparse_cyclotomic_to_mathml , search_wrap , redirect_no_cache )
16+ sparse_cyclotomic_to_mathml , search_wrap , redirect_no_cache , CodeSnippet )
1717from lmfdb .utils .interesting import interesting_knowls
1818from lmfdb .utils .search_columns import SearchColumns , LinkCol , MultiProcessedCol , MathCol , CheckCol , SearchCol
1919from lmfdb .api import datapage
@@ -341,7 +341,7 @@ def render_group_webpage(args):
341341 data ['malle_a' ] = wgg .malle_a
342342 downloads = []
343343 for lang in [("Magma" , "magma" ), ("Oscar" , "oscar" ), ("SageMath" , "sage" )]:
344- downloads .append (('{} commands' .format (lang [0 ]), url_for (".gg_code " , label = label , download_type = lang [1 ])))
344+ downloads .append (('{} commands' .format (lang [0 ]), url_for (".gg_code_download " , label = label , download_type = lang [1 ])))
345345 downloads .append (('Underlying data' , url_for (".gg_data" , label = label )))
346346 # split the label so that breadcrumbs point to a search for this object's degree
347347 parent_id , child_id = label .split ("T" )
@@ -360,20 +360,22 @@ def render_group_webpage(args):
360360 KNOWL_ID = "gg.%s" % label ,
361361 learnmore = learnmore_list ()+ [('Picture description' , url_for ('.pictures' ))])
362362
363+
364+ sorted_code_names = ['gg' , 'id' , 'order' , 'cyclic' , 'abelian' , 'solvable' , 'nilpotent' ,
365+ 'n' , 't' , 'even' , 'primitive' , 'auts' , 'gens' , 'ccs' , 'char_table' ]
366+
367+ def gg_code (label , download_type ):
368+ gg = WebGaloisGroup (label )
369+ gg .make_code_snippets ()
370+ code = CodeSnippet (gg .code )
371+ return code .export_code (label , download_type , sorted_code_names )
372+
363373@galois_groups_page .route ('/<label>/download/<download_type>' )
364- def gg_code (label ,download_type ):
365- if download_type == "magma" :
366- s = "// Magma code for creating transitive group " + label + "\n \n "
367- s += "G := TransitiveGroup(%s,%s);\n " % tuple (label .split ("T" ))
368- elif download_type == "oscar" :
369- s = "# Oscar code for creating transitive group " + label + "\n \n "
370- s += "G = transitive_group(%s,%s)\n " % tuple (label .split ("T" ))
371- elif download_type == "sage" :
372- s = "# Sage code for creating transitive group " + label + "\n \n "
373- s += "G = TransitiveGroup(%s,%s)\n " % tuple (label .split ("T" ))
374- else :
375- return abort (404 , f"Invalid download type { download_type } " )
376- response = make_response (s )
374+ def gg_code_download (** args ):
375+ try :
376+ response = make_response (gg_code (** args ))
377+ except Exception as err :
378+ return abort (404 , str (err ))
377379 response .headers ['Content-type' ] = 'text/plain'
378380 return response
379381
0 commit comments