Beispiel #1
0
def index():
    role_list=[]
    ren_lenth=0
    form = IndexForm()
    zu = Group.query.filter_by(groupname=form.name.data).first()
    if form.validate_on_submit():
        if zu is None :
            flash(u'此群未建立!')
        else:
             ren_list=zu.user.all()
             ren_lenth=len(ren_list)
             if g.user in ren_list:
                for rens in ren_list:
                    role_list.append(rens.role[0])   
             else:
                flash(u'你不属于该群成员!')
                return redirect(url_for('index'))   
    group_list= g.user.group.all()
    position_list=[]
    name_list=[]
    tel_list=[]
    for role in role_list:
        position_list.append(role.position)
        name_list.append(role.name)
        tel_list.append(role.tel)
    return render_template('index.html',
                           title='Home',
                           form=form,
                           position_list=position_list,name_list=name_list,tel_list=tel_list,role_list=role_list,group_list=group_list,zu=zu,ren_lenth=ren_lenth)
Beispiel #2
0
def index():
	user = g.user
	#print(tr_session.get_session)
	
	# recuperer les torrents de l'utilisateur et de lui uniquement !
	torrents_from_db = Torrent.query.filter_by(user = unicode(g.user)).all()
	# this listing will be used to fetch torrents, and after, to check the update of torrents
	listing =list()
	for x in torrents_from_db:
		listing.append(x.hashstring)
	
	# envoi d'un nouveau torrent
	form = IndexForm()
	torrents = client.get_torrents(listing)
	for torrent in torrents:
		torrent_x=TorrentIndex()
		torrent_x.bandwidthpriority=torrent.bandwidthPriority
		torrent_x.status = torrent.status
		torrent_x.torrentname = torrent.name
		torrent_x.progress = float(torrent.progress)
		torrent_x.tor_id = torrent.hashString
		form.torrents.append_entry(torrent_x)
	
	torrent_to_start = False
	if form.validate_on_submit():
		for torrent_un in form.torrents:
			x = client.get_torrent(unicode(torrent_un.tor_id.data))
			# if the torrent is in the listing...
			if torrent_un.bandwidthpriority.data != int(x.bandwidthPriority) and x.hashString in listing:
				app.logger.info('%s priorité intiale %s, finale %s.',x.name,x.bandwidthPriority,torrent_un.bandwidthpriority.data)
				# we update...
				updatebandwidthpriority(x.hashString,torrent_un.bandwidthpriority.data)
				# and we remove the id from the listing -> if we don't do so, torrents bandwidth priority is updated twice for some obscure reason
				# thus staying at the first priority instead of being really updated to the user wish.
				listing.remove(torrent_un.tor_id.data)
		
		if form.torrentseed_file.data.mimetype == 'application/x-bittorrent':
			filename = secure_filename(form.torrentseed_file.data.filename)
			form.torrentseed_file.data.save(os.path.join(basedir + '/tmp', filename))
			f = open(basedir + '/tmp/' + filename)
			torrent_to_start = base64.b64encode(f.read())
		else:
			if form.torrentseed_url.data != '':
				torrent_to_start = form.torrentseed_url.data
		if torrent_to_start:
			# ON ajoute le torrent à transmission
			new_tor = client.add_torrent(torrent_to_start)
			new_tor.start()
			
			app.logger.info('%s demarré et ajouté à la base de données par %s.',new_tor,user)
			
			# on ajoute le torrent à la base de données pour se souvenir à qui il appartient.
			torrent_to_add = Torrent(hashstring=new_tor.hashString,user=unicode(g.user))
			db.session.add(torrent_to_add)
			db.session.commit()
		#except tr.TransmissionError:
		#	app.logger.info(tr.TransmissionError)
		return redirect(redirect_url())
		
	return render_template("index.html", form = form, title = "Home", user = g.user)
Beispiel #3
0
def index():
    form = IndexForm()
    form.car.choices = [(key, key) for key in data]
    if form.validate_on_submit():
        context_dict = {"car": '', "model": '', "run": 0}
        return redirect(url_for('choice', context_dict=context_dict))
    return render_template('index.html', form=form)
Beispiel #4
0
def index():
    form = IndexForm(request.form)
    app.logger.debug("Main page entry")
    flask.session['memos'] = get_memos()
    for memo in flask.session['memos']:
        app.logger.debug("Memo: " + str(memo))
    if form.validate_on_submit():
        app.logger.debug("removed memo")
    return flask.render_template('index.html', form=form)
Beispiel #5
0
def index():
  form = IndexForm(request.form)
  app.logger.debug("Main page entry")
  flask.session['memos'] = get_memos()
  for memo in flask.session['memos']:
      app.logger.debug("Memo: " + str(memo))
  if form.validate_on_submit():
          app.logger.debug("removed memo")
  return flask.render_template('index.html', form=form)
Beispiel #6
0
def index():
    form = IndexForm(request.form)

    if request.method == 'POST' and form.validate_on_submit():
        return redirect(url_for('getMeasurementInput'))

    return render_template('index.html',
                           form=form,
                           timelineData=measurementDates)
Beispiel #7
0
def show_index():
    form = IndexForm()
    if form.validate_on_submit():
        personal = form.personal.data
        mes = form.mes.data
        anio = form.anio.data
        next = request.args.get('next', None)
        if next:
            return redirect(next)
        return "¡Puedes descargar el archivo desde!"
    return render_template("index.html", form=form)
Beispiel #8
0
def index():
    current_fx_config = get_current_fx_data()
    form = IndexForm()
    if form.validate_on_submit():
        flash("Changes applied")
        current_fx_config["enabled"] = form.enabled.data
        current_fx_config["brightness"] = float(form.brightness.data)
        current_fx_config["effect"] = form.effect.data
        set_current_fx_data(current_fx_config)
        return redirect(url_for("index"))
    else:
        form.enabled.data = current_fx_config["enabled"]
        form.brightness.data = current_fx_config["brightness"]
        form.effect.data = current_fx_config["effect"]
        return render_template("index.html", form=form)
Beispiel #9
0
def command():
    form = IndexForm()
    if form.validate_on_submit():
        data = {'from': DEVICE_NAME,'to': form.device_name.data, 'command': form.command.data}
        flash('New command for node {} add'.format(form.device_name.data))
        if os.path.exists('curr_commands.json'):
            if is_non_zero_file('curr_comands.json') == True:
                with open('curr_commands.json', 'r') as f:
                    js_data = json.load(f)
            with open('curr_commands.json', 'w') as f:
                if is_non_zero_file('curr_comands.json') == False:
                    index = 1
                    js_data = {}
                    js_data.update({index: data})
                    json.dump(js_data, f)
                else:
                    index = len(js_data) + 1
                    js_data.update({index: data})
                    json.dump(js_data, f)
        return redirect('/command')
    return render_template('/index.html', titles='', form=form)
Beispiel #10
0
def index():
    form = IndexForm()
    if form.validate_on_submit():
        return redirect(url_for('search_results', query = g.search_form.search.data))
    return render_template('index.html', form=form)