예제 #1
0
def init():
    a = models.Author.query.all()
    b = models.Book.query.all()
    for c in a:
        db.session.delete(c)
        db.session.commit()
    for c in b:
        db.session.delete(c)
        db.session.commit()
    a1 = models.Author('author1')
    a2 = models.Author('author2')
    a3 = models.Author('author3')
    a4 = models.Author('author4')
    b1 = models.Book('book1')
    b2 = models.Book('book2')
    b3 = models.Book('book3')
    b4 = models.Book('book4')
    a1.books.append(b1)
    a1.books.append(b2)
    a2.books.append(b2)
    a3.books.append(b2)
    a3.books.append(b3)
    a4.books.append(b1)
    a4.books.append(b2)
    a4.books.append(b3)
    a4.books.append(b4)
    db.session.add(a1)
    db.session.add(a2)
    db.session.add(a3)
    db.session.add(a4)
    db.session.commit()
    flash('Database was reinitiated')
    return redirect('/index')
예제 #2
0
파일: auth.py 프로젝트: kyonetca/colibri
def create_stuff():
    db.create_all()
    if models.Category.query.count() == 0:
        prog = models.Category()
        prog.name = 'Programming'
        db.session.add(prog)
        os = models.Category()
        os.name = 'Operating Systems'
        db.session.add(os)
        db.session.commit()

    if models.Position.query.count() == 0:
        m = models.Position()
        m.mnemonic = 'mensolone'
        m.description = 'quello grosso, dai!'
        m2 = models.Position()
        m2.mnemonic = 'scaffaluccio'
        m2.description = "piccino piccio'"

        aut_k = models.Author()
        aut_k.name = 'Kernighan'
        aut_r = models.Author()
        aut_r.name = 'Ritchie'
        op = models.Opera()
        op.title = 'Linguaggio C'
        op.authors = [aut_k, aut_r]
        es = models.Esemplare()
        es.opera = op
        es.position = m
        db.session.add(es)
        es = models.Esemplare()
        es.opera = op
        es.position = m2
        db.session.add(es)

        op = models.Opera()
        op.title = 'The UNIX programming environment'
        op.authors = [aut_k]
        es = models.Esemplare()
        es.opera = op
        es.position = m
        db.session.add(es)
        db.session.commit()
    if models.Role.query.count() == 0:
        supa = user_datastore.create_role(name='super',
                                          description='Will do ANYTHING')
        user_datastore.create_role(name='librarian',
                                   description='Can manage books')
        db.session.commit()
    if models.User.query.count() == 0:
        adm = user_datastore.create_user(email='admin@test',
                                         password=encrypt_password('password'))
        user_datastore.add_role_to_user(adm, supa)
        db.session.commit()
        return 'created'
    else:
        return "C'hai provato, furbettino!"
예제 #3
0
파일: views.py 프로젝트: vssaAnjos/estudos
def add_author():

    form = forms.AuthorForm()

    if form.validate_on_submit():

        author = models.Author()
        author.name = form.name.data
        db.session.add(author)
        db.session.commit()

        if not form.validate():
            flash('Name field is required', 'error')
            return render_template('author.html', form=form, add_author=True)

        try:
            db.session.add(author)
            db.session.commit()
            flash('You have successfully added a new author.')
        except:
            # in case author name already exists
            flash('Error: Author name already exists.')

        return redirect(url_for('index'))
    else:
        return render_template('author.html', form=form, add_author=True)
예제 #4
0
def register():
	redirect_if_logged_in('/')
	form = RegisterForm()
	if form.validate_on_submit():
		if models.Author.query.filter_by(name = form.username.data).first():
			flash('Nombre ya registrado')
		else:
			h = hash_object(form.password.data)
			ext = '.' + request.files['cert'].filename.split('.')[-1]
			cert = os.path.join(app.config['USER_CERTIFICATE_FOLDER'],
					form.username.data + ext)
			request.files['cert'].save(cert)
			#TODO: validate chain of trust
			try:
				if getCommonName(cert) == form.username.data:
					#Save as author
					author = models.Author(name = form.username.data)
					db.session.add(author)
					db.session.commit()
					
					#Save as user (author info needed)
					author = models.Author.query.filter_by(name = form.username.data).first()
					user = models.User(id = author.id, name = author.name, password = h)
					db.session.add(user)
					db.session.commit()
					return redirect('/')
				else:
					flash('Certificado no pertenece al usuario')
			except ValueError:
				flash('Archivo no es un certificado')
			#remove on failure
			os.remove(cert)
	flash_errors(form)
	return render_template('register.html', data=data_for('/register.html'),
			form=form)
예제 #5
0
def get_author(authorname):
    aut = models.Author.query.filter_by(name=authorname).first()
    if aut is None:
        aut = models.Author()
        aut.name = authorname
    else:
        print 'anvedi, ripescato', authorname, aut.id
    return aut
예제 #6
0
 def add_book(self, data):
     if 'csrf_token' in data:
         data.pop('csrf_token')
     new_book = models.Book(title=data['title'], borrowed=data['available'])
     for author in data['author']:
         new_book.authors.append(models.Author(name=author))
     db.session.add(new_book)
     db.session.commit()
예제 #7
0
 def change(self, id, data):
     if 'csrf_token' in data:
         data.pop('csrf_token')
     book = models.Book.query.get(id)
     book.title = data['title']
     book.borrowed = data['available']
     book.authors.clear()
     for author in data['author']:
         book.authors.append(models.Author(name=author))
     db.session.add(book)
     db.session.commit()
예제 #8
0
def add_book(book_form):
    new_title = book_form.data["title"]
    title = models.Title(title=new_title)
    db.session.add(title)

    new_author_input = book_form.data["author"]
    new_author_list = new_author_input.split(sep=",")

    for i in new_author_list:
        author = models.Author.query.filter_by(author=i).first()
        if author is None:
            author = models.Author(author=i)
            db.session.add(author)
            db.session.commit()
        title.authors.append(author)
        db.session.commit()
예제 #9
0
def create_group():
	form = NewGroupForm()
	if form.validate_on_submit():
		group_name = form.name.data
		master_key = form.master_key.data
		public_keys = form.public_keys.data
		challenge = form.answer.data
		if models.Group.query.filter_by(name = group_name).first() is None:
			#validate challenge
			if BoyenScheme.is_signature_valid(data_for('/register_group.html')['challenge'],
					challenge,
					group_name,
					public_keys = public_keys,
					master_key = master_key):
			#if (verify_boyen(master_key, public_keys,
			#		data_for('/register_group.html')['challenge'],
			#		challenge)):
				##add group
				
				#as author
				db.session.add(models.Author(name = group_name))
				db.session.commit()
				
				#as group
				gid = models.Author.query.filter_by(name = group_name).first().id
				db.session.add(models.Group(id = gid, name = group_name))
				db.session.commit()
				
				#save keys
				gid = str(gid)
				with open(os.path.join(app.config['GROUP_KEYS_FOLDER'],
						gid + '.mkey'), 'w') as f:
					f.write(master_key)
				with open(os.path.join(app.config['GROUP_KEYS_FOLDER'],
						gid + '.pkeys'), 'w') as f:
					f.write(public_keys)
				
				return redirect('/')
			else:
				flash('Fallo de validación, verifique que las claves y la firma son correctas')
		else:
			flash(u'Grupo ya existe con ese nombre')
	else:
		flash_errors(form)
	return render_template('register_group.html', data=data_for('/register_group.html'), form=form)
예제 #10
0
def add():
    form = AddForm()
    if form.validate_on_submit():
        if form.a_name.data in str(models.Author.query.all()):
            author = models.Author.query.filter_by(
                name=form.a_name.data).first()
        else:
            author = models.Author(form.a_name.data)
        if form.b_name.data in str(models.Book.query.all()):
            book = models.Book.query.filter_by(name=form.b_name.data).first()
        else:
            book = models.Book(form.b_name.data)
        author.books.append(book)
        db.session.add(author)
        db.session.commit()
        flash('Added successfully')
        return redirect('/index')
    return render_template('Add.html', title='Add', form=form)
예제 #11
0
파일: admin.py 프로젝트: kyonetca/colibri
def _author_lookup(author_string):
    aut = models.Author.query.filter_by(name=author_string).first()
    if aut is None:
        aut = models.Author()
        aut.name = author_string
    return aut
예제 #12
0
def newtitle():
    """Render the website's new title page."""
    folder = app.config['UPLOAD_FOLDER']
    
    if request.method=="POST":
        
        form = request.form
        title = form['title']
        subtitle = form['subtitle']
        description = form['description']
        category = int(form['category'])
        status = 'IN PROGRESS'
        
        tid = genID()
        
        newtitle = models.Title(titleid=tid,title=title,subtitle=subtitle,description=description,status=status)
        db.session.add(newtitle)
        
        authorfname = form['authorfname']
        authorlname = form['authorlname']
        
        if(db.session.query(db.exists().where(db.and_(models.Author.firstname==authorfname, models.Author.lastname==authorlname)))).scalar():
            aid = models.Author.query.filter_by(firstname=authorfname,lastname=authorlname).first()
        else:
            aid = genID()
            newauth = models.Author(authorid=aid,firstname=authorfname,lastname=authorlname)
            db.session.add(newauth)
        
        by = models.By(titleid=tid, authorid=aid)
        db.session.add(by)
        
        phase1 = models.Phase(phaseid=genID(),budget=0,stage='Acquisition',current=True)
        has1 = models.Has(titleid=tid,phaseid=phase1.phaseid)
        db.session.add(phase1)
        db.session.add(has1)
        phase2 = models.Phase(phaseid=genID(),budget=0,stage='EditorialProduction',current=False)
        has2 = models.Has(titleid=tid,phaseid=phase2.phaseid)
        db.session.add(phase2)
        db.session.add(has2)
        phase3 = models.Phase(phaseid=genID(),budget=0,stage='SalesMarketing',current=False)
        db.session.add(phase1)
        has3 = models.Has(titleid=tid,phaseid=phase3.phaseid)
        db.session.add(phase3)
        db.session.add(has3)
        
        sales = models.Sales(titleid=tid,localsales=0,regionalsales=0,internationalsales=0,totalsales=0)
        db.session.add(sales)
        
        belongs_to = models.Belongs_to(titleid=tid,categoryid=category)
        db.session.add(belongs_to)
        
        path = folder+'/'+str(tid)
        
        if not os.path.exists(path):
            os.makedirs(path)
            db.session.commit()
            return redirect(url_for('titleinfo'),titleid=tid)
        else:
            flash('Title already exists')
            
    return render_template('newtitle.html')