Skip to content

Commit

Permalink
Merge pull request #2 from Postcard/v0.2.1
Browse files Browse the repository at this point in the history
place name, place code, event name and event code can be rendered
  • Loading branch information
VictorienTardif authored Feb 2, 2018
2 parents eb42192 + c74c91d commit 1051e75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def read(fname):
setup(
name = "ticketrenderer",
packages = ["ticketrenderer"],
version = "0.2.0",
version = "0.2.1",
author = "Benoît Guigal",
author_email = "[email protected]",
description = ("A library used to render Figure tickets from ticket templates"),
url = "https://github.com/Postcard/ticket-renderer-python",
download_url = 'https://github.com/Postcard/ticket-renderer-python/tarball/0.2.0',
download_url = 'https://github.com/Postcard/ticket-renderer-python/tarball/0.2.1',
py_modules=('ticketrenderer',),
install_requires=[
'jinja2==2.7.3',
Expand Down
17 changes: 15 additions & 2 deletions ticketrenderer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def test_render(self):

html = '{{css_url}} {{picture}} {{code}} {{datetime | datetimeformat}} ' \
'{{textvariable_1}} {{imagevariable_2}} ' \
'{{image_3}}'
'{{image_3}}' \
'{{place_name}} {{place_code}} {{event_name}} {{event_code}}'
texts = [{'text':'Titi'}, {'text':'Vicky'}, {'text':'Benni'}]
text_variables = [{'id': '1', 'items': texts, 'mode': 'random'}]

Expand Down Expand Up @@ -48,14 +49,26 @@ def test_render(self):
code = 'SJ98H'
date = datetime(2016, 01, 01)
picture = 'http://path/to/picture'
rendered = ticket_renderer.render(code=code, date=date, picture=picture, counter=0)
place = {
'name': 'Place name',
'code': 'PPPP'
}
event = {
'name': 'Event name',
'code': 'EEEE'
}
rendered = ticket_renderer.render(code=code, date=date, picture=picture, counter=0, place=place, event=event)
self.assertIn("http://path/to/picture", rendered)
self.assertIn(code, rendered)
self.assertIn("http://static/ticket.css", rendered)
self.assertTrue("Titi" in rendered or "Vicky" in rendered or "Benni" in rendered)
self.assertTrue("http://media/images/image1" in rendered or "http://media/images/image2" in rendered)
self.assertTrue("http://media/images/image3" in rendered)
self.assertIn("01/01/2016 00:00", rendered)
self.assertIn("Place name", rendered)
self.assertIn("Event name", rendered)
self.assertIn("PPPP", rendered)
self.assertIn("EEEE", rendered)

def test_render_sequential(self):
html = '{{css_url}} {{picture}} {{code}} {{datetime | datetimeformat}} ' \
Expand Down
8 changes: 6 additions & 2 deletions ticketrenderer/ticketrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ def __init__(self, ticket_template, media_url, css_url):
self.media_url = media_url
self.css_url = css_url

def render(self, picture, code, date, counter):
def render(self, picture, code, date, counter, place, event):

context = {
'title': self.template['title'],
'description': self.template['description'],
'picture': picture,
'datetime': date,
'code': code,
'css_url': self.css_url
'css_url': self.css_url,
'place_name': place.name if place else None,
'place_code': place.code if place else None,
'event_name': event.name if event else None,
'event_code': event.code if event else None
}

for image in self.template['images']:
Expand Down

0 comments on commit 1051e75

Please sign in to comment.