<s> from plugit . utils import action , only_orga_member_user , only_orga_admin_user , PlugItRedirect , json_only , PlugItSendFile <EOL> from models import db , Station , Channel , Ecc <EOL> import re <EOL> import config <EOL> from plugit . api import PlugItAPI <EOL> import StringIO <EOL> @ action ( route = "<STR_LIT>" , template = "<STR_LIT>" ) <EOL> @ only_orga_member_user ( ) <EOL> def channels_home ( request ) : <EOL> """<STR_LIT>""" <EOL> list = [ ] <EOL> for elem in Channel . query . join ( Station ) . filter ( Station . orga == int ( request . args . get ( '<STR_LIT>' ) ) ) . order_by ( Channel . name ) . all ( ) : <EOL> list . append ( elem . json ) <EOL> saved = request . args . get ( '<STR_LIT>' ) == '<STR_LIT:yes>' <EOL> deleted = request . args . get ( '<STR_LIT>' ) == '<STR_LIT:yes>' <EOL> return { '<STR_LIT:list>' : list , '<STR_LIT>' : saved , '<STR_LIT>' : deleted } <EOL> @ action ( route = "<STR_LIT>" , template = "<STR_LIT>" , methods = [ '<STR_LIT:POST>' , '<STR_LIT:GET>' ] ) <EOL> @ only_orga_admin_user ( ) <EOL> def channels_edit ( request , id ) : <EOL> """<STR_LIT>""" <EOL> object = None <EOL> errors = [ ] <EOL> if id != '<STR_LIT:->' : <EOL> object = Channel . query . join ( Station ) . filter ( Channel . id == int ( id ) , Station . orga == int ( request . args . get ( '<STR_LIT>' ) or request . form . get ( '<STR_LIT>' ) ) ) . first ( ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> if not object : <EOL> object = Channel ( ) <EOL> object . station_id = int ( request . form . get ( '<STR_LIT>' ) ) <EOL> for x in [ '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> val = request . form . get ( x ) <EOL> if val == '<STR_LIT>' : <EOL> val = None <EOL> if x == '<STR_LIT>' and val is not None : <EOL> cc_obj = Ecc . query . filter_by ( id = val ) . first ( ) <EOL> val = cc_obj . pi + cc_obj . ecc <EOL> setattr ( object , x , val ) <EOL> if object . name == '<STR_LIT>' or object . name is None : <EOL> errors . append ( "<STR_LIT>" ) <EOL> list_props = None <EOL> for ( type_id , _ , type_props ) in Channel . TYPE_ID_CHOICES : <EOL> if type_id == object . type_id : <EOL> list_props = type_props <EOL> if list_props is None : <EOL> errors . append ( '<STR_LIT>' ) <EOL> if list_props : <EOL> for x in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if x in list_props : <EOL> if x != '<STR_LIT>' and x != '<STR_LIT>' : <EOL> if getattr ( object , x ) is None or getattr ( object , x ) == '<STR_LIT>' : <EOL> errors . append ( x + "<STR_LIT>" ) <EOL> else : <EOL> setattr ( object , x , None ) <EOL> if object . pi is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . pi ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . frequency is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . frequency ) and object . frequency != '<STR_LIT:*>' : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . eid is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . eid ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . sid is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . sid ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . scids is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . scids ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . appty_uatype is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . appty_uatype ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . pa is not None : <EOL> if object . pa < <NUM_LIT:1> or object . pa > <NUM_LIT> : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . tx is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . tx ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . cc is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . cc ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . fqdn is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . fqdn ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if object . serviceIdentifier is not None : <EOL> if not re . match ( r"<STR_LIT>" , object . serviceIdentifier ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> sta = Station . query . filter_by ( id = object . station_id ) . first ( ) <EOL> if not sta or sta . orga != int ( request . form . get ( '<STR_LIT>' ) ) : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if not errors : <EOL> if not object . id : <EOL> db . session . add ( object ) <EOL> db . session . commit ( ) <EOL> return PlugItRedirect ( '<STR_LIT>' ) <EOL> if object : <EOL> object = object . json <EOL> stations = [ ] <EOL> for station in Station . query . filter_by ( orga = int ( request . args . get ( '<STR_LIT>' ) or request . form . get ( '<STR_LIT>' ) ) ) . all ( ) : <EOL> stations . append ( station . json ) <EOL> return { '<STR_LIT:object>' : object , '<STR_LIT>' : errors , '<STR_LIT>' : stations , '<STR_LIT>' : Channel . TYPE_ID_CHOICES } <EOL> @ action ( route = "<STR_LIT>" ) <EOL> @ json_only ( ) <EOL> @ only_orga_admin_user ( ) <EOL> def channels_delete ( request , id ) : <EOL> """<STR_LIT>""" <EOL> object = Channel . query . join ( Station ) . filter ( Channel . id == int ( id ) , Station . orga == int ( request . args . get ( '<STR_LIT>' ) ) ) . first ( ) <EOL> db . session . delete ( object ) <EOL> db . session . commit ( ) <EOL> return PlugItRedirect ( '<STR_LIT>' ) <EOL> @ action ( route = "<STR_LIT>" ) <EOL> @ json_only ( ) <EOL> @ only_orga_member_user ( ) <EOL> def channels_check ( request , id ) : <EOL> """<STR_LIT>""" <EOL> object = Channel . query . join ( Station ) . filter ( Channel . id == int ( id ) , Station . orga == int ( request . args . get ( '<STR_LIT>' ) ) ) . first ( ) <EOL> ( fqdn , vis , epg ) = object . dns_values <EOL> return { '<STR_LIT>' : object . radiodns_entry , '<STR_LIT>' : fqdn , '<STR_LIT>' : vis , '<STR_LIT>' : epg } <EOL> @ action ( route = "<STR_LIT>" , template = "<STR_LIT>" ) <EOL> @ only_orga_member_user ( ) <EOL> def channels_export ( request ) : <EOL> """<STR_LIT>""" <EOL> plugitapi = PlugItAPI ( config . API_URL ) <EOL> retour = '<STR_LIT>' <EOL> retour += '<STR_LIT>' <EOL> retour += '<STR_LIT>' <EOL> retour += '<STR_LIT>' + plugitapi . get_orga ( request . args . get ( '<STR_LIT>' ) ) . name + '<STR_LIT>' <EOL> oldStationName = '<STR_LIT>' <EOL> for elem in Channel . query . join ( Station ) . filter ( Station . orga == int ( request . args . get ( '<STR_LIT>' ) ) ) . order_by ( Station . name , Channel . name ) . all ( ) : <EOL> if elem . station_name != oldStationName : <EOL> retour += '<STR_LIT>' + elem . station_name + '<STR_LIT:\n>' <EOL> oldStationName = elem . station_name <EOL> retour += elem . dns_entry . ljust ( <NUM_LIT> ) + '<STR_LIT>' <EOL> if request . args . get ( '<STR_LIT:to>' ) == '<STR_LIT:file>' : <EOL> retour_str = StringIO . StringIO ( ) <EOL> retour_str . write ( str ( retour ) ) <EOL> retour_str . seek ( <NUM_LIT:0> ) <EOL> return PlugItSendFile ( retour_str , '<STR_LIT>' , True , plugitapi . get_orga ( request . args . get ( '<STR_LIT>' ) ) . name + '<STR_LIT>' ) <EOL> return { '<STR_LIT>' : retour } </s>
