Merge pull request #1942 from jvanbraekel/master
Use request_reset_password + PDF and TSV exports
This commit is contained in:
@@ -10,8 +10,8 @@
|
||||
<a href="{{=URL('user/register')}}">{{=T('Register')}}</a>
|
||||
<br/>
|
||||
{{pass}}
|
||||
{{if request.args(0)=='login' and not 'request_reset_password' in auth.settings.actions_disabled:}}
|
||||
<a href="{{=URL('user/request_reset_password')}}">{{=T('Lost your password?')}}</a>
|
||||
{{if request.args(0)=='login' and not 'retrieve_password' in auth.settings.actions_disabled:}}
|
||||
<a href="{{=URL('user/retrieve_password')}}">{{=T('Lost your password?')}}</a>
|
||||
{{pass}}
|
||||
{{if request.args(0)=='register':}}
|
||||
<a href="{{=URL('user/login')}}">{{=T('Login')}}</a>
|
||||
|
||||
@@ -5,7 +5,7 @@ filename = '%s/%s.html' % (request.controller,request.function)
|
||||
if os.path.exists(os.path.join(request.folder,'views',filename)):
|
||||
html=response.render(filename)
|
||||
else:
|
||||
html=BODY(BEAUTIFY(response._vars)).xml()
|
||||
html=BODY(BEAUTIFY(response._vars))
|
||||
pass
|
||||
=pdf_from_html(html)
|
||||
}}
|
||||
|
||||
@@ -25,7 +25,7 @@ def wrapper(f):
|
||||
|
||||
def latex_from_html(html):
|
||||
markmin = TAG(html).element('body').flatten(markmin_serializer)
|
||||
return XML(markmin2latex(markmin))
|
||||
return markmin2latex(markmin)
|
||||
|
||||
|
||||
def pdflatex_from_html(html):
|
||||
@@ -39,7 +39,7 @@ def pdflatex_from_html(html):
|
||||
H1('warnings'),
|
||||
UL(*warnings))).xml())
|
||||
else:
|
||||
return XML(out)
|
||||
return out
|
||||
|
||||
|
||||
def pyfpdf_from_html(html):
|
||||
|
||||
@@ -10,7 +10,7 @@ import os.path
|
||||
import re
|
||||
import sys
|
||||
from tempfile import mkstemp, mkdtemp, NamedTemporaryFile
|
||||
from markmin2latex import markmin2latex
|
||||
from gluon.contrib.markmin.markmin2latex import markmin2latex
|
||||
|
||||
__all__ = ['markmin2pdf']
|
||||
|
||||
@@ -58,7 +58,7 @@ def latex2pdf(latex, pdflatex='pdflatex', passes=3):
|
||||
|
||||
# setup the envoriment
|
||||
tmpdir = mkdtemp()
|
||||
texfile = open(tmpdir + '/test.tex', 'wb')
|
||||
texfile = open(tmpdir + '/test.tex', 'wt',encoding="utf-8")
|
||||
texfile.write(latex)
|
||||
texfile.seek(0)
|
||||
texfile.close()
|
||||
@@ -90,15 +90,14 @@ def latex2pdf(latex, pdflatex='pdflatex', passes=3):
|
||||
os.unlink(logname)
|
||||
|
||||
pdffile = texfile.rsplit('.', 1)[0] + '.pdf'
|
||||
data = None
|
||||
|
||||
if os.path.isfile(pdffile):
|
||||
fpdf = open(pdffile, 'rb')
|
||||
try:
|
||||
with open(pdffile,'rb') as fpdf :
|
||||
data = fpdf.read()
|
||||
finally:
|
||||
fpdf.close()
|
||||
else:
|
||||
data = None
|
||||
|
||||
removeall(tmpdir)
|
||||
|
||||
return data, warnings, errors
|
||||
|
||||
|
||||
|
||||
+26
-29
@@ -19,7 +19,7 @@ import re
|
||||
import copy
|
||||
|
||||
import os
|
||||
from gluon._compat import StringIO, unichr, urllib_quote, iteritems, basestring, long, integer_types, unicodeT, to_native, to_unicode, urlencode
|
||||
from gluon._compat import StringIO,unichr, urllib_quote, iteritems, basestring, long, integer_types, unicodeT, to_native, to_unicode, urlencode
|
||||
from gluon.http import HTTP, redirect
|
||||
from gluon.html import XmlComponent, truncate_string
|
||||
from gluon.html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG
|
||||
@@ -2055,7 +2055,7 @@ class SQLFORM(FORM):
|
||||
reduce(lambda a,b: a|b, [
|
||||
field.contains(k) for field in sfields]
|
||||
) for k in key.split()])
|
||||
|
||||
|
||||
# from https://groups.google.com/forum/#!topic/web2py/hKe6lI25Bv4
|
||||
# needs testing...
|
||||
#words = key.split(' ') if key else []
|
||||
@@ -2630,8 +2630,7 @@ class SQLFORM(FORM):
|
||||
xml=(ExporterXML, 'XML', T('XML export of columns shown')),
|
||||
html=(ExporterHTML, 'HTML', T('HTML export of visible columns')),
|
||||
json=(ExporterJSON, 'JSON', T('JSON export of visible columns')),
|
||||
tsv_with_hidden_cols=
|
||||
(ExporterTSV, 'TSV (Spreadsheets, hidden cols)', T('Spreadsheet-optimised export of tab-separated content including hidden columns. May be slow')),
|
||||
tsv_with_hidden_cols=(ExporterTSV_hidden, 'TSV (Spreadsheets, hidden cols)', T('Spreadsheet-optimised export of tab-separated content including hidden columns. May be slow')),
|
||||
tsv=(ExporterTSV, 'TSV (Spreadsheets)', T('Spreadsheet-optimised export of tab-separated content, visible columns only. May be slow.')))
|
||||
if exportclasses is not None:
|
||||
"""
|
||||
@@ -3697,40 +3696,38 @@ class ExportClass(object):
|
||||
|
||||
|
||||
class ExporterTSV(ExportClass):
|
||||
# TSV, represent == True
|
||||
label = 'TSV'
|
||||
file_ext = "csv"
|
||||
file_ext = "tsv"
|
||||
content_type = "text/tab-separated-values"
|
||||
|
||||
def __init__(self, rows):
|
||||
ExportClass.__init__(self, rows)
|
||||
|
||||
def export(self):
|
||||
out = StringIO()
|
||||
final = StringIO()
|
||||
import csv
|
||||
writer = csv.writer(out, delimiter='\t')
|
||||
def export(self): # export TSV with rows.represent
|
||||
if self.rows:
|
||||
import codecs
|
||||
final.write(codecs.BOM_UTF16)
|
||||
writer.writerow(
|
||||
[to_unicode(col, "utf8") for col in self.rows.colnames])
|
||||
data = out.getvalue().decode("utf8")
|
||||
data = data.encode("utf-16")
|
||||
data = data[2:]
|
||||
final.write(data)
|
||||
out.truncate(0)
|
||||
s = StringIO()
|
||||
self.rows.export_to_csv_file(s, represent=True,delimiter='\t',newline='\n')
|
||||
return s.getvalue()
|
||||
else:
|
||||
return None
|
||||
|
||||
records = self.represented()
|
||||
for row in records:
|
||||
writer.writerow(
|
||||
[str(col).decode('utf8').encode("utf-8") for col in row])
|
||||
data = out.getvalue().decode("utf8")
|
||||
data = data.encode("utf-16")
|
||||
data = data[2:]
|
||||
final.write(data)
|
||||
|
||||
out.truncate(0)
|
||||
return str(final.getvalue())
|
||||
class ExporterTSV_hidden(ExportClass):
|
||||
label = 'TSV'
|
||||
file_ext = "tsv"
|
||||
content_type = "text/tab-separated-values"
|
||||
|
||||
def __init__(self, rows):
|
||||
ExportClass.__init__(self, rows)
|
||||
|
||||
def export(self): # export TSV with rows.represent
|
||||
if self.rows:
|
||||
s = StringIO()
|
||||
self.rows.export_to_csv_file(s,delimiter='\t',newline='\n')
|
||||
return s.getvalue()
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
class ExporterCSV(ExportClass):
|
||||
|
||||
Reference in New Issue
Block a user