23 |
23 |
24 class DjangoTagsMenuHandler(QObject): |
24 class DjangoTagsMenuHandler(QObject): |
25 """ |
25 """ |
26 Class implementing the Django tags menu handler. |
26 Class implementing the Django tags menu handler. |
27 """ |
27 """ |
|
28 |
28 def __init__(self, ui, parent=None): |
29 def __init__(self, ui, parent=None): |
29 """ |
30 """ |
30 Constructor |
31 Constructor |
31 |
32 |
32 @param ui reference to the user interface object |
33 @param ui reference to the user interface object |
33 @type UserInterface |
34 @type UserInterface |
34 @param parent reference to the parent object |
35 @param parent reference to the parent object |
35 @type QObject |
36 @type QObject |
36 """ |
37 """ |
37 super().__init__(parent) |
38 super().__init__(parent) |
38 self.__ui = ui |
39 self.__ui = ui |
39 |
40 |
40 self.__findDialog = None |
41 self.__findDialog = None |
41 |
42 |
42 def closeAllWindows(self): |
43 def closeAllWindows(self): |
43 """ |
44 """ |
44 Public method to close all dialogs managed by the handler. |
45 Public method to close all dialogs managed by the handler. |
45 """ |
46 """ |
46 if self.__findDialog: |
47 if self.__findDialog: |
47 self.__findDialog.close() |
48 self.__findDialog.close() |
48 |
49 |
49 def initMenus(self, mainMenu): |
50 def initMenus(self, mainMenu): |
50 """ |
51 """ |
51 Public method to initialize the various menus. |
52 Public method to initialize the various menus. |
52 |
53 |
53 @param mainMenu reference to the main tags menu |
54 @param mainMenu reference to the main tags menu |
54 @type QMenu |
55 @type QMenu |
55 """ |
56 """ |
56 mainMenu.addAction(self.tr("Django Template Tags Locator"), |
57 mainMenu.addAction( |
57 self.__findTemplateTag) |
58 self.tr("Django Template Tags Locator"), self.__findTemplateTag |
|
59 ) |
58 mainMenu.addSeparator() |
60 mainMenu.addSeparator() |
59 mainMenu.addMenu(self.__initTagsMenu()) |
61 mainMenu.addMenu(self.__initTagsMenu()) |
60 mainMenu.addMenu(self.__initFiltersMenu()) |
62 mainMenu.addMenu(self.__initFiltersMenu()) |
61 mainMenu.addMenu(self.__initHumanizeMenu()) |
63 mainMenu.addMenu(self.__initHumanizeMenu()) |
62 mainMenu.addMenu(self.__initWebDesignMenu()) |
64 mainMenu.addMenu(self.__initWebDesignMenu()) |
63 mainMenu.addMenu(self.__initStaticMenu()) |
65 mainMenu.addMenu(self.__initStaticMenu()) |
64 mainMenu.addMenu(self.__initCommentsMenu()) |
66 mainMenu.addMenu(self.__initCommentsMenu()) |
65 mainMenu.addMenu(self.__initInternationalizationMenu()) |
67 mainMenu.addMenu(self.__initInternationalizationMenu()) |
66 mainMenu.addMenu(self.__initLocalizationMenu()) |
68 mainMenu.addMenu(self.__initLocalizationMenu()) |
67 mainMenu.addMenu(self.__initTimezoneMenu()) |
69 mainMenu.addMenu(self.__initTimezoneMenu()) |
68 |
70 |
69 def __initTagsMenu(self): |
71 def __initTagsMenu(self): |
70 """ |
72 """ |
71 Private method to initialize the tags menu. |
73 Private method to initialize the tags menu. |
72 |
74 |
73 @return generated menu |
75 @return generated menu |
74 @rtype QMenu |
76 @rtype QMenu |
75 """ |
77 """ |
76 menu = QMenu(self.tr("Tags")) |
78 menu = QMenu(self.tr("Tags")) |
77 menu.addAction( |
79 menu.addAction( |
78 self.tr("autoescape - Auto Escape Characters"), |
80 self.tr("autoescape - Auto Escape Characters"), |
79 lambda: self.__applyTemplate("autoescape")) |
81 lambda: self.__applyTemplate("autoescape"), |
80 menu.addSeparator() |
82 ) |
81 menu.addAction( |
83 menu.addSeparator() |
82 self.tr("block - Named Block"), |
84 menu.addAction( |
83 lambda: self.__applyTemplate("block")) |
85 self.tr("block - Named Block"), lambda: self.__applyTemplate("block") |
|
86 ) |
84 menu.addSeparator() |
87 menu.addSeparator() |
85 menu.addAction( |
88 menu.addAction( |
86 self.tr("comment - Multiline Comment"), |
89 self.tr("comment - Multiline Comment"), |
87 lambda: self.__applyTemplate("comment")) |
90 lambda: self.__applyTemplate("comment"), |
|
91 ) |
88 menu.addAction( |
92 menu.addAction( |
89 self.tr("csrf_token - Cross Site Request Forgery Token"), |
93 self.tr("csrf_token - Cross Site Request Forgery Token"), |
90 lambda: self.__applyTemplate("csrf_token")) |
94 lambda: self.__applyTemplate("csrf_token"), |
|
95 ) |
91 menu.addAction( |
96 menu.addAction( |
92 self.tr("cycle - Cycle variables each time used"), |
97 self.tr("cycle - Cycle variables each time used"), |
93 lambda: self.__applyTemplate("cycle")) |
98 lambda: self.__applyTemplate("cycle"), |
|
99 ) |
94 menu.addSeparator() |
100 menu.addSeparator() |
95 menu.addAction( |
101 menu.addAction( |
96 self.tr("debug - Output Debug Information"), |
102 self.tr("debug - Output Debug Information"), |
97 lambda: self.__applyTemplate("debug")) |
103 lambda: self.__applyTemplate("debug"), |
|
104 ) |
98 menu.addSeparator() |
105 menu.addSeparator() |
99 menu.addAction( |
106 menu.addAction( |
100 self.tr("extends - Extend a template with variable contents"), |
107 self.tr("extends - Extend a template with variable contents"), |
101 lambda: self.__applyTemplate("extendsvariable")) |
108 lambda: self.__applyTemplate("extendsvariable"), |
|
109 ) |
102 menu.addAction( |
110 menu.addAction( |
103 self.tr("extends - Extend a template with file"), |
111 self.tr("extends - Extend a template with file"), |
104 lambda: self.__applyTemplate("extendsfile")) |
112 lambda: self.__applyTemplate("extendsfile"), |
|
113 ) |
105 menu.addSeparator() |
114 menu.addSeparator() |
106 menu.addAction( |
115 menu.addAction( |
107 self.tr("filter - Filtered Block for one or more filters"), |
116 self.tr("filter - Filtered Block for one or more filters"), |
108 lambda: self.__applyTemplate("filter")) |
117 lambda: self.__applyTemplate("filter"), |
|
118 ) |
109 menu.addAction( |
119 menu.addAction( |
110 self.tr("firstof - Outputs first argument variable that is True"), |
120 self.tr("firstof - Outputs first argument variable that is True"), |
111 lambda: self.__applyTemplate("firstof")) |
121 lambda: self.__applyTemplate("firstof"), |
112 menu.addAction( |
122 ) |
113 self.tr("for - For Loop"), |
123 menu.addAction(self.tr("for - For Loop"), lambda: self.__applyTemplate("for")) |
114 lambda: self.__applyTemplate("for")) |
|
115 menu.addAction( |
124 menu.addAction( |
116 self.tr("for...empty - For Loop with fallback for empty loop"), |
125 self.tr("for...empty - For Loop with fallback for empty loop"), |
117 lambda: self.__applyTemplate("for...empty")) |
126 lambda: self.__applyTemplate("for...empty"), |
|
127 ) |
118 menu.addSeparator() |
128 menu.addSeparator() |
119 menu.addAction( |
129 menu.addAction( |
120 self.tr("if - if...elif...else... clauses"), |
130 self.tr("if - if...elif...else... clauses"), |
121 lambda: self.__applyTemplate("if")) |
131 lambda: self.__applyTemplate("if"), |
|
132 ) |
122 menu.addAction( |
133 menu.addAction( |
123 self.tr("ifchanged - Check if a value has changed"), |
134 self.tr("ifchanged - Check if a value has changed"), |
124 lambda: self.__applyTemplate("ifchanged")) |
135 lambda: self.__applyTemplate("ifchanged"), |
|
136 ) |
125 menu.addAction( |
137 menu.addAction( |
126 self.tr("ifequal - Output block if variables are equal"), |
138 self.tr("ifequal - Output block if variables are equal"), |
127 lambda: self.__applyTemplate("ifequal")) |
139 lambda: self.__applyTemplate("ifequal"), |
|
140 ) |
128 menu.addAction( |
141 menu.addAction( |
129 self.tr("ifnotequal - Output block if variables are not equal"), |
142 self.tr("ifnotequal - Output block if variables are not equal"), |
130 lambda: self.__applyTemplate("ifnotequal")) |
143 lambda: self.__applyTemplate("ifnotequal"), |
|
144 ) |
131 menu.addAction( |
145 menu.addAction( |
132 self.tr("include - Render template given by variable"), |
146 self.tr("include - Render template given by variable"), |
133 lambda: self.__applyTemplate("includevariable")) |
147 lambda: self.__applyTemplate("includevariable"), |
|
148 ) |
134 menu.addAction( |
149 menu.addAction( |
135 self.tr("include - Render template given by file name"), |
150 self.tr("include - Render template given by file name"), |
136 lambda: self.__applyTemplate("includefile")) |
151 lambda: self.__applyTemplate("includefile"), |
|
152 ) |
137 menu.addSeparator() |
153 menu.addSeparator() |
138 menu.addAction( |
154 menu.addAction( |
139 self.tr("load - Load a custom template tag set"), |
155 self.tr("load - Load a custom template tag set"), |
140 lambda: self.__applyTemplate("load")) |
156 lambda: self.__applyTemplate("load"), |
|
157 ) |
141 menu.addSeparator() |
158 menu.addSeparator() |
142 menu.addAction( |
159 menu.addAction( |
143 self.tr("now - Display current date and time"), |
160 self.tr("now - Display current date and time"), |
144 lambda: self.__applyTemplate("now")) |
161 lambda: self.__applyTemplate("now"), |
145 menu.addSeparator() |
162 ) |
146 menu.addAction( |
163 menu.addSeparator() |
147 self.tr("regroup - Regroup list of alike objects by a common" |
164 menu.addAction( |
148 " attribute"), |
165 self.tr("regroup - Regroup list of alike objects by a common" " attribute"), |
149 lambda: self.__applyTemplate("regroup")) |
166 lambda: self.__applyTemplate("regroup"), |
|
167 ) |
150 menu.addSeparator() |
168 menu.addSeparator() |
151 menu.addAction( |
169 menu.addAction( |
152 self.tr("spaceless - Remove whitespace between HTML tags"), |
170 self.tr("spaceless - Remove whitespace between HTML tags"), |
153 lambda: self.__applyTemplate("spaceless")) |
171 lambda: self.__applyTemplate("spaceless"), |
|
172 ) |
154 menu.addAction( |
173 menu.addAction( |
155 self.tr("ssi - Output contents of a given file into the page"), |
174 self.tr("ssi - Output contents of a given file into the page"), |
156 lambda: self.__applyTemplate("ssi")) |
175 lambda: self.__applyTemplate("ssi"), |
157 menu.addAction( |
176 ) |
158 self.tr("ssi - Output contents of a given file into the page" |
177 menu.addAction( |
159 " (dialog selection)"), |
178 self.tr( |
160 lambda: self.__applyTemplate("ssifile")) |
179 "ssi - Output contents of a given file into the page" |
161 menu.addSeparator() |
180 " (dialog selection)" |
162 menu.addAction( |
181 ), |
163 self.tr("templatetag - Output syntax characters used for" |
182 lambda: self.__applyTemplate("ssifile"), |
164 " template"), |
183 ) |
165 lambda: self.__applyTemplate("templatetag")) |
184 menu.addSeparator() |
|
185 menu.addAction( |
|
186 self.tr("templatetag - Output syntax characters used for" " template"), |
|
187 lambda: self.__applyTemplate("templatetag"), |
|
188 ) |
166 menu.addSeparator() |
189 menu.addSeparator() |
167 menu.addAction( |
190 menu.addAction( |
168 self.tr("url - Return an absolute path reference"), |
191 self.tr("url - Return an absolute path reference"), |
169 lambda: self.__applyTemplate("url")) |
192 lambda: self.__applyTemplate("url"), |
|
193 ) |
170 menu.addAction( |
194 menu.addAction( |
171 self.tr("url...as - Return an absolute path reference"), |
195 self.tr("url...as - Return an absolute path reference"), |
172 lambda: self.__applyTemplate("urlas")) |
196 lambda: self.__applyTemplate("urlas"), |
|
197 ) |
173 menu.addSeparator() |
198 menu.addSeparator() |
174 menu.addAction( |
199 menu.addAction( |
175 self.tr("verbatim - Output block contents without rendering"), |
200 self.tr("verbatim - Output block contents without rendering"), |
176 lambda: self.__applyTemplate("verbatim")) |
201 lambda: self.__applyTemplate("verbatim"), |
|
202 ) |
177 menu.addSeparator() |
203 menu.addSeparator() |
178 menu.addAction( |
204 menu.addAction( |
179 self.tr("widthratio - Calculate width ratio"), |
205 self.tr("widthratio - Calculate width ratio"), |
180 lambda: self.__applyTemplate("verbatim")) |
206 lambda: self.__applyTemplate("verbatim"), |
|
207 ) |
181 menu.addAction( |
208 menu.addAction( |
182 self.tr("with - Cache a complex variable under a simpler name"), |
209 self.tr("with - Cache a complex variable under a simpler name"), |
183 lambda: self.__applyTemplate("verbatim")) |
210 lambda: self.__applyTemplate("verbatim"), |
184 |
211 ) |
|
212 |
185 self.__tagsMenu = menu |
213 self.__tagsMenu = menu |
186 return menu |
214 return menu |
187 |
215 |
188 def __initFiltersMenu(self): |
216 def __initFiltersMenu(self): |
189 """ |
217 """ |
190 Private method to initialize the filters menu. |
218 Private method to initialize the filters menu. |
191 |
219 |
192 @return generated menu |
220 @return generated menu |
193 @rtype QMenu |
221 @rtype QMenu |
194 """ |
222 """ |
195 mainMenu = QMenu(self.tr("Filters")) |
223 mainMenu = QMenu(self.tr("Filters")) |
196 |
224 |
197 menu = QMenu(self.tr("A-I"), mainMenu) |
225 menu = QMenu(self.tr("A-I"), mainMenu) |
198 menu.addAction( |
226 menu.addAction( |
199 self.tr("add - Add variable or string"), |
227 self.tr("add - Add variable or string"), lambda: self.__applyTemplate("add") |
200 lambda: self.__applyTemplate("add")) |
228 ) |
201 menu.addAction( |
229 menu.addAction( |
202 self.tr("addslashes - Add slashes before quotes"), |
230 self.tr("addslashes - Add slashes before quotes"), |
203 lambda: self.__applyTemplate("addslashes")) |
231 lambda: self.__applyTemplate("addslashes"), |
|
232 ) |
204 menu.addSeparator() |
233 menu.addSeparator() |
205 menu.addAction( |
234 menu.addAction( |
206 self.tr("capfirst - Capitalize first character"), |
235 self.tr("capfirst - Capitalize first character"), |
207 lambda: self.__applyTemplate("capfirst")) |
236 lambda: self.__applyTemplate("capfirst"), |
208 menu.addAction( |
237 ) |
209 self.tr("center - Center value"), |
238 menu.addAction( |
210 lambda: self.__applyTemplate("center")) |
239 self.tr("center - Center value"), lambda: self.__applyTemplate("center") |
211 menu.addAction( |
240 ) |
212 self.tr("cut - Cut characters"), |
241 menu.addAction( |
213 lambda: self.__applyTemplate("cut")) |
242 self.tr("cut - Cut characters"), lambda: self.__applyTemplate("cut") |
214 menu.addSeparator() |
243 ) |
215 menu.addAction( |
244 menu.addSeparator() |
216 self.tr("date - Format date"), |
245 menu.addAction( |
217 lambda: self.__applyTemplate("date")) |
246 self.tr("date - Format date"), lambda: self.__applyTemplate("date") |
|
247 ) |
218 menu.addAction( |
248 menu.addAction( |
219 self.tr("default - Use default if False"), |
249 self.tr("default - Use default if False"), |
220 lambda: self.__applyTemplate("default")) |
250 lambda: self.__applyTemplate("default"), |
|
251 ) |
221 menu.addAction( |
252 menu.addAction( |
222 self.tr("default_if_none - Use default if None"), |
253 self.tr("default_if_none - Use default if None"), |
223 lambda: self.__applyTemplate("default_if_none")) |
254 lambda: self.__applyTemplate("default_if_none"), |
|
255 ) |
224 menu.addAction( |
256 menu.addAction( |
225 self.tr("dictsort - Sort dictionaries"), |
257 self.tr("dictsort - Sort dictionaries"), |
226 lambda: self.__applyTemplate("dictsort")) |
258 lambda: self.__applyTemplate("dictsort"), |
|
259 ) |
227 menu.addAction( |
260 menu.addAction( |
228 self.tr("dictsortreversed - Sort dictionaries reversed"), |
261 self.tr("dictsortreversed - Sort dictionaries reversed"), |
229 lambda: self.__applyTemplate("dictsortreversed")) |
262 lambda: self.__applyTemplate("dictsortreversed"), |
|
263 ) |
230 menu.addAction( |
264 menu.addAction( |
231 self.tr("divisibleby - Check divisibility"), |
265 self.tr("divisibleby - Check divisibility"), |
232 lambda: self.__applyTemplate("divisibleby")) |
266 lambda: self.__applyTemplate("divisibleby"), |
233 menu.addSeparator() |
267 ) |
234 menu.addAction( |
268 menu.addSeparator() |
235 self.tr("escape - Escape as HTML"), |
269 menu.addAction( |
236 lambda: self.__applyTemplate("escape")) |
270 self.tr("escape - Escape as HTML"), lambda: self.__applyTemplate("escape") |
|
271 ) |
237 menu.addAction( |
272 menu.addAction( |
238 self.tr("escapejs - Escape as JavaScript"), |
273 self.tr("escapejs - Escape as JavaScript"), |
239 lambda: self.__applyTemplate("escapejs")) |
274 lambda: self.__applyTemplate("escapejs"), |
|
275 ) |
240 menu.addSeparator() |
276 menu.addSeparator() |
241 menu.addAction( |
277 menu.addAction( |
242 self.tr("filesizeformat - Format file sizes"), |
278 self.tr("filesizeformat - Format file sizes"), |
243 lambda: self.__applyTemplate("filesizeformat")) |
279 lambda: self.__applyTemplate("filesizeformat"), |
|
280 ) |
244 menu.addAction( |
281 menu.addAction( |
245 self.tr("first - First item of a list"), |
282 self.tr("first - First item of a list"), |
246 lambda: self.__applyTemplate("first")) |
283 lambda: self.__applyTemplate("first"), |
|
284 ) |
247 menu.addAction( |
285 menu.addAction( |
248 self.tr("fix_ampersands - Replace ampersands"), |
286 self.tr("fix_ampersands - Replace ampersands"), |
249 lambda: self.__applyTemplate("fix_ampersands")) |
287 lambda: self.__applyTemplate("fix_ampersands"), |
|
288 ) |
250 menu.addAction( |
289 menu.addAction( |
251 self.tr("floatformat - Format floating numbers"), |
290 self.tr("floatformat - Format floating numbers"), |
252 lambda: self.__applyTemplate("floatformat")) |
291 lambda: self.__applyTemplate("floatformat"), |
|
292 ) |
253 menu.addAction( |
293 menu.addAction( |
254 self.tr("force_escape - Escape as HTML immediately"), |
294 self.tr("force_escape - Escape as HTML immediately"), |
255 lambda: self.__applyTemplate("force_escape")) |
295 lambda: self.__applyTemplate("force_escape"), |
|
296 ) |
256 menu.addSeparator() |
297 menu.addSeparator() |
257 menu.addAction( |
298 menu.addAction( |
258 self.tr("get_digit - Extract rightmost digit"), |
299 self.tr("get_digit - Extract rightmost digit"), |
259 lambda: self.__applyTemplate("get_digit")) |
300 lambda: self.__applyTemplate("get_digit"), |
|
301 ) |
260 menu.addSeparator() |
302 menu.addSeparator() |
261 menu.addAction( |
303 menu.addAction( |
262 self.tr("iriencode - Convert IRI to string"), |
304 self.tr("iriencode - Convert IRI to string"), |
263 lambda: self.__applyTemplate("iriencode")) |
305 lambda: self.__applyTemplate("iriencode"), |
|
306 ) |
264 mainMenu.addMenu(menu) |
307 mainMenu.addMenu(menu) |
265 |
308 |
266 menu = QMenu(self.tr("J-R"), mainMenu) |
309 menu = QMenu(self.tr("J-R"), mainMenu) |
267 menu.addAction( |
310 menu.addAction( |
268 self.tr("join - Join list"), |
311 self.tr("join - Join list"), lambda: self.__applyTemplate("join") |
269 lambda: self.__applyTemplate("join")) |
312 ) |
270 menu.addSeparator() |
313 menu.addSeparator() |
271 menu.addAction( |
314 menu.addAction( |
272 self.tr("last - Return last item in list"), |
315 self.tr("last - Return last item in list"), |
273 lambda: self.__applyTemplate("last")) |
316 lambda: self.__applyTemplate("last"), |
|
317 ) |
274 menu.addAction( |
318 menu.addAction( |
275 self.tr("length - Return length of the value"), |
319 self.tr("length - Return length of the value"), |
276 lambda: self.__applyTemplate("length")) |
320 lambda: self.__applyTemplate("length"), |
|
321 ) |
277 menu.addAction( |
322 menu.addAction( |
278 self.tr("length_is - Check length"), |
323 self.tr("length_is - Check length"), |
279 lambda: self.__applyTemplate("length_is")) |
324 lambda: self.__applyTemplate("length_is"), |
|
325 ) |
280 menu.addAction( |
326 menu.addAction( |
281 self.tr("linebreaks - Replace line breaks with HTML"), |
327 self.tr("linebreaks - Replace line breaks with HTML"), |
282 lambda: self.__applyTemplate("linebreaks")) |
328 lambda: self.__applyTemplate("linebreaks"), |
|
329 ) |
283 menu.addAction( |
330 menu.addAction( |
284 self.tr("linebreaksbr - Replace line breaks with <br/>"), |
331 self.tr("linebreaksbr - Replace line breaks with <br/>"), |
285 lambda: self.__applyTemplate("linebreaksbr")) |
332 lambda: self.__applyTemplate("linebreaksbr"), |
|
333 ) |
286 menu.addAction( |
334 menu.addAction( |
287 self.tr("linenumbers - Display text with line numbers"), |
335 self.tr("linenumbers - Display text with line numbers"), |
288 lambda: self.__applyTemplate("linenumbers")) |
336 lambda: self.__applyTemplate("linenumbers"), |
289 menu.addAction( |
337 ) |
290 self.tr("ljust - Left-align value"), |
338 menu.addAction( |
291 lambda: self.__applyTemplate("ljust")) |
339 self.tr("ljust - Left-align value"), lambda: self.__applyTemplate("ljust") |
|
340 ) |
292 menu.addAction( |
341 menu.addAction( |
293 self.tr("lower - Convert to lowercase"), |
342 self.tr("lower - Convert to lowercase"), |
294 lambda: self.__applyTemplate("lower")) |
343 lambda: self.__applyTemplate("lower"), |
|
344 ) |
295 menu.addSeparator() |
345 menu.addSeparator() |
296 menu.addAction( |
346 menu.addAction( |
297 self.tr("make_list - Turn value into a list"), |
347 self.tr("make_list - Turn value into a list"), |
298 lambda: self.__applyTemplate("make_list")) |
348 lambda: self.__applyTemplate("make_list"), |
|
349 ) |
299 menu.addSeparator() |
350 menu.addSeparator() |
300 menu.addAction( |
351 menu.addAction( |
301 self.tr("phone2numeric - Convert phone number into numeric"), |
352 self.tr("phone2numeric - Convert phone number into numeric"), |
302 lambda: self.__applyTemplate("phone2numeric")) |
353 lambda: self.__applyTemplate("phone2numeric"), |
|
354 ) |
303 menu.addAction( |
355 menu.addAction( |
304 self.tr("pluralize - Return plural suffix"), |
356 self.tr("pluralize - Return plural suffix"), |
305 lambda: self.__applyTemplate("pluralize")) |
357 lambda: self.__applyTemplate("pluralize"), |
306 menu.addAction( |
358 ) |
307 self.tr("pprint - Pretty Print"), |
359 menu.addAction( |
308 lambda: self.__applyTemplate("pprint")) |
360 self.tr("pprint - Pretty Print"), lambda: self.__applyTemplate("pprint") |
|
361 ) |
309 menu.addSeparator() |
362 menu.addSeparator() |
310 menu.addAction( |
363 menu.addAction( |
311 self.tr("random - Return random item from list"), |
364 self.tr("random - Return random item from list"), |
312 lambda: self.__applyTemplate("random")) |
365 lambda: self.__applyTemplate("random"), |
|
366 ) |
313 menu.addAction( |
367 menu.addAction( |
314 self.tr("removetags - Remove HTML tags"), |
368 self.tr("removetags - Remove HTML tags"), |
315 lambda: self.__applyTemplate("removetags")) |
369 lambda: self.__applyTemplate("removetags"), |
316 menu.addAction( |
370 ) |
317 self.tr("rjust - Right-align value"), |
371 menu.addAction( |
318 lambda: self.__applyTemplate("rjust")) |
372 self.tr("rjust - Right-align value"), lambda: self.__applyTemplate("rjust") |
|
373 ) |
319 mainMenu.addMenu(menu) |
374 mainMenu.addMenu(menu) |
320 |
375 |
321 menu = QMenu(self.tr("S-Z"), mainMenu) |
376 menu = QMenu(self.tr("S-Z"), mainMenu) |
322 menu.addAction( |
377 menu.addAction( |
323 self.tr("safe - Mark as not requiring HTML escaping "), |
378 self.tr("safe - Mark as not requiring HTML escaping "), |
324 lambda: self.__applyTemplate("safe")) |
379 lambda: self.__applyTemplate("safe"), |
|
380 ) |
325 menu.addAction( |
381 menu.addAction( |
326 self.tr("safeseq - Mark as a safe sequence"), |
382 self.tr("safeseq - Mark as a safe sequence"), |
327 lambda: self.__applyTemplate("safeseq")) |
383 lambda: self.__applyTemplate("safeseq"), |
|
384 ) |
328 menu.addAction( |
385 menu.addAction( |
329 self.tr("slice - Return a slice of a list"), |
386 self.tr("slice - Return a slice of a list"), |
330 lambda: self.__applyTemplate("slice")) |
387 lambda: self.__applyTemplate("slice"), |
|
388 ) |
331 menu.addAction( |
389 menu.addAction( |
332 self.tr("slugify - Return value slugified"), |
390 self.tr("slugify - Return value slugified"), |
333 lambda: self.__applyTemplate("slugify")) |
391 lambda: self.__applyTemplate("slugify"), |
|
392 ) |
334 menu.addAction( |
393 menu.addAction( |
335 self.tr("stringformat - Format variable"), |
394 self.tr("stringformat - Format variable"), |
336 lambda: self.__applyTemplate("stringformat")) |
395 lambda: self.__applyTemplate("stringformat"), |
|
396 ) |
337 menu.addAction( |
397 menu.addAction( |
338 self.tr("striptags - Strip all HTML tags"), |
398 self.tr("striptags - Strip all HTML tags"), |
339 lambda: self.__applyTemplate("striptags")) |
399 lambda: self.__applyTemplate("striptags"), |
340 menu.addSeparator() |
400 ) |
341 menu.addAction( |
401 menu.addSeparator() |
342 self.tr("time - Format time"), |
402 menu.addAction( |
343 lambda: self.__applyTemplate("time")) |
403 self.tr("time - Format time"), lambda: self.__applyTemplate("time") |
|
404 ) |
344 menu.addAction( |
405 menu.addAction( |
345 self.tr("timesince - Format as time since"), |
406 self.tr("timesince - Format as time since"), |
346 lambda: self.__applyTemplate("timesince")) |
407 lambda: self.__applyTemplate("timesince"), |
|
408 ) |
347 menu.addAction( |
409 menu.addAction( |
348 self.tr("timeuntil - Format as time until"), |
410 self.tr("timeuntil - Format as time until"), |
349 lambda: self.__applyTemplate("timeuntil")) |
411 lambda: self.__applyTemplate("timeuntil"), |
|
412 ) |
350 menu.addAction( |
413 menu.addAction( |
351 self.tr("title - Convert to titlecase"), |
414 self.tr("title - Convert to titlecase"), |
352 lambda: self.__applyTemplate("title")) |
415 lambda: self.__applyTemplate("title"), |
|
416 ) |
353 menu.addAction( |
417 menu.addAction( |
354 self.tr("truncatechars - Truncate after a number of characters"), |
418 self.tr("truncatechars - Truncate after a number of characters"), |
355 lambda: self.__applyTemplate("truncatechars")) |
419 lambda: self.__applyTemplate("truncatechars"), |
|
420 ) |
356 menu.addAction( |
421 menu.addAction( |
357 self.tr("truncatewords - Truncate after a number of words"), |
422 self.tr("truncatewords - Truncate after a number of words"), |
358 lambda: self.__applyTemplate("truncatewords")) |
423 lambda: self.__applyTemplate("truncatewords"), |
359 menu.addAction( |
424 ) |
360 self.tr("truncatewords_html - Truncate after a number of words" |
425 menu.addAction( |
361 " (HTML aware)"), |
426 self.tr( |
362 lambda: self.__applyTemplate("truncatewords_html")) |
427 "truncatewords_html - Truncate after a number of words" " (HTML aware)" |
|
428 ), |
|
429 lambda: self.__applyTemplate("truncatewords_html"), |
|
430 ) |
363 menu.addSeparator() |
431 menu.addSeparator() |
364 menu.addAction( |
432 menu.addAction( |
365 self.tr("unordered_list - Return HTML unordered list"), |
433 self.tr("unordered_list - Return HTML unordered list"), |
366 lambda: self.__applyTemplate("unordered_list")) |
434 lambda: self.__applyTemplate("unordered_list"), |
|
435 ) |
367 menu.addAction( |
436 menu.addAction( |
368 self.tr("upper - Convert to uppercase"), |
437 self.tr("upper - Convert to uppercase"), |
369 lambda: self.__applyTemplate("upper")) |
438 lambda: self.__applyTemplate("upper"), |
|
439 ) |
370 menu.addAction( |
440 menu.addAction( |
371 self.tr("urlencode - Escape as URL"), |
441 self.tr("urlencode - Escape as URL"), |
372 lambda: self.__applyTemplate("urlencode")) |
442 lambda: self.__applyTemplate("urlencode"), |
|
443 ) |
373 menu.addAction( |
444 menu.addAction( |
374 self.tr("urlize - Convert URLs as clickable links"), |
445 self.tr("urlize - Convert URLs as clickable links"), |
375 lambda: self.__applyTemplate("urlize")) |
446 lambda: self.__applyTemplate("urlize"), |
376 menu.addAction( |
447 ) |
377 self.tr("urlizetrunc - Convert URLs as clickable links and" |
448 menu.addAction( |
378 " truncate"), |
449 self.tr("urlizetrunc - Convert URLs as clickable links and" " truncate"), |
379 lambda: self.__applyTemplate("urlizetrunc")) |
450 lambda: self.__applyTemplate("urlizetrunc"), |
|
451 ) |
380 menu.addSeparator() |
452 menu.addSeparator() |
381 menu.addAction( |
453 menu.addAction( |
382 self.tr("wordcount - Return number of word"), |
454 self.tr("wordcount - Return number of word"), |
383 lambda: self.__applyTemplate("wordcount")) |
455 lambda: self.__applyTemplate("wordcount"), |
384 menu.addAction( |
456 ) |
385 self.tr("wordwrap - Wrap words"), |
457 menu.addAction( |
386 lambda: self.__applyTemplate("wordwrap")) |
458 self.tr("wordwrap - Wrap words"), lambda: self.__applyTemplate("wordwrap") |
|
459 ) |
387 menu.addSeparator() |
460 menu.addSeparator() |
388 menu.addAction( |
461 menu.addAction( |
389 self.tr("yesno - Map True, False and None"), |
462 self.tr("yesno - Map True, False and None"), |
390 lambda: self.__applyTemplate("yesno")) |
463 lambda: self.__applyTemplate("yesno"), |
|
464 ) |
391 mainMenu.addMenu(menu) |
465 mainMenu.addMenu(menu) |
392 |
466 |
393 self.__filtersMenu = mainMenu |
467 self.__filtersMenu = mainMenu |
394 return mainMenu |
468 return mainMenu |
395 |
469 |
396 def __initHumanizeMenu(self): |
470 def __initHumanizeMenu(self): |
397 """ |
471 """ |
398 Private method to initialize the humanize menu. |
472 Private method to initialize the humanize menu. |
399 |
473 |
400 @return generated menu |
474 @return generated menu |
401 @rtype QMenu |
475 @rtype QMenu |
402 """ |
476 """ |
403 menu = QMenu(self.tr("Humanize")) |
477 menu = QMenu(self.tr("Humanize")) |
404 menu.addAction( |
478 menu.addAction( |
405 self.tr("Load Package"), |
479 self.tr("Load Package"), lambda: self.__applyTemplate("loadhumanize") |
406 lambda: self.__applyTemplate("loadhumanize")) |
480 ) |
407 menu.addSeparator() |
481 menu.addSeparator() |
408 menu.addAction( |
482 menu.addAction( |
409 self.tr("apnumber - Format integer the Associated Press style"), |
483 self.tr("apnumber - Format integer the Associated Press style"), |
410 lambda: self.__applyTemplate("apnumber")) |
484 lambda: self.__applyTemplate("apnumber"), |
|
485 ) |
411 menu.addSeparator() |
486 menu.addSeparator() |
412 menu.addAction( |
487 menu.addAction( |
413 self.tr("intcomma - Format integer with commas"), |
488 self.tr("intcomma - Format integer with commas"), |
414 lambda: self.__applyTemplate("intcomma")) |
489 lambda: self.__applyTemplate("intcomma"), |
|
490 ) |
415 menu.addAction( |
491 menu.addAction( |
416 self.tr("intword - Convert integer to word"), |
492 self.tr("intword - Convert integer to word"), |
417 lambda: self.__applyTemplate("intword")) |
493 lambda: self.__applyTemplate("intword"), |
|
494 ) |
418 menu.addSeparator() |
495 menu.addSeparator() |
419 menu.addAction( |
496 menu.addAction( |
420 self.tr("naturalday - Format date naturally"), |
497 self.tr("naturalday - Format date naturally"), |
421 lambda: self.__applyTemplate("naturalday")) |
498 lambda: self.__applyTemplate("naturalday"), |
|
499 ) |
422 menu.addAction( |
500 menu.addAction( |
423 self.tr("naturaltime - Format time naturally"), |
501 self.tr("naturaltime - Format time naturally"), |
424 lambda: self.__applyTemplate("naturaltime")) |
502 lambda: self.__applyTemplate("naturaltime"), |
|
503 ) |
425 menu.addSeparator() |
504 menu.addSeparator() |
426 menu.addAction( |
505 menu.addAction( |
427 self.tr("ordinal - Convert integer to ordinal"), |
506 self.tr("ordinal - Convert integer to ordinal"), |
428 lambda: self.__applyTemplate("ordinal")) |
507 lambda: self.__applyTemplate("ordinal"), |
429 |
508 ) |
|
509 |
430 self.__humanizeMenu = menu |
510 self.__humanizeMenu = menu |
431 return menu |
511 return menu |
432 |
512 |
433 def __initWebDesignMenu(self): |
513 def __initWebDesignMenu(self): |
434 """ |
514 """ |
435 Private method to initialize the web design menu. |
515 Private method to initialize the web design menu. |
436 |
516 |
437 @return generated menu |
517 @return generated menu |
438 @rtype QMenu |
518 @rtype QMenu |
439 """ |
519 """ |
440 menu = QMenu(self.tr("Web Design")) |
520 menu = QMenu(self.tr("Web Design")) |
441 menu.addAction( |
521 menu.addAction(self.tr("Load Package"), lambda: self.__applyTemplate("loadweb")) |
442 self.tr("Load Package"), |
|
443 lambda: self.__applyTemplate("loadweb")) |
|
444 menu.addSeparator() |
522 menu.addSeparator() |
445 menu.addAction( |
523 menu.addAction( |
446 self.tr("lorem - Builtin Lorem Ipsum Generator"), |
524 self.tr("lorem - Builtin Lorem Ipsum Generator"), |
447 lambda: self.__applyTemplate("lorem")) |
525 lambda: self.__applyTemplate("lorem"), |
448 |
526 ) |
|
527 |
449 self.__webMenu = menu |
528 self.__webMenu = menu |
450 return menu |
529 return menu |
451 |
530 |
452 def __initStaticMenu(self): |
531 def __initStaticMenu(self): |
453 """ |
532 """ |
454 Private method to initialize the static menu. |
533 Private method to initialize the static menu. |
455 |
534 |
456 @return generated menu |
535 @return generated menu |
457 @rtype QMenu |
536 @rtype QMenu |
458 """ |
537 """ |
459 menu = QMenu(self.tr("Static")) |
538 menu = QMenu(self.tr("Static")) |
460 menu.addAction( |
539 menu.addAction( |
461 self.tr("Load Package"), |
540 self.tr("Load Package"), lambda: self.__applyTemplate("loadstatic") |
462 lambda: self.__applyTemplate("loadstatic")) |
541 ) |
463 menu.addSeparator() |
542 menu.addSeparator() |
464 menu.addAction( |
543 menu.addAction( |
465 self.tr("static - Link to static file"), |
544 self.tr("static - Link to static file"), |
466 lambda: self.__applyTemplate("staticfile")) |
545 lambda: self.__applyTemplate("staticfile"), |
|
546 ) |
467 menu.addAction( |
547 menu.addAction( |
468 self.tr("static - Link to static file (via variable)"), |
548 self.tr("static - Link to static file (via variable)"), |
469 lambda: self.__applyTemplate("staticvariable")) |
549 lambda: self.__applyTemplate("staticvariable"), |
|
550 ) |
470 menu.addAction( |
551 menu.addAction( |
471 self.tr("get_static_prefix - Insert static URL"), |
552 self.tr("get_static_prefix - Insert static URL"), |
472 lambda: self.__applyTemplate("get_static_prefix")) |
553 lambda: self.__applyTemplate("get_static_prefix"), |
|
554 ) |
473 menu.addAction( |
555 menu.addAction( |
474 self.tr("get_media_prefix - Insert media URL"), |
556 self.tr("get_media_prefix - Insert media URL"), |
475 lambda: self.__applyTemplate("get_media_prefix")) |
557 lambda: self.__applyTemplate("get_media_prefix"), |
476 |
558 ) |
|
559 |
477 self.__staticMenu = menu |
560 self.__staticMenu = menu |
478 return menu |
561 return menu |
479 |
562 |
480 def __initCommentsMenu(self): |
563 def __initCommentsMenu(self): |
481 """ |
564 """ |
482 Private method to initialize the comments menu. |
565 Private method to initialize the comments menu. |
483 |
566 |
484 @return generated menu |
567 @return generated menu |
485 @rtype QMenu |
568 @rtype QMenu |
486 """ |
569 """ |
487 menu = QMenu(self.tr("Comment")) |
570 menu = QMenu(self.tr("Comment")) |
488 menu.addAction( |
571 menu.addAction( |
489 self.tr("Single Line Comment Selected Text"), |
572 self.tr("Single Line Comment Selected Text"), |
490 lambda: self.__applyTemplate("singlelinecommentselect")) |
573 lambda: self.__applyTemplate("singlelinecommentselect"), |
|
574 ) |
491 menu.addAction( |
575 menu.addAction( |
492 self.tr("Multi Line Comment Selected Text"), |
576 self.tr("Multi Line Comment Selected Text"), |
493 lambda: self.__applyTemplate("multilinecommentselect")) |
577 lambda: self.__applyTemplate("multilinecommentselect"), |
|
578 ) |
494 menu.addSeparator() |
579 menu.addSeparator() |
495 menu.addAction( |
580 menu.addAction( |
496 self.tr("Single Line Comment from Input Dialog"), |
581 self.tr("Single Line Comment from Input Dialog"), |
497 lambda: self.__applyTemplate("singlelinecommentdialog")) |
582 lambda: self.__applyTemplate("singlelinecommentdialog"), |
|
583 ) |
498 menu.addAction( |
584 menu.addAction( |
499 self.tr("Multi Line Comment from Input Dialog"), |
585 self.tr("Multi Line Comment from Input Dialog"), |
500 lambda: self.__applyTemplate("multilinecommentdialog")) |
586 lambda: self.__applyTemplate("multilinecommentdialog"), |
|
587 ) |
501 menu.addSeparator() |
588 menu.addSeparator() |
502 menu.addAction( |
589 menu.addAction( |
503 self.tr("Single Line Comment from Clipboard"), |
590 self.tr("Single Line Comment from Clipboard"), |
504 lambda: self.__applyTemplate("singlelinecommentclipboard")) |
591 lambda: self.__applyTemplate("singlelinecommentclipboard"), |
|
592 ) |
505 menu.addAction( |
593 menu.addAction( |
506 self.tr("Multi Line Comment from Clipboard"), |
594 self.tr("Multi Line Comment from Clipboard"), |
507 lambda: self.__applyTemplate("multilinecommentclipboard")) |
595 lambda: self.__applyTemplate("multilinecommentclipboard"), |
|
596 ) |
508 menu.addSeparator() |
597 menu.addSeparator() |
509 menu.addAction( |
598 menu.addAction( |
510 self.tr("Multi Line Comment from File"), |
599 self.tr("Multi Line Comment from File"), |
511 lambda: self.__applyTemplate("multilinecommentfile")) |
600 lambda: self.__applyTemplate("multilinecommentfile"), |
|
601 ) |
512 menu.addSeparator() |
602 menu.addSeparator() |
513 menu.addAction( |
603 menu.addAction( |
514 self.tr("Single Line Comment from Date Time Now"), |
604 self.tr("Single Line Comment from Date Time Now"), |
515 lambda: self.__applyTemplate("singlelinecommentdatetime")) |
605 lambda: self.__applyTemplate("singlelinecommentdatetime"), |
|
606 ) |
516 menu.addSeparator() |
607 menu.addSeparator() |
517 menu.addAction( |
608 menu.addAction( |
518 self.tr("HTML Comment Out Selected Text"), |
609 self.tr("HTML Comment Out Selected Text"), |
519 lambda: self.__applyTemplate("htmlcomment")) |
610 lambda: self.__applyTemplate("htmlcomment"), |
|
611 ) |
520 menu.addAction( |
612 menu.addAction( |
521 self.tr("MS IE Conditional Comment Selected Text"), |
613 self.tr("MS IE Conditional Comment Selected Text"), |
522 lambda: self.__applyTemplate("iecomment")) |
614 lambda: self.__applyTemplate("iecomment"), |
523 |
615 ) |
|
616 |
524 self.__commentsMenu = menu |
617 self.__commentsMenu = menu |
525 return menu |
618 return menu |
526 |
619 |
527 def __initInternationalizationMenu(self): |
620 def __initInternationalizationMenu(self): |
528 """ |
621 """ |
529 Private method to initialize the static menu. |
622 Private method to initialize the static menu. |
530 |
623 |
531 @return generated menu |
624 @return generated menu |
532 @rtype QMenu |
625 @rtype QMenu |
533 """ |
626 """ |
534 mainMenu = QMenu(self.tr("Internationalization (i18n)")) |
627 mainMenu = QMenu(self.tr("Internationalization (i18n)")) |
535 mainMenu.addAction( |
628 mainMenu.addAction( |
536 self.tr("Load Package"), |
629 self.tr("Load Package"), lambda: self.__applyTemplate("loadi18n") |
537 lambda: self.__applyTemplate("loadi18n")) |
630 ) |
538 mainMenu.addSeparator() |
631 mainMenu.addSeparator() |
539 |
632 |
540 menu = QMenu(self.tr("Tags"), mainMenu) |
633 menu = QMenu(self.tr("Tags"), mainMenu) |
541 menu.addAction( |
634 menu.addAction( |
542 self.tr("trans - Translate String or Variable"), |
635 self.tr("trans - Translate String or Variable"), |
543 lambda: self.__applyTemplate("trans")) |
636 lambda: self.__applyTemplate("trans"), |
|
637 ) |
544 menu.addAction( |
638 menu.addAction( |
545 self.tr("trans..as - Translate String into Variable"), |
639 self.tr("trans..as - Translate String into Variable"), |
546 lambda: self.__applyTemplate("trans..as")) |
640 lambda: self.__applyTemplate("trans..as"), |
|
641 ) |
547 menu.addSeparator() |
642 menu.addSeparator() |
548 menu.addAction( |
643 menu.addAction( |
549 self.tr("blocktrans - Translate Block"), |
644 self.tr("blocktrans - Translate Block"), |
550 lambda: self.__applyTemplate("blocktrans")) |
645 lambda: self.__applyTemplate("blocktrans"), |
|
646 ) |
551 menu.addAction( |
647 menu.addAction( |
552 self.tr("blocktrans..with - Translate Block with Attributes"), |
648 self.tr("blocktrans..with - Translate Block with Attributes"), |
553 lambda: self.__applyTemplate("blocktrans..with")) |
649 lambda: self.__applyTemplate("blocktrans..with"), |
554 menu.addAction( |
650 ) |
555 self.tr("plural - Plural Block"), |
651 menu.addAction( |
556 lambda: self.__applyTemplate("plural")) |
652 self.tr("plural - Plural Block"), lambda: self.__applyTemplate("plural") |
|
653 ) |
557 menu.addAction( |
654 menu.addAction( |
558 self.tr("language - Switch language"), |
655 self.tr("language - Switch language"), |
559 lambda: self.__applyTemplate("language")) |
656 lambda: self.__applyTemplate("language"), |
|
657 ) |
560 menu.addSeparator() |
658 menu.addSeparator() |
561 menu.addAction( |
659 menu.addAction( |
562 self.tr("get_current_language - Current language"), |
660 self.tr("get_current_language - Current language"), |
563 lambda: self.__applyTemplate("get_current_language")) |
661 lambda: self.__applyTemplate("get_current_language"), |
|
662 ) |
564 menu.addAction( |
663 menu.addAction( |
565 self.tr("get_available_languages - Available languages"), |
664 self.tr("get_available_languages - Available languages"), |
566 lambda: self.__applyTemplate("get_available_languages")) |
665 lambda: self.__applyTemplate("get_available_languages"), |
567 menu.addAction( |
666 ) |
568 self.tr("get_current_language_bidi - Current language's" |
667 menu.addAction( |
569 " direction"), |
668 self.tr("get_current_language_bidi - Current language's" " direction"), |
570 lambda: self.__applyTemplate("get_current_language_bidi")) |
669 lambda: self.__applyTemplate("get_current_language_bidi"), |
|
670 ) |
571 menu.addAction( |
671 menu.addAction( |
572 self.tr("get_language_info - Language Information"), |
672 self.tr("get_language_info - Language Information"), |
573 lambda: self.__applyTemplate("get_language_info")) |
673 lambda: self.__applyTemplate("get_language_info"), |
574 menu.addAction( |
674 ) |
575 self.tr("get_language_info_list - Language Information for a list" |
675 menu.addAction( |
576 " of languages"), |
676 self.tr( |
577 lambda: self.__applyTemplate("get_language_info_list")) |
677 "get_language_info_list - Language Information for a list" |
|
678 " of languages" |
|
679 ), |
|
680 lambda: self.__applyTemplate("get_language_info_list"), |
|
681 ) |
578 mainMenu.addMenu(menu) |
682 mainMenu.addMenu(menu) |
579 |
683 |
580 menu = QMenu(self.tr("Filters"), mainMenu) |
684 menu = QMenu(self.tr("Filters"), mainMenu) |
581 menu.addAction( |
685 menu.addAction( |
582 self.tr("language_name - Language name"), |
686 self.tr("language_name - Language name"), |
583 lambda: self.__applyTemplate("language_name")) |
687 lambda: self.__applyTemplate("language_name"), |
|
688 ) |
584 menu.addAction( |
689 menu.addAction( |
585 self.tr("language_name_local - Language name translated"), |
690 self.tr("language_name_local - Language name translated"), |
586 lambda: self.__applyTemplate("language_name_local")) |
691 lambda: self.__applyTemplate("language_name_local"), |
587 menu.addAction( |
692 ) |
588 self.tr("bidi - Language's direction"), |
693 menu.addAction( |
589 lambda: self.__applyTemplate("bidi")) |
694 self.tr("bidi - Language's direction"), lambda: self.__applyTemplate("bidi") |
|
695 ) |
590 mainMenu.addMenu(menu) |
696 mainMenu.addMenu(menu) |
591 |
697 |
592 self.__internationalizationMenu = mainMenu |
698 self.__internationalizationMenu = mainMenu |
593 return mainMenu |
699 return mainMenu |
594 |
700 |
595 def __initLocalizationMenu(self): |
701 def __initLocalizationMenu(self): |
596 """ |
702 """ |
597 Private method to initialize the static menu. |
703 Private method to initialize the static menu. |
598 |
704 |
599 @return generated menu |
705 @return generated menu |
600 @rtype QMenu |
706 @rtype QMenu |
601 """ |
707 """ |
602 mainMenu = QMenu(self.tr("Localization (l10n)")) |
708 mainMenu = QMenu(self.tr("Localization (l10n)")) |
603 mainMenu.addAction( |
709 mainMenu.addAction( |
604 self.tr("Load Package"), |
710 self.tr("Load Package"), lambda: self.__applyTemplate("loadl10n") |
605 lambda: self.__applyTemplate("loadl10n")) |
711 ) |
606 mainMenu.addSeparator() |
712 mainMenu.addSeparator() |
607 |
713 |
608 menu = QMenu(self.tr("Tags"), mainMenu) |
714 menu = QMenu(self.tr("Tags"), mainMenu) |
609 menu.addAction( |
715 menu.addAction( |
610 self.tr("localize on - Activate Localization"), |
716 self.tr("localize on - Activate Localization"), |
611 lambda: self.__applyTemplate("localize_on")) |
717 lambda: self.__applyTemplate("localize_on"), |
|
718 ) |
612 menu.addAction( |
719 menu.addAction( |
613 self.tr("localize off - Dectivate Localization"), |
720 self.tr("localize off - Dectivate Localization"), |
614 lambda: self.__applyTemplate("localize_off")) |
721 lambda: self.__applyTemplate("localize_off"), |
|
722 ) |
615 mainMenu.addMenu(menu) |
723 mainMenu.addMenu(menu) |
616 |
724 |
617 menu = QMenu(self.tr("Filters"), mainMenu) |
725 menu = QMenu(self.tr("Filters"), mainMenu) |
618 menu.addAction( |
726 menu.addAction( |
619 self.tr("localize - Output value localized"), |
727 self.tr("localize - Output value localized"), |
620 lambda: self.__applyTemplate("localize")) |
728 lambda: self.__applyTemplate("localize"), |
|
729 ) |
621 menu.addAction( |
730 menu.addAction( |
622 self.tr("unlocalize - Output value non-localized"), |
731 self.tr("unlocalize - Output value non-localized"), |
623 lambda: self.__applyTemplate("unlocalize")) |
732 lambda: self.__applyTemplate("unlocalize"), |
|
733 ) |
624 mainMenu.addMenu(menu) |
734 mainMenu.addMenu(menu) |
625 |
735 |
626 self.__localizationMenu = mainMenu |
736 self.__localizationMenu = mainMenu |
627 return mainMenu |
737 return mainMenu |
628 |
738 |
629 def __initTimezoneMenu(self): |
739 def __initTimezoneMenu(self): |
630 """ |
740 """ |
631 Private method to initialize the static menu. |
741 Private method to initialize the static menu. |
632 |
742 |
633 @return generated menu |
743 @return generated menu |
634 @rtype QMenu |
744 @rtype QMenu |
635 """ |
745 """ |
636 mainMenu = QMenu(self.tr("Timezone (tz)")) |
746 mainMenu = QMenu(self.tr("Timezone (tz)")) |
637 mainMenu.addAction( |
747 mainMenu.addAction( |
638 self.tr("Load Package"), |
748 self.tr("Load Package"), lambda: self.__applyTemplate("loadtz") |
639 lambda: self.__applyTemplate("loadtz")) |
749 ) |
640 mainMenu.addSeparator() |
750 mainMenu.addSeparator() |
641 |
751 |
642 menu = QMenu(self.tr("Tags"), mainMenu) |
752 menu = QMenu(self.tr("Tags"), mainMenu) |
643 menu.addAction( |
753 menu.addAction( |
644 self.tr("localtime on - Activate date and time conversion"), |
754 self.tr("localtime on - Activate date and time conversion"), |
645 lambda: self.__applyTemplate("localtime_on")) |
755 lambda: self.__applyTemplate("localtime_on"), |
|
756 ) |
646 menu.addAction( |
757 menu.addAction( |
647 self.tr("localtime off - Deactivate date and time conversion"), |
758 self.tr("localtime off - Deactivate date and time conversion"), |
648 lambda: self.__applyTemplate("localtime_off")) |
759 lambda: self.__applyTemplate("localtime_off"), |
|
760 ) |
649 menu.addAction( |
761 menu.addAction( |
650 self.tr("timezone - Set timezone for date and time conversion"), |
762 self.tr("timezone - Set timezone for date and time conversion"), |
651 lambda: self.__applyTemplate("timezone_set")) |
763 lambda: self.__applyTemplate("timezone_set"), |
652 menu.addAction( |
764 ) |
653 self.tr("timezone None - Unset timezone for date and time" |
765 menu.addAction( |
654 " conversion"), |
766 self.tr("timezone None - Unset timezone for date and time" " conversion"), |
655 lambda: self.__applyTemplate("timezone_unset")) |
767 lambda: self.__applyTemplate("timezone_unset"), |
|
768 ) |
656 menu.addAction( |
769 menu.addAction( |
657 self.tr("get_current_timezone - Get current time zone"), |
770 self.tr("get_current_timezone - Get current time zone"), |
658 lambda: self.__applyTemplate("get_current_timezone")) |
771 lambda: self.__applyTemplate("get_current_timezone"), |
|
772 ) |
659 mainMenu.addMenu(menu) |
773 mainMenu.addMenu(menu) |
660 |
774 |
661 menu = QMenu(self.tr("Filters"), mainMenu) |
775 menu = QMenu(self.tr("Filters"), mainMenu) |
662 menu.addAction( |
776 menu.addAction( |
663 self.tr("localtime - Convert to local time zone"), |
777 self.tr("localtime - Convert to local time zone"), |
664 lambda: self.__applyTemplate("localtime")) |
778 lambda: self.__applyTemplate("localtime"), |
665 menu.addAction( |
779 ) |
666 self.tr("utc - Convert to UTC"), |
780 menu.addAction( |
667 lambda: self.__applyTemplate("utc")) |
781 self.tr("utc - Convert to UTC"), lambda: self.__applyTemplate("utc") |
|
782 ) |
668 menu.addAction( |
783 menu.addAction( |
669 self.tr("timezone - Convert to a specific time zone"), |
784 self.tr("timezone - Convert to a specific time zone"), |
670 lambda: self.__applyTemplate("timezone")) |
785 lambda: self.__applyTemplate("timezone"), |
|
786 ) |
671 mainMenu.addMenu(menu) |
787 mainMenu.addMenu(menu) |
672 |
788 |
673 self.__timezoneMenu = mainMenu |
789 self.__timezoneMenu = mainMenu |
674 return mainMenu |
790 return mainMenu |
675 |
791 |
676 def __findTemplateTag(self): |
792 def __findTemplateTag(self): |
677 """ |
793 """ |
678 Private slot to find a template tag and insert its text. |
794 Private slot to find a template tag and insert its text. |
679 """ |
795 """ |
680 if self.__findDialog is None: |
796 if self.__findDialog is None: |
681 from .FindTemplateTagDialog import FindTemplateTagDialog |
797 from .FindTemplateTagDialog import FindTemplateTagDialog |
|
798 |
682 self.__findDialog = FindTemplateTagDialog() |
799 self.__findDialog = FindTemplateTagDialog() |
683 self.__findDialog.tag.connect(self.__applyTemplate) |
800 self.__findDialog.tag.connect(self.__applyTemplate) |
684 self.__findDialog.show() |
801 self.__findDialog.show() |
685 self.__findDialog.raise_() |
802 self.__findDialog.raise_() |
686 self.__findDialog.activateWindow() |
803 self.__findDialog.activateWindow() |
687 |
804 |
688 def __applyTemplate(self, tag): |
805 def __applyTemplate(self, tag): |
689 """ |
806 """ |
690 Private slot to generate and insert the template text. |
807 Private slot to generate and insert the template text. |
691 |
808 |
692 @param tag name of the tag to insert |
809 @param tag name of the tag to insert |
693 @type str |
810 @type str |
694 """ |
811 """ |
695 editor = ericApp().getObject("ViewManager").activeWindow() |
812 editor = ericApp().getObject("ViewManager").activeWindow() |
696 if editor is None: |
813 if editor is None: |
697 return |
814 return |
698 |
815 |
699 templateText, replace = self.__generateTemplateText( |
816 templateText, replace = self.__generateTemplateText(tag, editor.selectedText()) |
700 tag, editor.selectedText()) |
817 |
701 |
|
702 if templateText: |
818 if templateText: |
703 editor.beginUndoAction() |
819 editor.beginUndoAction() |
704 if replace: |
820 if replace: |
705 editor.replaceSelectedText(templateText) |
821 editor.replaceSelectedText(templateText) |
706 else: |
822 else: |
707 editor.insert(templateText) |
823 editor.insert(templateText) |
708 editor.endUndoAction() |
824 editor.endUndoAction() |
709 |
825 |
710 def __generateTemplateText(self, tag, selectedText): |
826 def __generateTemplateText(self, tag, selectedText): |
711 """ |
827 """ |
712 Private slot to generate the template text. |
828 Private slot to generate the template text. |
713 |
829 |
714 @param tag name of the tag to insert |
830 @param tag name of the tag to insert |
715 @type str |
831 @type str |
716 @param selectedText selected text of the current editor |
832 @param selectedText selected text of the current editor |
717 @type str |
833 @type str |
718 @return tuple of generated template text, a flag indicating to perform |
834 @return tuple of generated template text, a flag indicating to perform |
719 a replace operation |
835 a replace operation |
720 @rtype tuple of (str, bool) |
836 @rtype tuple of (str, bool) |
721 """ |
837 """ |
722 replace = False # safe value |
838 replace = False # safe value |
723 ok = True |
839 ok = True |
724 templateText = "" |
840 templateText = "" |
725 |
841 |
726 #################################################### |
842 #################################################### |
727 ## Template Tags ## |
843 ## Template Tags ## |
728 #################################################### |
844 #################################################### |
729 |
845 |
730 if tag == "autoescape": |
846 if tag == "autoescape": |
731 templateText = ( |
847 templateText = "{{% autoescape on %}} {0} {{% endautoescape %}}".format( |
732 "{{% autoescape on %}} {0} {{% endautoescape %}}".format( |
848 selectedText |
733 selectedText)) |
849 ) |
734 replace = True |
850 replace = True |
735 elif tag == "block": |
851 elif tag == "block": |
736 data, ok = DjangoTagInputDialog.getText( |
852 data, ok = DjangoTagInputDialog.getText( |
737 None, |
853 None, |
738 self.tr("Named Block"), |
854 self.tr("Named Block"), |
739 [self.tr("Enter block name:")], |
855 [self.tr("Enter block name:")], |
740 ["block_name"]) |
856 ["block_name"], |
|
857 ) |
741 if ok: |
858 if ok: |
742 templateText = "{{% block {0} %}} {1} {{% endblock %}}".format( |
859 templateText = "{{% block {0} %}} {1} {{% endblock %}}".format( |
743 data[0], selectedText) |
860 data[0], selectedText |
|
861 ) |
744 replace = True |
862 replace = True |
745 elif tag == "csrf_token": |
863 elif tag == "csrf_token": |
746 templateText = "{% csrf_token %}" |
864 templateText = "{% csrf_token %}" |
747 elif tag == "cycle": |
865 elif tag == "cycle": |
748 data, ok = DjangoTagInputDialog.getText( |
866 data, ok = DjangoTagInputDialog.getText( |
749 None, |
867 None, |
750 self.tr("Cycle Variables"), |
868 self.tr("Cycle Variables"), |
751 [self.tr("Enter items to cycle, space separated")], |
869 [self.tr("Enter items to cycle, space separated")], |
752 ["item1 item2 item3"]) |
870 ["item1 item2 item3"], |
|
871 ) |
753 if ok: |
872 if ok: |
754 templateText = "{{% cycle {0} %}}".format(data[0]) |
873 templateText = "{{% cycle {0} %}}".format(data[0]) |
755 elif tag == "debug": |
874 elif tag == "debug": |
756 templateText = "{% debug %}" |
875 templateText = "{% debug %}" |
757 elif tag == "extendsvariable": |
876 elif tag == "extendsvariable": |
758 data, ok = DjangoTagInputDialog.getText( |
877 data, ok = DjangoTagInputDialog.getText( |
759 None, |
878 None, |
760 self.tr("Extends"), |
879 self.tr("Extends"), |
761 [self.tr("Enter variable name:")], |
880 [self.tr("Enter variable name:")], |
762 ["variable"]) |
881 ["variable"], |
|
882 ) |
763 if ok: |
883 if ok: |
764 templateText = "{{% extends {0} %}}".format(data[0]) |
884 templateText = "{{% extends {0} %}}".format(data[0]) |
765 elif tag == "extendsfile": |
885 elif tag == "extendsfile": |
766 data, ok = DjangoTagInputDialog.getText( |
886 data, ok = DjangoTagInputDialog.getText( |
767 None, |
887 None, |
768 self.tr("Extends"), |
888 self.tr("Extends"), |
769 [self.tr("Enter parent file name:")], |
889 [self.tr("Enter parent file name:")], |
770 ["base.html"]) |
890 ["base.html"], |
|
891 ) |
771 if ok: |
892 if ok: |
772 templateText = '{{% extends "{0}" %}}'.format(data[0]) |
893 templateText = '{{% extends "{0}" %}}'.format(data[0]) |
773 elif tag == "filter": |
894 elif tag == "filter": |
774 data, ok = DjangoTagInputDialog.getText( |
895 data, ok = DjangoTagInputDialog.getText( |
775 None, |
896 None, |
776 self.tr("Tag Filters"), |
897 self.tr("Tag Filters"), |
777 [self.tr("Multiple filters with arguments, pipes separated:")], |
898 [self.tr("Multiple filters with arguments, pipes separated:")], |
778 ["lower|safe"]) |
899 ["lower|safe"], |
779 if ok: |
900 ) |
780 templateText = ( |
901 if ok: |
781 "{{% filter {0} %}} {1} {{% endfilter %}}".format( |
902 templateText = "{{% filter {0} %}} {1} {{% endfilter %}}".format( |
782 data[0], selectedText)) |
903 data[0], selectedText |
|
904 ) |
783 replace = True |
905 replace = True |
784 elif tag == "firstof": |
906 elif tag == "firstof": |
785 data, ok = DjangoTagInputDialog.getText( |
907 data, ok = DjangoTagInputDialog.getText( |
786 None, |
908 None, |
787 self.tr("First Of"), |
909 self.tr("First Of"), |
788 [self.tr("Enter multiple variables, space separated:"), |
910 [ |
789 self.tr("Enter fallback value:")], |
911 self.tr("Enter multiple variables, space separated:"), |
790 ["var1 var2", "fallback_value"]) |
912 self.tr("Enter fallback value:"), |
|
913 ], |
|
914 ["var1 var2", "fallback_value"], |
|
915 ) |
791 if ok: |
916 if ok: |
792 templateText = ( |
917 templateText = ( |
793 '{{% filter force_escape %}}{{% firstof {0} "{1}" %}}' |
918 '{{% filter force_escape %}}{{% firstof {0} "{1}" %}}' |
794 ' {2} {{% endfilter %}}'.format( |
919 " {2} {{% endfilter %}}".format(data[0], data[1], selectedText) |
795 data[0], data[1], selectedText)) |
920 ) |
796 replace = True |
921 replace = True |
797 elif tag == "for": |
922 elif tag == "for": |
798 data, ok = DjangoTagInputDialog.getText( |
923 data, ok = DjangoTagInputDialog.getText( |
799 None, |
924 None, |
800 self.tr("For Loop"), |
925 self.tr("For Loop"), |
801 [self.tr("Enter variable to use for iteration:"), |
926 [ |
802 self.tr("Enter sequence to iterate over:")], |
927 self.tr("Enter variable to use for iteration:"), |
803 ["item", "values"]) |
928 self.tr("Enter sequence to iterate over:"), |
804 if ok: |
929 ], |
805 templateText = ( |
930 ["item", "values"], |
806 "{{% for {0} in {1} %}} {2} {{% endfor %}}".format( |
931 ) |
807 data[0], data[1], selectedText)) |
932 if ok: |
|
933 templateText = "{{% for {0} in {1} %}} {2} {{% endfor %}}".format( |
|
934 data[0], data[1], selectedText |
|
935 ) |
808 replace = True |
936 replace = True |
809 elif tag == "for...empty": |
937 elif tag == "for...empty": |
810 data, ok = DjangoTagInputDialog.getText( |
938 data, ok = DjangoTagInputDialog.getText( |
811 None, |
939 None, |
812 self.tr("For Loop"), |
940 self.tr("For Loop"), |
813 [self.tr("Enter variable to use for iteration:"), |
941 [ |
814 self.tr("Enter sequence to iterate over:"), |
942 self.tr("Enter variable to use for iteration:"), |
815 self.tr("Enter output to use if loop is empty:")], |
943 self.tr("Enter sequence to iterate over:"), |
816 ["item", "values", '"Nothing."']) |
944 self.tr("Enter output to use if loop is empty:"), |
|
945 ], |
|
946 ["item", "values", '"Nothing."'], |
|
947 ) |
817 if ok: |
948 if ok: |
818 templateText = ( |
949 templateText = ( |
819 "{{% for {0} in {1} %}} {2} {{% empty %}} {3}" |
950 "{{% for {0} in {1} %}} {2} {{% empty %}} {3}" |
820 " {{% endfor %}}".format( |
951 " {{% endfor %}}".format(data[0], data[1], selectedText, data[2]) |
821 data[0], data[1], selectedText, data[2])) |
952 ) |
822 replace = True |
953 replace = True |
823 elif tag == "if": |
954 elif tag == "if": |
824 from .IfTagInputDialog import IfTagInputDialog |
955 from .IfTagInputDialog import IfTagInputDialog |
|
956 |
825 dlg = IfTagInputDialog() |
957 dlg = IfTagInputDialog() |
826 if dlg.exec() == QDialog.DialogCode.Accepted: |
958 if dlg.exec() == QDialog.DialogCode.Accepted: |
827 templateText = dlg.getTag() |
959 templateText = dlg.getTag() |
828 elif tag == "ifchanged": |
960 elif tag == "ifchanged": |
829 data, ok = DjangoTagInputDialog.getText( |
961 data, ok = DjangoTagInputDialog.getText( |
830 None, |
962 None, |
831 self.tr("Check Variables for Changes"), |
963 self.tr("Check Variables for Changes"), |
832 [self.tr("Enter variables to check (space separated):")], |
964 [self.tr("Enter variables to check (space separated):")], |
833 ["variable1 variable2"]) |
965 ["variable1 variable2"], |
834 if ok: |
966 ) |
835 templateText = ( |
967 if ok: |
836 '{{% ifchanged {0} %}}{1}{{% endifchanged %}}' |
968 templateText = "{{% ifchanged {0} %}}{1}{{% endifchanged %}}".format( |
837 .format(data[0], selectedText)) |
969 data[0], selectedText |
|
970 ) |
838 replace = True |
971 replace = True |
839 elif tag == "ifequal": |
972 elif tag == "ifequal": |
840 data, ok = DjangoTagInputDialog.getText( |
973 data, ok = DjangoTagInputDialog.getText( |
841 None, |
974 None, |
842 self.tr("Check If Equal"), |
975 self.tr("Check If Equal"), |
843 [self.tr("Enter first variable or string to check:"), |
976 [ |
844 self.tr("Enter second variable or string to check:")], |
977 self.tr("Enter first variable or string to check:"), |
845 ["user.username", '"adrian"']) |
978 self.tr("Enter second variable or string to check:"), |
846 if ok: |
979 ], |
847 templateText = ( |
980 ["user.username", '"adrian"'], |
848 '{{% ifequal {0} {1} %}}{2}{{% endifequal %}}' |
981 ) |
849 .format(data[0], data[1], selectedText)) |
982 if ok: |
|
983 templateText = "{{% ifequal {0} {1} %}}{2}{{% endifequal %}}".format( |
|
984 data[0], data[1], selectedText |
|
985 ) |
850 replace = True |
986 replace = True |
851 elif tag == "ifnotequal": |
987 elif tag == "ifnotequal": |
852 data, ok = DjangoTagInputDialog.getText( |
988 data, ok = DjangoTagInputDialog.getText( |
853 None, |
989 None, |
854 self.tr("Check If Not Equal"), |
990 self.tr("Check If Not Equal"), |
855 [self.tr("Enter first variable or string to check:"), |
991 [ |
856 self.tr("Enter second variable or string to check:")], |
992 self.tr("Enter first variable or string to check:"), |
857 ["user.username", '"adrian"']) |
993 self.tr("Enter second variable or string to check:"), |
|
994 ], |
|
995 ["user.username", '"adrian"'], |
|
996 ) |
858 if ok: |
997 if ok: |
859 templateText = ( |
998 templateText = ( |
860 '{{% ifnotequal {0} {1} %}}{2}{{% endifnotequal %}}' |
999 "{{% ifnotequal {0} {1} %}}{2}{{% endifnotequal %}}".format( |
861 .format(data[0], data[1], selectedText)) |
1000 data[0], data[1], selectedText |
|
1001 ) |
|
1002 ) |
862 replace = True |
1003 replace = True |
863 elif tag == "includevariable": |
1004 elif tag == "includevariable": |
864 data, ok = DjangoTagInputDialog.getText( |
1005 data, ok = DjangoTagInputDialog.getText( |
865 None, |
1006 None, |
866 self.tr("Include"), |
1007 self.tr("Include"), |
867 [self.tr("Enter variable name:")], |
1008 [self.tr("Enter variable name:")], |
868 ["variable"]) |
1009 ["variable"], |
869 if ok: |
1010 ) |
870 templateText = '{{% include {0} %}}'.format(data[0]) |
1011 if ok: |
|
1012 templateText = "{{% include {0} %}}".format(data[0]) |
871 elif tag == "includefile": |
1013 elif tag == "includefile": |
872 data, ok = DjangoTagInputDialog.getText( |
1014 data, ok = DjangoTagInputDialog.getText( |
873 None, |
1015 None, self.tr("Include"), [self.tr("Enter file name:")], ["other.html"] |
874 self.tr("Include"), |
1016 ) |
875 [self.tr("Enter file name:")], |
|
876 ["other.html"]) |
|
877 if ok: |
1017 if ok: |
878 templateText = '{{% include "{0}" %}}'.format(data[0]) |
1018 templateText = '{{% include "{0}" %}}'.format(data[0]) |
879 elif tag == "load": |
1019 elif tag == "load": |
880 data, ok = DjangoTagInputDialog.getText( |
1020 data, ok = DjangoTagInputDialog.getText( |
881 None, |
1021 None, |
882 self.tr("Load"), |
1022 self.tr("Load"), |
883 [self.tr("Enter template tag set to load:")], |
1023 [self.tr("Enter template tag set to load:")], |
884 ["foo bar"]) |
1024 ["foo bar"], |
|
1025 ) |
885 if ok: |
1026 if ok: |
886 templateText = '{{% load "{0}" %}}'.format(data[0]) |
1027 templateText = '{{% load "{0}" %}}'.format(data[0]) |
887 elif tag == "now": |
1028 elif tag == "now": |
888 dateformat, ok = QInputDialog.getItem( |
1029 dateformat, ok = QInputDialog.getItem( |
889 None, |
1030 None, |
890 self.tr("Now"), |
1031 self.tr("Now"), |
891 self.tr("Current date time format:"), |
1032 self.tr("Current date time format:"), |
892 ["DATETIME_FORMAT", "SHORT_DATETIME_FORMAT", |
1033 [ |
893 "SHORT_DATE_FORMAT", "DATE_FORMAT"], |
1034 "DATETIME_FORMAT", |
894 0, False) |
1035 "SHORT_DATETIME_FORMAT", |
|
1036 "SHORT_DATE_FORMAT", |
|
1037 "DATE_FORMAT", |
|
1038 ], |
|
1039 0, |
|
1040 False, |
|
1041 ) |
895 if ok: |
1042 if ok: |
896 templateText = '{{% now "{0}" %}}'.format(dateformat) |
1043 templateText = '{{% now "{0}" %}}'.format(dateformat) |
897 elif tag == "regroup": |
1044 elif tag == "regroup": |
898 data, ok = DjangoTagInputDialog.getText( |
1045 data, ok = DjangoTagInputDialog.getText( |
899 None, |
1046 None, |
900 self.tr("Regroup List"), |
1047 self.tr("Regroup List"), |
901 [self.tr("List Variable:"), self.tr("Common Attribute:"), |
1048 [ |
902 self.tr("Name of resulting list:")], |
1049 self.tr("List Variable:"), |
903 ["cities", "country", "country_list"]) |
1050 self.tr("Common Attribute:"), |
904 if ok: |
1051 self.tr("Name of resulting list:"), |
905 templateText = '{{% regroup {0} by {1} as {2} %}}'.format( |
1052 ], |
906 data[0], data[1], data[2]) |
1053 ["cities", "country", "country_list"], |
|
1054 ) |
|
1055 if ok: |
|
1056 templateText = "{{% regroup {0} by {1} as {2} %}}".format( |
|
1057 data[0], data[1], data[2] |
|
1058 ) |
907 elif tag == "spaceless": |
1059 elif tag == "spaceless": |
908 templateText = "{{% spaceless %}} {0} {{% endspaceless %}}".format( |
1060 templateText = "{{% spaceless %}} {0} {{% endspaceless %}}".format( |
909 selectedText) |
1061 selectedText |
|
1062 ) |
910 replace = True |
1063 replace = True |
911 elif tag == "ssi": |
1064 elif tag == "ssi": |
912 data, ok = DjangoTagInputDialog.getText( |
1065 data, ok = DjangoTagInputDialog.getText( |
913 None, |
1066 None, |
914 self.tr("SSI"), |
1067 self.tr("SSI"), |
915 [self.tr("Full path to template:")], |
1068 [self.tr("Full path to template:")], |
916 ["/tmp/ssi_template.html"]) # secok |
1069 ["/tmp/ssi_template.html"], |
|
1070 ) # secok |
917 if ok: |
1071 if ok: |
918 templateText = '{{% ssi "{0}" parsed %}}'.format(data[0]) |
1072 templateText = '{{% ssi "{0}" parsed %}}'.format(data[0]) |
919 elif tag == "ssifile": |
1073 elif tag == "ssifile": |
920 ssi = EricFileDialog.getOpenFileName( |
1074 ssi = EricFileDialog.getOpenFileName( |
921 None, |
1075 None, self.tr("SSI"), os.path.expanduser("~"), self.tr("All Files (*)") |
922 self.tr("SSI"), |
1076 ) |
923 os.path.expanduser("~"), |
|
924 self.tr("All Files (*)")) |
|
925 if ssi: |
1077 if ssi: |
926 templateText = '{{% ssi "{0}" parsed %}}'.format(ssi) |
1078 templateText = '{{% ssi "{0}" parsed %}}'.format(ssi) |
927 elif tag == "templatetag": |
1079 elif tag == "templatetag": |
928 templatetag, ok = QInputDialog.getItem( |
1080 templatetag, ok = QInputDialog.getItem( |
929 None, |
1081 None, |
930 self.tr("Template Tag"), |
1082 self.tr("Template Tag"), |
931 self.tr("Argument:"), |
1083 self.tr("Argument:"), |
932 ["block", "variable", "brace", "comment"], |
1084 ["block", "variable", "brace", "comment"], |
933 0, False) |
1085 0, |
|
1086 False, |
|
1087 ) |
934 if ok: |
1088 if ok: |
935 templateText = ( |
1089 templateText = ( |
936 '{{% templatetag open{0} %}} {1} {{% templatetag' |
1090 "{{% templatetag open{0} %}} {1} {{% templatetag" |
937 ' close{0} %}}'.format(templatetag, selectedText)) |
1091 " close{0} %}}".format(templatetag, selectedText) |
|
1092 ) |
938 replace = True |
1093 replace = True |
939 elif tag == "url": |
1094 elif tag == "url": |
940 data, ok = DjangoTagInputDialog.getText( |
1095 data, ok = DjangoTagInputDialog.getText( |
941 None, |
1096 None, |
942 self.tr("URL"), |
1097 self.tr("URL"), |
943 [self.tr("View method name:"), |
1098 [ |
944 self.tr("Optional arguments (space separated):")], |
1099 self.tr("View method name:"), |
945 ["path.to.some_view", "var1 var2"]) |
1100 self.tr("Optional arguments (space separated):"), |
|
1101 ], |
|
1102 ["path.to.some_view", "var1 var2"], |
|
1103 ) |
946 if ok: |
1104 if ok: |
947 if data[1]: |
1105 if data[1]: |
948 data[1] = ' ' + data[1] |
1106 data[1] = " " + data[1] |
949 templateText = '{{% url "{0}"{1} %}}'.format( |
1107 templateText = '{{% url "{0}"{1} %}}'.format(data[0], data[1]) |
950 data[0], data[1]) |
|
951 elif tag == "urlas": |
1108 elif tag == "urlas": |
952 data, ok = DjangoTagInputDialog.getText( |
1109 data, ok = DjangoTagInputDialog.getText( |
953 None, |
1110 None, |
954 self.tr("URL...as"), |
1111 self.tr("URL...as"), |
955 [self.tr("View method name:"), |
1112 [ |
956 self.tr("Optional arguments (space separated):"), |
1113 self.tr("View method name:"), |
957 self.tr("URL name:")], |
1114 self.tr("Optional arguments (space separated):"), |
958 ["path.to.some_view", "var1 var2", "url_name"]) |
1115 self.tr("URL name:"), |
|
1116 ], |
|
1117 ["path.to.some_view", "var1 var2", "url_name"], |
|
1118 ) |
959 if ok: |
1119 if ok: |
960 if data[1]: |
1120 if data[1]: |
961 data[1] = ' ' + data[1] |
1121 data[1] = " " + data[1] |
962 templateText = '{{% url "{0}"{1} as {2} %}}'.format( |
1122 templateText = '{{% url "{0}"{1} as {2} %}}'.format( |
963 data[0], data[1], data[2]) |
1123 data[0], data[1], data[2] |
|
1124 ) |
964 elif tag == "verbatim": |
1125 elif tag == "verbatim": |
965 templateText = "{{% verbatim %}} {0} {{% endverbatim %}}".format( |
1126 templateText = "{{% verbatim %}} {0} {{% endverbatim %}}".format( |
966 selectedText) |
1127 selectedText |
|
1128 ) |
967 replace = True |
1129 replace = True |
968 elif tag == "widthratio": |
1130 elif tag == "widthratio": |
969 data, ok = DjangoTagInputDialog.getText( |
1131 data, ok = DjangoTagInputDialog.getText( |
970 None, |
1132 None, |
971 self.tr("Width Ratio"), |
1133 self.tr("Width Ratio"), |
972 [self.tr("Variable:"), |
1134 [ |
973 self.tr("Maximum Value:"), |
1135 self.tr("Variable:"), |
974 self.tr("Maximum Width:")], |
1136 self.tr("Maximum Value:"), |
975 ["variable", "max_value", "max_width"]) |
1137 self.tr("Maximum Width:"), |
|
1138 ], |
|
1139 ["variable", "max_value", "max_width"], |
|
1140 ) |
976 if ok: |
1141 if ok: |
977 templateText = "{{% widthratio {0} {1} {2} %}}".format( |
1142 templateText = "{{% widthratio {0} {1} {2} %}}".format( |
978 data[0], data[1], data[2]) |
1143 data[0], data[1], data[2] |
|
1144 ) |
979 elif tag == "with": |
1145 elif tag == "with": |
980 data, ok = DjangoTagInputDialog.getText( |
1146 data, ok = DjangoTagInputDialog.getText( |
981 None, |
1147 None, |
982 self.tr("Cache Variables"), |
1148 self.tr("Cache Variables"), |
983 [self.tr("Variables to cache as key=value (space separated):") |
1149 [self.tr("Variables to cache as key=value (space separated):")], |
984 ], |
1150 ["variable1=foo.bar variable2=bar.baz"], |
985 ["variable1=foo.bar variable2=bar.baz"]) |
1151 ) |
986 if ok: |
1152 if ok: |
987 templateText = '{{% with {0} %}} {1} {{% endwith %}}'.format( |
1153 templateText = "{{% with {0} %}} {1} {{% endwith %}}".format( |
988 data[0], selectedText) |
1154 data[0], selectedText |
989 |
1155 ) |
|
1156 |
990 #################################################### |
1157 #################################################### |
991 ## Template Filters ## |
1158 ## Template Filters ## |
992 #################################################### |
1159 #################################################### |
993 |
1160 |
994 elif tag == "add": |
1161 elif tag == "add": |
995 data, ok = DjangoTagInputDialog.getText( |
1162 data, ok = DjangoTagInputDialog.getText( |
996 None, |
1163 None, |
997 self.tr("Add Variable or String"), |
1164 self.tr("Add Variable or String"), |
998 [self.tr("Variables or String to add:")], |
1165 [self.tr("Variables or String to add:")], |
999 ["variable"]) |
1166 ["variable"], |
|
1167 ) |
1000 if ok: |
1168 if ok: |
1001 templateText = "|add:{0}".format(data[0]) |
1169 templateText = "|add:{0}".format(data[0]) |
1002 elif tag == "addslashes": |
1170 elif tag == "addslashes": |
1003 templateText = "|addslashes" |
1171 templateText = "|addslashes" |
1004 elif tag == "capfirst": |
1172 elif tag == "capfirst": |
1006 elif tag == "center": |
1174 elif tag == "center": |
1007 width, ok = QInputDialog.getInt( |
1175 width, ok = QInputDialog.getInt( |
1008 None, |
1176 None, |
1009 self.tr("Center Value"), |
1177 self.tr("Center Value"), |
1010 self.tr("Enter width of the output:"), |
1178 self.tr("Enter width of the output:"), |
1011 10, 1, 99, 1) |
1179 10, |
|
1180 1, |
|
1181 99, |
|
1182 1, |
|
1183 ) |
1012 if ok: |
1184 if ok: |
1013 templateText = '|center:"{0}"'.format(width) |
1185 templateText = '|center:"{0}"'.format(width) |
1014 elif tag == "cut": |
1186 elif tag == "cut": |
1015 data, ok = DjangoTagInputDialog.getText( |
1187 data, ok = DjangoTagInputDialog.getText( |
1016 None, |
1188 None, self.tr("Cut Characters"), [self.tr("Characters to cut:")], [" "] |
1017 self.tr("Cut Characters"), |
1189 ) |
1018 [self.tr("Characters to cut:")], |
|
1019 [" "]) |
|
1020 if ok: |
1190 if ok: |
1021 templateText = '|cut:"{0}"'.format(data[0]) |
1191 templateText = '|cut:"{0}"'.format(data[0]) |
1022 elif tag == "date": |
1192 elif tag == "date": |
1023 date, ok = QInputDialog.getItem( |
1193 date, ok = QInputDialog.getItem( |
1024 None, |
1194 None, |
1025 self.tr("Format Date"), |
1195 self.tr("Format Date"), |
1026 self.tr("Enter date format:"), |
1196 self.tr("Enter date format:"), |
1027 ["DATETIME_FORMAT", "SHORT_DATETIME_FORMAT", |
1197 [ |
1028 "SHORT_DATE_FORMAT", "DATE_FORMAT"], |
1198 "DATETIME_FORMAT", |
1029 0, True) |
1199 "SHORT_DATETIME_FORMAT", |
|
1200 "SHORT_DATE_FORMAT", |
|
1201 "DATE_FORMAT", |
|
1202 ], |
|
1203 0, |
|
1204 True, |
|
1205 ) |
1030 if ok: |
1206 if ok: |
1031 if date: |
1207 if date: |
1032 templateText = '|date:"{0}"'.format(date) |
1208 templateText = '|date:"{0}"'.format(date) |
1033 else: |
1209 else: |
1034 templateText = '|date' |
1210 templateText = "|date" |
1035 elif tag == "default": |
1211 elif tag == "default": |
1036 data, ok = DjangoTagInputDialog.getText( |
1212 data, ok = DjangoTagInputDialog.getText( |
1037 None, |
1213 None, |
1038 self.tr("Default Value if False"), |
1214 self.tr("Default Value if False"), |
1039 [self.tr("Enter default value if result is False:")], |
1215 [self.tr("Enter default value if result is False:")], |
1040 ["nothing"]) |
1216 ["nothing"], |
|
1217 ) |
1041 if ok: |
1218 if ok: |
1042 templateText = '|default:"{0}"'.format(data[0]) |
1219 templateText = '|default:"{0}"'.format(data[0]) |
1043 elif tag == "default_if_none": |
1220 elif tag == "default_if_none": |
1044 data, ok = DjangoTagInputDialog.getText( |
1221 data, ok = DjangoTagInputDialog.getText( |
1045 None, |
1222 None, |
1046 self.tr("Default Value if None"), |
1223 self.tr("Default Value if None"), |
1047 [self.tr("Enter default value if result is None:")], |
1224 [self.tr("Enter default value if result is None:")], |
1048 ["nothing"]) |
1225 ["nothing"], |
|
1226 ) |
1049 if ok: |
1227 if ok: |
1050 templateText = '|default:"{0}"'.format(data[0]) |
1228 templateText = '|default:"{0}"'.format(data[0]) |
1051 elif tag == "dictsort": |
1229 elif tag == "dictsort": |
1052 data, ok = DjangoTagInputDialog.getText( |
1230 data, ok = DjangoTagInputDialog.getText( |
1053 None, |
1231 None, |
1054 self.tr("Sort Dictionaries"), |
1232 self.tr("Sort Dictionaries"), |
1055 [self.tr("Enter key to sort on:")], |
1233 [self.tr("Enter key to sort on:")], |
1056 ["key"]) |
1234 ["key"], |
|
1235 ) |
1057 if ok: |
1236 if ok: |
1058 templateText = '|dictsort:"{0}"'.format(data[0]) |
1237 templateText = '|dictsort:"{0}"'.format(data[0]) |
1059 elif tag == "dictsortreversed": |
1238 elif tag == "dictsortreversed": |
1060 data, ok = DjangoTagInputDialog.getText( |
1239 data, ok = DjangoTagInputDialog.getText( |
1061 None, |
1240 None, |
1062 self.tr("Sort Dictionaries reversed"), |
1241 self.tr("Sort Dictionaries reversed"), |
1063 [self.tr("Enter key to sort on:")], |
1242 [self.tr("Enter key to sort on:")], |
1064 ["key"]) |
1243 ["key"], |
|
1244 ) |
1065 if ok: |
1245 if ok: |
1066 templateText = '|dictsortreversed:"{0}"'.format(data[0]) |
1246 templateText = '|dictsortreversed:"{0}"'.format(data[0]) |
1067 elif tag == "divisibleby": |
1247 elif tag == "divisibleby": |
1068 divisor, ok = QInputDialog.getInt( |
1248 divisor, ok = QInputDialog.getInt( |
1069 None, |
1249 None, |
1070 self.tr("Check Divisibility"), |
1250 self.tr("Check Divisibility"), |
1071 self.tr("Enter divisor value:"), |
1251 self.tr("Enter divisor value:"), |
1072 2, 1, 99, 1) |
1252 2, |
|
1253 1, |
|
1254 99, |
|
1255 1, |
|
1256 ) |
1073 if ok: |
1257 if ok: |
1074 templateText = '|divisibleby:"{0}"'.format(divisor) |
1258 templateText = '|divisibleby:"{0}"'.format(divisor) |
1075 elif tag == "escape": |
1259 elif tag == "escape": |
1076 templateText = '|escape' |
1260 templateText = "|escape" |
1077 elif tag == "escapejs": |
1261 elif tag == "escapejs": |
1078 templateText = '|escapejs' |
1262 templateText = "|escapejs" |
1079 elif tag == "filesizeformat": |
1263 elif tag == "filesizeformat": |
1080 templateText = '|filesizeformat' |
1264 templateText = "|filesizeformat" |
1081 elif tag == "first": |
1265 elif tag == "first": |
1082 templateText = '|first' |
1266 templateText = "|first" |
1083 elif tag == "fix_ampersands": |
1267 elif tag == "fix_ampersands": |
1084 templateText = '|fix_ampersands' |
1268 templateText = "|fix_ampersands" |
1085 elif tag == "floatformat": |
1269 elif tag == "floatformat": |
1086 decimals, ok = QInputDialog.getInt( |
1270 decimals, ok = QInputDialog.getInt( |
1087 None, |
1271 None, |
1088 self.tr("Format Floating Number"), |
1272 self.tr("Format Floating Number"), |
1089 self.tr("Enter number of decimal places:"), |
1273 self.tr("Enter number of decimal places:"), |
1090 2, -20, 20, 1) |
1274 2, |
|
1275 -20, |
|
1276 20, |
|
1277 1, |
|
1278 ) |
1091 if ok: |
1279 if ok: |
1092 templateText = '|floatformat:"{0}"'.format(decimals) |
1280 templateText = '|floatformat:"{0}"'.format(decimals) |
1093 elif tag == "force_escape": |
1281 elif tag == "force_escape": |
1094 templateText = '|force_escape' |
1282 templateText = "|force_escape" |
1095 elif tag == "get_digit": |
1283 elif tag == "get_digit": |
1096 digit, ok = QInputDialog.getInt( |
1284 digit, ok = QInputDialog.getInt( |
1097 None, |
1285 None, |
1098 self.tr("Get Rightmost Digit"), |
1286 self.tr("Get Rightmost Digit"), |
1099 self.tr("Enter index of digit:"), |
1287 self.tr("Enter index of digit:"), |
1100 1, 1, 99, 1) |
1288 1, |
|
1289 1, |
|
1290 99, |
|
1291 1, |
|
1292 ) |
1101 if ok: |
1293 if ok: |
1102 templateText = '|get_digit:"{0}"'.format(digit) |
1294 templateText = '|get_digit:"{0}"'.format(digit) |
1103 elif tag == "iriencode": |
1295 elif tag == "iriencode": |
1104 templateText = '|iriencode' |
1296 templateText = "|iriencode" |
1105 elif tag == "join": |
1297 elif tag == "join": |
1106 data, ok = DjangoTagInputDialog.getText( |
1298 data, ok = DjangoTagInputDialog.getText( |
1107 None, |
1299 None, |
1108 self.tr("Join List"), |
1300 self.tr("Join List"), |
1109 [self.tr("Enter string to join by:")], |
1301 [self.tr("Enter string to join by:")], |
1110 ["//"]) |
1302 ["//"], |
|
1303 ) |
1111 if ok: |
1304 if ok: |
1112 templateText = '|join:"{0}"'.format(data[0]) |
1305 templateText = '|join:"{0}"'.format(data[0]) |
1113 elif tag == "last": |
1306 elif tag == "last": |
1114 templateText = '|last' |
1307 templateText = "|last" |
1115 elif tag == "length": |
1308 elif tag == "length": |
1116 templateText = '|length' |
1309 templateText = "|length" |
1117 elif tag == "length_is": |
1310 elif tag == "length_is": |
1118 length, ok = QInputDialog.getInt( |
1311 length, ok = QInputDialog.getInt( |
1119 None, |
1312 None, |
1120 self.tr("Check Length"), |
1313 self.tr("Check Length"), |
1121 self.tr("Enter desired length:"), |
1314 self.tr("Enter desired length:"), |
1122 10, 1, 99, 1) |
1315 10, |
|
1316 1, |
|
1317 99, |
|
1318 1, |
|
1319 ) |
1123 if ok: |
1320 if ok: |
1124 templateText = '|length_is:"{0}"'.format(length) |
1321 templateText = '|length_is:"{0}"'.format(length) |
1125 elif tag == "linebreaks": |
1322 elif tag == "linebreaks": |
1126 templateText = '|linebreaks' |
1323 templateText = "|linebreaks" |
1127 elif tag == "linebreaksbr": |
1324 elif tag == "linebreaksbr": |
1128 templateText = '|linebreaksbr' |
1325 templateText = "|linebreaksbr" |
1129 elif tag == "linenumbers": |
1326 elif tag == "linenumbers": |
1130 templateText = '|linenumbers' |
1327 templateText = "|linenumbers" |
1131 elif tag == "ljust": |
1328 elif tag == "ljust": |
1132 width, ok = QInputDialog.getInt( |
1329 width, ok = QInputDialog.getInt( |
1133 None, |
1330 None, |
1134 self.tr("Left-align Value"), |
1331 self.tr("Left-align Value"), |
1135 self.tr("Enter width of the output:"), |
1332 self.tr("Enter width of the output:"), |
1136 10, 1, 99, 1) |
1333 10, |
|
1334 1, |
|
1335 99, |
|
1336 1, |
|
1337 ) |
1137 if ok: |
1338 if ok: |
1138 templateText = '|ljust:"{0}"'.format(width) |
1339 templateText = '|ljust:"{0}"'.format(width) |
1139 elif tag == "lower": |
1340 elif tag == "lower": |
1140 templateText = '|lower' |
1341 templateText = "|lower" |
1141 elif tag == "make_list": |
1342 elif tag == "make_list": |
1142 templateText = '|make_list' |
1343 templateText = "|make_list" |
1143 elif tag == "phone2numeric": |
1344 elif tag == "phone2numeric": |
1144 templateText = '|phone2numeric' |
1345 templateText = "|phone2numeric" |
1145 elif tag == "pluralize": |
1346 elif tag == "pluralize": |
1146 data, ok = DjangoTagInputDialog.getText( |
1347 data, ok = DjangoTagInputDialog.getText( |
1147 None, |
1348 None, |
1148 self.tr("Plural Suffix"), |
1349 self.tr("Plural Suffix"), |
1149 [self.tr("Enter plural suffix (nothing for default):")], |
1350 [self.tr("Enter plural suffix (nothing for default):")], |
1150 [""]) |
1351 [""], |
|
1352 ) |
1151 if ok: |
1353 if ok: |
1152 if data[0]: |
1354 if data[0]: |
1153 templateText = '|pluralize:"{0}"'.format(data[0]) |
1355 templateText = '|pluralize:"{0}"'.format(data[0]) |
1154 else: |
1356 else: |
1155 templateText = '|pluralize' |
1357 templateText = "|pluralize" |
1156 elif tag == "pprint": |
1358 elif tag == "pprint": |
1157 templateText = '|pprint' |
1359 templateText = "|pprint" |
1158 elif tag == "random": |
1360 elif tag == "random": |
1159 templateText = '|random' |
1361 templateText = "|random" |
1160 elif tag == "removetags": |
1362 elif tag == "removetags": |
1161 data, ok = DjangoTagInputDialog.getText( |
1363 data, ok = DjangoTagInputDialog.getText( |
1162 None, |
1364 None, |
1163 self.tr("Remove HTML Tags"), |
1365 self.tr("Remove HTML Tags"), |
1164 [self.tr("Enter HTML tags to remove (space separated):")], |
1366 [self.tr("Enter HTML tags to remove (space separated):")], |
1165 ["b span"]) |
1367 ["b span"], |
|
1368 ) |
1166 if ok: |
1369 if ok: |
1167 templateText = '|removetags:"{0}"'.format(data[0]) |
1370 templateText = '|removetags:"{0}"'.format(data[0]) |
1168 elif tag == "rjust": |
1371 elif tag == "rjust": |
1169 width, ok = QInputDialog.getInt( |
1372 width, ok = QInputDialog.getInt( |
1170 None, |
1373 None, |
1171 self.tr("Right-align Value"), |
1374 self.tr("Right-align Value"), |
1172 self.tr("Enter width of the output:"), |
1375 self.tr("Enter width of the output:"), |
1173 10, 1, 99, 1) |
1376 10, |
|
1377 1, |
|
1378 99, |
|
1379 1, |
|
1380 ) |
1174 if ok: |
1381 if ok: |
1175 templateText = '|rjust:"{0}"'.format(width) |
1382 templateText = '|rjust:"{0}"'.format(width) |
1176 elif tag == "safe": |
1383 elif tag == "safe": |
1177 templateText = '|safe' |
1384 templateText = "|safe" |
1178 elif tag == "safeseq": |
1385 elif tag == "safeseq": |
1179 templateText = '|safeseq' |
1386 templateText = "|safeseq" |
1180 elif tag == "slice": |
1387 elif tag == "slice": |
1181 data, ok = DjangoTagInputDialog.getText( |
1388 data, ok = DjangoTagInputDialog.getText( |
1182 None, |
1389 None, |
1183 self.tr("Extract slice of a list"), |
1390 self.tr("Extract slice of a list"), |
1184 [self.tr("Enter Python like slice expression:")], |
1391 [self.tr("Enter Python like slice expression:")], |
1185 ["1:5"]) |
1392 ["1:5"], |
|
1393 ) |
1186 if ok: |
1394 if ok: |
1187 templateText = '|slice:"{0}"'.format(data[0]) |
1395 templateText = '|slice:"{0}"'.format(data[0]) |
1188 elif tag == "slugify": |
1396 elif tag == "slugify": |
1189 templateText = '|slugify' |
1397 templateText = "|slugify" |
1190 elif tag == "stringformat": |
1398 elif tag == "stringformat": |
1191 data, ok = DjangoTagInputDialog.getText( |
1399 data, ok = DjangoTagInputDialog.getText( |
1192 None, |
1400 None, |
1193 self.tr("Perform String Formatting"), |
1401 self.tr("Perform String Formatting"), |
1194 [self.tr("Enter Python like string format:")], |
1402 [self.tr("Enter Python like string format:")], |
1195 [""]) |
1403 [""], |
|
1404 ) |
1196 if ok: |
1405 if ok: |
1197 templateText = '|stringformat:"{0}"'.format(data[0]) |
1406 templateText = '|stringformat:"{0}"'.format(data[0]) |
1198 elif tag == "striptags": |
1407 elif tag == "striptags": |
1199 templateText = '|striptags' |
1408 templateText = "|striptags" |
1200 elif tag == "time": |
1409 elif tag == "time": |
1201 time, ok = QInputDialog.getItem( |
1410 time, ok = QInputDialog.getItem( |
1202 None, |
1411 None, |
1203 self.tr("Format Date"), |
1412 self.tr("Format Date"), |
1204 self.tr("Enter date format:"), |
1413 self.tr("Enter date format:"), |
1205 ["TIME_FORMAT"], |
1414 ["TIME_FORMAT"], |
1206 0, True) |
1415 0, |
|
1416 True, |
|
1417 ) |
1207 if ok: |
1418 if ok: |
1208 if time: |
1419 if time: |
1209 templateText = '|time:"{0}"'.format(time) |
1420 templateText = '|time:"{0}"'.format(time) |
1210 else: |
1421 else: |
1211 templateText = '|time' |
1422 templateText = "|time" |
1212 elif tag == "timesince": |
1423 elif tag == "timesince": |
1213 data[0], ok = DjangoTagInputDialog.getText( |
1424 data[0], ok = DjangoTagInputDialog.getText( |
1214 None, |
1425 None, |
1215 self.tr("Time Since"), |
1426 self.tr("Time Since"), |
1216 [self.tr("Enter variable containing time reference:")], |
1427 [self.tr("Enter variable containing time reference:")], |
1217 ["comment_date"]) |
1428 ["comment_date"], |
|
1429 ) |
1218 if ok: |
1430 if ok: |
1219 if data[0]: |
1431 if data[0]: |
1220 templateText = '|timesince:{0}'.format(data[0]) |
1432 templateText = "|timesince:{0}".format(data[0]) |
1221 else: |
1433 else: |
1222 templateText = '|timesince' |
1434 templateText = "|timesince" |
1223 elif tag == "timeuntil": |
1435 elif tag == "timeuntil": |
1224 data[0], ok = DjangoTagInputDialog.getText( |
1436 data[0], ok = DjangoTagInputDialog.getText( |
1225 None, |
1437 None, |
1226 self.tr("Time Until"), |
1438 self.tr("Time Until"), |
1227 [self.tr("Enter variable containing time reference:")], |
1439 [self.tr("Enter variable containing time reference:")], |
1228 ["from_date"]) |
1440 ["from_date"], |
|
1441 ) |
1229 if ok: |
1442 if ok: |
1230 if data[0]: |
1443 if data[0]: |
1231 templateText = '|timeuntil:{0}'.format(data[0]) |
1444 templateText = "|timeuntil:{0}".format(data[0]) |
1232 else: |
1445 else: |
1233 templateText = '|timeuntil' |
1446 templateText = "|timeuntil" |
1234 elif tag == "title": |
1447 elif tag == "title": |
1235 templateText = '|title' |
1448 templateText = "|title" |
1236 elif tag == "truncatechars": |
1449 elif tag == "truncatechars": |
1237 characters, ok = QInputDialog.getInt( |
1450 characters, ok = QInputDialog.getInt( |
1238 None, |
1451 None, |
1239 self.tr("Truncate String"), |
1452 self.tr("Truncate String"), |
1240 self.tr("Enter number of characters:"), |
1453 self.tr("Enter number of characters:"), |
1241 10, 1, 99, 1) |
1454 10, |
1242 if ok: |
1455 1, |
1243 templateText = '|truncatechars:{0}'.format(characters) |
1456 99, |
|
1457 1, |
|
1458 ) |
|
1459 if ok: |
|
1460 templateText = "|truncatechars:{0}".format(characters) |
1244 elif tag == "truncatewords": |
1461 elif tag == "truncatewords": |
1245 words, ok = QInputDialog.getInt( |
1462 words, ok = QInputDialog.getInt( |
1246 None, |
1463 None, |
1247 self.tr("Truncate String"), |
1464 self.tr("Truncate String"), |
1248 self.tr("Enter number of words:"), |
1465 self.tr("Enter number of words:"), |
1249 10, 1, 99, 1) |
1466 10, |
1250 if ok: |
1467 1, |
1251 templateText = '|truncatewords:{0}'.format(words) |
1468 99, |
|
1469 1, |
|
1470 ) |
|
1471 if ok: |
|
1472 templateText = "|truncatewords:{0}".format(words) |
1252 elif tag == "truncatewords_html": |
1473 elif tag == "truncatewords_html": |
1253 words, ok = QInputDialog.getInt( |
1474 words, ok = QInputDialog.getInt( |
1254 None, |
1475 None, |
1255 self.tr("Truncate String"), |
1476 self.tr("Truncate String"), |
1256 self.tr("Enter number of words:"), |
1477 self.tr("Enter number of words:"), |
1257 10, 1, 99, 1) |
1478 10, |
1258 if ok: |
1479 1, |
1259 templateText = '|truncatewords_html:{0}'.format(words) |
1480 99, |
|
1481 1, |
|
1482 ) |
|
1483 if ok: |
|
1484 templateText = "|truncatewords_html:{0}".format(words) |
1260 elif tag == "unordered_list": |
1485 elif tag == "unordered_list": |
1261 templateText = '|unordered_list' |
1486 templateText = "|unordered_list" |
1262 elif tag == "upper": |
1487 elif tag == "upper": |
1263 templateText = '|upper' |
1488 templateText = "|upper" |
1264 elif tag == "urlencode": |
1489 elif tag == "urlencode": |
1265 templateText = '|urlencode' |
1490 templateText = "|urlencode" |
1266 elif tag == "urlize": |
1491 elif tag == "urlize": |
1267 templateText = '|urlize' |
1492 templateText = "|urlize" |
1268 elif tag == "urlizetrunc": |
1493 elif tag == "urlizetrunc": |
1269 characters, ok = QInputDialog.getInt( |
1494 characters, ok = QInputDialog.getInt( |
1270 None, |
1495 None, |
1271 self.tr("Convert URLs as clickable links and truncate"), |
1496 self.tr("Convert URLs as clickable links and truncate"), |
1272 self.tr("Enter number of characters:"), |
1497 self.tr("Enter number of characters:"), |
1273 10, 1, 199, 1) |
1498 10, |
1274 if ok: |
1499 1, |
1275 templateText = '|urlizetrunc:{0}'.format(characters) |
1500 199, |
|
1501 1, |
|
1502 ) |
|
1503 if ok: |
|
1504 templateText = "|urlizetrunc:{0}".format(characters) |
1276 elif tag == "wordcount": |
1505 elif tag == "wordcount": |
1277 templateText = '|wordcount' |
1506 templateText = "|wordcount" |
1278 elif tag == "wordwrap": |
1507 elif tag == "wordwrap": |
1279 characters, ok = QInputDialog.getInt( |
1508 characters, ok = QInputDialog.getInt( |
1280 None, |
1509 None, |
1281 self.tr("Wrap words"), |
1510 self.tr("Wrap words"), |
1282 self.tr("Enter number of characters:"), |
1511 self.tr("Enter number of characters:"), |
1283 10, 1, 99, 1) |
1512 10, |
1284 if ok: |
1513 1, |
1285 templateText = '|wordwrap:{0}'.format(characters) |
1514 99, |
|
1515 1, |
|
1516 ) |
|
1517 if ok: |
|
1518 templateText = "|wordwrap:{0}".format(characters) |
1286 elif tag == "yesno": |
1519 elif tag == "yesno": |
1287 data, ok = DjangoTagInputDialog.getText( |
1520 data, ok = DjangoTagInputDialog.getText( |
1288 None, |
1521 None, |
1289 self.tr("Map True, False and None"), |
1522 self.tr("Map True, False and None"), |
1290 [self.tr("Enter mapping (comma separated):")], |
1523 [self.tr("Enter mapping (comma separated):")], |
1291 ["yeah,no,maybe"]) |
1524 ["yeah,no,maybe"], |
|
1525 ) |
1292 if ok: |
1526 if ok: |
1293 if data[0]: |
1527 if data[0]: |
1294 templateText = '|yesno:"{0}"'.format(data[0]) |
1528 templateText = '|yesno:"{0}"'.format(data[0]) |
1295 else: |
1529 else: |
1296 templateText = '|yesno' |
1530 templateText = "|yesno" |
1297 |
1531 |
1298 #################################################### |
1532 #################################################### |
1299 ## Humanize Template Tags ## |
1533 ## Humanize Template Tags ## |
1300 #################################################### |
1534 #################################################### |
1301 |
1535 |
1302 elif tag == "loadhumanize": |
1536 elif tag == "loadhumanize": |
1303 templateText = '{% load humanize %}' |
1537 templateText = "{% load humanize %}" |
1304 elif tag == "apnumber": |
1538 elif tag == "apnumber": |
1305 templateText = '|apnumber' |
1539 templateText = "|apnumber" |
1306 elif tag == "intcomma": |
1540 elif tag == "intcomma": |
1307 templateText = '|intcomma' |
1541 templateText = "|intcomma" |
1308 elif tag == "intword": |
1542 elif tag == "intword": |
1309 templateText = '|intword' |
1543 templateText = "|intword" |
1310 elif tag == "naturalday": |
1544 elif tag == "naturalday": |
1311 templateText = '|naturalday' |
1545 templateText = "|naturalday" |
1312 elif tag == "naturaltime": |
1546 elif tag == "naturaltime": |
1313 templateText = '|naturaltime' |
1547 templateText = "|naturaltime" |
1314 elif tag == "ordinal": |
1548 elif tag == "ordinal": |
1315 templateText = '|ordinal' |
1549 templateText = "|ordinal" |
1316 |
1550 |
1317 #################################################### |
1551 #################################################### |
1318 ## Web Design Template Tags ## |
1552 ## Web Design Template Tags ## |
1319 #################################################### |
1553 #################################################### |
1320 |
1554 |
1321 elif tag == "loadweb": |
1555 elif tag == "loadweb": |
1322 templateText = '{% load webdesign %}' |
1556 templateText = "{% load webdesign %}" |
1323 elif tag == "lorem": |
1557 elif tag == "lorem": |
1324 from .LoremTagInputDialog import LoremTagInputDialog |
1558 from .LoremTagInputDialog import LoremTagInputDialog |
|
1559 |
1325 dlg = LoremTagInputDialog() |
1560 dlg = LoremTagInputDialog() |
1326 if dlg.exec() == QDialog.DialogCode.Accepted: |
1561 if dlg.exec() == QDialog.DialogCode.Accepted: |
1327 templateText = "{{% {0} %}}".format(dlg.getTag()) |
1562 templateText = "{{% {0} %}}".format(dlg.getTag()) |
1328 |
1563 |
1329 #################################################### |
1564 #################################################### |
1330 ## Static Template Tags ## |
1565 ## Static Template Tags ## |
1331 #################################################### |
1566 #################################################### |
1332 |
1567 |
1333 elif tag == "loadstatic": |
1568 elif tag == "loadstatic": |
1334 templateText = '{% load static %}' |
1569 templateText = "{% load static %}" |
1335 elif tag == "staticfile": |
1570 elif tag == "staticfile": |
1336 data, ok = DjangoTagInputDialog.getText( |
1571 data, ok = DjangoTagInputDialog.getText( |
1337 None, |
1572 None, |
1338 self.tr("Link to static file"), |
1573 self.tr("Link to static file"), |
1339 [self.tr("Enter relative path of static file:")], |
1574 [self.tr("Enter relative path of static file:")], |
1340 ["images/hi.jpg"]) |
1575 ["images/hi.jpg"], |
|
1576 ) |
1341 if ok: |
1577 if ok: |
1342 templateText = '{{% static "{0}" %}}'.format(data[0]) |
1578 templateText = '{{% static "{0}" %}}'.format(data[0]) |
1343 elif tag == "staticvariable": |
1579 elif tag == "staticvariable": |
1344 data, ok = DjangoTagInputDialog.getText( |
1580 data, ok = DjangoTagInputDialog.getText( |
1345 None, |
1581 None, |
1346 self.tr("Link to static file"), |
1582 self.tr("Link to static file"), |
1347 [self.tr("Enter variable containing relative path of" |
1583 [self.tr("Enter variable containing relative path of" " static file:")], |
1348 " static file:")], |
1584 ["user_stylesheet"], |
1349 ["user_stylesheet"]) |
1585 ) |
1350 if ok: |
1586 if ok: |
1351 templateText = '{{% static {0} %}}'.format(data[0]) |
1587 templateText = "{{% static {0} %}}".format(data[0]) |
1352 elif tag == "get_static_prefix": |
1588 elif tag == "get_static_prefix": |
1353 templateText = '{% get_static_prefix %}' |
1589 templateText = "{% get_static_prefix %}" |
1354 elif tag == "get_media_prefix": |
1590 elif tag == "get_media_prefix": |
1355 templateText = '{% get_media_prefix %}' |
1591 templateText = "{% get_media_prefix %}" |
1356 |
1592 |
1357 #################################################### |
1593 #################################################### |
1358 ## Comments ## |
1594 ## Comments ## |
1359 #################################################### |
1595 #################################################### |
1360 |
1596 |
1361 elif tag in ("comment", "multilinecommentselect"): |
1597 elif tag in ("comment", "multilinecommentselect"): |
1362 templateText = "{{% comment %}} {0} {{% endcomment %}}".format( |
1598 templateText = "{{% comment %}} {0} {{% endcomment %}}".format(selectedText) |
1363 selectedText) |
|
1364 replace = True |
1599 replace = True |
1365 elif tag == "singlelinecommentselect": |
1600 elif tag == "singlelinecommentselect": |
1366 templateText = '{{# {0} #}}'.format(selectedText) |
1601 templateText = "{{# {0} #}}".format(selectedText) |
1367 replace = True |
1602 replace = True |
1368 elif tag == "singlelinecommentdialog": |
1603 elif tag == "singlelinecommentdialog": |
1369 data, ok = DjangoTagInputDialog.getText( |
1604 data, ok = DjangoTagInputDialog.getText( |
1370 None, |
1605 None, self.tr("Single Line Comment"), [self.tr("Enter comment:")], [""] |
1371 self.tr("Single Line Comment"), |
1606 ) |
1372 [self.tr("Enter comment:")], |
1607 if ok: |
1373 [""]) |
1608 templateText = "{{# {0} #}}".format(data[0]) |
1374 if ok: |
|
1375 templateText = '{{# {0} #}}'.format(data[0]) |
|
1376 elif tag == "multilinecommentdialog": |
1609 elif tag == "multilinecommentdialog": |
1377 from .MultiLineInputDialog import MultiLineInputDialog |
1610 from .MultiLineInputDialog import MultiLineInputDialog |
|
1611 |
1378 comment, ok = MultiLineInputDialog.getText( |
1612 comment, ok = MultiLineInputDialog.getText( |
1379 None, self.tr("Multi Line Comment"), |
1613 None, self.tr("Multi Line Comment"), self.tr("Enter comment:"), "" |
1380 self.tr("Enter comment:"), "") |
1614 ) |
1381 if ok: |
1615 if ok: |
1382 templateText = '{{% comment %}} {0} {{% endcomment %}}'.format( |
1616 templateText = "{{% comment %}} {0} {{% endcomment %}}".format(comment) |
1383 comment) |
|
1384 elif tag == "singlelinecommentclipboard": |
1617 elif tag == "singlelinecommentclipboard": |
1385 templateText = '{{# {0} #}}'.format( |
1618 templateText = "{{# {0} #}}".format(QApplication.clipboard().text().strip()) |
1386 QApplication.clipboard().text().strip()) |
|
1387 elif tag == "multilinecommentclipboard": |
1619 elif tag == "multilinecommentclipboard": |
1388 templateText = '{{% comment %}} {0} {{% endcomment %}}'.format( |
1620 templateText = "{{% comment %}} {0} {{% endcomment %}}".format( |
1389 QApplication.clipboard().text().strip()) |
1621 QApplication.clipboard().text().strip() |
|
1622 ) |
1390 elif tag == "multilinecommentfile": |
1623 elif tag == "multilinecommentfile": |
1391 filename = EricFileDialog.getOpenFileName( |
1624 filename = EricFileDialog.getOpenFileName( |
1392 None, |
1625 None, |
1393 self.tr("Comment File"), |
1626 self.tr("Comment File"), |
1394 Utilities.getHomeDir(), |
1627 Utilities.getHomeDir(), |
1395 self.tr("All Files (*)")) |
1628 self.tr("All Files (*)"), |
|
1629 ) |
1396 if filename: |
1630 if filename: |
1397 try: |
1631 try: |
1398 with open(filename, "r", encoding="utf-8") as f: |
1632 with open(filename, "r", encoding="utf-8") as f: |
1399 comment = f.read() |
1633 comment = f.read() |
1400 templateText = ( |
1634 templateText = "{{% comment %}} {0} {{% endcomment %}}".format( |
1401 '{{% comment %}} {0} {{% endcomment %}}'.format( |
1635 comment |
1402 comment)) |
1636 ) |
1403 except (IOError, OSError) as err: |
1637 except OSError as err: |
1404 EricMessageBox.critical( |
1638 EricMessageBox.critical( |
1405 None, |
1639 None, |
1406 self.tr("Comment File"), |
1640 self.tr("Comment File"), |
1407 self.tr("""<p>The file <b>{0}</b> could not be""" |
1641 self.tr( |
1408 """ read.</p><p>Reason: {1}</p>""").format( |
1642 """<p>The file <b>{0}</b> could not be""" |
1409 str(err))) |
1643 """ read.</p><p>Reason: {1}</p>""" |
|
1644 ).format(str(err)), |
|
1645 ) |
1410 elif tag == "singlelinecommentdatetime": |
1646 elif tag == "singlelinecommentdatetime": |
1411 templateText = '{{# {0} by {1} #}}'.format( |
1647 templateText = "{{# {0} by {1} #}}".format( |
1412 datetime.datetime.now().isoformat().split(), |
1648 datetime.datetime.now().isoformat().split(), Utilities.getUserName() |
1413 Utilities.getUserName()) |
1649 ) |
1414 elif tag == "htmlcomment": |
1650 elif tag == "htmlcomment": |
1415 templateText = '<!-- {0} -->'.format(selectedText) |
1651 templateText = "<!-- {0} -->".format(selectedText) |
1416 replace = True |
1652 replace = True |
1417 elif tag == "iecomment": |
1653 elif tag == "iecomment": |
1418 from .IeCommentDialog import IeCommentDialog |
1654 from .IeCommentDialog import IeCommentDialog |
|
1655 |
1419 tag, ok = IeCommentDialog.getTag(selectedText) |
1656 tag, ok = IeCommentDialog.getTag(selectedText) |
1420 if ok: |
1657 if ok: |
1421 templateText = '<!--{0}-->'.format(tag) |
1658 templateText = "<!--{0}-->".format(tag) |
1422 replace = True |
1659 replace = True |
1423 |
1660 |
1424 #################################################### |
1661 #################################################### |
1425 ## Internationalization ## |
1662 ## Internationalization ## |
1426 #################################################### |
1663 #################################################### |
1427 |
1664 |
1428 elif tag == "loadi18n": |
1665 elif tag == "loadi18n": |
1429 templateText = '{% load i18n %}' |
1666 templateText = "{% load i18n %}" |
1430 ## Tags ## |
1667 ## Tags ## |
1431 elif tag == "trans": |
1668 elif tag == "trans": |
1432 if ' ' in selectedText: |
1669 if " " in selectedText: |
1433 selectedText = '"{0}"'.format(selectedText) |
1670 selectedText = '"{0}"'.format(selectedText) |
1434 templateText = '{{% trans {0} %}}'.format(selectedText) |
1671 templateText = "{{% trans {0} %}}".format(selectedText) |
1435 replace = True |
1672 replace = True |
1436 elif tag == "trans..as": |
1673 elif tag == "trans..as": |
1437 data, ok = DjangoTagInputDialog.getText( |
1674 data, ok = DjangoTagInputDialog.getText( |
1438 None, |
1675 None, |
1439 self.tr("Translate String into Variable"), |
1676 self.tr("Translate String into Variable"), |
1440 [self.tr("Enter variable receiving translation:")], |
1677 [self.tr("Enter variable receiving translation:")], |
1441 ["translation"]) |
1678 ["translation"], |
|
1679 ) |
1442 if ok: |
1680 if ok: |
1443 templateText = '{{% trans "{0}" as {1} %}}'.format( |
1681 templateText = '{{% trans "{0}" as {1} %}}'.format( |
1444 selectedText, data[0]) |
1682 selectedText, data[0] |
|
1683 ) |
1445 replace = True |
1684 replace = True |
1446 elif tag == "blocktrans": |
1685 elif tag == "blocktrans": |
1447 templateText = '{{% blocktrans %}}{0}{{% endblocktrans %}}'.format( |
1686 templateText = "{{% blocktrans %}}{0}{{% endblocktrans %}}".format( |
1448 selectedText) |
1687 selectedText |
|
1688 ) |
1449 replace = True |
1689 replace = True |
1450 elif tag == "blocktrans..with": |
1690 elif tag == "blocktrans..with": |
1451 data, ok = DjangoTagInputDialog.getText( |
1691 data, ok = DjangoTagInputDialog.getText( |
1452 None, |
1692 None, |
1453 self.tr("Translate Block with Attributes"), |
1693 self.tr("Translate Block with Attributes"), |
1454 [self.tr("Enter attribute binding expressions" |
1694 [self.tr("Enter attribute binding expressions" " (space separated):")], |
1455 " (space separated):")], |
1695 ["myvar1=value1 myvar2=value2"], |
1456 ["myvar1=value1 myvar2=value2"]) |
1696 ) |
1457 if ok: |
1697 if ok: |
1458 templateText = ( |
1698 templateText = ( |
1459 '{{% blocktrans with {0} %}}{1}{{% endblocktrans %}}' |
1699 "{{% blocktrans with {0} %}}{1}{{% endblocktrans %}}".format( |
1460 .format(data[0], selectedText)) |
1700 data[0], selectedText |
|
1701 ) |
|
1702 ) |
1461 replace = True |
1703 replace = True |
1462 elif tag == "plural": |
1704 elif tag == "plural": |
1463 templateText = '{{% plural %}} {0}'.format(selectedText) |
1705 templateText = "{{% plural %}} {0}".format(selectedText) |
1464 replace = True |
1706 replace = True |
1465 elif tag == "language": |
1707 elif tag == "language": |
1466 data, ok = DjangoTagInputDialog.getText( |
1708 data, ok = DjangoTagInputDialog.getText( |
1467 None, |
1709 None, self.tr("Switch language"), [self.tr("Enter language:")], ["en"] |
1468 self.tr("Switch language"), |
1710 ) |
1469 [self.tr("Enter language:")], |
1711 if ok: |
1470 ["en"]) |
1712 templateText = "{{% language '{0}' %}}{1}{{% endlanguage %}}".format( |
1471 if ok: |
1713 data[0], selectedText |
1472 templateText = ( |
1714 ) |
1473 "{{% language '{0}' %}}{1}{{% endlanguage %}}" |
|
1474 .format(data[0], selectedText)) |
|
1475 replace = True |
1715 replace = True |
1476 elif tag == "get_current_language": |
1716 elif tag == "get_current_language": |
1477 templateText = '{% get_current_language as LANGUAGE_CODE %}' |
1717 templateText = "{% get_current_language as LANGUAGE_CODE %}" |
1478 elif tag == "get_available_languages": |
1718 elif tag == "get_available_languages": |
1479 templateText = '{% get_available_languages as LANGUAGES %}' |
1719 templateText = "{% get_available_languages as LANGUAGES %}" |
1480 elif tag == "get_current_language_bidi": |
1720 elif tag == "get_current_language_bidi": |
1481 templateText = '{% get_current_language_bidi as LANGUAGE_BIDI %}' |
1721 templateText = "{% get_current_language_bidi as LANGUAGE_BIDI %}" |
1482 elif tag == "get_language_info": |
1722 elif tag == "get_language_info": |
1483 data, ok = DjangoTagInputDialog.getText( |
1723 data, ok = DjangoTagInputDialog.getText( |
1484 None, |
1724 None, |
1485 self.tr("Language Information"), |
1725 self.tr("Language Information"), |
1486 [self.tr("Enter language string or variable (empty for" |
1726 [ |
1487 " LANGUAGE_CODE):")], |
1727 self.tr( |
1488 ['"en"']) |
1728 "Enter language string or variable (empty for" |
|
1729 " LANGUAGE_CODE):" |
|
1730 ) |
|
1731 ], |
|
1732 ['"en"'], |
|
1733 ) |
|
1734 if ok: |
|
1735 if data[0]: |
|
1736 templateText = '{{% get_language_info for "{0}" as lang %}}'.format( |
|
1737 data[0] |
|
1738 ) |
|
1739 else: |
|
1740 templateText = ( |
|
1741 "{% get_language_info for LANGUAGE_CODE" " as lang %}" |
|
1742 ) |
|
1743 elif tag == "get_language_info_list": |
|
1744 data, ok = DjangoTagInputDialog.getText( |
|
1745 None, |
|
1746 self.tr("Language Information for a list of languages"), |
|
1747 [self.tr("Enter language list variable (empty for" " LANGUAGES):")], |
|
1748 ["available_languages"], |
|
1749 ) |
1489 if ok: |
1750 if ok: |
1490 if data[0]: |
1751 if data[0]: |
1491 templateText = ( |
1752 templateText = ( |
1492 '{{% get_language_info for "{0}" as lang %}}' |
1753 "{{% get_language_info_list for {0} as langs %}}".format( |
1493 .format(data[0])) |
1754 data[0] |
|
1755 ) |
|
1756 ) |
1494 else: |
1757 else: |
1495 templateText = ("{% get_language_info for LANGUAGE_CODE" |
|
1496 " as lang %}") |
|
1497 elif tag == "get_language_info_list": |
|
1498 data, ok = DjangoTagInputDialog.getText( |
|
1499 None, |
|
1500 self.tr("Language Information for a list of languages"), |
|
1501 [self.tr("Enter language list variable (empty for" |
|
1502 " LANGUAGES):")], |
|
1503 ["available_languages"]) |
|
1504 if ok: |
|
1505 if data[0]: |
|
1506 templateText = ( |
1758 templateText = ( |
1507 '{{% get_language_info_list for {0} as langs %}}' |
1759 "{% get_language_info_list for LANGUAGES" " as langs %}" |
1508 .format(data[0])) |
1760 ) |
1509 else: |
|
1510 templateText = ("{% get_language_info_list for LANGUAGES" |
|
1511 " as langs %}") |
|
1512 ## Filters ## |
1761 ## Filters ## |
1513 elif tag == "language_name": |
1762 elif tag == "language_name": |
1514 templateText = '|language_name' |
1763 templateText = "|language_name" |
1515 elif tag == "language_name_local": |
1764 elif tag == "language_name_local": |
1516 templateText = '|language_name_local' |
1765 templateText = "|language_name_local" |
1517 elif tag == "bidi": |
1766 elif tag == "bidi": |
1518 templateText = '|bidi' |
1767 templateText = "|bidi" |
1519 |
1768 |
1520 #################################################### |
1769 #################################################### |
1521 ## Localization ## |
1770 ## Localization ## |
1522 #################################################### |
1771 #################################################### |
1523 |
1772 |
1524 elif tag == "loadl10n": |
1773 elif tag == "loadl10n": |
1525 templateText = '{% load l10n %}' |
1774 templateText = "{% load l10n %}" |
1526 ## Tags ## |
1775 ## Tags ## |
1527 elif tag == "localize_on": |
1776 elif tag == "localize_on": |
1528 templateText = '{{% localize on %}}{0}{{% endlocalize %}}'.format( |
1777 templateText = "{{% localize on %}}{0}{{% endlocalize %}}".format( |
1529 selectedText) |
1778 selectedText |
|
1779 ) |
1530 replace = True |
1780 replace = True |
1531 elif tag == "localize_off": |
1781 elif tag == "localize_off": |
1532 templateText = '{{% localize off %}}{0}{{% endlocalize %}}'.format( |
1782 templateText = "{{% localize off %}}{0}{{% endlocalize %}}".format( |
1533 selectedText) |
1783 selectedText |
|
1784 ) |
1534 replace = True |
1785 replace = True |
1535 ## Filters ## |
1786 ## Filters ## |
1536 elif tag == "localize": |
1787 elif tag == "localize": |
1537 templateText = '|localize' |
1788 templateText = "|localize" |
1538 elif tag == "unlocalize": |
1789 elif tag == "unlocalize": |
1539 templateText = '|unlocalize' |
1790 templateText = "|unlocalize" |
1540 |
1791 |
1541 #################################################### |
1792 #################################################### |
1542 ## Timezone ## |
1793 ## Timezone ## |
1543 #################################################### |
1794 #################################################### |
1544 |
1795 |
1545 elif tag == "loadtz": |
1796 elif tag == "loadtz": |
1546 templateText = '{% load tz %}' |
1797 templateText = "{% load tz %}" |
1547 ## Tags ## |
1798 ## Tags ## |
1548 elif tag == "localtime_on": |
1799 elif tag == "localtime_on": |
1549 templateText = ( |
1800 templateText = "{{% localtime on %}}{0}{{% endlocaltime %}}".format( |
1550 '{{% localtime on %}}{0}{{% endlocaltime %}}'.format( |
1801 selectedText |
1551 selectedText)) |
1802 ) |
1552 replace = True |
1803 replace = True |
1553 elif tag == "localtime_off": |
1804 elif tag == "localtime_off": |
1554 templateText = ( |
1805 templateText = "{{% localtime off %}}{0}{{% endlocaltime %}}".format( |
1555 '{{% localtime off %}}{0}{{% endlocaltime %}}'.format( |
1806 selectedText |
1556 selectedText)) |
1807 ) |
1557 replace = True |
1808 replace = True |
1558 elif tag == "timezone_set": |
1809 elif tag == "timezone_set": |
1559 from .TimezoneSelectionDialog import TimezoneSelectionDialog |
1810 from .TimezoneSelectionDialog import TimezoneSelectionDialog |
|
1811 |
1560 timezone, ok = TimezoneSelectionDialog.getTimezone() |
1812 timezone, ok = TimezoneSelectionDialog.getTimezone() |
1561 if ok: |
1813 if ok: |
1562 templateText = ( |
1814 templateText = '{{% timezone "{0}" %}}{1}{{% endtimezone %}}'.format( |
1563 '{{% timezone "{0}" %}}{1}{{% endtimezone %}}'.format( |
1815 timezone, selectedText |
1564 timezone, selectedText)) |
1816 ) |
1565 replace = True |
1817 replace = True |
1566 elif tag == "timezone_unset": |
1818 elif tag == "timezone_unset": |
1567 templateText = ( |
1819 templateText = "{{% timezone None %}}{0}{{% endlocaltime %}}".format( |
1568 '{{% timezone None %}}{0}{{% endlocaltime %}}'.format( |
1820 selectedText |
1569 selectedText)) |
1821 ) |
1570 replace = True |
1822 replace = True |
1571 elif tag == "get_current_timezone": |
1823 elif tag == "get_current_timezone": |
1572 templateText = '{% get_current_timezone as TIME_ZONE %}' |
1824 templateText = "{% get_current_timezone as TIME_ZONE %}" |
1573 ## Filters ## |
1825 ## Filters ## |
1574 elif tag == "localtime": |
1826 elif tag == "localtime": |
1575 templateText = '|localtime' |
1827 templateText = "|localtime" |
1576 elif tag == "utc": |
1828 elif tag == "utc": |
1577 templateText = '|utc' |
1829 templateText = "|utc" |
1578 elif tag == "timezone": |
1830 elif tag == "timezone": |
1579 from .TimezoneSelectionDialog import TimezoneSelectionDialog |
1831 from .TimezoneSelectionDialog import TimezoneSelectionDialog |
|
1832 |
1580 timezone, ok = TimezoneSelectionDialog.getTimezone() |
1833 timezone, ok = TimezoneSelectionDialog.getTimezone() |
1581 if ok: |
1834 if ok: |
1582 templateText = '|timezone:"{0}"'.format(timezone) |
1835 templateText = '|timezone:"{0}"'.format(timezone) |
1583 |
1836 |
1584 #################################################### |
1837 #################################################### |
1585 ## Fallback: return just the tag name ## |
1838 ## Fallback: return just the tag name ## |
1586 #################################################### |
1839 #################################################### |
1587 |
1840 |
1588 else: |
1841 else: |
1589 templateText = tag |
1842 templateText = tag |
1590 |
1843 |
1591 return templateText, replace |
1844 return templateText, replace |