Changeset 92:53dafd0b9cc4
- Timestamp:
- 01/20/09 09:37:29 (14 months ago)
- Author:
- Ga?tan de Menten <ged@…>
- Branch:
- default
- Message:
-
made factory and loader arguments of the Report constructor optional (use
defaults)
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r79
|
r92
|
|
| 82 | 82 | cls.mime_func.append(id_function) |
| 83 | 83 | |
| | 84 | default_loader = MIMETemplateLoader(auto_reload=True) |
| | 85 | |
| | 86 | class DefaultFactory: |
| | 87 | """This is the default factory used by relatorio. |
| | 88 | |
| | 89 | It just returns a copy of the data it receives""" |
| | 90 | |
| | 91 | def __call__(self, **kwargs): |
| | 92 | data = kwargs.copy() |
| | 93 | return data |
| | 94 | |
| | 95 | default_factory = DefaultFactory() |
| 84 | 96 | |
| 85 | 97 | class Report: |
| … |
… |
|
| 87 | 99 | """ |
| 88 | 100 | |
| 89 | | def __init__(self, path, mimetype, factory, loader): |
| | 101 | def __init__(self, path, mimetype, |
| | 102 | factory=default_factory, loader=default_loader): |
| 90 | 103 | self.fpath = path |
| 91 | 104 | self.mimetype = mimetype |
| … |
… |
|
| 102 | 115 | return '<relatorio report on %s>' % self.fpath |
| 103 | 116 | |
| 104 | | |
| 105 | | class DefaultFactory: |
| 106 | | """This is the default factory used by relatorio. |
| 107 | | |
| 108 | | It just returns a copy of the data it receives""" |
| 109 | | |
| 110 | | def __call__(self, **kwargs): |
| 111 | | data = kwargs.copy() |
| 112 | | return data |
| 113 | 117 | |
| 114 | 118 | |
| … |
… |
|
| 130 | 134 | self.classes = {} |
| 131 | 135 | self.default_factory = datafactory |
| 132 | | self.loader = MIMETemplateLoader(auto_reload=True) |
| | 136 | self.loader = default_loader |
| 133 | 137 | |
| 134 | 138 | def add_report(self, klass, mimetype, template_path, data_factory=None, |
| … |
… |
|
| 136 | 140 | """adds a report to the repository. |
| 137 | 141 | |
| 138 | | You will be able to find the report via |
| | 142 | You will be able to find the report via |
| 139 | 143 | - the class it is working on |
| 140 | 144 | - the mimetype it outputs |
| 141 | 145 | - the name of the report |
| 142 | | |
| | 146 | |
| 143 | 147 | You also have the opportunity to define a specific data_factory. |
| 144 | 148 | """ |
| … |
… |
|
| 149 | 153 | self.loader) |
| 150 | 154 | reports.ids[report_name] = report, mimetype |
| 151 | | reports.mimetypes.setdefault(mimetype, []).append((report, report_name)) |
| | 155 | reports.mimetypes.setdefault(mimetype, []) \ |
| | 156 | .append((report, report_name)) |
| 152 | 157 | |
| 153 | 158 | def by_mime(self, klass, mimetype): |