Example #1
0
def generate_ticket(eventUser, lang='en_US.UTF8'):
    ticket_template = svglue.load(file=os.path.join(settings.STATIC_ROOT, 'manager/img/ticket_template_p.svg'))
    ticket_template.set_text('event_name', eventUser.event.name[:30])
    locale.setlocale(locale.LC_TIME, lang)  # Locale del request
    ticket_template.set_text('event_date', (eventUser.event.date.strftime("%A %d de %B de %Y")).decode('utf-8'))
    place = json.loads(eventUser.event.place)
    if place.get("name"):  # Si tiene nombre cargado
        ticket_template.set_text('event_place_name', place.get("name"))
        ticket_template.set_text('event_place_address', place.get("formatted_address")[:50])
    else:
        ticket_template.set_text('event_place_name', place.get("formatted_address")[:50])
        ticket_template.set_text('event_place_address', '')

    ticket_template.set_text('ticket_type', u'Entrada General')
    qr = pyqrcode.create(eventUser.id)
    code = io.BytesIO()
    qr.png(code, scale=7, quiet_zone=0)
    ticket_template.set_image('qr_code', code.getvalue(), mimetype='image/png')
    ticket_template.set_text('eventUser_PK', str(eventUser.id).zfill(12))
    ticket_template.set_text('eventUser_email', eventUser.user.email)  # No se enviara a los NonRegisteredAttendee

    userName_l1 = u"%s %s" % (eventUser.user.first_name, eventUser.user.last_name)
    userName_l2 = ''
    if (len(userName_l1) > 30):
        userName_l1 = eventUser.user.first_name[:30]  # Por si tiene mas de 30 caracteres
        userName_l2 = eventUser.user.last_name[:30]

    ticket_template.set_text('eventUser_name_l1', userName_l1)
    ticket_template.set_text('eventUser_name_l2', userName_l2)

    return str(ticket_template)
Example #2
0
def generate_ticket(eventUser, lang='en_US.UTF8'):
    ticket_template = svglue.load(file=os.path.join(settings.STATIC_ROOT, 'manager/img/ticket_template_p.svg'))
    ticket_template.set_text('event_name', eventUser.event.name[:30])
    locale.setlocale(locale.LC_TIME, lang) #Locale del request
    ticket_template.set_text('event_date', (eventUser.event.date.strftime("%A %d de %B de %Y")).decode('utf-8'))
    place = json.loads(eventUser.event.place)
    if place.get("name"):  # Si tiene nombre cargado
        ticket_template.set_text('event_place_name', place.get("name"))
        ticket_template.set_text('event_place_address', place.get("formatted_address")[:50])
    else:
        ticket_template.set_text('event_place_name', place.get("formatted_address")[:50])
        ticket_template.set_text('event_place_address', '')

    ticket_template.set_text('ticket_type', u'Entrada General')
    qr = pyqrcode.create(eventUser.id)
    code = io.BytesIO()
    qr.png(code, scale=7, quiet_zone=0)
    ticket_template.set_image('qr_code', code.getvalue(), mimetype='image/png')
    ticket_template.set_text('eventUser_PK', str(eventUser.id).zfill(12))
    ticket_template.set_text('eventUser_email', eventUser.user.email)  # No se enviara a los NonRegisteredAttendee

    userName_l1 = u"%s %s" % (eventUser.user.first_name, eventUser.user.last_name)
    userName_l2 = ''
    if (len(userName_l1) > 30):
        userName_l1 = eventUser.user.first_name[:30]  # Por si tiene mas de 30 caracteres
        userName_l2 = eventUser.user.last_name[:30]

    ticket_template.set_text('eventUser_name_l1', userName_l1)
    ticket_template.set_text('eventUser_name_l2', userName_l2)

    return str(ticket_template)
Example #3
0
    def save_substitutes(self, fo=None, fi=None, group=None):
        """Substitute texts and store the substitutions to SVG file.
 
        Note
        ----
            In most cases it is convenient to skip the arguments fi and fo.
     
        """
        log.debug("Substitute text and store to SVG file.")
        if fi == None:
            fi = self._fn
        if fo == None:
            fo = self._fn

        if group is None:
            group = self.layer.default_group

        tpl = svglue.load(file=self._fn)

        for cpt_key, cpt_val in self.cpt_tspan.items():
            tpl.set_text(cpt_key, cpt_val)

        for cpt_key, cpt_val in self.cpt_flowpara.items():
            tpl.set_flowtext(cpt_key, cpt_val)

        for cpt_key, cpt_val in self.cpt_rect.items():
            tpl.set_image(cpt_key, file=cpt_val, mimetype='image/png')

        src = tpl.__str__()  #str(tpl) #str(tpl) does not work in python3
        open(self._fn, 'wb').write(src)
Example #4
0
def generate_ticket(user):
    ticket_data = user.get_ticket_data()
    ticket_template = svglue.load(file=os.path.join(settings.STATIC_ROOT, 'manager/img/ticket_template_p.svg'))
    ticket_template.set_text('event_name', "FLISoL " + ticket_data['event'].name[:24])
    ticket_template.set_text('event_date', localize(ticket_data['event_date']).decode('utf-8'))
    place = json.loads(ticket_data['event'].place)
    if place.get("name"):  # Si tiene nombre cargado
        ticket_template.set_text('event_place_name', place.get("name"))
        ticket_template.set_text('event_place_address', place.get("formatted_address")[:50])
    else:
        ticket_template.set_text('event_place_name', place.get("formatted_address")[:50])
        ticket_template.set_text('event_place_address', '')

    ticket_template.set_text('ticket_type', unicode(_(u"General Ticket")))
    qr = pyqrcode.create(ticket_data['ticket'].id)
    code = io.BytesIO()
    qr.png(code, scale=7, quiet_zone=0)
    ticket_template.set_image('qr_code', code.getvalue(), mimetype='image/png')
    ticket_template.set_text('eventUser_PK', str(ticket_data['ticket'].id).zfill(12))
    ticket_template.set_text('eventUser_email', ticket_data['email'])

    if ticket_data['first_name'] is not None or ticket_data['last_name'] is not None:
        user_name_l1 = u"%s %s" % (ticket_data['first_name'], ticket_data['last_name'])
        user_name_l2 = ''
        if len(user_name_l1) > 30:
            user_name_l1 = ticket_data['first_name'][:30]  # Por si tiene mas de 30 caracteres
            user_name_l2 = ticket_data['last_name'][:30]
    elif ticket_data.nickname is not None:
        user_name_l1 = u"%s" % ticket_data['nickname'][:30]
        user_name_l2 = ''
    elif ticket_data['email'] is not None:
        user_name_l1 = u"%s" % ticket_data['email'][:30]
        user_name_l2 = ''

    ticket_template.set_text('eventUser_name_l1', user_name_l1)
    ticket_template.set_text('eventUser_name_l2', user_name_l2)

    return str(ticket_template)
Example #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import svglue


# load the template from a file
tpl = svglue.load(file='sample-tpl.svg')

# replace some text
tpl.set_text('sample-text', u'This was replaced.')

# replace the pink box with 'hello.png'. if you do not specify the mimetype,
# the image will get linked instead of embedded
tpl.set_image('pink-box', file='hello.png', mimetype='image/png')

# svgs are merged into the svg document (i.e. always embedded)
tpl.set_svg('yellow-box', file='Ghostscript_Tiger.svg')

# to render the template, cast it to a string. this also allows passing it
# as a parameter to set_svg() of another template
src = str(tpl)

# write out the result as an SVG image and render it to pdf using cairosvg
import cairosvg
with open('output.pdf', 'w') as out, open('output.svg', 'w') as svgout:
    svgout.write(src)
    cairosvg.svg2pdf(bytestring=src, write_to=out)
Example #6
0
parser.add_argument(
    'export',
    nargs='?',
    const=ExportCore.cairosvg,
    type=ExportCore,
    choices=list(ExportCore),
    help="export to PDF svgs files using inkscape or cairosvg lib")
args = parser.parse_args()
print(args)

if args.name != None:
    svg_filename = '{}.svg'.format(args.name)
    csv_filename = '{}.csv'.format(args.name)

    # load the template from a file
    tpl = svglue.load(file=svg_filename)

    with open(csv_filename, encoding="ISO-8859-1") as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        count = 0
        for row in csv_reader:
            # replace some text
            fullname = '{} {}'.format(row[0], row[1])
            tpl.set_text('textVAR_name', fullname)
            #print(f'\t{row[0]} {row[1]}')

            # to render the template, cast it to a string. this also allows passing it
            # as a parameter to set_svg() of another template
            src = str(tpl)

            count += 1
 def load_data(self):
     """Loads the svg and the replacement data"""
     self.svg = svglue.load(file=self.svg_filename)
     with open(self.replace_filename, 'r') as f:
         self.replace_items = f.readlines()
     self.replace_items = [item.rstrip() for item in self.replace_items]
Example #8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import svglue

# load the template from a file
tpl = svglue.load(file='sample-tpl.svg')

# replace some text
tpl.set_text('sample-text', u'This was replaced.')

# replace the pink box with 'hello.png'. if you do not specify the mimetype,
# the image will get linked instead of embedded
tpl.set_image('pink-box', file='hello.png', mimetype='image/png')

# svgs are merged into the svg document (i.e. always embedded)
tpl.set_svg('yellow-box', file='Ghostscript_Tiger.svg')

# to render the template, cast it to a string. this also allows passing it
# as a parameter to set_svg() of another template
src = str(tpl)

# write out the result as an SVG image and render it to pdf using cairosvg
import cairosvg
with open('output.pdf', 'w') as out, open('output.svg', 'w') as svgout:
    svgout.write(src)
    cairosvg.svg2pdf(bytestring=src, write_to=out)
Example #9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import argparse
import svglue
import cairosvg

parser = argparse.ArgumentParser(
    description="read meter, post to internet and send to energy wristband")
parser.add_argument('--text', action='store', help="text")
parser.add_argument('--image', action='store', help="image")
args = parser.parse_args()

# load the template from a file
tpl = svglue.load(file='cover-template.svg')

# replace date
tpl.set_text('sample-text', args.text)

# replace the pink box with 'hello.png'. if you do not specify the mimetype,
# the image will get linked instead of embedded
tpl.set_image('yellow-box', file=args.image)

# to render the template, cast it to a string. this also allows passing it
# as a parameter to set_svg() of another template
src = str(tpl)

# write out the result as an SVG image and render it to pdf using cairosvg
with open('cover.pdf', 'w') as out:
    cairosvg.svg2pdf(bytestring=src, write_to=out)
import cairosvg
#SVG templates
facebook_fanpage_header_image = 'Facebook/Facebook_fan_page_headerimage.svg'
#template variables
city_name_FBFPHI = "city_name"
city_photo_FBFPHI = "city_photo"

name_of_your_city = "Paris"  #ENTER **YOUR** CITY NAME!
path_to_your_image = 'images/architecture-buildings-church-338515.jpg'  #ENTER Path your your FB Fanpage header image (PNG format)

all_image_templates = [facebook_fanpage_header_image
                       ]  #list of all template files

for template in all_image_templates:
    # load the template from a file
    tpl = svglue.load(file=template)

    # replace some text
    tpl.set_text("city_name", str(name_of_your_city))

    # replace the pink box with 'hello.png'. if you do not specify the mimetype,
    # the image will get linked instead of embedded
    tpl.set_image("city_photo", file=path_to_your_image, mimetype='image/png')

    # svgs are merged into the svg document (i.e. always embedded)
    tpl.set_svg('yellow-box', file='Ghostscript_Tiger.svg')

    # to render the template, cast it to a string. this also allows passing it
    # as a parameter to set_svg() of another template
    src = str(tpl)
pg_firm = u'ООО "АРКОМ"'
pg_bank = u'СТ-ПЕТЕРБУРГСКИЙ ФИЛИАЛ ПАО "ПРОМСВЯЗЬБАНК"'
pg_account = '40702810506000011363'
pg_corresp = '30101810000000000920'
pg_bik = '044030920'
pg_order = '1220-1229' 
pg_amount = '2870,00'
"""

pg_account_bank = u''
pg_account_bank = pg_account + u' в ' + pg_bank.decode('UTF-8')
pg_firm = pg_firm.decode('UTF-8')
pg_mgr_name = pg_mgr_name.decode('UTF-8')

# load the template from a file
tpl = svglue.load(file='person-bank.svg')

# replace some text
#tpl.set_text('bill_amount1', u'2870,00')
#tpl.set_text('bill_amount2', u'2870,00')
#tpl.set_text('inn_kpp1', u'ИНН: 7802731174 КПП: 780201001')
#tpl.set_text('inn_kpp2', u'ИНН: 7802731174 КПП: 780201001')

import textwrap

wr = textwrap.TextWrapper(width=50, break_long_words=False)
a_b_list = wr.wrap(pg_account_bank)

tpl.set_text('firm1', pg_firm)
tpl.set_text('firm2', pg_firm)
tpl.set_text('inn1', pg_inn)