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 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 edit_channel(channel): form = ChannelForm(obj=channel) if form.validate_on_submit(): channel.id=form.data.get('id') channel.name = form.data.get('name') channel.token = form.data.get('token') try: channel.put() flash(u'Channel %s successfully saved.' % channel.name, 'success') return redirect(url_for('qq.list_channels')) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return render_template('edit_channel.html', form=form)
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 list_channels(): """List all channels""" channels = Channel.query() form = ChannelForm() if form.validate_on_submit(): channel = Channel( id = form.id.data, name = form.name.data, token = form.token.data, ) try: channel.put() flash(u'Channel %s successfully saved.' % channel.id, 'success') return redirect(url_for('qq.list_channels')) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return redirect(url_for('qq.list_channels')) return render_template('list_channels.html', channels=channels, form=form)
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 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 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 updateChannel(request): prname = request.session['project'] pr = Project.objects.get ( project_name = prname ) pd = ocpcaproj.OCPCAProjectsDB() if request.method == 'POST': if 'updatechannel' in request.POST: chname = request.session["channel_name"] channel_to_update = get_object_or_404(Channel,channel_name=chname,project_id=pr) form = ChannelForm(data=request.POST or None, instance=channel_to_update) if form.is_valid(): newchannel = form.save(commit=False) else: # Invalid form context = {'form': form, 'project': prname} return render_to_response('updatechannel.html', context, context_instance=RequestContext(request)) elif 'createchannel' in request.POST: form = ChannelForm(data=request.POST or None) if form.is_valid(): new_channel = form.save( commit=False ) # populate the channel type and data type from choices combo = request.POST.get('channelcombo') if combo=='i:8': new_channel.channel_type = IMAGE new_channel.channel_datatype = UINT8 elif combo=='i:16': new_channel.channel_type = IMAGE new_channel.channel_datatype = UINT16 elif combo=='i:32': new_channel.channel_type = IMAGE new_channel.channel_datatype = UINT32 elif combo=='a:32': new_channel.channel_type = ANNOTATION new_channel.channel_datatype = UINT32 elif combo=='f:32': new_channel.channel_type = IMAGE new_channel.channel_datatype = FLOAT32 elif combo=='t:8': new_channel.channel_type = TIMESERIES new_channel.channel_datatype = UINT8 elif combo=='t:16': new_channel.channel_type = TIMESERIES new_channel.channel_datatype = UINT16 elif combo=='t:32': new_channel.channel_type = TIMESERIES new_channel.channel_datatype = FLOAT32 else: logger.error("Illegal channel combination requested: {}.".format(combo)) messages.error(request,"Illegal channel combination requested or none selected.") return HttpResponseRedirect(get_script_prefix()+'ocpuser/channels') if pr.user_id == request.user.id or request.user.is_superuser: # if there is no default channel, make this default if not Channel.objects.filter(project_id=pr, default=True): new_channel.default = True new_channel.save() if not request.POST.get('nocreate') == 'on': try: # create the tables for the channel pd.newOCPCAChannel( pr.project_name, new_channel.channel_name) except Exception, e: logger.error("Failed to create channel. Error {}".format(e)) messages.error(request,"Failed to create channel. {}".format(e)) new_channel.delete() return HttpResponseRedirect(get_script_prefix()+'ocpuser/channels') else: messages.error(request,"Cannot update. You are not owner of this token or not superuser.") return HttpResponseRedirect(get_script_prefix()+'ocpuser/channels') else: #Invalid form context = {'form': form, 'project': prname} return render_to_response('createchannel.html', context, context_instance=RequestContext(request)) else: #unrecognized option return redirect(getChannels) if pr.user_id == request.user.id or request.user.is_superuser: # if setting the default channel, remove previous default if newchannel.default == True: olddefault = Channel.objects.filter(default=True, project_id=pr) for od in olddefault: od.default = False od.save() # if there is no default channel, make this default if not Channel.objects.filter(project_id=pr): newchannel.default = True newchannel.save() return HttpResponseRedirect(get_script_prefix()+'ocpuser/channels') else: messages.error(request,"Cannot update. You are not owner of this token or not superuser.") return HttpResponseRedirect(get_script_prefix()+'ocpuser/channels')
def index(): return render_template('index.html', channel_form=ChannelForm())