diff -r dba433b4f3d6 -r 85418cf03fdb ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py --- a/ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py Wed Sep 21 16:38:40 2022 +0200 @@ -25,10 +25,11 @@ """ Class implementing the Django tags menu handler. """ + def __init__(self, ui, parent=None): """ Constructor - + @param ui reference to the user interface object @type UserInterface @param parent reference to the parent object @@ -36,25 +37,26 @@ """ super().__init__(parent) self.__ui = ui - + self.__findDialog = None - + def closeAllWindows(self): """ Public method to close all dialogs managed by the handler. """ if self.__findDialog: self.__findDialog.close() - + def initMenus(self, mainMenu): """ Public method to initialize the various menus. - + @param mainMenu reference to the main tags menu @type QMenu """ - mainMenu.addAction(self.tr("Django Template Tags Locator"), - self.__findTemplateTag) + mainMenu.addAction( + self.tr("Django Template Tags Locator"), self.__findTemplateTag + ) mainMenu.addSeparator() mainMenu.addMenu(self.__initTagsMenu()) mainMenu.addMenu(self.__initFiltersMenu()) @@ -65,640 +67,754 @@ mainMenu.addMenu(self.__initInternationalizationMenu()) mainMenu.addMenu(self.__initLocalizationMenu()) mainMenu.addMenu(self.__initTimezoneMenu()) - + def __initTagsMenu(self): """ Private method to initialize the tags menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Tags")) menu.addAction( self.tr("autoescape - Auto Escape Characters"), - lambda: self.__applyTemplate("autoescape")) + lambda: self.__applyTemplate("autoescape"), + ) menu.addSeparator() menu.addAction( - self.tr("block - Named Block"), - lambda: self.__applyTemplate("block")) + self.tr("block - Named Block"), lambda: self.__applyTemplate("block") + ) menu.addSeparator() menu.addAction( self.tr("comment - Multiline Comment"), - lambda: self.__applyTemplate("comment")) + lambda: self.__applyTemplate("comment"), + ) menu.addAction( self.tr("csrf_token - Cross Site Request Forgery Token"), - lambda: self.__applyTemplate("csrf_token")) + lambda: self.__applyTemplate("csrf_token"), + ) menu.addAction( self.tr("cycle - Cycle variables each time used"), - lambda: self.__applyTemplate("cycle")) + lambda: self.__applyTemplate("cycle"), + ) menu.addSeparator() menu.addAction( self.tr("debug - Output Debug Information"), - lambda: self.__applyTemplate("debug")) + lambda: self.__applyTemplate("debug"), + ) menu.addSeparator() menu.addAction( self.tr("extends - Extend a template with variable contents"), - lambda: self.__applyTemplate("extendsvariable")) + lambda: self.__applyTemplate("extendsvariable"), + ) menu.addAction( self.tr("extends - Extend a template with file"), - lambda: self.__applyTemplate("extendsfile")) + lambda: self.__applyTemplate("extendsfile"), + ) menu.addSeparator() menu.addAction( self.tr("filter - Filtered Block for one or more filters"), - lambda: self.__applyTemplate("filter")) + lambda: self.__applyTemplate("filter"), + ) menu.addAction( self.tr("firstof - Outputs first argument variable that is True"), - lambda: self.__applyTemplate("firstof")) - menu.addAction( - self.tr("for - For Loop"), - lambda: self.__applyTemplate("for")) + lambda: self.__applyTemplate("firstof"), + ) + menu.addAction(self.tr("for - For Loop"), lambda: self.__applyTemplate("for")) menu.addAction( self.tr("for...empty - For Loop with fallback for empty loop"), - lambda: self.__applyTemplate("for...empty")) + lambda: self.__applyTemplate("for...empty"), + ) menu.addSeparator() menu.addAction( self.tr("if - if...elif...else... clauses"), - lambda: self.__applyTemplate("if")) + lambda: self.__applyTemplate("if"), + ) menu.addAction( self.tr("ifchanged - Check if a value has changed"), - lambda: self.__applyTemplate("ifchanged")) + lambda: self.__applyTemplate("ifchanged"), + ) menu.addAction( self.tr("ifequal - Output block if variables are equal"), - lambda: self.__applyTemplate("ifequal")) + lambda: self.__applyTemplate("ifequal"), + ) menu.addAction( self.tr("ifnotequal - Output block if variables are not equal"), - lambda: self.__applyTemplate("ifnotequal")) + lambda: self.__applyTemplate("ifnotequal"), + ) menu.addAction( self.tr("include - Render template given by variable"), - lambda: self.__applyTemplate("includevariable")) + lambda: self.__applyTemplate("includevariable"), + ) menu.addAction( self.tr("include - Render template given by file name"), - lambda: self.__applyTemplate("includefile")) + lambda: self.__applyTemplate("includefile"), + ) menu.addSeparator() menu.addAction( self.tr("load - Load a custom template tag set"), - lambda: self.__applyTemplate("load")) + lambda: self.__applyTemplate("load"), + ) menu.addSeparator() menu.addAction( self.tr("now - Display current date and time"), - lambda: self.__applyTemplate("now")) + lambda: self.__applyTemplate("now"), + ) menu.addSeparator() menu.addAction( - self.tr("regroup - Regroup list of alike objects by a common" - " attribute"), - lambda: self.__applyTemplate("regroup")) + self.tr("regroup - Regroup list of alike objects by a common" " attribute"), + lambda: self.__applyTemplate("regroup"), + ) menu.addSeparator() menu.addAction( self.tr("spaceless - Remove whitespace between HTML tags"), - lambda: self.__applyTemplate("spaceless")) + lambda: self.__applyTemplate("spaceless"), + ) menu.addAction( self.tr("ssi - Output contents of a given file into the page"), - lambda: self.__applyTemplate("ssi")) + lambda: self.__applyTemplate("ssi"), + ) menu.addAction( - self.tr("ssi - Output contents of a given file into the page" - " (dialog selection)"), - lambda: self.__applyTemplate("ssifile")) + self.tr( + "ssi - Output contents of a given file into the page" + " (dialog selection)" + ), + lambda: self.__applyTemplate("ssifile"), + ) menu.addSeparator() menu.addAction( - self.tr("templatetag - Output syntax characters used for" - " template"), - lambda: self.__applyTemplate("templatetag")) + self.tr("templatetag - Output syntax characters used for" " template"), + lambda: self.__applyTemplate("templatetag"), + ) menu.addSeparator() menu.addAction( self.tr("url - Return an absolute path reference"), - lambda: self.__applyTemplate("url")) + lambda: self.__applyTemplate("url"), + ) menu.addAction( self.tr("url...as - Return an absolute path reference"), - lambda: self.__applyTemplate("urlas")) + lambda: self.__applyTemplate("urlas"), + ) menu.addSeparator() menu.addAction( self.tr("verbatim - Output block contents without rendering"), - lambda: self.__applyTemplate("verbatim")) + lambda: self.__applyTemplate("verbatim"), + ) menu.addSeparator() menu.addAction( self.tr("widthratio - Calculate width ratio"), - lambda: self.__applyTemplate("verbatim")) + lambda: self.__applyTemplate("verbatim"), + ) menu.addAction( self.tr("with - Cache a complex variable under a simpler name"), - lambda: self.__applyTemplate("verbatim")) - + lambda: self.__applyTemplate("verbatim"), + ) + self.__tagsMenu = menu return menu - + def __initFiltersMenu(self): """ Private method to initialize the filters menu. - + @return generated menu @rtype QMenu """ mainMenu = QMenu(self.tr("Filters")) - + menu = QMenu(self.tr("A-I"), mainMenu) menu.addAction( - self.tr("add - Add variable or string"), - lambda: self.__applyTemplate("add")) + self.tr("add - Add variable or string"), lambda: self.__applyTemplate("add") + ) menu.addAction( self.tr("addslashes - Add slashes before quotes"), - lambda: self.__applyTemplate("addslashes")) + lambda: self.__applyTemplate("addslashes"), + ) menu.addSeparator() menu.addAction( self.tr("capfirst - Capitalize first character"), - lambda: self.__applyTemplate("capfirst")) + lambda: self.__applyTemplate("capfirst"), + ) menu.addAction( - self.tr("center - Center value"), - lambda: self.__applyTemplate("center")) + self.tr("center - Center value"), lambda: self.__applyTemplate("center") + ) menu.addAction( - self.tr("cut - Cut characters"), - lambda: self.__applyTemplate("cut")) + self.tr("cut - Cut characters"), lambda: self.__applyTemplate("cut") + ) menu.addSeparator() menu.addAction( - self.tr("date - Format date"), - lambda: self.__applyTemplate("date")) + self.tr("date - Format date"), lambda: self.__applyTemplate("date") + ) menu.addAction( self.tr("default - Use default if False"), - lambda: self.__applyTemplate("default")) + lambda: self.__applyTemplate("default"), + ) menu.addAction( self.tr("default_if_none - Use default if None"), - lambda: self.__applyTemplate("default_if_none")) + lambda: self.__applyTemplate("default_if_none"), + ) menu.addAction( self.tr("dictsort - Sort dictionaries"), - lambda: self.__applyTemplate("dictsort")) + lambda: self.__applyTemplate("dictsort"), + ) menu.addAction( self.tr("dictsortreversed - Sort dictionaries reversed"), - lambda: self.__applyTemplate("dictsortreversed")) + lambda: self.__applyTemplate("dictsortreversed"), + ) menu.addAction( self.tr("divisibleby - Check divisibility"), - lambda: self.__applyTemplate("divisibleby")) + lambda: self.__applyTemplate("divisibleby"), + ) menu.addSeparator() menu.addAction( - self.tr("escape - Escape as HTML"), - lambda: self.__applyTemplate("escape")) + self.tr("escape - Escape as HTML"), lambda: self.__applyTemplate("escape") + ) menu.addAction( self.tr("escapejs - Escape as JavaScript"), - lambda: self.__applyTemplate("escapejs")) + lambda: self.__applyTemplate("escapejs"), + ) menu.addSeparator() menu.addAction( self.tr("filesizeformat - Format file sizes"), - lambda: self.__applyTemplate("filesizeformat")) + lambda: self.__applyTemplate("filesizeformat"), + ) menu.addAction( self.tr("first - First item of a list"), - lambda: self.__applyTemplate("first")) + lambda: self.__applyTemplate("first"), + ) menu.addAction( self.tr("fix_ampersands - Replace ampersands"), - lambda: self.__applyTemplate("fix_ampersands")) + lambda: self.__applyTemplate("fix_ampersands"), + ) menu.addAction( self.tr("floatformat - Format floating numbers"), - lambda: self.__applyTemplate("floatformat")) + lambda: self.__applyTemplate("floatformat"), + ) menu.addAction( self.tr("force_escape - Escape as HTML immediately"), - lambda: self.__applyTemplate("force_escape")) + lambda: self.__applyTemplate("force_escape"), + ) menu.addSeparator() menu.addAction( self.tr("get_digit - Extract rightmost digit"), - lambda: self.__applyTemplate("get_digit")) + lambda: self.__applyTemplate("get_digit"), + ) menu.addSeparator() menu.addAction( self.tr("iriencode - Convert IRI to string"), - lambda: self.__applyTemplate("iriencode")) + lambda: self.__applyTemplate("iriencode"), + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("J-R"), mainMenu) menu.addAction( - self.tr("join - Join list"), - lambda: self.__applyTemplate("join")) + self.tr("join - Join list"), lambda: self.__applyTemplate("join") + ) menu.addSeparator() menu.addAction( self.tr("last - Return last item in list"), - lambda: self.__applyTemplate("last")) + lambda: self.__applyTemplate("last"), + ) menu.addAction( self.tr("length - Return length of the value"), - lambda: self.__applyTemplate("length")) + lambda: self.__applyTemplate("length"), + ) menu.addAction( self.tr("length_is - Check length"), - lambda: self.__applyTemplate("length_is")) + lambda: self.__applyTemplate("length_is"), + ) menu.addAction( self.tr("linebreaks - Replace line breaks with HTML"), - lambda: self.__applyTemplate("linebreaks")) + lambda: self.__applyTemplate("linebreaks"), + ) menu.addAction( self.tr("linebreaksbr - Replace line breaks with <br/>"), - lambda: self.__applyTemplate("linebreaksbr")) + lambda: self.__applyTemplate("linebreaksbr"), + ) menu.addAction( self.tr("linenumbers - Display text with line numbers"), - lambda: self.__applyTemplate("linenumbers")) + lambda: self.__applyTemplate("linenumbers"), + ) menu.addAction( - self.tr("ljust - Left-align value"), - lambda: self.__applyTemplate("ljust")) + self.tr("ljust - Left-align value"), lambda: self.__applyTemplate("ljust") + ) menu.addAction( self.tr("lower - Convert to lowercase"), - lambda: self.__applyTemplate("lower")) + lambda: self.__applyTemplate("lower"), + ) menu.addSeparator() menu.addAction( self.tr("make_list - Turn value into a list"), - lambda: self.__applyTemplate("make_list")) + lambda: self.__applyTemplate("make_list"), + ) menu.addSeparator() menu.addAction( self.tr("phone2numeric - Convert phone number into numeric"), - lambda: self.__applyTemplate("phone2numeric")) + lambda: self.__applyTemplate("phone2numeric"), + ) menu.addAction( self.tr("pluralize - Return plural suffix"), - lambda: self.__applyTemplate("pluralize")) + lambda: self.__applyTemplate("pluralize"), + ) menu.addAction( - self.tr("pprint - Pretty Print"), - lambda: self.__applyTemplate("pprint")) + self.tr("pprint - Pretty Print"), lambda: self.__applyTemplate("pprint") + ) menu.addSeparator() menu.addAction( self.tr("random - Return random item from list"), - lambda: self.__applyTemplate("random")) + lambda: self.__applyTemplate("random"), + ) menu.addAction( self.tr("removetags - Remove HTML tags"), - lambda: self.__applyTemplate("removetags")) + lambda: self.__applyTemplate("removetags"), + ) menu.addAction( - self.tr("rjust - Right-align value"), - lambda: self.__applyTemplate("rjust")) + self.tr("rjust - Right-align value"), lambda: self.__applyTemplate("rjust") + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("S-Z"), mainMenu) menu.addAction( self.tr("safe - Mark as not requiring HTML escaping "), - lambda: self.__applyTemplate("safe")) + lambda: self.__applyTemplate("safe"), + ) menu.addAction( self.tr("safeseq - Mark as a safe sequence"), - lambda: self.__applyTemplate("safeseq")) + lambda: self.__applyTemplate("safeseq"), + ) menu.addAction( self.tr("slice - Return a slice of a list"), - lambda: self.__applyTemplate("slice")) + lambda: self.__applyTemplate("slice"), + ) menu.addAction( self.tr("slugify - Return value slugified"), - lambda: self.__applyTemplate("slugify")) + lambda: self.__applyTemplate("slugify"), + ) menu.addAction( self.tr("stringformat - Format variable"), - lambda: self.__applyTemplate("stringformat")) + lambda: self.__applyTemplate("stringformat"), + ) menu.addAction( self.tr("striptags - Strip all HTML tags"), - lambda: self.__applyTemplate("striptags")) + lambda: self.__applyTemplate("striptags"), + ) menu.addSeparator() menu.addAction( - self.tr("time - Format time"), - lambda: self.__applyTemplate("time")) + self.tr("time - Format time"), lambda: self.__applyTemplate("time") + ) menu.addAction( self.tr("timesince - Format as time since"), - lambda: self.__applyTemplate("timesince")) + lambda: self.__applyTemplate("timesince"), + ) menu.addAction( self.tr("timeuntil - Format as time until"), - lambda: self.__applyTemplate("timeuntil")) + lambda: self.__applyTemplate("timeuntil"), + ) menu.addAction( self.tr("title - Convert to titlecase"), - lambda: self.__applyTemplate("title")) + lambda: self.__applyTemplate("title"), + ) menu.addAction( self.tr("truncatechars - Truncate after a number of characters"), - lambda: self.__applyTemplate("truncatechars")) + lambda: self.__applyTemplate("truncatechars"), + ) menu.addAction( self.tr("truncatewords - Truncate after a number of words"), - lambda: self.__applyTemplate("truncatewords")) + lambda: self.__applyTemplate("truncatewords"), + ) menu.addAction( - self.tr("truncatewords_html - Truncate after a number of words" - " (HTML aware)"), - lambda: self.__applyTemplate("truncatewords_html")) + self.tr( + "truncatewords_html - Truncate after a number of words" " (HTML aware)" + ), + lambda: self.__applyTemplate("truncatewords_html"), + ) menu.addSeparator() menu.addAction( self.tr("unordered_list - Return HTML unordered list"), - lambda: self.__applyTemplate("unordered_list")) + lambda: self.__applyTemplate("unordered_list"), + ) menu.addAction( self.tr("upper - Convert to uppercase"), - lambda: self.__applyTemplate("upper")) + lambda: self.__applyTemplate("upper"), + ) menu.addAction( self.tr("urlencode - Escape as URL"), - lambda: self.__applyTemplate("urlencode")) + lambda: self.__applyTemplate("urlencode"), + ) menu.addAction( self.tr("urlize - Convert URLs as clickable links"), - lambda: self.__applyTemplate("urlize")) + lambda: self.__applyTemplate("urlize"), + ) menu.addAction( - self.tr("urlizetrunc - Convert URLs as clickable links and" - " truncate"), - lambda: self.__applyTemplate("urlizetrunc")) + self.tr("urlizetrunc - Convert URLs as clickable links and" " truncate"), + lambda: self.__applyTemplate("urlizetrunc"), + ) menu.addSeparator() menu.addAction( self.tr("wordcount - Return number of word"), - lambda: self.__applyTemplate("wordcount")) + lambda: self.__applyTemplate("wordcount"), + ) menu.addAction( - self.tr("wordwrap - Wrap words"), - lambda: self.__applyTemplate("wordwrap")) + self.tr("wordwrap - Wrap words"), lambda: self.__applyTemplate("wordwrap") + ) menu.addSeparator() menu.addAction( self.tr("yesno - Map True, False and None"), - lambda: self.__applyTemplate("yesno")) + lambda: self.__applyTemplate("yesno"), + ) mainMenu.addMenu(menu) - + self.__filtersMenu = mainMenu return mainMenu - + def __initHumanizeMenu(self): """ Private method to initialize the humanize menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Humanize")) menu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadhumanize")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadhumanize") + ) menu.addSeparator() menu.addAction( self.tr("apnumber - Format integer the Associated Press style"), - lambda: self.__applyTemplate("apnumber")) + lambda: self.__applyTemplate("apnumber"), + ) menu.addSeparator() menu.addAction( self.tr("intcomma - Format integer with commas"), - lambda: self.__applyTemplate("intcomma")) + lambda: self.__applyTemplate("intcomma"), + ) menu.addAction( self.tr("intword - Convert integer to word"), - lambda: self.__applyTemplate("intword")) + lambda: self.__applyTemplate("intword"), + ) menu.addSeparator() menu.addAction( self.tr("naturalday - Format date naturally"), - lambda: self.__applyTemplate("naturalday")) + lambda: self.__applyTemplate("naturalday"), + ) menu.addAction( self.tr("naturaltime - Format time naturally"), - lambda: self.__applyTemplate("naturaltime")) + lambda: self.__applyTemplate("naturaltime"), + ) menu.addSeparator() menu.addAction( self.tr("ordinal - Convert integer to ordinal"), - lambda: self.__applyTemplate("ordinal")) - + lambda: self.__applyTemplate("ordinal"), + ) + self.__humanizeMenu = menu return menu - + def __initWebDesignMenu(self): """ Private method to initialize the web design menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Web Design")) - menu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadweb")) + menu.addAction(self.tr("Load Package"), lambda: self.__applyTemplate("loadweb")) menu.addSeparator() menu.addAction( self.tr("lorem - Builtin Lorem Ipsum Generator"), - lambda: self.__applyTemplate("lorem")) - + lambda: self.__applyTemplate("lorem"), + ) + self.__webMenu = menu return menu - + def __initStaticMenu(self): """ Private method to initialize the static menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Static")) menu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadstatic")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadstatic") + ) menu.addSeparator() menu.addAction( self.tr("static - Link to static file"), - lambda: self.__applyTemplate("staticfile")) + lambda: self.__applyTemplate("staticfile"), + ) menu.addAction( self.tr("static - Link to static file (via variable)"), - lambda: self.__applyTemplate("staticvariable")) + lambda: self.__applyTemplate("staticvariable"), + ) menu.addAction( self.tr("get_static_prefix - Insert static URL"), - lambda: self.__applyTemplate("get_static_prefix")) + lambda: self.__applyTemplate("get_static_prefix"), + ) menu.addAction( self.tr("get_media_prefix - Insert media URL"), - lambda: self.__applyTemplate("get_media_prefix")) - + lambda: self.__applyTemplate("get_media_prefix"), + ) + self.__staticMenu = menu return menu - + def __initCommentsMenu(self): """ Private method to initialize the comments menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Comment")) menu.addAction( self.tr("Single Line Comment Selected Text"), - lambda: self.__applyTemplate("singlelinecommentselect")) + lambda: self.__applyTemplate("singlelinecommentselect"), + ) menu.addAction( self.tr("Multi Line Comment Selected Text"), - lambda: self.__applyTemplate("multilinecommentselect")) + lambda: self.__applyTemplate("multilinecommentselect"), + ) menu.addSeparator() menu.addAction( self.tr("Single Line Comment from Input Dialog"), - lambda: self.__applyTemplate("singlelinecommentdialog")) + lambda: self.__applyTemplate("singlelinecommentdialog"), + ) menu.addAction( self.tr("Multi Line Comment from Input Dialog"), - lambda: self.__applyTemplate("multilinecommentdialog")) + lambda: self.__applyTemplate("multilinecommentdialog"), + ) menu.addSeparator() menu.addAction( self.tr("Single Line Comment from Clipboard"), - lambda: self.__applyTemplate("singlelinecommentclipboard")) + lambda: self.__applyTemplate("singlelinecommentclipboard"), + ) menu.addAction( self.tr("Multi Line Comment from Clipboard"), - lambda: self.__applyTemplate("multilinecommentclipboard")) + lambda: self.__applyTemplate("multilinecommentclipboard"), + ) menu.addSeparator() menu.addAction( self.tr("Multi Line Comment from File"), - lambda: self.__applyTemplate("multilinecommentfile")) + lambda: self.__applyTemplate("multilinecommentfile"), + ) menu.addSeparator() menu.addAction( self.tr("Single Line Comment from Date Time Now"), - lambda: self.__applyTemplate("singlelinecommentdatetime")) + lambda: self.__applyTemplate("singlelinecommentdatetime"), + ) menu.addSeparator() menu.addAction( self.tr("HTML Comment Out Selected Text"), - lambda: self.__applyTemplate("htmlcomment")) + lambda: self.__applyTemplate("htmlcomment"), + ) menu.addAction( self.tr("MS IE Conditional Comment Selected Text"), - lambda: self.__applyTemplate("iecomment")) - + lambda: self.__applyTemplate("iecomment"), + ) + self.__commentsMenu = menu return menu - + def __initInternationalizationMenu(self): """ Private method to initialize the static menu. - + @return generated menu @rtype QMenu """ mainMenu = QMenu(self.tr("Internationalization (i18n)")) mainMenu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadi18n")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadi18n") + ) mainMenu.addSeparator() - + menu = QMenu(self.tr("Tags"), mainMenu) menu.addAction( self.tr("trans - Translate String or Variable"), - lambda: self.__applyTemplate("trans")) + lambda: self.__applyTemplate("trans"), + ) menu.addAction( self.tr("trans..as - Translate String into Variable"), - lambda: self.__applyTemplate("trans..as")) + lambda: self.__applyTemplate("trans..as"), + ) menu.addSeparator() menu.addAction( self.tr("blocktrans - Translate Block"), - lambda: self.__applyTemplate("blocktrans")) + lambda: self.__applyTemplate("blocktrans"), + ) menu.addAction( self.tr("blocktrans..with - Translate Block with Attributes"), - lambda: self.__applyTemplate("blocktrans..with")) + lambda: self.__applyTemplate("blocktrans..with"), + ) menu.addAction( - self.tr("plural - Plural Block"), - lambda: self.__applyTemplate("plural")) + self.tr("plural - Plural Block"), lambda: self.__applyTemplate("plural") + ) menu.addAction( self.tr("language - Switch language"), - lambda: self.__applyTemplate("language")) + lambda: self.__applyTemplate("language"), + ) menu.addSeparator() menu.addAction( self.tr("get_current_language - Current language"), - lambda: self.__applyTemplate("get_current_language")) + lambda: self.__applyTemplate("get_current_language"), + ) menu.addAction( self.tr("get_available_languages - Available languages"), - lambda: self.__applyTemplate("get_available_languages")) + lambda: self.__applyTemplate("get_available_languages"), + ) menu.addAction( - self.tr("get_current_language_bidi - Current language's" - " direction"), - lambda: self.__applyTemplate("get_current_language_bidi")) + self.tr("get_current_language_bidi - Current language's" " direction"), + lambda: self.__applyTemplate("get_current_language_bidi"), + ) menu.addAction( self.tr("get_language_info - Language Information"), - lambda: self.__applyTemplate("get_language_info")) + lambda: self.__applyTemplate("get_language_info"), + ) menu.addAction( - self.tr("get_language_info_list - Language Information for a list" - " of languages"), - lambda: self.__applyTemplate("get_language_info_list")) + self.tr( + "get_language_info_list - Language Information for a list" + " of languages" + ), + lambda: self.__applyTemplate("get_language_info_list"), + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("Filters"), mainMenu) menu.addAction( self.tr("language_name - Language name"), - lambda: self.__applyTemplate("language_name")) + lambda: self.__applyTemplate("language_name"), + ) menu.addAction( self.tr("language_name_local - Language name translated"), - lambda: self.__applyTemplate("language_name_local")) + lambda: self.__applyTemplate("language_name_local"), + ) menu.addAction( - self.tr("bidi - Language's direction"), - lambda: self.__applyTemplate("bidi")) + self.tr("bidi - Language's direction"), lambda: self.__applyTemplate("bidi") + ) mainMenu.addMenu(menu) - + self.__internationalizationMenu = mainMenu return mainMenu - + def __initLocalizationMenu(self): """ Private method to initialize the static menu. - + @return generated menu @rtype QMenu """ mainMenu = QMenu(self.tr("Localization (l10n)")) mainMenu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadl10n")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadl10n") + ) mainMenu.addSeparator() - + menu = QMenu(self.tr("Tags"), mainMenu) menu.addAction( self.tr("localize on - Activate Localization"), - lambda: self.__applyTemplate("localize_on")) + lambda: self.__applyTemplate("localize_on"), + ) menu.addAction( self.tr("localize off - Dectivate Localization"), - lambda: self.__applyTemplate("localize_off")) + lambda: self.__applyTemplate("localize_off"), + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("Filters"), mainMenu) menu.addAction( self.tr("localize - Output value localized"), - lambda: self.__applyTemplate("localize")) + lambda: self.__applyTemplate("localize"), + ) menu.addAction( self.tr("unlocalize - Output value non-localized"), - lambda: self.__applyTemplate("unlocalize")) + lambda: self.__applyTemplate("unlocalize"), + ) mainMenu.addMenu(menu) - + self.__localizationMenu = mainMenu return mainMenu - + def __initTimezoneMenu(self): """ Private method to initialize the static menu. - + @return generated menu @rtype QMenu """ mainMenu = QMenu(self.tr("Timezone (tz)")) mainMenu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadtz")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadtz") + ) mainMenu.addSeparator() - + menu = QMenu(self.tr("Tags"), mainMenu) menu.addAction( self.tr("localtime on - Activate date and time conversion"), - lambda: self.__applyTemplate("localtime_on")) + lambda: self.__applyTemplate("localtime_on"), + ) menu.addAction( self.tr("localtime off - Deactivate date and time conversion"), - lambda: self.__applyTemplate("localtime_off")) + lambda: self.__applyTemplate("localtime_off"), + ) menu.addAction( self.tr("timezone - Set timezone for date and time conversion"), - lambda: self.__applyTemplate("timezone_set")) + lambda: self.__applyTemplate("timezone_set"), + ) menu.addAction( - self.tr("timezone None - Unset timezone for date and time" - " conversion"), - lambda: self.__applyTemplate("timezone_unset")) + self.tr("timezone None - Unset timezone for date and time" " conversion"), + lambda: self.__applyTemplate("timezone_unset"), + ) menu.addAction( self.tr("get_current_timezone - Get current time zone"), - lambda: self.__applyTemplate("get_current_timezone")) + lambda: self.__applyTemplate("get_current_timezone"), + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("Filters"), mainMenu) menu.addAction( self.tr("localtime - Convert to local time zone"), - lambda: self.__applyTemplate("localtime")) + lambda: self.__applyTemplate("localtime"), + ) menu.addAction( - self.tr("utc - Convert to UTC"), - lambda: self.__applyTemplate("utc")) + self.tr("utc - Convert to UTC"), lambda: self.__applyTemplate("utc") + ) menu.addAction( self.tr("timezone - Convert to a specific time zone"), - lambda: self.__applyTemplate("timezone")) + lambda: self.__applyTemplate("timezone"), + ) mainMenu.addMenu(menu) - + self.__timezoneMenu = mainMenu return mainMenu - + def __findTemplateTag(self): """ Private slot to find a template tag and insert its text. """ if self.__findDialog is None: from .FindTemplateTagDialog import FindTemplateTagDialog + self.__findDialog = FindTemplateTagDialog() self.__findDialog.tag.connect(self.__applyTemplate) self.__findDialog.show() self.__findDialog.raise_() self.__findDialog.activateWindow() - + def __applyTemplate(self, tag): """ Private slot to generate and insert the template text. - + @param tag name of the tag to insert @type str """ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - - templateText, replace = self.__generateTemplateText( - tag, editor.selectedText()) - + + templateText, replace = self.__generateTemplateText(tag, editor.selectedText()) + if templateText: editor.beginUndoAction() if replace: @@ -706,11 +822,11 @@ else: editor.insert(templateText) editor.endUndoAction() - + def __generateTemplateText(self, tag, selectedText): """ Private slot to generate the template text. - + @param tag name of the tag to insert @type str @param selectedText selected text of the current editor @@ -719,28 +835,30 @@ a replace operation @rtype tuple of (str, bool) """ - replace = False # safe value + replace = False # safe value ok = True templateText = "" - + #################################################### ## Template Tags ## #################################################### - + if tag == "autoescape": - templateText = ( - "{{% autoescape on %}} {0} {{% endautoescape %}}".format( - selectedText)) + templateText = "{{% autoescape on %}} {0} {{% endautoescape %}}".format( + selectedText + ) replace = True elif tag == "block": data, ok = DjangoTagInputDialog.getText( None, self.tr("Named Block"), [self.tr("Enter block name:")], - ["block_name"]) + ["block_name"], + ) if ok: templateText = "{{% block {0} %}} {1} {{% endblock %}}".format( - data[0], selectedText) + data[0], selectedText + ) replace = True elif tag == "csrf_token": templateText = "{% csrf_token %}" @@ -749,7 +867,8 @@ None, self.tr("Cycle Variables"), [self.tr("Enter items to cycle, space separated")], - ["item1 item2 item3"]) + ["item1 item2 item3"], + ) if ok: templateText = "{{% cycle {0} %}}".format(data[0]) elif tag == "debug": @@ -759,7 +878,8 @@ None, self.tr("Extends"), [self.tr("Enter variable name:")], - ["variable"]) + ["variable"], + ) if ok: templateText = "{{% extends {0} %}}".format(data[0]) elif tag == "extendsfile": @@ -767,7 +887,8 @@ None, self.tr("Extends"), [self.tr("Enter parent file name:")], - ["base.html"]) + ["base.html"], + ) if ok: templateText = '{{% extends "{0}" %}}'.format(data[0]) elif tag == "filter": @@ -775,53 +896,64 @@ None, self.tr("Tag Filters"), [self.tr("Multiple filters with arguments, pipes separated:")], - ["lower|safe"]) + ["lower|safe"], + ) if ok: - templateText = ( - "{{% filter {0} %}} {1} {{% endfilter %}}".format( - data[0], selectedText)) + templateText = "{{% filter {0} %}} {1} {{% endfilter %}}".format( + data[0], selectedText + ) replace = True elif tag == "firstof": data, ok = DjangoTagInputDialog.getText( None, self.tr("First Of"), - [self.tr("Enter multiple variables, space separated:"), - self.tr("Enter fallback value:")], - ["var1 var2", "fallback_value"]) + [ + self.tr("Enter multiple variables, space separated:"), + self.tr("Enter fallback value:"), + ], + ["var1 var2", "fallback_value"], + ) if ok: templateText = ( '{{% filter force_escape %}}{{% firstof {0} "{1}" %}}' - ' {2} {{% endfilter %}}'.format( - data[0], data[1], selectedText)) + " {2} {{% endfilter %}}".format(data[0], data[1], selectedText) + ) replace = True elif tag == "for": data, ok = DjangoTagInputDialog.getText( None, self.tr("For Loop"), - [self.tr("Enter variable to use for iteration:"), - self.tr("Enter sequence to iterate over:")], - ["item", "values"]) + [ + self.tr("Enter variable to use for iteration:"), + self.tr("Enter sequence to iterate over:"), + ], + ["item", "values"], + ) if ok: - templateText = ( - "{{% for {0} in {1} %}} {2} {{% endfor %}}".format( - data[0], data[1], selectedText)) + templateText = "{{% for {0} in {1} %}} {2} {{% endfor %}}".format( + data[0], data[1], selectedText + ) replace = True elif tag == "for...empty": data, ok = DjangoTagInputDialog.getText( None, self.tr("For Loop"), - [self.tr("Enter variable to use for iteration:"), - self.tr("Enter sequence to iterate over:"), - self.tr("Enter output to use if loop is empty:")], - ["item", "values", '"Nothing."']) + [ + self.tr("Enter variable to use for iteration:"), + self.tr("Enter sequence to iterate over:"), + self.tr("Enter output to use if loop is empty:"), + ], + ["item", "values", '"Nothing."'], + ) if ok: templateText = ( "{{% for {0} in {1} %}} {2} {{% empty %}} {3}" - " {{% endfor %}}".format( - data[0], data[1], selectedText, data[2])) + " {{% endfor %}}".format(data[0], data[1], selectedText, data[2]) + ) replace = True elif tag == "if": from .IfTagInputDialog import IfTagInputDialog + dlg = IfTagInputDialog() if dlg.exec() == QDialog.DialogCode.Accepted: templateText = dlg.getTag() @@ -830,50 +962,58 @@ None, self.tr("Check Variables for Changes"), [self.tr("Enter variables to check (space separated):")], - ["variable1 variable2"]) + ["variable1 variable2"], + ) if ok: - templateText = ( - '{{% ifchanged {0} %}}{1}{{% endifchanged %}}' - .format(data[0], selectedText)) + templateText = "{{% ifchanged {0} %}}{1}{{% endifchanged %}}".format( + data[0], selectedText + ) replace = True elif tag == "ifequal": data, ok = DjangoTagInputDialog.getText( None, self.tr("Check If Equal"), - [self.tr("Enter first variable or string to check:"), - self.tr("Enter second variable or string to check:")], - ["user.username", '"adrian"']) + [ + self.tr("Enter first variable or string to check:"), + self.tr("Enter second variable or string to check:"), + ], + ["user.username", '"adrian"'], + ) if ok: - templateText = ( - '{{% ifequal {0} {1} %}}{2}{{% endifequal %}}' - .format(data[0], data[1], selectedText)) + templateText = "{{% ifequal {0} {1} %}}{2}{{% endifequal %}}".format( + data[0], data[1], selectedText + ) replace = True elif tag == "ifnotequal": data, ok = DjangoTagInputDialog.getText( None, self.tr("Check If Not Equal"), - [self.tr("Enter first variable or string to check:"), - self.tr("Enter second variable or string to check:")], - ["user.username", '"adrian"']) + [ + self.tr("Enter first variable or string to check:"), + self.tr("Enter second variable or string to check:"), + ], + ["user.username", '"adrian"'], + ) if ok: templateText = ( - '{{% ifnotequal {0} {1} %}}{2}{{% endifnotequal %}}' - .format(data[0], data[1], selectedText)) + "{{% ifnotequal {0} {1} %}}{2}{{% endifnotequal %}}".format( + data[0], data[1], selectedText + ) + ) replace = True elif tag == "includevariable": data, ok = DjangoTagInputDialog.getText( None, self.tr("Include"), [self.tr("Enter variable name:")], - ["variable"]) + ["variable"], + ) if ok: - templateText = '{{% include {0} %}}'.format(data[0]) + templateText = "{{% include {0} %}}".format(data[0]) elif tag == "includefile": data, ok = DjangoTagInputDialog.getText( - None, - self.tr("Include"), - [self.tr("Enter file name:")], - ["other.html"]) + None, self.tr("Include"), [self.tr("Enter file name:")], ["other.html"] + ) if ok: templateText = '{{% include "{0}" %}}'.format(data[0]) elif tag == "load": @@ -881,7 +1021,8 @@ None, self.tr("Load"), [self.tr("Enter template tag set to load:")], - ["foo bar"]) + ["foo bar"], + ) if ok: templateText = '{{% load "{0}" %}}'.format(data[0]) elif tag == "now": @@ -889,39 +1030,50 @@ None, self.tr("Now"), self.tr("Current date time format:"), - ["DATETIME_FORMAT", "SHORT_DATETIME_FORMAT", - "SHORT_DATE_FORMAT", "DATE_FORMAT"], - 0, False) + [ + "DATETIME_FORMAT", + "SHORT_DATETIME_FORMAT", + "SHORT_DATE_FORMAT", + "DATE_FORMAT", + ], + 0, + False, + ) if ok: templateText = '{{% now "{0}" %}}'.format(dateformat) elif tag == "regroup": data, ok = DjangoTagInputDialog.getText( None, self.tr("Regroup List"), - [self.tr("List Variable:"), self.tr("Common Attribute:"), - self.tr("Name of resulting list:")], - ["cities", "country", "country_list"]) + [ + self.tr("List Variable:"), + self.tr("Common Attribute:"), + self.tr("Name of resulting list:"), + ], + ["cities", "country", "country_list"], + ) if ok: - templateText = '{{% regroup {0} by {1} as {2} %}}'.format( - data[0], data[1], data[2]) + templateText = "{{% regroup {0} by {1} as {2} %}}".format( + data[0], data[1], data[2] + ) elif tag == "spaceless": templateText = "{{% spaceless %}} {0} {{% endspaceless %}}".format( - selectedText) + selectedText + ) replace = True elif tag == "ssi": data, ok = DjangoTagInputDialog.getText( None, self.tr("SSI"), [self.tr("Full path to template:")], - ["/tmp/ssi_template.html"]) # secok + ["/tmp/ssi_template.html"], + ) # secok if ok: templateText = '{{% ssi "{0}" parsed %}}'.format(data[0]) elif tag == "ssifile": ssi = EricFileDialog.getOpenFileName( - None, - self.tr("SSI"), - os.path.expanduser("~"), - self.tr("All Files (*)")) + None, self.tr("SSI"), os.path.expanduser("~"), self.tr("All Files (*)") + ) if ssi: templateText = '{{% ssi "{0}" parsed %}}'.format(ssi) elif tag == "templatetag": @@ -930,73 +1082,89 @@ self.tr("Template Tag"), self.tr("Argument:"), ["block", "variable", "brace", "comment"], - 0, False) + 0, + False, + ) if ok: templateText = ( - '{{% templatetag open{0} %}} {1} {{% templatetag' - ' close{0} %}}'.format(templatetag, selectedText)) + "{{% templatetag open{0} %}} {1} {{% templatetag" + " close{0} %}}".format(templatetag, selectedText) + ) replace = True elif tag == "url": data, ok = DjangoTagInputDialog.getText( None, self.tr("URL"), - [self.tr("View method name:"), - self.tr("Optional arguments (space separated):")], - ["path.to.some_view", "var1 var2"]) + [ + self.tr("View method name:"), + self.tr("Optional arguments (space separated):"), + ], + ["path.to.some_view", "var1 var2"], + ) if ok: if data[1]: - data[1] = ' ' + data[1] - templateText = '{{% url "{0}"{1} %}}'.format( - data[0], data[1]) + data[1] = " " + data[1] + templateText = '{{% url "{0}"{1} %}}'.format(data[0], data[1]) elif tag == "urlas": data, ok = DjangoTagInputDialog.getText( None, self.tr("URL...as"), - [self.tr("View method name:"), - self.tr("Optional arguments (space separated):"), - self.tr("URL name:")], - ["path.to.some_view", "var1 var2", "url_name"]) + [ + self.tr("View method name:"), + self.tr("Optional arguments (space separated):"), + self.tr("URL name:"), + ], + ["path.to.some_view", "var1 var2", "url_name"], + ) if ok: if data[1]: - data[1] = ' ' + data[1] + data[1] = " " + data[1] templateText = '{{% url "{0}"{1} as {2} %}}'.format( - data[0], data[1], data[2]) + data[0], data[1], data[2] + ) elif tag == "verbatim": templateText = "{{% verbatim %}} {0} {{% endverbatim %}}".format( - selectedText) + selectedText + ) replace = True elif tag == "widthratio": data, ok = DjangoTagInputDialog.getText( None, self.tr("Width Ratio"), - [self.tr("Variable:"), - self.tr("Maximum Value:"), - self.tr("Maximum Width:")], - ["variable", "max_value", "max_width"]) + [ + self.tr("Variable:"), + self.tr("Maximum Value:"), + self.tr("Maximum Width:"), + ], + ["variable", "max_value", "max_width"], + ) if ok: templateText = "{{% widthratio {0} {1} {2} %}}".format( - data[0], data[1], data[2]) + data[0], data[1], data[2] + ) elif tag == "with": data, ok = DjangoTagInputDialog.getText( None, self.tr("Cache Variables"), - [self.tr("Variables to cache as key=value (space separated):") - ], - ["variable1=foo.bar variable2=bar.baz"]) + [self.tr("Variables to cache as key=value (space separated):")], + ["variable1=foo.bar variable2=bar.baz"], + ) if ok: - templateText = '{{% with {0} %}} {1} {{% endwith %}}'.format( - data[0], selectedText) - + templateText = "{{% with {0} %}} {1} {{% endwith %}}".format( + data[0], selectedText + ) + #################################################### ## Template Filters ## #################################################### - + elif tag == "add": data, ok = DjangoTagInputDialog.getText( None, self.tr("Add Variable or String"), [self.tr("Variables or String to add:")], - ["variable"]) + ["variable"], + ) if ok: templateText = "|add:{0}".format(data[0]) elif tag == "addslashes": @@ -1008,15 +1176,17 @@ None, self.tr("Center Value"), self.tr("Enter width of the output:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: templateText = '|center:"{0}"'.format(width) elif tag == "cut": data, ok = DjangoTagInputDialog.getText( - None, - self.tr("Cut Characters"), - [self.tr("Characters to cut:")], - [" "]) + None, self.tr("Cut Characters"), [self.tr("Characters to cut:")], [" "] + ) if ok: templateText = '|cut:"{0}"'.format(data[0]) elif tag == "date": @@ -1024,20 +1194,27 @@ None, self.tr("Format Date"), self.tr("Enter date format:"), - ["DATETIME_FORMAT", "SHORT_DATETIME_FORMAT", - "SHORT_DATE_FORMAT", "DATE_FORMAT"], - 0, True) + [ + "DATETIME_FORMAT", + "SHORT_DATETIME_FORMAT", + "SHORT_DATE_FORMAT", + "DATE_FORMAT", + ], + 0, + True, + ) if ok: if date: templateText = '|date:"{0}"'.format(date) else: - templateText = '|date' + templateText = "|date" elif tag == "default": data, ok = DjangoTagInputDialog.getText( None, self.tr("Default Value if False"), [self.tr("Enter default value if result is False:")], - ["nothing"]) + ["nothing"], + ) if ok: templateText = '|default:"{0}"'.format(data[0]) elif tag == "default_if_none": @@ -1045,7 +1222,8 @@ None, self.tr("Default Value if None"), [self.tr("Enter default value if result is None:")], - ["nothing"]) + ["nothing"], + ) if ok: templateText = '|default:"{0}"'.format(data[0]) elif tag == "dictsort": @@ -1053,7 +1231,8 @@ None, self.tr("Sort Dictionaries"), [self.tr("Enter key to sort on:")], - ["key"]) + ["key"], + ) if ok: templateText = '|dictsort:"{0}"'.format(data[0]) elif tag == "dictsortreversed": @@ -1061,7 +1240,8 @@ None, self.tr("Sort Dictionaries reversed"), [self.tr("Enter key to sort on:")], - ["key"]) + ["key"], + ) if ok: templateText = '|dictsortreversed:"{0}"'.format(data[0]) elif tag == "divisibleby": @@ -1069,100 +1249,123 @@ None, self.tr("Check Divisibility"), self.tr("Enter divisor value:"), - 2, 1, 99, 1) + 2, + 1, + 99, + 1, + ) if ok: templateText = '|divisibleby:"{0}"'.format(divisor) elif tag == "escape": - templateText = '|escape' + templateText = "|escape" elif tag == "escapejs": - templateText = '|escapejs' + templateText = "|escapejs" elif tag == "filesizeformat": - templateText = '|filesizeformat' + templateText = "|filesizeformat" elif tag == "first": - templateText = '|first' + templateText = "|first" elif tag == "fix_ampersands": - templateText = '|fix_ampersands' + templateText = "|fix_ampersands" elif tag == "floatformat": decimals, ok = QInputDialog.getInt( None, self.tr("Format Floating Number"), self.tr("Enter number of decimal places:"), - 2, -20, 20, 1) + 2, + -20, + 20, + 1, + ) if ok: templateText = '|floatformat:"{0}"'.format(decimals) elif tag == "force_escape": - templateText = '|force_escape' + templateText = "|force_escape" elif tag == "get_digit": digit, ok = QInputDialog.getInt( None, self.tr("Get Rightmost Digit"), self.tr("Enter index of digit:"), - 1, 1, 99, 1) + 1, + 1, + 99, + 1, + ) if ok: templateText = '|get_digit:"{0}"'.format(digit) elif tag == "iriencode": - templateText = '|iriencode' + templateText = "|iriencode" elif tag == "join": data, ok = DjangoTagInputDialog.getText( None, self.tr("Join List"), [self.tr("Enter string to join by:")], - ["//"]) + ["//"], + ) if ok: templateText = '|join:"{0}"'.format(data[0]) elif tag == "last": - templateText = '|last' + templateText = "|last" elif tag == "length": - templateText = '|length' + templateText = "|length" elif tag == "length_is": length, ok = QInputDialog.getInt( None, self.tr("Check Length"), self.tr("Enter desired length:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: templateText = '|length_is:"{0}"'.format(length) elif tag == "linebreaks": - templateText = '|linebreaks' + templateText = "|linebreaks" elif tag == "linebreaksbr": - templateText = '|linebreaksbr' + templateText = "|linebreaksbr" elif tag == "linenumbers": - templateText = '|linenumbers' + templateText = "|linenumbers" elif tag == "ljust": width, ok = QInputDialog.getInt( None, self.tr("Left-align Value"), self.tr("Enter width of the output:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: templateText = '|ljust:"{0}"'.format(width) elif tag == "lower": - templateText = '|lower' + templateText = "|lower" elif tag == "make_list": - templateText = '|make_list' + templateText = "|make_list" elif tag == "phone2numeric": - templateText = '|phone2numeric' + templateText = "|phone2numeric" elif tag == "pluralize": data, ok = DjangoTagInputDialog.getText( None, self.tr("Plural Suffix"), [self.tr("Enter plural suffix (nothing for default):")], - [""]) + [""], + ) if ok: if data[0]: templateText = '|pluralize:"{0}"'.format(data[0]) else: - templateText = '|pluralize' + templateText = "|pluralize" elif tag == "pprint": - templateText = '|pprint' + templateText = "|pprint" elif tag == "random": - templateText = '|random' + templateText = "|random" elif tag == "removetags": data, ok = DjangoTagInputDialog.getText( None, self.tr("Remove HTML Tags"), [self.tr("Enter HTML tags to remove (space separated):")], - ["b span"]) + ["b span"], + ) if ok: templateText = '|removetags:"{0}"'.format(data[0]) elif tag == "rjust": @@ -1170,422 +1373,472 @@ None, self.tr("Right-align Value"), self.tr("Enter width of the output:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: templateText = '|rjust:"{0}"'.format(width) elif tag == "safe": - templateText = '|safe' + templateText = "|safe" elif tag == "safeseq": - templateText = '|safeseq' + templateText = "|safeseq" elif tag == "slice": data, ok = DjangoTagInputDialog.getText( None, self.tr("Extract slice of a list"), [self.tr("Enter Python like slice expression:")], - ["1:5"]) + ["1:5"], + ) if ok: templateText = '|slice:"{0}"'.format(data[0]) elif tag == "slugify": - templateText = '|slugify' + templateText = "|slugify" elif tag == "stringformat": data, ok = DjangoTagInputDialog.getText( None, self.tr("Perform String Formatting"), [self.tr("Enter Python like string format:")], - [""]) + [""], + ) if ok: templateText = '|stringformat:"{0}"'.format(data[0]) elif tag == "striptags": - templateText = '|striptags' + templateText = "|striptags" elif tag == "time": time, ok = QInputDialog.getItem( None, self.tr("Format Date"), self.tr("Enter date format:"), ["TIME_FORMAT"], - 0, True) + 0, + True, + ) if ok: if time: templateText = '|time:"{0}"'.format(time) else: - templateText = '|time' + templateText = "|time" elif tag == "timesince": data[0], ok = DjangoTagInputDialog.getText( None, self.tr("Time Since"), [self.tr("Enter variable containing time reference:")], - ["comment_date"]) + ["comment_date"], + ) if ok: if data[0]: - templateText = '|timesince:{0}'.format(data[0]) + templateText = "|timesince:{0}".format(data[0]) else: - templateText = '|timesince' + templateText = "|timesince" elif tag == "timeuntil": data[0], ok = DjangoTagInputDialog.getText( None, self.tr("Time Until"), [self.tr("Enter variable containing time reference:")], - ["from_date"]) + ["from_date"], + ) if ok: if data[0]: - templateText = '|timeuntil:{0}'.format(data[0]) + templateText = "|timeuntil:{0}".format(data[0]) else: - templateText = '|timeuntil' + templateText = "|timeuntil" elif tag == "title": - templateText = '|title' + templateText = "|title" elif tag == "truncatechars": characters, ok = QInputDialog.getInt( None, self.tr("Truncate String"), self.tr("Enter number of characters:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: - templateText = '|truncatechars:{0}'.format(characters) + templateText = "|truncatechars:{0}".format(characters) elif tag == "truncatewords": words, ok = QInputDialog.getInt( None, self.tr("Truncate String"), self.tr("Enter number of words:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: - templateText = '|truncatewords:{0}'.format(words) + templateText = "|truncatewords:{0}".format(words) elif tag == "truncatewords_html": words, ok = QInputDialog.getInt( None, self.tr("Truncate String"), self.tr("Enter number of words:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: - templateText = '|truncatewords_html:{0}'.format(words) + templateText = "|truncatewords_html:{0}".format(words) elif tag == "unordered_list": - templateText = '|unordered_list' + templateText = "|unordered_list" elif tag == "upper": - templateText = '|upper' + templateText = "|upper" elif tag == "urlencode": - templateText = '|urlencode' + templateText = "|urlencode" elif tag == "urlize": - templateText = '|urlize' + templateText = "|urlize" elif tag == "urlizetrunc": characters, ok = QInputDialog.getInt( None, self.tr("Convert URLs as clickable links and truncate"), self.tr("Enter number of characters:"), - 10, 1, 199, 1) + 10, + 1, + 199, + 1, + ) if ok: - templateText = '|urlizetrunc:{0}'.format(characters) + templateText = "|urlizetrunc:{0}".format(characters) elif tag == "wordcount": - templateText = '|wordcount' + templateText = "|wordcount" elif tag == "wordwrap": characters, ok = QInputDialog.getInt( None, self.tr("Wrap words"), self.tr("Enter number of characters:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: - templateText = '|wordwrap:{0}'.format(characters) + templateText = "|wordwrap:{0}".format(characters) elif tag == "yesno": data, ok = DjangoTagInputDialog.getText( None, self.tr("Map True, False and None"), [self.tr("Enter mapping (comma separated):")], - ["yeah,no,maybe"]) + ["yeah,no,maybe"], + ) if ok: if data[0]: templateText = '|yesno:"{0}"'.format(data[0]) else: - templateText = '|yesno' - + templateText = "|yesno" + #################################################### ## Humanize Template Tags ## #################################################### - + elif tag == "loadhumanize": - templateText = '{% load humanize %}' + templateText = "{% load humanize %}" elif tag == "apnumber": - templateText = '|apnumber' + templateText = "|apnumber" elif tag == "intcomma": - templateText = '|intcomma' + templateText = "|intcomma" elif tag == "intword": - templateText = '|intword' + templateText = "|intword" elif tag == "naturalday": - templateText = '|naturalday' + templateText = "|naturalday" elif tag == "naturaltime": - templateText = '|naturaltime' + templateText = "|naturaltime" elif tag == "ordinal": - templateText = '|ordinal' - + templateText = "|ordinal" + #################################################### ## Web Design Template Tags ## #################################################### - + elif tag == "loadweb": - templateText = '{% load webdesign %}' + templateText = "{% load webdesign %}" elif tag == "lorem": from .LoremTagInputDialog import LoremTagInputDialog + dlg = LoremTagInputDialog() if dlg.exec() == QDialog.DialogCode.Accepted: templateText = "{{% {0} %}}".format(dlg.getTag()) - + #################################################### ## Static Template Tags ## #################################################### - + elif tag == "loadstatic": - templateText = '{% load static %}' + templateText = "{% load static %}" elif tag == "staticfile": data, ok = DjangoTagInputDialog.getText( None, self.tr("Link to static file"), [self.tr("Enter relative path of static file:")], - ["images/hi.jpg"]) + ["images/hi.jpg"], + ) if ok: templateText = '{{% static "{0}" %}}'.format(data[0]) elif tag == "staticvariable": data, ok = DjangoTagInputDialog.getText( None, self.tr("Link to static file"), - [self.tr("Enter variable containing relative path of" - " static file:")], - ["user_stylesheet"]) + [self.tr("Enter variable containing relative path of" " static file:")], + ["user_stylesheet"], + ) if ok: - templateText = '{{% static {0} %}}'.format(data[0]) + templateText = "{{% static {0} %}}".format(data[0]) elif tag == "get_static_prefix": - templateText = '{% get_static_prefix %}' + templateText = "{% get_static_prefix %}" elif tag == "get_media_prefix": - templateText = '{% get_media_prefix %}' - + templateText = "{% get_media_prefix %}" + #################################################### ## Comments ## #################################################### - + elif tag in ("comment", "multilinecommentselect"): - templateText = "{{% comment %}} {0} {{% endcomment %}}".format( - selectedText) + templateText = "{{% comment %}} {0} {{% endcomment %}}".format(selectedText) replace = True elif tag == "singlelinecommentselect": - templateText = '{{# {0} #}}'.format(selectedText) + templateText = "{{# {0} #}}".format(selectedText) replace = True elif tag == "singlelinecommentdialog": data, ok = DjangoTagInputDialog.getText( - None, - self.tr("Single Line Comment"), - [self.tr("Enter comment:")], - [""]) + None, self.tr("Single Line Comment"), [self.tr("Enter comment:")], [""] + ) if ok: - templateText = '{{# {0} #}}'.format(data[0]) + templateText = "{{# {0} #}}".format(data[0]) elif tag == "multilinecommentdialog": from .MultiLineInputDialog import MultiLineInputDialog + comment, ok = MultiLineInputDialog.getText( - None, self.tr("Multi Line Comment"), - self.tr("Enter comment:"), "") + None, self.tr("Multi Line Comment"), self.tr("Enter comment:"), "" + ) if ok: - templateText = '{{% comment %}} {0} {{% endcomment %}}'.format( - comment) + templateText = "{{% comment %}} {0} {{% endcomment %}}".format(comment) elif tag == "singlelinecommentclipboard": - templateText = '{{# {0} #}}'.format( - QApplication.clipboard().text().strip()) + templateText = "{{# {0} #}}".format(QApplication.clipboard().text().strip()) elif tag == "multilinecommentclipboard": - templateText = '{{% comment %}} {0} {{% endcomment %}}'.format( - QApplication.clipboard().text().strip()) + templateText = "{{% comment %}} {0} {{% endcomment %}}".format( + QApplication.clipboard().text().strip() + ) elif tag == "multilinecommentfile": filename = EricFileDialog.getOpenFileName( None, self.tr("Comment File"), Utilities.getHomeDir(), - self.tr("All Files (*)")) + self.tr("All Files (*)"), + ) if filename: try: with open(filename, "r", encoding="utf-8") as f: comment = f.read() - templateText = ( - '{{% comment %}} {0} {{% endcomment %}}'.format( - comment)) - except (IOError, OSError) as err: + templateText = "{{% comment %}} {0} {{% endcomment %}}".format( + comment + ) + except OSError as err: EricMessageBox.critical( None, self.tr("Comment File"), - self.tr("""<p>The file <b>{0}</b> could not be""" - """ read.</p><p>Reason: {1}</p>""").format( - str(err))) + self.tr( + """<p>The file <b>{0}</b> could not be""" + """ read.</p><p>Reason: {1}</p>""" + ).format(str(err)), + ) elif tag == "singlelinecommentdatetime": - templateText = '{{# {0} by {1} #}}'.format( - datetime.datetime.now().isoformat().split(), - Utilities.getUserName()) + templateText = "{{# {0} by {1} #}}".format( + datetime.datetime.now().isoformat().split(), Utilities.getUserName() + ) elif tag == "htmlcomment": - templateText = '<!-- {0} -->'.format(selectedText) + templateText = "<!-- {0} -->".format(selectedText) replace = True elif tag == "iecomment": from .IeCommentDialog import IeCommentDialog + tag, ok = IeCommentDialog.getTag(selectedText) if ok: - templateText = '<!--{0}-->'.format(tag) + templateText = "<!--{0}-->".format(tag) replace = True - + #################################################### ## Internationalization ## #################################################### - + elif tag == "loadi18n": - templateText = '{% load i18n %}' + templateText = "{% load i18n %}" ## Tags ## elif tag == "trans": - if ' ' in selectedText: + if " " in selectedText: selectedText = '"{0}"'.format(selectedText) - templateText = '{{% trans {0} %}}'.format(selectedText) + templateText = "{{% trans {0} %}}".format(selectedText) replace = True elif tag == "trans..as": data, ok = DjangoTagInputDialog.getText( None, self.tr("Translate String into Variable"), [self.tr("Enter variable receiving translation:")], - ["translation"]) + ["translation"], + ) if ok: templateText = '{{% trans "{0}" as {1} %}}'.format( - selectedText, data[0]) + selectedText, data[0] + ) replace = True elif tag == "blocktrans": - templateText = '{{% blocktrans %}}{0}{{% endblocktrans %}}'.format( - selectedText) + templateText = "{{% blocktrans %}}{0}{{% endblocktrans %}}".format( + selectedText + ) replace = True elif tag == "blocktrans..with": data, ok = DjangoTagInputDialog.getText( None, self.tr("Translate Block with Attributes"), - [self.tr("Enter attribute binding expressions" - " (space separated):")], - ["myvar1=value1 myvar2=value2"]) + [self.tr("Enter attribute binding expressions" " (space separated):")], + ["myvar1=value1 myvar2=value2"], + ) if ok: templateText = ( - '{{% blocktrans with {0} %}}{1}{{% endblocktrans %}}' - .format(data[0], selectedText)) + "{{% blocktrans with {0} %}}{1}{{% endblocktrans %}}".format( + data[0], selectedText + ) + ) replace = True elif tag == "plural": - templateText = '{{% plural %}} {0}'.format(selectedText) + templateText = "{{% plural %}} {0}".format(selectedText) replace = True elif tag == "language": data, ok = DjangoTagInputDialog.getText( - None, - self.tr("Switch language"), - [self.tr("Enter language:")], - ["en"]) + None, self.tr("Switch language"), [self.tr("Enter language:")], ["en"] + ) if ok: - templateText = ( - "{{% language '{0}' %}}{1}{{% endlanguage %}}" - .format(data[0], selectedText)) + templateText = "{{% language '{0}' %}}{1}{{% endlanguage %}}".format( + data[0], selectedText + ) replace = True elif tag == "get_current_language": - templateText = '{% get_current_language as LANGUAGE_CODE %}' + templateText = "{% get_current_language as LANGUAGE_CODE %}" elif tag == "get_available_languages": - templateText = '{% get_available_languages as LANGUAGES %}' + templateText = "{% get_available_languages as LANGUAGES %}" elif tag == "get_current_language_bidi": - templateText = '{% get_current_language_bidi as LANGUAGE_BIDI %}' + templateText = "{% get_current_language_bidi as LANGUAGE_BIDI %}" elif tag == "get_language_info": data, ok = DjangoTagInputDialog.getText( None, self.tr("Language Information"), - [self.tr("Enter language string or variable (empty for" - " LANGUAGE_CODE):")], - ['"en"']) + [ + self.tr( + "Enter language string or variable (empty for" + " LANGUAGE_CODE):" + ) + ], + ['"en"'], + ) if ok: if data[0]: + templateText = '{{% get_language_info for "{0}" as lang %}}'.format( + data[0] + ) + else: templateText = ( - '{{% get_language_info for "{0}" as lang %}}' - .format(data[0])) - else: - templateText = ("{% get_language_info for LANGUAGE_CODE" - " as lang %}") + "{% get_language_info for LANGUAGE_CODE" " as lang %}" + ) elif tag == "get_language_info_list": data, ok = DjangoTagInputDialog.getText( None, self.tr("Language Information for a list of languages"), - [self.tr("Enter language list variable (empty for" - " LANGUAGES):")], - ["available_languages"]) + [self.tr("Enter language list variable (empty for" " LANGUAGES):")], + ["available_languages"], + ) if ok: if data[0]: templateText = ( - '{{% get_language_info_list for {0} as langs %}}' - .format(data[0])) + "{{% get_language_info_list for {0} as langs %}}".format( + data[0] + ) + ) else: - templateText = ("{% get_language_info_list for LANGUAGES" - " as langs %}") + templateText = ( + "{% get_language_info_list for LANGUAGES" " as langs %}" + ) ## Filters ## elif tag == "language_name": - templateText = '|language_name' + templateText = "|language_name" elif tag == "language_name_local": - templateText = '|language_name_local' + templateText = "|language_name_local" elif tag == "bidi": - templateText = '|bidi' - + templateText = "|bidi" + #################################################### ## Localization ## #################################################### - + elif tag == "loadl10n": - templateText = '{% load l10n %}' + templateText = "{% load l10n %}" ## Tags ## elif tag == "localize_on": - templateText = '{{% localize on %}}{0}{{% endlocalize %}}'.format( - selectedText) + templateText = "{{% localize on %}}{0}{{% endlocalize %}}".format( + selectedText + ) replace = True elif tag == "localize_off": - templateText = '{{% localize off %}}{0}{{% endlocalize %}}'.format( - selectedText) + templateText = "{{% localize off %}}{0}{{% endlocalize %}}".format( + selectedText + ) replace = True ## Filters ## elif tag == "localize": - templateText = '|localize' + templateText = "|localize" elif tag == "unlocalize": - templateText = '|unlocalize' - + templateText = "|unlocalize" + #################################################### ## Timezone ## #################################################### - + elif tag == "loadtz": - templateText = '{% load tz %}' + templateText = "{% load tz %}" ## Tags ## elif tag == "localtime_on": - templateText = ( - '{{% localtime on %}}{0}{{% endlocaltime %}}'.format( - selectedText)) + templateText = "{{% localtime on %}}{0}{{% endlocaltime %}}".format( + selectedText + ) replace = True elif tag == "localtime_off": - templateText = ( - '{{% localtime off %}}{0}{{% endlocaltime %}}'.format( - selectedText)) + templateText = "{{% localtime off %}}{0}{{% endlocaltime %}}".format( + selectedText + ) replace = True elif tag == "timezone_set": from .TimezoneSelectionDialog import TimezoneSelectionDialog + timezone, ok = TimezoneSelectionDialog.getTimezone() if ok: - templateText = ( - '{{% timezone "{0}" %}}{1}{{% endtimezone %}}'.format( - timezone, selectedText)) + templateText = '{{% timezone "{0}" %}}{1}{{% endtimezone %}}'.format( + timezone, selectedText + ) replace = True elif tag == "timezone_unset": - templateText = ( - '{{% timezone None %}}{0}{{% endlocaltime %}}'.format( - selectedText)) + templateText = "{{% timezone None %}}{0}{{% endlocaltime %}}".format( + selectedText + ) replace = True elif tag == "get_current_timezone": - templateText = '{% get_current_timezone as TIME_ZONE %}' + templateText = "{% get_current_timezone as TIME_ZONE %}" ## Filters ## elif tag == "localtime": - templateText = '|localtime' + templateText = "|localtime" elif tag == "utc": - templateText = '|utc' + templateText = "|utc" elif tag == "timezone": from .TimezoneSelectionDialog import TimezoneSelectionDialog + timezone, ok = TimezoneSelectionDialog.getTimezone() if ok: templateText = '|timezone:"{0}"'.format(timezone) - + #################################################### ## Fallback: return just the tag name ## #################################################### - + else: templateText = tag - + return templateText, replace