Hi,
maybe some Pictures can demonstrate what i mean.The source code is also 
attached:
This excample is of my Countries Report.


<https://lh3.googleusercontent.com/-3qSbBrXf50Y/Vj22n9l93iI/AAAAAAAAAAw/siaI3TBfrNA/s1600/CountriesReport1.jpg>

<https://lh3.googleusercontent.com/--0nkparVSI0/Vj22ttxTSPI/AAAAAAAAAA4/oyZwenqUf2Y/s1600/CountriesReport2.jpg>

<https://lh3.googleusercontent.com/-Ulyv9Uo-U_Y/Vj22zDAUz4I/AAAAAAAAABA/XhiEfVLB8zs/s1600/CountriesReport3.jpg>
<https://lh3.googleusercontent.com/-QigPM6MGLS8/Vj223l3AiwI/AAAAAAAAABI/oynrIlh7lcM/s1600/CountriesReport4.jpg>
First Picture is start of app
Second Picture is after Print Report Button was pressed
Third Picture is my pdf-file
Fourth Picture is after closing the pdf viewer 

Any suggestions will be appreciated.

Karl:-) :) :] =)

Am Freitag, 6. November 2015 20:36:33 UTC+1 schrieb Anthony:

> Also, dict() is for creating a dictionary -- there is no reason to do 
> dict(redirect(...)). Also, you do not return a redirect() -- you simply 
> call it, and it immediately raises an HTTP exception.
>
> Anthony
>
> On Friday, November 6, 2015 at 1:50:15 PM UTC-5, Dave S wrote:
>>
>>
>>
>> On Friday, November 6, 2015 at 9:33:47 AM UTC-8, Karl Florian wrote:
>>>
>>> *Sorry everybody but i need your help again.*
>>>
>>> Here is my code:
>>>
>>> def languages_pedit(): 
>>>
>>
>> [...]
>>  
>>
>>>   
>>>
>>>  * #I tried this mk_pdffile(pdffile,'languages.pdf') but it did not 
>>> work*
>>>
>>> def mk_pdffile(pdffile,pdfname):
>>>
>>>   import cStringIO
>>>
>>>   pdfdata = open(pdffile,"rb").read()
>>>
>>>   response.headers['Content-Type']='application/pdf' 
>>>
>>>   return response.stream(cStringIO.StringIO(pdfdata), attachment=True, 
>>> filename=pdfname)
>>>
>>>
>> Where does the "does not work" part stop and the "this works fine part 
>> start? 
>>
>>>  
>>>
>>> @auth.requires_login()
>>>
>>> def print_languages(): 
>>>
>> [...]  .......................................
>>>
>>>   #Code to make my texfile....................
>>>
>>>   .......................................
>>>
>>>   texfile.write('\\end{document}\n')
>>>
>>> [...] 
>>
>>>   return response.stream(cStringIO.StringIO(pdfdata), attachment=True, 
>>> filename='languages.pdf') 
>>>
>>>  
>>>
>>> *This works fine but the code below does not get excecuted and my SUBMIT 
>>> Button stays pressed?*
>>>
>>>   
>>>
>>>   return dict(redirect(URL('languages_pedit')))
>>>
>>>
>>
>> Where does this go?  If right after the "return response.stream()", then 
>> it will never get executed.
>>  
>>
>>> def example():
>>   return 1
>>   return 2
>>
>>
>> will always return 1.
>>
>> /dps
>>  
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
### Model File ###
db.define_table(
    'allanguages',
    Field('lang_iso', 'string', length=2, unique=True, label='Language-ISO', 
comment='Test comment'),
    Field('description', 'string', length=80, requires=[IS_NOT_EMPTY()], 
label='Description', comment='Test comment'),
    Field('date_changed', 'datetime', update = request.now, writable = False, 
label='Modified'),
    Field('user_id', 'reference auth_user', update=auth.user and auth.user.id, 
writable = False, readable = False),
    migrate=settings.migrapp,
    redefine=settings.redefin,
    format='%(lang_iso)s'
)

### Controller ###
@auth.requires_login()
def print_countries():
    btn_list = [TAG.button(SPAN(_class="icon-print glyphicon 
glyphicon-print"),' Report', _type='submit', 
_id='submit_btn'),TAG.button(SPAN(_class="icon-refresh glyphicon 
glyphicon-refresh"),' Refresh',_type='button',_onClick = "parent.location='%s' 
" % URL('print_countries'))]
    form = SQLFORM.factory(
        Field('sortpdf', 'string', label='Sort-by', 
requires=IS_IN_SET(['ISO-Code','Description']), default='ISO-Code'),
        buttons = btn_list,
        formstyle = 'table3cols',
        submit_button='Submit')

    if form.process().accepted:
        import datetime
        now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
        sortpdf = form.vars.sortpdf
        if sortpdf=='ISO-Code': 
            ORDERBY=db.alcountries.ctry_iso
        else: ORDERBY=db.alcountries.description
        records = db(db.alcountries.id>=0).select(orderby=ORDERBY)
        ltxfile = str(os.path.join(request.folder, 'tex', 'countries.tex'))
        pdffile = str(os.path.join(request.folder, 'tex', 'countries.pdf'))
        with open (ltxfile, 'wb') as texfile:
                #...
                ### this is where i creat my texfile ###
                #...
        texfile.close()
        os.system('pdflatex '+ltxfile)
        if os.path.isfile(pdffile): 
            os.remove(pdffile)
        os.rename('countries.pdf', pdffile)
        import cStringIO
        pdfdata = open(pdffile,"rb").read()
        response.headers['Content-Type']='application/pdf'     
        return response.stream(cStringIO.StringIO(pdfdata), attachment=True, 
filename='countries.pdf')
  
    elif form.errors:
        response.flash = 'form has errors'
    response.title = 'Countries'
    return dict(form=form)

Reply via email to