コード例 #1
0
    def test_model(self):
        """Creates some new objects in the database and tries to query
        them.

        """

        # Creates some authors
        author1 = Author()
        author1.first_name = "Pascal"
        author1.last_name = "Hartig"

        author2 = Author()
        author2.first_name = "Ali"
        author2.last_name = "Afshar"

        session.add_all([author1, author2])
        session.commit()

        # Catch unique constraint failures
        author3 = Author()
        author3.first_name = "Pascal"
        author3.last_name = "Hartig"
        session.add(author3)

        assert_raises(IntegrityError, lambda: session.commit())
        session.rollback()

        self._test_author_queries()
コード例 #2
0
 def test_objects(self):
     assert session.query(self.Note).count() == 0
     for t in 'abcdef':
         n = self.Note()
         n.title = n.note = n.importance = t
         session.add(n)
     session.commit()
     assert session.query(self.Note).count() == 6
コード例 #3
0
ファイル: notes.py プロジェクト: passy/glashammer-rdrei
def edit_submit_view(req, nid):
    # find note
    note = session.query(Note).get(nid)
    # TODO: check if note exists
    note.title = req.form.get('title')
    note.note = req.form.get('text')
    note.importance = req.form.get('importance')
    session.add(note)
    session.commit()
    return render_response('notes_success.jinja')
コード例 #4
0
ファイル: notes.py プロジェクト: passy/glashammer-rdrei
def add_view(req):
    # validate form
    title = req.form.get('title', 'kT')
    text = req.form.get('text')
    prio = req.form.get('importance')
    if not text:
        text = "kT"
    note = Note(title, text, prio)
    session.add(note)
    session.commit()
    return render_response('notes_success.jinja')
コード例 #5
0
ファイル: __init__.py プロジェクト: fugu13/opp-frontpage
 def new(self, req, model_name):
     model = self.model.get_model_or_404(model_name)
     if req.method == 'POST':
         item = model()
         fs = FieldSet(item, session=session, data=req.form)
         if fs.validate():
             fs.sync()
             item.save()
             session.commit()
             return self.redirect_to('list', model_name=model_name)
     else:
         fs = FieldSet(model, session=session)
     return self.render_response('_admin/new.jinja',
         item=None, model_name=model_name, fs=fs)
コード例 #6
0
ファイル: __init__.py プロジェクト: fugu13/opp-frontpage
 def edit(self, req, model_name, id):
     model = self.model.get_model_or_404(model_name)
     item = model.query.get(id)
     if req.method == 'POST':
         fs = FieldSet(item, data=req.form)
         if fs.validate():
             fs.sync()
             item.save()
             session.commit()
             return self.redirect_to('list', model_name=model_name)
     else:
         fs = FieldSet(item)
     return self.render_response('_admin/new.jinja',
         item=item, model_name=model_name, fs=fs, crumbs=[model_name, 'Edit'])