#NEWLINE# @ action ( route = '/stations/edit/<id>' , template = 'stations/edit.html' , methods = [ 'POST' , 'GET' ] ) #NEWLINE# @ only_orga_admin_user ( ) #NEWLINE# def stations_edit( request , id ) : #NEWLINE# #INDENT# 'Edit a station.' #NEWLINE# object = None #NEWLINE# errors = [ ] #NEWLINE# if ( id != '-' ) : #NEWLINE# #INDENT# object = Station . query . filter_by ( orga = int ( ( request . args . get ( 'ebuio_orgapk' ) or request . form . get ( 'ebuio_orgapk' ) ) ) , id = int ( id ) ) . first ( ) #NEWLINE# #UNINDENT# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# if ( not object ) : #NEWLINE# #INDENT# object = Station ( int ( request . form . get ( 'ebuio_orgapk' ) ) ) #NEWLINE# #UNINDENT# object . name = request . form . get ( 'name' ) #NEWLINE# object . short_name = request . form . get ( 'short_name' ) #NEWLINE# object . short_description = request . form . get ( 'short_description' ) #NEWLINE# object . ip_allowed = request . form . get ( 'ip_allowed' ) #NEWLINE# genres = [ ] #NEWLINE# genre_href = request . form . getlist ( 'genrehref[]' ) #NEWLINE# genre_name = request . form . getlist ( 'genrename[]' ) #NEWLINE# for h in h : #NEWLINE# #INDENT# genres . append ( { #NEWLINE# #INDENT# 'href' : h , #NEWLINE# 'name' : genre_name . pop ( 0 ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# object . genres = json . dumps ( genres ) #NEWLINE# if ( object . name == '' ) : #NEWLINE# #INDENT# errors . append ( 'Please set a name' ) #NEWLINE# #UNINDENT# if ( not errors ) : #NEWLINE# #INDENT# if ( not object . id ) : #NEWLINE# #INDENT# object . gen_random_password ( ) #NEWLINE# db . session . add ( object ) #NEWLINE# #UNINDENT# db . session . commit ( ) #NEWLINE# return PlugItRedirect ( 'stations/?saved=yes' ) #NEWLINE# #UNINDENT# #UNINDENT# if object : #NEWLINE# #INDENT# object = object . json #NEWLINE# #UNINDENT# return { #NEWLINE# #INDENT# 'object' : object , #NEWLINE# 'errors' : errors , #NEWLINE# #UNINDENT# }