web2py FPDF子类和super()

时间:2018-03-23 13:27:44

标签: python-2.7 subclass web2py fpdf super

Python 2.7

又一个新的风格问题......但不是。

我已经阅读了其他问题而且我似乎得到了相反的结果,但这可能是我的无知。

class t1(object):
     pass

c1 = t1()
print type(c1) # <class '__main__.t1'> within web2py <class '__restricted__.t1>

class t2():
    pass

c2 = t2()
print type(c2) # <type 'instance'>

确定。伟大的我不必通过&#39;对象&#39;获得新的风格课程(或者我错过了什么)。 因此,当我将一些应该是新样式类的子类化(即具有&#39;对象&#39;在声明中传递)时,我得到一个类对象,我无法通过传递&#39;对象&#39来修复它;在我的班级宣言中。

现在根据我的具体情况: 我是FPDF的子类,它被声明为类FPDF(对象)并试图在我的声明中使用超级函数。

class MyFPDF(FPDF):
    def __init__(self, data):
        super(MyFPDF, self).__init__()
        self.res = data['res'] # reseller info
        self.cust = data['customer'] # customer info

    super(MyFPDF, self).__init__()
TypeError: super() argument 1 must be type, not function

我无法在任何地方找到对此特定错误的引用。

更新

# -*- coding: utf-8 -*-

from fpdf import FPDF, HTMLMixin
import datetime
import os
import codecs
import PIL

@auth.requires_login()
class MyFPDF(FPDF, HTMLMixin):

    # cutoff to start the next page. Not using auto page break.
    cutoff = 275
    footerLineheight = 3
    footerFontSize = 6.5
    footerTextColor = 128

    def __init__(self, data):
        super(MyFPDF, self).__init__()
        self.res = data['res'] # reseller info
        self.cust = data['customer'] # customer info


def pdfDoc():

    data = _select_offer(offerId) # data.offer data.customer
    data['res'] = db.reseller[data.offer.reseller_id] # data.res
    pdf = MyFPDF(data)
    pdf.add_page() # from here is the code for the pdf document

我覆盖 init ()的唯一原因是我可以传递页脚的地址信息。我无法将其直接传递给我的页脚方法,因为该方法在模块内部使用。所以添加一个参数会导致其他问题。

1 个答案:

答案 0 :(得分:0)

我刚刚完成了它。 问题是类声明上不必要的decorator @ auth.requires_login()。