Exemplo n.º 1
0
def save():
    my_form = CreateForm(csrf_enabled=False)
    my_post = None
    if not my_form.post_id.data and my_form.validate_on_submit():
        my_post = Post(my_form.title.data, my_form.text.data)
        db.session.add(my_post)
    if my_form.post_id.data and my_form.validate_on_submit():
        my_post = Post.query.get(my_form.post_id.data)
        my_post.title = my_form.title.data
        my_post.text = my_form.text.data
    db.session.commit()
    return redirect(url_for('view', post_id=my_post.post_id))
Exemplo n.º 2
0
def create():
    """
    Page to create a new project account
    """
    form = CreateForm(request.form)
    if form.validate_on_submit():
        # On submit, grab form information
        project_name = form.project_name.data
        email = form.email.data
        password = form.password.data
        hashed_password = generate_password_hash(password)
        description = form.description.data

        # Create the account
        db = DB()
        resp = db.create(project_name,
                         password,
                         hashed_password,
                         description=description,
                         email=email)
        if resp['status']:
            flash(u'Project successfully created!')
            return redirect(
                url_for('admin_home', admin_id=g.admin['project_id']))
        else:
            flash(resp['message'])

    return render_template('create.html', form=form)
Exemplo n.º 3
0
def create():
    form = CreateForm()
    if request.method == 'POST' and form.validate_on_submit():
        file = request.files['userfile']
        if file:
            filename = secure_filename(file.filename)
            if not (check_file_extension(file.filename)):
                flash(('red', 'Неподдерживаемый формат файла'))
                view_log.error('Неподдерживаемый формат файла')
                view_log.error(filename)
                return redirect(url_for('create'))
            view_log.info('check new article ' + request.form['article_name'] +
                          'by ' + request.form['author_name'])
            article = articles(article_name = request.form['article_name'],\
                               author_name = request.form['author_name'],\
                               article_file = filename,\
                               email = request.form['email'])
            flash(save_article(article, file, filename))
            #add email notification about add new article
            return render_template('create.html',\
                                    form=form)
        else:
            flash(('red', 'Прикрепите файл'))
            return redirect(url_for('create'))

    return render_template("create.html",\
                           form=form)
Exemplo n.º 4
0
def create():
    form = CreateForm()
    if form.validate_on_submit():
	newuser = form.username.data
	password = crypt.crypt(form.password.data,salt())
	user = User(nickname=newuser, password=sha256_crypt.encrypt(form.password.data), email=form.email.data, role=ROLE_USER)
	db.session.add(user)
	db.session.commit()
	os.system("sudo mkdir " + settings.WORKING_DIR + newuser)
        os.system("sudo mkdir " + settings.REMOTE_DIR + newuser)
	os.system("sudo mkdir " + settings.WORKING_DIR + newuser + "/myRepo")
	os.system("sudo chmod 777 " + settings.REMOTE_DIR + newuser)
        os.system("sudo chmod 777 " + settings.WORKING_DIR + newuser)
	repo = Repo.init_bare(settings.REMOTE_DIR + newuser + "/")
	newrepo = Rpstry(repourl="/myRepo/", owner=user)
	db.session.add(newrepo)
        db.session.commit()
	working_repo = repo.clone(settings.WORKING_DIR + newuser + newrepo.repourl, False, False, "origin")
	p = subprocess.Popen(["sudo", "git", "remote", "add", "origin", "file:///" + settings.REMOTE_DIR + newuser + "/"], cwd=settings.WORKING_DIR + newuser + "/myRepo/")
	p.wait()
	open(settings.REMOTE_DIR + newuser + "/.htpasswd", 'a').writelines(newuser + ":" + password + "\n")
	s = get_serializer()
    	payload = s.dumps(user.id)
    	url = url_for('activate_user', payload=payload, _external=True)	
	msg = Message('Confirm Email Address', sender = ADMINS[0], recipients = [user.email])
	msg.body = "Follow this link to activate account: " + url
	mail.send(msg)
	flash("User created and activation email sent")
	return redirect(url_for('login'))
    return render_template('createAccount.html',
        title = 'Create New Account',
        form = form)
Exemplo n.º 5
0
def create():
    form = CreateForm()
    if request.method == 'POST' and form.validate_on_submit():
        file = request.files['userfile']
        if file:
            filename = secure_filename(file.filename)
            if not(check_file_extension(file.filename)):
                flash(('red','Неподдерживаемый формат файла'))
                view_log.error('Неподдерживаемый формат файла')
                view_log.error(filename)
                return redirect(url_for('create'))
            view_log.info('check new article ' + request.form['article_name'] + 'by '+ request.form['author_name'])
            article = articles(article_name = request.form['article_name'],\
                               author_name = request.form['author_name'],\
                               article_file = filename,\
                               email = request.form['email'])
            flash(save_article(article, file, filename))
            #add email notification about add new article
            return render_template('create.html',\
                                    form=form)
        else: 
            flash(('red','Прикрепите файл'))
            return redirect(url_for('create'))

    return render_template("create.html",\
                           form=form)
Exemplo n.º 6
0
def new():
    form = CreateForm()
    if form.validate_on_submit():
        todo = TodoModel(title=form.title.data, remarks=form.remarks.data)
        todo.save_to_db()
        return redirect(url_for('view.home'))
    return render_template('create.html', form=form)
Exemplo n.º 7
0
def create():
    form = CreateForm()

    if form.validate_on_submit():
        page = pm.save_new_page(form.title.data, content=form.body.data, tags=form.tags.data)
        flash(_('Page created.'), 'success')
        return redirect(url_for('show', id=page.id))
    return render_template("editor.html", form=form, title=_('create a new page'), flag='Create', highlight=True)
Exemplo n.º 8
0
def create():
    """
    Creates a new organization belonging to the currently signed in user
    :return:
    """
    form = CreateForm(request.form)
    if form.validate_on_submit():
        org, membership = utils.organization.create_organization(form.name.data, g.user.id)
        return redirect('/organization/' + str(org.id))

    return render_template('main/create.html', form=CreateForm())
Exemplo n.º 9
0
def add():
    form = CreateForm()
    nick = session['profile']['name']
    if form.validate_on_submit():
        data = {
            'author': form.author.data,
            'title': form.title.data,
            'year': form.year.data
        }
        response = requests.post('http://service/publications',
                                 headers={"Authorization": nick + ":password"},
                                 data=data)
        redis.publish(nick, 'There is new publication!')
        return redirect(url_for('publications'))
    return render_template('create.html', form=form)
Exemplo n.º 10
0
def create():
    # creates a drink recipe and enters into recipes collection
    form = CreateForm(request.form)
    if form.validate_on_submit():
        # set the collection
        recipes_db = mongo.db.recipes
        # insert the new recipe
        recipes_db.insert_one({
            'name': request.form['name'],
            'user': session['username'],
            'image': request.form['image'],
            'ingredients': request.form['ingredients'],
            'instructions': request.form['instructions']
        })
        return redirect(url_for('home', title='New Drink Created'))
    return render_template('create.html', title='Create a Drink', form=form)
Exemplo n.º 11
0
def create():
    form = CreateForm()
    if form.validate_on_submit():
        eventOwner = Users.query.filter_by(id=int(session['user'])).first()
        new_event = Events(sport=form.sport.data,
                           starttime=form.starttime.data,
                           endtime=form.endtime.data,
                           date=form.date.data,
                           place=form.place.data,
                           n_ppl=form.n_ppl.data,
                           eventOwner=eventOwner)
        db.session.add(new_event)
        db.session.commit()
        flash('Event successfully created by ' +
              new_event.eventOwner.firstname)
        return redirect('/index')
    return render_template('create.html', title='Create', form=form)
Exemplo n.º 12
0
def create_account():
    form = CreateForm()

    if form.validate_on_submit():
        name = form.name.data
        password = form.password.data
        if form.balance.data > 0:
            balance = form.balance.data
        else:
            balance = 0
        new_account = Account(name, password, balance)
        db.session.add(new_account)
        db.session.commit()
        new_transaction = Transaction('deposit', 'account opening',
                                      new_account.id, balance)
        db.session.add(new_transaction)
        db.session.commit()
        session['username'] = new_account.name

        return redirect(url_for('my_account'))

    return render_template('create_account.html', form=form)
Exemplo n.º 13
0
def create():
    """
    Page to create a new project account
    """
    form = CreateForm(request.form)
    if form.validate_on_submit():
        # On submit, grab form information
        project_name = form.project_name.data
        email = form.email.data
        password = form.password.data
        hashed_password = generate_password_hash(password)
        description = form.description.data

        # Create the account
        db = DB()
        resp = db.create(project_name, password, hashed_password, description=description, email=email)
        if resp['status']:
            flash(u'Project successfully created!')
            return redirect(url_for('admin_home', admin_id=g.admin['project_id']))
        else:
            flash(resp['message'])

    return render_template('create.html', form=form)