def add_channel(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/') if request.method == 'POST': form = ChannelForm(request.POST) if not form.is_valid(): return render(request, 'add_channel_form.html', {'form': form}) ch_data = form.cleaned_data if ch_data['multicast_in'] == ch_data['multicast_out']: return render(request, 'add_channel_form.html', { 'form': form, 'm_error': True }) else: new_channel = Channel( name=ch_data['name'], sid=ch_data['sid'], multicast_in=ch_data['multicast_in'], multicast_out=ch_data['multicast_out'], bitrate=ch_data['bitrate'], pcr_period=ch_data['pcr_period'], command=ch_data['command'], status=False, ffmpeg_pid=1, parse_pid=1, astra_pid=1, ) new_channel.save() return HttpResponseRedirect('/channels') return render(request, 'add_channel_form.html')
def edit_channel_data(request, id, name, data): d = {name: data} form = ChannelForm(d) if form[name].errors: return render(request, 'info_response.html', {'error': form[name].errors}) else: Channel.objects.filter(id=id).update(**d) return render(request, 'info_response.html')
def add_channel(): form = ChannelForm(request.form) if request.method == 'POST' and form.validate(): channel = Channel(name = form.name.data) channel.owner_id = g.user.id db.session.add(channel) db.session.commit() return redirect(url_for('channel_view', id=channel.id)) return render_template('add_channel.html', title = 'Add channel', user = g.user, form = form)
def search(): form = ChannelForm(request.form) if request.method == "POST" and form.validate(): channels = Channel.query.filter(Channel.name.like( '%' + form.name.data + '%' )) else: channels = Channel.query.all() return render_template('search.html', channels=channels, form = form, title = 'Search channels', user = g.user)
def get_context_data(self, *args, **kwargs): context = super(DiscussionOrganizationView, self).get_context_data(*args, **kwargs) account = get_current_account(self.request) membership = self.request.user.get_membership(account) discussion_slug = '{}_organization'.format(account.id) feed_discussion = Discussions.objects.get(slug=discussion_slug, account=account) all_members_objects = Membership.objects.filter( account=account, is_active=True).order_by('last_name') all_members = { member.id: { 'full_name': member.get_full_name(), 'avatar_url': member.avatar_url(geometry='50x50') if member.avatar else '/static/images/default_avatar_sq.svg' } for member in all_members_objects } feed_channels = feed_manager.get_feed( 'timeline', '{}_channels_events'.format(account.id)) context[ 'not_auto_feed_discussion_public'] = Discussions.objects.filter( private=False, auto=False, account=account) context[ 'not_auto_feed_discussion_private'] = Discussions.objects.filter( private=True, auto=False, account=account, member_ids=membership) context['feed_discussion'] = feed_discussion.slug context['folder'] = Folder.objects.get_discussion_folder(account) context['folder_add_form'] = DocumentAddForm() context['channel_add_form'] = ChannelForm({'account': account}) context['channel_edit_form'] = EditChannelForm({'account': account}) context['message_edit_form'] = MessageEditForm() context['getstream_key'] = STREAM_API_KEY context['getstream_app_id'] = STREAM_APP_ID context['active_member'] = self.get_queryset().filter(is_active=True) context['all_members_objects'] = all_members_objects context['active_news_rooms'] = News.objects.filter(account=account) context['active_committee'] = Committee.objects.for_membership( membership=membership) context['all_members'] = json.dumps(all_members) context['feed_channels_token'] = feed_channels.get_readonly_token() return context
def submit_channel(): try: form = ChannelForm() if form.validate_on_submit(): if form.update_data(): return jsonify({ 'message': get_flashed_messages(category_filter='success') }), 200, {} except Exception, e: current_app.logger.error( 'Fatal error updating data; error: {}'.format(e)) jsonify({ 'message_modal': get_flashed_messages(category_filter='error') }), 500, {}
def desetup(): global theStatus, theDataStatus global statusFT8, statusWSPR, statusRG, statusSnap, statusFHR print("hit desetup2; request.method=",request.method) parser = configparser.ConfigParser(allow_no_value=True) parser.read('config.ini') ringbufferPath = parser['settings']['ringbuffer_path'] maxringbufsize = parser['settings']['ringbuf_maxsize'] if request.method == 'GET' : channellistform = ChannelListForm() # populate channel settings from config file channelcount = parser['channels']['numChannels'] form = ChannelControlForm() form.channelcount.data = channelcount print("form maxringbufsize=",form.maxRingbufsize.data) print("Max ringbuf size=", maxringbufsize) form.maxRingbufsize.data = maxringbufsize print("form maxringbufsize=",form.maxRingbufsize.data) rate_list = [] # populate rate capabilities from config file. # The config file should have been updated from DE sample rate list buffer. numRates = parser['datarates']['numRates'] for r in range(int(numRates)): theRate = parser['datarates']['r'+str(r)] theTuple = [ str(theRate), int(theRate) ] rate_list.append(theTuple) form.channelrate.choices = rate_list rate1 = int(parser['channels']['datarate']) # print("rate1 type = ",type(rate1)) form.channelrate.data = rate1 for ch in range(int(channelcount)): channelform = ChannelForm() channelform.channel_ant = parser['channels']['p' + str(ch)] channelform.channel_freq = parser['channels']['f' + str(ch)] channellistform.channels.append_entry(channelform) print("form maxringbufsize=",form.maxRingbufsize.data) return render_template('desetup.html', ringbufferPath = ringbufferPath, channelcount = channelcount, channellistform = channellistform, form = form, status = theStatus) # if we arrive here, user has hit one of the buttons on page result = request.form print("F: result=", result.get('csubmit')) # does user want to start over? if result.get('csubmit') == "Discard Changes" : channellistform = ChannelListForm() # populate channel settings from config file channelcount = parser['channels']['numChannels'] form = ChannelControlForm() form.channelcount.data = channelcount rate_list = [] # populate rate capabilities from config file. # The config file should have been updated from DE sample rate list buffer. numRates = parser['datarates']['numRates'] for r in range(int(numRates)): theRate = parser['datarates']['r'+str(r)] theTuple = [ str(theRate), int(theRate) ] rate_list.append(theTuple) form.channelrate.choices = rate_list rate1 = int(parser['channels']['datarate']) form.channelrate.data = rate1 form.maxRingbufsize.data = maxringbufsize for ch in range(int(channelcount)): channelform = ChannelForm() channelform.channel_ant = parser['channels']['p' + str(ch)] channelform.channel_freq = parser['channels']['f' + str(ch)] channellistform.channels.append_entry(channelform) return render_template('desetup.html', ringbufferPath = ringbufferPath, channelcount = channelcount, channellistform = channellistform, form = form, status = theStatus) # did user hit the Set channel count button? if result.get('csubmit') == "Set no. of channels": channelcount = result.get('channelcount') print("set #channels to ",channelcount) channellistform = ChannelListForm() form = ChannelControlForm() form.channelcount.data = channelcount rate_list = [] numRates = parser['datarates']['numRates'] for r in range(int(numRates)): theRate = parser['datarates']['r'+str(r)] theTuple = [ str(theRate), int(theRate) ] rate_list.append(theTuple) form.channelrate.choices = rate_list rate1 = int(parser['channels']['datarate']) form.channelrate.data = rate1 form.maxRingbufsize.data = maxringbufsize for ch in range(int(channelcount)): # print("add channel ",ch) channelform = ChannelForm() channelform.channel_ant = parser['channels']['p' + str(ch)] channelform.channel_freq = parser['channels']['f' + str(ch)] channellistform.channels.append_entry(channelform) print("return to desetup") return render_template('desetup.html', ringbufferPath = ringbufferPath, channelcount = channelcount, form = form, status = theStatus, channellistform = channellistform) # user wants to save changes; update configuration file # The range validation is done in code here due to problems with the # WTForms range validator inside a FieldList if result.get('csubmit') == "Save Changes": statusCheck = True # theStatus = "ERROR-" channelcount = result.get('channelcount') channelrate = result.get('channelrate') maxringbufsize = result.get('maxRingbufsize') print("Set maxringbuf size to", maxringbufsize) parser.set('settings','ringbuf_maxsize',maxringbufsize) print("set data rate to ", channelrate) parser.set('channels','datarate',channelrate) # theStatus = "" print("set #channels to ",channelcount) parser.set('channels','numChannels',channelcount) print("RESULT: ", result) rgPathExists = os.path.isdir(result.get('ringbufferPath')) print("path / directory existence check: ", rgPathExists) if (statusRG == 1 or statusFHR == 1 or statusSnap == 1 ): dataCollStatus = 1 if rgPathExists == False: theStatus = "Ringbuffer path invalid or not a directory. " statusCheck = False elif dataCollStatus == 1: theStatus = theStatus + "ERROR: you must stop data collection before saving changes here. " statusCheck = False # save channel config to config file for ch in range(int(channelcount)): p = 'channels-' + str(ch) + '-channel_ant' parser.set('channels','p' + str(ch), result.get(p)) print("p = ",p) print("channel #",ch," ant:",result.get(p)) f = 'channels-' + str(ch) + '-channel_freq' fstr = result.get(f) if(is_numeric(fstr)): fval = float(fstr) if(fval < 0.1 or fval > 54.0): theStatus = theStatus + "Freq for channel "+ str(ch) + " out of range;" statusCheck = False else: parser.set('channels','f' + str(ch), result.get(f)) else: theStatus = theStatus + "Freq for channel " + str(ch) + " must be numeric;" statusCheck = False if(statusCheck == True): print("Save config; ringbuffer_path=" + result.get('ringbufferPath')) parser.set('settings', 'ringbuffer_path', result.get('ringbufferPath')) fp = open('config.ini','w') parser.write(fp) fp.close() channellistform = ChannelListForm() channelcount = parser['channels']['numChannels'] form = ChannelControlForm() form.channelcount.data = channelcount rate_list = [] numRates = parser['datarates']['numRates'] for r in range(int(numRates)): theRate = parser['datarates']['r'+str(r)] theTuple = [ str(theRate), int(theRate) ] rate_list.append(theTuple) form.channelrate.choices = rate_list print("set channelrate to ", parser['channels']['datarate']) rate1 = int( parser['channels']['datarate']) form.channelrate.data = rate1 rate_list = [] numRates = parser['datarates']['numRates'] for r in range(int(numRates)): theRate = parser['datarates']['r'+str(r)] theTuple = [ str(theRate), int(theRate) ] rate_list.append(theTuple) form.channelrate.choices = rate_list # configCmd = CONFIG_CHANNELS + "," + channelcount + "," + parser['channels']['datarate'] + "," for ch in range(int(channelcount)): # print("add channel ",ch) channelform = ChannelForm() channelform.channel_ant = parser['channels']['p' + str(ch)] # configCmd = configCmd + str(ch) + "," + parser['channels']['p' + str(ch)] + "," channelform.channel_freq = parser['channels']['f' + str(ch)] # configCmd = configCmd + parser['channels']['f' + str(ch)] + "," channellistform.channels.append_entry(channelform) # send_to_mainctl(configCmd,1); if(statusCheck == True): send_channel_config() theStatus = "OK" else: theStatus = theStatus + " NOT SAVED" print("return to desetup") return render_template('desetup.html', ringbufferPath = ringbufferPath, channelcount = channelcount, form = form, status = theStatus, channellistform = channellistform)
def index(): return render_template('index.html', channel_form=ChannelForm())