コード例 #1
0
ファイル: tests.py プロジェクト: pombredanne/django-dogwood
    def test_combine_envelope_contents(self):
        # Make some pages.
        p1 = Page()
        p1.save()
        p2 = Page()
        p2.save()
        p3 = Page()
        p3.save()
        p4 = Page()
        p4.save()

        # Make a box for them.
        b = Box()
        b.save()

        # Put them in the box.
        box.add_content( (p1, p2, p3, p4) )

        # Make two envelopes and put pages in them.
        e1 = Envelope()
        e1.add_content( (p1, p2) )
        e2 = Envelope()
        e2.add_content( (p3, p4) )

        # Combine envelope contents.
        e2.send_contents_to_envelope(e1)

        self.assertEqual(len(e2.contents.all()), 0,
                         "Some content is still left in sending envelope.")
        self.assertEqual(len(e1.contents.all()), 4,
                         "Content in receiving envelope is not correct.")
        for page in [p1, p2, p3, p4]:
            self.assertTrue(page in e1.get_content(),
                            "Page not found in receiving envelope.")
コード例 #2
0
def envelope_entry(envelope_id):

    app.logger.info('inside envelope entry')        	

    form = EnvelopeForm()


    #user = g.user
    holder_form = EnvelopeHoldersForm()
    #holder_form.populate_obj(user)
    #holder_form.holders.choices = [(g.id, g.nickname) for g in User.query.order_by('nickname')]


    if request.method == "POST" and form.validate_on_submit():
	app.logger.info('id %s' % form.id)        	
	

	if envelope_id > 0 :
	    envelope = Envelope.query.filter_by(id = envelope_id).first()	
	else:
	    envelope = Envelope()
	form.populate_obj(envelope)

	envelope.timestamp = datetime.utcnow()
	#envelope.user_id = g.user.id

        db.session.add(envelope)
	db.session.flush()

        db.session.commit()
        flash(gettext('Data saved successfully' ))
        return redirect(url_for('envelope_list'))


    envelope = Envelope.query.filter_by(id = envelope_id).first()
    form = EnvelopeForm(obj=envelope)






    holders = User.query.join(Holders).filter_by(envelope_id = envelope_id).paginate(1, POSTS_PER_PAGE, False)
    #holders = db.session.query(User,Holders).join(Holders).filter_by(envelope_id = envelope_id).all()


    
    
        
    return render_template('envelope_entry.html',
        title = 'List of Envelopes',
        form = form,
        holder_form = holder_form,
        envelope = envelope, 
        pagination = holders)
コード例 #3
0
ファイル: tests.py プロジェクト: pombredanne/django-dogwood
    def test_envelope_descriptor(self):
        e = Envelope()
        self.assertTrue(e.descriptor is None, "Descriptor not initialized to None.")

        p = Page()
        p.title = 'TestEnvelope 1'
        p.data = 'This Page is used as the descriptor for TestEnvelope 1.'
        p.save()

        e.descriptor = p
        e.save()
        self.assertTrue(e.descriptor == p, "Descriptor not saved.")
        self.assertTrue(p.describes_envelope == b, "Descriptor does not point back to envelope.")
コード例 #4
0
def get_employees(request: Request):
    # TODO add a wrapper params handler that allows you to specify the type
    # and handles validation errors automatically.
    page_size = request.params.get('page[size]')
    if page_size is None:
        page_size = 10
    else:
        page_size = int(page_size)  # error thrown here

    page_after = request.params.get('page[after]')

    query = select([db.employee
                    ]).limit(page_size + 1).order_by(db.employee.c.id.asc())
    if page_after is not None:
        query = query.where(db.employee.c.id > id_from_cursor(page_after))

    employees = list(db.execute(Employee, query))
    next_id = None
    if len(employees) > page_size:
        next_id = employees[-1].id
        employees = employees[:-1]

    return Envelope(
        employees,
        Pagination(next=None if next_id is None else cursor_from_id(next_id)))
コード例 #5
0
 def wrapped(request):
     raw_response = func(request)
     
     if type(raw_response) is Response:
         return raw_response
         
     if type(raw_response) is not Envelope:
         raw_response = Envelope(raw_response)
         
     return cattr.unstructure(raw_response)
コード例 #6
0
async def api_create_envelope(request, *, remarks, postcards):
    check_admin(request)
    if not remarks or not remarks.strip():
        raise APIValueError('remarks', 'remarks cannot be empty.')
    if not postcards or not postcards.strip():
        raise APIValueError('postcards', 'postcards cannot be empty.')
    envelope = Envelope(user_id=request.__user__.id,
                        user_name=request.__user__.name,
                        user_image=request.__user__.image,
                        remarks=remarks.strip(),
                        postcards=postcards.strip())
    await envelope.save()
    return envelope
コード例 #7
0
ファイル: tests.py プロジェクト: pombredanne/django-dogwood
    def test_envelope_contents(self):
        e = Envelope()
        e.save()
        self.assertEqual(len(e.contents), 0, "Envelope should start out empty.")

        p1 = Page()
        p1.title = 'Test Page 1'
        e.add_content(p1)
        p2 = Page()
        p2.title = 'Test Page 2'
        e.add_content(p2)
        self.assertTrue(e.contains_content(p1), "Page 1 not found in envelope.")
        self.assertTrue(e.contains_content(p2), "Page 2 not found in envelope.")

        e.remove_content(p1)
        self.assertFalse(e.contains_content(p1), "Page 1 not removed from envelope.")
        e.remove_content(p2)
        self.assertFalse(e.contains_content(p2), "Page 2 not removed from envelope.")

        self.assertEqual(len(e.contents), 0, "Envelope should now be empty.")
コード例 #8
0
ファイル: tests.py プロジェクト: pombredanne/django-dogwood
 def test_new_envelope(self):
     e = Envelope()
     e.save()
     self.assertTrue(e.pk > 0, "Envelope not created.")