155 menu.addAction( |
156 menu.addAction( |
156 self.tr("with - Cache a complex variable under a simpler name"), |
157 self.tr("with - Cache a complex variable under a simpler name"), |
157 lambda: self.__applyTemplate("verbatim")) |
158 lambda: self.__applyTemplate("verbatim")) |
158 |
159 |
159 self.__tagsMenu = menu |
160 self.__tagsMenu = menu |
|
161 return menu |
|
162 |
|
163 def __initFiltersMenu(self): |
|
164 """ |
|
165 Private method to initialize the filters menu. |
|
166 |
|
167 @return generated menu (QMenu) |
|
168 """ |
|
169 menu = QMenu(self.tr("Filters")) |
|
170 menu.addAction( |
|
171 self.tr("add - Add variable or string"), |
|
172 lambda: self.__applyTemplate("add")) |
|
173 menu.addAction( |
|
174 self.tr("addslashes - Add slashes before quotes"), |
|
175 lambda: self.__applyTemplate("addslashes")) |
|
176 menu.addSeparator() |
|
177 menu.addAction( |
|
178 self.tr("capfirst - Capitalize first character"), |
|
179 lambda: self.__applyTemplate("capfirst")) |
|
180 menu.addAction( |
|
181 self.tr("center - Center value"), |
|
182 lambda: self.__applyTemplate("center")) |
|
183 menu.addAction( |
|
184 self.tr("cut - Cut characters"), |
|
185 lambda: self.__applyTemplate("cut")) |
|
186 menu.addSeparator() |
|
187 menu.addAction( |
|
188 self.tr("date - Format date"), |
|
189 lambda: self.__applyTemplate("date")) |
|
190 menu.addAction( |
|
191 self.tr("default - Use dafault if False"), |
|
192 lambda: self.__applyTemplate("default")) |
|
193 menu.addAction( |
|
194 self.tr("default_if_none - Use default if None"), |
|
195 lambda: self.__applyTemplate("default_if_none")) |
|
196 menu.addAction( |
|
197 self.tr("dictsort - Sort dictionaries"), |
|
198 lambda: self.__applyTemplate("dictsort")) |
|
199 menu.addAction( |
|
200 self.tr("dictsortreversed - Sort dictionaries reversed"), |
|
201 lambda: self.__applyTemplate("dictsortreversed")) |
|
202 menu.addAction( |
|
203 self.tr("divisibleby - Check divisibility"), |
|
204 lambda: self.__applyTemplate("divisibleby")) |
|
205 menu.addSeparator() |
|
206 menu.addAction( |
|
207 self.tr("escape - Escape as HTML"), |
|
208 lambda: self.__applyTemplate("escape")) |
|
209 menu.addAction( |
|
210 self.tr("escapejs - Escape as JavaScript"), |
|
211 lambda: self.__applyTemplate("escapejs")) |
|
212 menu.addSeparator() |
|
213 menu.addAction( |
|
214 self.tr("filesizeformat - Format file sizes"), |
|
215 lambda: self.__applyTemplate("filesizeformat")) |
|
216 menu.addAction( |
|
217 self.tr("first - First item of a list"), |
|
218 lambda: self.__applyTemplate("first")) |
|
219 menu.addAction( |
|
220 self.tr("fix_ampersands - Replace ampersands"), |
|
221 lambda: self.__applyTemplate("fix_ampersands")) |
|
222 menu.addAction( |
|
223 self.tr("floatformat - Format floating numbers"), |
|
224 lambda: self.__applyTemplate("floatformat")) |
|
225 menu.addAction( |
|
226 self.tr("force_escape - Escape as HTML immediately"), |
|
227 lambda: self.__applyTemplate("force_escape")) |
|
228 menu.addSeparator() |
|
229 |
|
230 self.__filtersMenu = menu |
160 return menu |
231 return menu |
161 |
232 |
162 def __findTemplateTag(self): |
233 def __findTemplateTag(self): |
163 """ |
234 """ |
164 Private slot to find a template tag and insert its text. |
235 Private slot to find a template tag and insert its text. |
433 if ok: |
504 if ok: |
434 templateText = '{{% with {0} %}} {1} {{% endwith %}}'.format( |
505 templateText = '{{% with {0} %}} {1} {{% endwith %}}'.format( |
435 data[0], selectedText) |
506 data[0], selectedText) |
436 |
507 |
437 #################################################### |
508 #################################################### |
|
509 ## Template Filters ## |
|
510 #################################################### |
|
511 |
|
512 elif tag == "add": |
|
513 data, ok = DjangoTagInputDialog.getText( |
|
514 None, |
|
515 self.tr("Add Variable or String"), |
|
516 [self.tr("Variables or String to add:") |
|
517 ], |
|
518 ["variable"]) |
|
519 if ok: |
|
520 templateText = "|add:{0}".format(data[0]) |
|
521 elif tag == "addslashes": |
|
522 templateText = "|addslashes " |
|
523 elif tag == "capfirst": |
|
524 templateText = "|capfirst " |
|
525 elif tag == "center": |
|
526 width, ok = QInputDialog.getInt( |
|
527 None, |
|
528 self.tr("Center Value"), |
|
529 self.tr("Enter width of the output:"), |
|
530 10, 1, 99, 1) |
|
531 if ok: |
|
532 templateText = '|center:"{0}"'.format(width) |
|
533 elif tag == "cut": |
|
534 data, ok = DjangoTagInputDialog.getText( |
|
535 None, |
|
536 self.tr("Cut Characters"), |
|
537 [self.tr("Characters to cut:") |
|
538 ], |
|
539 [" "]) |
|
540 if ok: |
|
541 templateText = '|cut:"{0}"'.format(data[0]) |
|
542 elif tag == "date": |
|
543 date, ok = QInputDialog.getItem( |
|
544 None, |
|
545 self.tr("Format Date"), |
|
546 self.tr("Enter date format:"), |
|
547 ["DATETIME_FORMAT", "SHORT_DATETIME_FORMAT", |
|
548 "SHORT_DATE_FORMAT", "DATE_FORMAT"], |
|
549 0, True) |
|
550 if ok: |
|
551 templateText = '|date:"{0}" '.format(date) |
|
552 elif tag == "default": |
|
553 data, ok = DjangoTagInputDialog.getText( |
|
554 None, |
|
555 self.tr("Default Value if False"), |
|
556 [self.tr("Enter default value if result is False:") |
|
557 ], |
|
558 ["nothing"]) |
|
559 if ok: |
|
560 templateText = '|default:"{0}" '.format(data[0]) |
|
561 elif tag == "default_if_none": |
|
562 data, ok = DjangoTagInputDialog.getText( |
|
563 None, |
|
564 self.tr("Default Value if None"), |
|
565 [self.tr("Enter default value if result is None:") |
|
566 ], |
|
567 ["nothing"]) |
|
568 if ok: |
|
569 templateText = '|default:"{0}" '.format(data[0]) |
|
570 elif tag == "dictsort": |
|
571 data, ok = DjangoTagInputDialog.getText( |
|
572 None, |
|
573 self.tr("Sort Dictionaries"), |
|
574 [self.tr("Enter key to sort on:") |
|
575 ], |
|
576 ["key"]) |
|
577 if ok: |
|
578 templateText = '|dictsort:"{0}" '.format(data[0]) |
|
579 elif tag == "dictsortreversed": |
|
580 data, ok = DjangoTagInputDialog.getText( |
|
581 None, |
|
582 self.tr("Sort Dictionaries reversed"), |
|
583 [self.tr("Enter key to sort on:") |
|
584 ], |
|
585 ["key"]) |
|
586 if ok: |
|
587 templateText = '|dictsortreversed:"{0}" '.format(data[0]) |
|
588 elif tag == "divisibleby": |
|
589 divisor, ok = QInputDialog.getInt( |
|
590 None, |
|
591 self.tr("Check Divisibility"), |
|
592 self.tr("Enter divisor value:"), |
|
593 2, 1, 99, 1) |
|
594 if ok: |
|
595 templateText = '|divisibleby:"{0}" '.format(divisor) |
|
596 elif tag == "escape": |
|
597 templateText = '|escape ' |
|
598 elif tag == "escapejs": |
|
599 templateText = '|escapejs ' |
|
600 elif tag == "filesizeformat": |
|
601 templateText = '|filesizeformat ' |
|
602 elif tag == "first": |
|
603 templateText = '|first ' |
|
604 elif tag == "fix_ampersands": |
|
605 templateText = '|fix_ampersands ' |
|
606 elif tag == "floatformat": |
|
607 decimals, ok = QInputDialog.getInt( |
|
608 None, |
|
609 self.tr("Format Floating Number"), |
|
610 self.tr("Enter number of decimal places:"), |
|
611 2, -20, 20, 1) |
|
612 if ok: |
|
613 templateText = '|floatformat:"{0}" '.format(decimals) |
|
614 elif tag == "force_escape": |
|
615 templateText = '|force_escape ' |
|
616 |
|
617 #################################################### |
438 ## Fallback: return just the tag name ## |
618 ## Fallback: return just the tag name ## |
439 #################################################### |
619 #################################################### |
440 |
620 |
441 else: |
621 else: |
442 templateText = tag |
622 templateText = tag |