ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py

branch
eric7
changeset 72
529f1c17c93e
parent 71
fc1ab84c242f
child 74
a25b858e18a7
equal deleted inserted replaced
71:fc1ab84c242f 72:529f1c17c93e
858 selectedText 858 selectedText
859 ) 859 )
860 replace = True 860 replace = True
861 elif tag == "block": 861 elif tag == "block":
862 data, ok = DjangoTagInputDialog.getText( 862 data, ok = DjangoTagInputDialog.getText(
863 None, 863 self.__ui,
864 self.tr("Named Block"), 864 self.tr("Named Block"),
865 [self.tr("Enter block name:")], 865 [self.tr("Enter block name:")],
866 ["block_name"], 866 ["block_name"],
867 ) 867 )
868 if ok: 868 if ok:
872 replace = True 872 replace = True
873 elif tag == "csrf_token": 873 elif tag == "csrf_token":
874 templateText = "{% csrf_token %}" 874 templateText = "{% csrf_token %}"
875 elif tag == "cycle": 875 elif tag == "cycle":
876 data, ok = DjangoTagInputDialog.getText( 876 data, ok = DjangoTagInputDialog.getText(
877 None, 877 self.__ui,
878 self.tr("Cycle Variables"), 878 self.tr("Cycle Variables"),
879 [self.tr("Enter items to cycle, space separated")], 879 [self.tr("Enter items to cycle, space separated")],
880 ["item1 item2 item3"], 880 ["item1 item2 item3"],
881 ) 881 )
882 if ok: 882 if ok:
883 templateText = "{{% cycle {0} %}}".format(data[0]) 883 templateText = "{{% cycle {0} %}}".format(data[0])
884 elif tag == "debug": 884 elif tag == "debug":
885 templateText = "{% debug %}" 885 templateText = "{% debug %}"
886 elif tag == "extendsvariable": 886 elif tag == "extendsvariable":
887 data, ok = DjangoTagInputDialog.getText( 887 data, ok = DjangoTagInputDialog.getText(
888 None, 888 self.__ui,
889 self.tr("Extends"), 889 self.tr("Extends"),
890 [self.tr("Enter variable name:")], 890 [self.tr("Enter variable name:")],
891 ["variable"], 891 ["variable"],
892 ) 892 )
893 if ok: 893 if ok:
894 templateText = "{{% extends {0} %}}".format(data[0]) 894 templateText = "{{% extends {0} %}}".format(data[0])
895 elif tag == "extendsfile": 895 elif tag == "extendsfile":
896 data, ok = DjangoTagInputDialog.getText( 896 data, ok = DjangoTagInputDialog.getText(
897 None, 897 self.__ui,
898 self.tr("Extends"), 898 self.tr("Extends"),
899 [self.tr("Enter parent file name:")], 899 [self.tr("Enter parent file name:")],
900 ["base.html"], 900 ["base.html"],
901 ) 901 )
902 if ok: 902 if ok:
903 templateText = '{{% extends "{0}" %}}'.format(data[0]) 903 templateText = '{{% extends "{0}" %}}'.format(data[0])
904 elif tag == "filter": 904 elif tag == "filter":
905 data, ok = DjangoTagInputDialog.getText( 905 data, ok = DjangoTagInputDialog.getText(
906 None, 906 self.__ui,
907 self.tr("Tag Filters"), 907 self.tr("Tag Filters"),
908 [self.tr("Multiple filters with arguments, pipes separated:")], 908 [self.tr("Multiple filters with arguments, pipes separated:")],
909 ["lower|safe"], 909 ["lower|safe"],
910 ) 910 )
911 if ok: 911 if ok:
913 data[0], selectedText 913 data[0], selectedText
914 ) 914 )
915 replace = True 915 replace = True
916 elif tag == "firstof": 916 elif tag == "firstof":
917 data, ok = DjangoTagInputDialog.getText( 917 data, ok = DjangoTagInputDialog.getText(
918 None, 918 self.__ui,
919 self.tr("First Of"), 919 self.tr("First Of"),
920 [ 920 [
921 self.tr("Enter multiple variables, space separated:"), 921 self.tr("Enter multiple variables, space separated:"),
922 self.tr("Enter fallback value:"), 922 self.tr("Enter fallback value:"),
923 ], 923 ],
929 " {2} {{% endfilter %}}".format(data[0], data[1], selectedText) 929 " {2} {{% endfilter %}}".format(data[0], data[1], selectedText)
930 ) 930 )
931 replace = True 931 replace = True
932 elif tag == "for": 932 elif tag == "for":
933 data, ok = DjangoTagInputDialog.getText( 933 data, ok = DjangoTagInputDialog.getText(
934 None, 934 self.__ui,
935 self.tr("For Loop"), 935 self.tr("For Loop"),
936 [ 936 [
937 self.tr("Enter variable to use for iteration:"), 937 self.tr("Enter variable to use for iteration:"),
938 self.tr("Enter sequence to iterate over:"), 938 self.tr("Enter sequence to iterate over:"),
939 ], 939 ],
944 data[0], data[1], selectedText 944 data[0], data[1], selectedText
945 ) 945 )
946 replace = True 946 replace = True
947 elif tag == "for...empty": 947 elif tag == "for...empty":
948 data, ok = DjangoTagInputDialog.getText( 948 data, ok = DjangoTagInputDialog.getText(
949 None, 949 self.__ui,
950 self.tr("For Loop"), 950 self.tr("For Loop"),
951 [ 951 [
952 self.tr("Enter variable to use for iteration:"), 952 self.tr("Enter variable to use for iteration:"),
953 self.tr("Enter sequence to iterate over:"), 953 self.tr("Enter sequence to iterate over:"),
954 self.tr("Enter output to use if loop is empty:"), 954 self.tr("Enter output to use if loop is empty:"),
960 "{{% for {0} in {1} %}} {2} {{% empty %}} {3}" 960 "{{% for {0} in {1} %}} {2} {{% empty %}} {3}"
961 " {{% endfor %}}".format(data[0], data[1], selectedText, data[2]) 961 " {{% endfor %}}".format(data[0], data[1], selectedText, data[2])
962 ) 962 )
963 replace = True 963 replace = True
964 elif tag == "if": 964 elif tag == "if":
965 dlg = IfTagInputDialog() 965 dlg = IfTagInputDialog(parent=self.__ui)
966 if dlg.exec() == QDialog.DialogCode.Accepted: 966 if dlg.exec() == QDialog.DialogCode.Accepted:
967 templateText = dlg.getTag() 967 templateText = dlg.getTag()
968 elif tag == "ifchanged": 968 elif tag == "ifchanged":
969 data, ok = DjangoTagInputDialog.getText( 969 data, ok = DjangoTagInputDialog.getText(
970 None, 970 self.__ui,
971 self.tr("Check Variables for Changes"), 971 self.tr("Check Variables for Changes"),
972 [self.tr("Enter variables to check (space separated):")], 972 [self.tr("Enter variables to check (space separated):")],
973 ["variable1 variable2"], 973 ["variable1 variable2"],
974 ) 974 )
975 if ok: 975 if ok:
977 data[0], selectedText 977 data[0], selectedText
978 ) 978 )
979 replace = True 979 replace = True
980 elif tag == "ifequal": 980 elif tag == "ifequal":
981 data, ok = DjangoTagInputDialog.getText( 981 data, ok = DjangoTagInputDialog.getText(
982 None, 982 self.__ui,
983 self.tr("Check If Equal"), 983 self.tr("Check If Equal"),
984 [ 984 [
985 self.tr("Enter first variable or string to check:"), 985 self.tr("Enter first variable or string to check:"),
986 self.tr("Enter second variable or string to check:"), 986 self.tr("Enter second variable or string to check:"),
987 ], 987 ],
992 data[0], data[1], selectedText 992 data[0], data[1], selectedText
993 ) 993 )
994 replace = True 994 replace = True
995 elif tag == "ifnotequal": 995 elif tag == "ifnotequal":
996 data, ok = DjangoTagInputDialog.getText( 996 data, ok = DjangoTagInputDialog.getText(
997 None, 997 self.__ui,
998 self.tr("Check If Not Equal"), 998 self.tr("Check If Not Equal"),
999 [ 999 [
1000 self.tr("Enter first variable or string to check:"), 1000 self.tr("Enter first variable or string to check:"),
1001 self.tr("Enter second variable or string to check:"), 1001 self.tr("Enter second variable or string to check:"),
1002 ], 1002 ],
1009 ) 1009 )
1010 ) 1010 )
1011 replace = True 1011 replace = True
1012 elif tag == "includevariable": 1012 elif tag == "includevariable":
1013 data, ok = DjangoTagInputDialog.getText( 1013 data, ok = DjangoTagInputDialog.getText(
1014 None, 1014 self.__ui,
1015 self.tr("Include"), 1015 self.tr("Include"),
1016 [self.tr("Enter variable name:")], 1016 [self.tr("Enter variable name:")],
1017 ["variable"], 1017 ["variable"],
1018 ) 1018 )
1019 if ok: 1019 if ok:
1020 templateText = "{{% include {0} %}}".format(data[0]) 1020 templateText = "{{% include {0} %}}".format(data[0])
1021 elif tag == "includefile": 1021 elif tag == "includefile":
1022 data, ok = DjangoTagInputDialog.getText( 1022 data, ok = DjangoTagInputDialog.getText(
1023 None, self.tr("Include"), [self.tr("Enter file name:")], ["other.html"] 1023 self.__ui,
1024 self.tr("Include"),
1025 [self.tr("Enter file name:")],
1026 ["other.html"],
1024 ) 1027 )
1025 if ok: 1028 if ok:
1026 templateText = '{{% include "{0}" %}}'.format(data[0]) 1029 templateText = '{{% include "{0}" %}}'.format(data[0])
1027 elif tag == "load": 1030 elif tag == "load":
1028 data, ok = DjangoTagInputDialog.getText( 1031 data, ok = DjangoTagInputDialog.getText(
1029 None, 1032 self.__ui,
1030 self.tr("Load"), 1033 self.tr("Load"),
1031 [self.tr("Enter template tag set to load:")], 1034 [self.tr("Enter template tag set to load:")],
1032 ["foo bar"], 1035 ["foo bar"],
1033 ) 1036 )
1034 if ok: 1037 if ok:
1049 ) 1052 )
1050 if ok: 1053 if ok:
1051 templateText = '{{% now "{0}" %}}'.format(dateformat) 1054 templateText = '{{% now "{0}" %}}'.format(dateformat)
1052 elif tag == "regroup": 1055 elif tag == "regroup":
1053 data, ok = DjangoTagInputDialog.getText( 1056 data, ok = DjangoTagInputDialog.getText(
1054 None, 1057 self.__ui,
1055 self.tr("Regroup List"), 1058 self.tr("Regroup List"),
1056 [ 1059 [
1057 self.tr("List Variable:"), 1060 self.tr("List Variable:"),
1058 self.tr("Common Attribute:"), 1061 self.tr("Common Attribute:"),
1059 self.tr("Name of resulting list:"), 1062 self.tr("Name of resulting list:"),
1069 selectedText 1072 selectedText
1070 ) 1073 )
1071 replace = True 1074 replace = True
1072 elif tag == "ssi": 1075 elif tag == "ssi":
1073 data, ok = DjangoTagInputDialog.getText( 1076 data, ok = DjangoTagInputDialog.getText(
1074 None, 1077 self.__ui,
1075 self.tr("SSI"), 1078 self.tr("SSI"),
1076 [self.tr("Full path to template:")], 1079 [self.tr("Full path to template:")],
1077 ["/tmp/ssi_template.html"], 1080 ["/tmp/ssi_template.html"],
1078 ) # secok 1081 ) # secok
1079 if ok: 1082 if ok:
1099 " close{0} %}}".format(templatetag, selectedText) 1102 " close{0} %}}".format(templatetag, selectedText)
1100 ) 1103 )
1101 replace = True 1104 replace = True
1102 elif tag == "url": 1105 elif tag == "url":
1103 data, ok = DjangoTagInputDialog.getText( 1106 data, ok = DjangoTagInputDialog.getText(
1104 None, 1107 self.__ui,
1105 self.tr("URL"), 1108 self.tr("URL"),
1106 [ 1109 [
1107 self.tr("View method name:"), 1110 self.tr("View method name:"),
1108 self.tr("Optional arguments (space separated):"), 1111 self.tr("Optional arguments (space separated):"),
1109 ], 1112 ],
1113 if data[1]: 1116 if data[1]:
1114 data[1] = " " + data[1] 1117 data[1] = " " + data[1]
1115 templateText = '{{% url "{0}"{1} %}}'.format(data[0], data[1]) 1118 templateText = '{{% url "{0}"{1} %}}'.format(data[0], data[1])
1116 elif tag == "urlas": 1119 elif tag == "urlas":
1117 data, ok = DjangoTagInputDialog.getText( 1120 data, ok = DjangoTagInputDialog.getText(
1118 None, 1121 self.__ui,
1119 self.tr("URL...as"), 1122 self.tr("URL...as"),
1120 [ 1123 [
1121 self.tr("View method name:"), 1124 self.tr("View method name:"),
1122 self.tr("Optional arguments (space separated):"), 1125 self.tr("Optional arguments (space separated):"),
1123 self.tr("URL name:"), 1126 self.tr("URL name:"),
1135 selectedText 1138 selectedText
1136 ) 1139 )
1137 replace = True 1140 replace = True
1138 elif tag == "widthratio": 1141 elif tag == "widthratio":
1139 data, ok = DjangoTagInputDialog.getText( 1142 data, ok = DjangoTagInputDialog.getText(
1140 None, 1143 self.__ui,
1141 self.tr("Width Ratio"), 1144 self.tr("Width Ratio"),
1142 [ 1145 [
1143 self.tr("Variable:"), 1146 self.tr("Variable:"),
1144 self.tr("Maximum Value:"), 1147 self.tr("Maximum Value:"),
1145 self.tr("Maximum Width:"), 1148 self.tr("Maximum Width:"),
1150 templateText = "{{% widthratio {0} {1} {2} %}}".format( 1153 templateText = "{{% widthratio {0} {1} {2} %}}".format(
1151 data[0], data[1], data[2] 1154 data[0], data[1], data[2]
1152 ) 1155 )
1153 elif tag == "with": 1156 elif tag == "with":
1154 data, ok = DjangoTagInputDialog.getText( 1157 data, ok = DjangoTagInputDialog.getText(
1155 None, 1158 self.__ui,
1156 self.tr("Cache Variables"), 1159 self.tr("Cache Variables"),
1157 [self.tr("Variables to cache as key=value (space separated):")], 1160 [self.tr("Variables to cache as key=value (space separated):")],
1158 ["variable1=foo.bar variable2=bar.baz"], 1161 ["variable1=foo.bar variable2=bar.baz"],
1159 ) 1162 )
1160 if ok: 1163 if ok:
1166 ## Template Filters ## 1169 ## Template Filters ##
1167 #################################################### 1170 ####################################################
1168 1171
1169 elif tag == "add": 1172 elif tag == "add":
1170 data, ok = DjangoTagInputDialog.getText( 1173 data, ok = DjangoTagInputDialog.getText(
1171 None, 1174 self.__ui,
1172 self.tr("Add Variable or String"), 1175 self.tr("Add Variable or String"),
1173 [self.tr("Variables or String to add:")], 1176 [self.tr("Variables or String to add:")],
1174 ["variable"], 1177 ["variable"],
1175 ) 1178 )
1176 if ok: 1179 if ok:
1191 ) 1194 )
1192 if ok: 1195 if ok:
1193 templateText = '|center:"{0}"'.format(width) 1196 templateText = '|center:"{0}"'.format(width)
1194 elif tag == "cut": 1197 elif tag == "cut":
1195 data, ok = DjangoTagInputDialog.getText( 1198 data, ok = DjangoTagInputDialog.getText(
1196 None, self.tr("Cut Characters"), [self.tr("Characters to cut:")], [" "] 1199 self.__ui,
1200 self.tr("Cut Characters"),
1201 [self.tr("Characters to cut:")],
1202 [" "],
1197 ) 1203 )
1198 if ok: 1204 if ok:
1199 templateText = '|cut:"{0}"'.format(data[0]) 1205 templateText = '|cut:"{0}"'.format(data[0])
1200 elif tag == "date": 1206 elif tag == "date":
1201 date, ok = QInputDialog.getItem( 1207 date, ok = QInputDialog.getItem(
1216 templateText = '|date:"{0}"'.format(date) 1222 templateText = '|date:"{0}"'.format(date)
1217 else: 1223 else:
1218 templateText = "|date" 1224 templateText = "|date"
1219 elif tag == "default": 1225 elif tag == "default":
1220 data, ok = DjangoTagInputDialog.getText( 1226 data, ok = DjangoTagInputDialog.getText(
1221 None, 1227 self.__ui,
1222 self.tr("Default Value if False"), 1228 self.tr("Default Value if False"),
1223 [self.tr("Enter default value if result is False:")], 1229 [self.tr("Enter default value if result is False:")],
1224 ["nothing"], 1230 ["nothing"],
1225 ) 1231 )
1226 if ok: 1232 if ok:
1227 templateText = '|default:"{0}"'.format(data[0]) 1233 templateText = '|default:"{0}"'.format(data[0])
1228 elif tag == "default_if_none": 1234 elif tag == "default_if_none":
1229 data, ok = DjangoTagInputDialog.getText( 1235 data, ok = DjangoTagInputDialog.getText(
1230 None, 1236 self.__ui,
1231 self.tr("Default Value if None"), 1237 self.tr("Default Value if None"),
1232 [self.tr("Enter default value if result is None:")], 1238 [self.tr("Enter default value if result is None:")],
1233 ["nothing"], 1239 ["nothing"],
1234 ) 1240 )
1235 if ok: 1241 if ok:
1236 templateText = '|default:"{0}"'.format(data[0]) 1242 templateText = '|default:"{0}"'.format(data[0])
1237 elif tag == "dictsort": 1243 elif tag == "dictsort":
1238 data, ok = DjangoTagInputDialog.getText( 1244 data, ok = DjangoTagInputDialog.getText(
1239 None, 1245 self.__ui,
1240 self.tr("Sort Dictionaries"), 1246 self.tr("Sort Dictionaries"),
1241 [self.tr("Enter key to sort on:")], 1247 [self.tr("Enter key to sort on:")],
1242 ["key"], 1248 ["key"],
1243 ) 1249 )
1244 if ok: 1250 if ok:
1245 templateText = '|dictsort:"{0}"'.format(data[0]) 1251 templateText = '|dictsort:"{0}"'.format(data[0])
1246 elif tag == "dictsortreversed": 1252 elif tag == "dictsortreversed":
1247 data, ok = DjangoTagInputDialog.getText( 1253 data, ok = DjangoTagInputDialog.getText(
1248 None, 1254 self.__ui,
1249 self.tr("Sort Dictionaries reversed"), 1255 self.tr("Sort Dictionaries reversed"),
1250 [self.tr("Enter key to sort on:")], 1256 [self.tr("Enter key to sort on:")],
1251 ["key"], 1257 ["key"],
1252 ) 1258 )
1253 if ok: 1259 if ok:
1302 templateText = '|get_digit:"{0}"'.format(digit) 1308 templateText = '|get_digit:"{0}"'.format(digit)
1303 elif tag == "iriencode": 1309 elif tag == "iriencode":
1304 templateText = "|iriencode" 1310 templateText = "|iriencode"
1305 elif tag == "join": 1311 elif tag == "join":
1306 data, ok = DjangoTagInputDialog.getText( 1312 data, ok = DjangoTagInputDialog.getText(
1307 None, 1313 self.__ui,
1308 self.tr("Join List"), 1314 self.tr("Join List"),
1309 [self.tr("Enter string to join by:")], 1315 [self.tr("Enter string to join by:")],
1310 ["//"], 1316 ["//"],
1311 ) 1317 )
1312 if ok: 1318 if ok:
1351 templateText = "|make_list" 1357 templateText = "|make_list"
1352 elif tag == "phone2numeric": 1358 elif tag == "phone2numeric":
1353 templateText = "|phone2numeric" 1359 templateText = "|phone2numeric"
1354 elif tag == "pluralize": 1360 elif tag == "pluralize":
1355 data, ok = DjangoTagInputDialog.getText( 1361 data, ok = DjangoTagInputDialog.getText(
1356 None, 1362 self.__ui,
1357 self.tr("Plural Suffix"), 1363 self.tr("Plural Suffix"),
1358 [self.tr("Enter plural suffix (nothing for default):")], 1364 [self.tr("Enter plural suffix (nothing for default):")],
1359 [""], 1365 [""],
1360 ) 1366 )
1361 if ok: 1367 if ok:
1367 templateText = "|pprint" 1373 templateText = "|pprint"
1368 elif tag == "random": 1374 elif tag == "random":
1369 templateText = "|random" 1375 templateText = "|random"
1370 elif tag == "removetags": 1376 elif tag == "removetags":
1371 data, ok = DjangoTagInputDialog.getText( 1377 data, ok = DjangoTagInputDialog.getText(
1372 None, 1378 self.__ui,
1373 self.tr("Remove HTML Tags"), 1379 self.tr("Remove HTML Tags"),
1374 [self.tr("Enter HTML tags to remove (space separated):")], 1380 [self.tr("Enter HTML tags to remove (space separated):")],
1375 ["b span"], 1381 ["b span"],
1376 ) 1382 )
1377 if ok: 1383 if ok:
1392 templateText = "|safe" 1398 templateText = "|safe"
1393 elif tag == "safeseq": 1399 elif tag == "safeseq":
1394 templateText = "|safeseq" 1400 templateText = "|safeseq"
1395 elif tag == "slice": 1401 elif tag == "slice":
1396 data, ok = DjangoTagInputDialog.getText( 1402 data, ok = DjangoTagInputDialog.getText(
1397 None, 1403 self.__ui,
1398 self.tr("Extract slice of a list"), 1404 self.tr("Extract slice of a list"),
1399 [self.tr("Enter Python like slice expression:")], 1405 [self.tr("Enter Python like slice expression:")],
1400 ["1:5"], 1406 ["1:5"],
1401 ) 1407 )
1402 if ok: 1408 if ok:
1403 templateText = '|slice:"{0}"'.format(data[0]) 1409 templateText = '|slice:"{0}"'.format(data[0])
1404 elif tag == "slugify": 1410 elif tag == "slugify":
1405 templateText = "|slugify" 1411 templateText = "|slugify"
1406 elif tag == "stringformat": 1412 elif tag == "stringformat":
1407 data, ok = DjangoTagInputDialog.getText( 1413 data, ok = DjangoTagInputDialog.getText(
1408 None, 1414 self.__ui,
1409 self.tr("Perform String Formatting"), 1415 self.tr("Perform String Formatting"),
1410 [self.tr("Enter Python like string format:")], 1416 [self.tr("Enter Python like string format:")],
1411 [""], 1417 [""],
1412 ) 1418 )
1413 if ok: 1419 if ok:
1428 templateText = '|time:"{0}"'.format(time) 1434 templateText = '|time:"{0}"'.format(time)
1429 else: 1435 else:
1430 templateText = "|time" 1436 templateText = "|time"
1431 elif tag == "timesince": 1437 elif tag == "timesince":
1432 data[0], ok = DjangoTagInputDialog.getText( 1438 data[0], ok = DjangoTagInputDialog.getText(
1433 None, 1439 self.__ui,
1434 self.tr("Time Since"), 1440 self.tr("Time Since"),
1435 [self.tr("Enter variable containing time reference:")], 1441 [self.tr("Enter variable containing time reference:")],
1436 ["comment_date"], 1442 ["comment_date"],
1437 ) 1443 )
1438 if ok: 1444 if ok:
1440 templateText = "|timesince:{0}".format(data[0]) 1446 templateText = "|timesince:{0}".format(data[0])
1441 else: 1447 else:
1442 templateText = "|timesince" 1448 templateText = "|timesince"
1443 elif tag == "timeuntil": 1449 elif tag == "timeuntil":
1444 data[0], ok = DjangoTagInputDialog.getText( 1450 data[0], ok = DjangoTagInputDialog.getText(
1445 None, 1451 self.__ui,
1446 self.tr("Time Until"), 1452 self.tr("Time Until"),
1447 [self.tr("Enter variable containing time reference:")], 1453 [self.tr("Enter variable containing time reference:")],
1448 ["from_date"], 1454 ["from_date"],
1449 ) 1455 )
1450 if ok: 1456 if ok:
1524 ) 1530 )
1525 if ok: 1531 if ok:
1526 templateText = "|wordwrap:{0}".format(characters) 1532 templateText = "|wordwrap:{0}".format(characters)
1527 elif tag == "yesno": 1533 elif tag == "yesno":
1528 data, ok = DjangoTagInputDialog.getText( 1534 data, ok = DjangoTagInputDialog.getText(
1529 None, 1535 self.__ui,
1530 self.tr("Map True, False and None"), 1536 self.tr("Map True, False and None"),
1531 [self.tr("Enter mapping (comma separated):")], 1537 [self.tr("Enter mapping (comma separated):")],
1532 ["yeah,no,maybe"], 1538 ["yeah,no,maybe"],
1533 ) 1539 )
1534 if ok: 1540 if ok:
1561 #################################################### 1567 ####################################################
1562 1568
1563 elif tag == "loadweb": 1569 elif tag == "loadweb":
1564 templateText = "{% load webdesign %}" 1570 templateText = "{% load webdesign %}"
1565 elif tag == "lorem": 1571 elif tag == "lorem":
1566 dlg = LoremTagInputDialog() 1572 dlg = LoremTagInputDialog(parent=self.__ui)
1567 if dlg.exec() == QDialog.DialogCode.Accepted: 1573 if dlg.exec() == QDialog.DialogCode.Accepted:
1568 templateText = "{{% {0} %}}".format(dlg.getTag()) 1574 templateText = "{{% {0} %}}".format(dlg.getTag())
1569 1575
1570 #################################################### 1576 ####################################################
1571 ## Static Template Tags ## 1577 ## Static Template Tags ##
1573 1579
1574 elif tag == "loadstatic": 1580 elif tag == "loadstatic":
1575 templateText = "{% load static %}" 1581 templateText = "{% load static %}"
1576 elif tag == "staticfile": 1582 elif tag == "staticfile":
1577 data, ok = DjangoTagInputDialog.getText( 1583 data, ok = DjangoTagInputDialog.getText(
1578 None, 1584 self.__ui,
1579 self.tr("Link to static file"), 1585 self.tr("Link to static file"),
1580 [self.tr("Enter relative path of static file:")], 1586 [self.tr("Enter relative path of static file:")],
1581 ["images/hi.jpg"], 1587 ["images/hi.jpg"],
1582 ) 1588 )
1583 if ok: 1589 if ok:
1584 templateText = '{{% static "{0}" %}}'.format(data[0]) 1590 templateText = '{{% static "{0}" %}}'.format(data[0])
1585 elif tag == "staticvariable": 1591 elif tag == "staticvariable":
1586 data, ok = DjangoTagInputDialog.getText( 1592 data, ok = DjangoTagInputDialog.getText(
1587 None, 1593 self.__ui,
1588 self.tr("Link to static file"), 1594 self.tr("Link to static file"),
1589 [self.tr("Enter variable containing relative path of static file:")], 1595 [self.tr("Enter variable containing relative path of static file:")],
1590 ["user_stylesheet"], 1596 ["user_stylesheet"],
1591 ) 1597 )
1592 if ok: 1598 if ok:
1606 elif tag == "singlelinecommentselect": 1612 elif tag == "singlelinecommentselect":
1607 templateText = "{{# {0} #}}".format(selectedText) 1613 templateText = "{{# {0} #}}".format(selectedText)
1608 replace = True 1614 replace = True
1609 elif tag == "singlelinecommentdialog": 1615 elif tag == "singlelinecommentdialog":
1610 data, ok = DjangoTagInputDialog.getText( 1616 data, ok = DjangoTagInputDialog.getText(
1611 None, self.tr("Single Line Comment"), [self.tr("Enter comment:")], [""] 1617 self.__ui,
1618 self.tr("Single Line Comment"),
1619 [self.tr("Enter comment:")],
1620 [""],
1612 ) 1621 )
1613 if ok: 1622 if ok:
1614 templateText = "{{# {0} #}}".format(data[0]) 1623 templateText = "{{# {0} #}}".format(data[0])
1615 elif tag == "multilinecommentdialog": 1624 elif tag == "multilinecommentdialog":
1616 comment, ok = MultiLineInputDialog.getText( 1625 comment, ok = MultiLineInputDialog.getText(
1617 None, self.tr("Multi Line Comment"), self.tr("Enter comment:"), "" 1626 self.__ui, self.tr("Multi Line Comment"), self.tr("Enter comment:"), ""
1618 ) 1627 )
1619 if ok: 1628 if ok:
1620 templateText = "{{% comment %}} {0} {{% endcomment %}}".format(comment) 1629 templateText = "{{% comment %}} {0} {{% endcomment %}}".format(comment)
1621 elif tag == "singlelinecommentclipboard": 1630 elif tag == "singlelinecommentclipboard":
1622 templateText = "{{# {0} #}}".format(QApplication.clipboard().text().strip()) 1631 templateText = "{{# {0} #}}".format(QApplication.clipboard().text().strip())
1653 ) 1662 )
1654 elif tag == "htmlcomment": 1663 elif tag == "htmlcomment":
1655 templateText = "<!-- {0} -->".format(selectedText) 1664 templateText = "<!-- {0} -->".format(selectedText)
1656 replace = True 1665 replace = True
1657 elif tag == "iecomment": 1666 elif tag == "iecomment":
1658 tag, ok = IeCommentDialog.getTag(selectedText) 1667 tag, ok = IeCommentDialog.getTag(selectedText, parent=self.__ui)
1659 if ok: 1668 if ok:
1660 templateText = "<!--{0}-->".format(tag) 1669 templateText = "<!--{0}-->".format(tag)
1661 replace = True 1670 replace = True
1662 1671
1663 #################################################### 1672 ####################################################
1672 selectedText = '"{0}"'.format(selectedText) 1681 selectedText = '"{0}"'.format(selectedText)
1673 templateText = "{{% trans {0} %}}".format(selectedText) 1682 templateText = "{{% trans {0} %}}".format(selectedText)
1674 replace = True 1683 replace = True
1675 elif tag == "trans..as": 1684 elif tag == "trans..as":
1676 data, ok = DjangoTagInputDialog.getText( 1685 data, ok = DjangoTagInputDialog.getText(
1677 None, 1686 self.__ui,
1678 self.tr("Translate String into Variable"), 1687 self.tr("Translate String into Variable"),
1679 [self.tr("Enter variable receiving translation:")], 1688 [self.tr("Enter variable receiving translation:")],
1680 ["translation"], 1689 ["translation"],
1681 ) 1690 )
1682 if ok: 1691 if ok:
1689 selectedText 1698 selectedText
1690 ) 1699 )
1691 replace = True 1700 replace = True
1692 elif tag == "blocktrans..with": 1701 elif tag == "blocktrans..with":
1693 data, ok = DjangoTagInputDialog.getText( 1702 data, ok = DjangoTagInputDialog.getText(
1694 None, 1703 self.__ui,
1695 self.tr("Translate Block with Attributes"), 1704 self.tr("Translate Block with Attributes"),
1696 [self.tr("Enter attribute binding expressions (space separated):")], 1705 [self.tr("Enter attribute binding expressions (space separated):")],
1697 ["myvar1=value1 myvar2=value2"], 1706 ["myvar1=value1 myvar2=value2"],
1698 ) 1707 )
1699 if ok: 1708 if ok:
1706 elif tag == "plural": 1715 elif tag == "plural":
1707 templateText = "{{% plural %}} {0}".format(selectedText) 1716 templateText = "{{% plural %}} {0}".format(selectedText)
1708 replace = True 1717 replace = True
1709 elif tag == "language": 1718 elif tag == "language":
1710 data, ok = DjangoTagInputDialog.getText( 1719 data, ok = DjangoTagInputDialog.getText(
1711 None, self.tr("Switch language"), [self.tr("Enter language:")], ["en"] 1720 self.__ui,
1721 self.tr("Switch language"),
1722 [self.tr("Enter language:")],
1723 ["en"],
1712 ) 1724 )
1713 if ok: 1725 if ok:
1714 templateText = "{{% language '{0}' %}}{1}{{% endlanguage %}}".format( 1726 templateText = "{{% language '{0}' %}}{1}{{% endlanguage %}}".format(
1715 data[0], selectedText 1727 data[0], selectedText
1716 ) 1728 )
1721 templateText = "{% get_available_languages as LANGUAGES %}" 1733 templateText = "{% get_available_languages as LANGUAGES %}"
1722 elif tag == "get_current_language_bidi": 1734 elif tag == "get_current_language_bidi":
1723 templateText = "{% get_current_language_bidi as LANGUAGE_BIDI %}" 1735 templateText = "{% get_current_language_bidi as LANGUAGE_BIDI %}"
1724 elif tag == "get_language_info": 1736 elif tag == "get_language_info":
1725 data, ok = DjangoTagInputDialog.getText( 1737 data, ok = DjangoTagInputDialog.getText(
1726 None, 1738 self.__ui,
1727 self.tr("Language Information"), 1739 self.tr("Language Information"),
1728 [ 1740 [
1729 self.tr( 1741 self.tr(
1730 "Enter language string or variable (empty for" 1742 "Enter language string or variable (empty for"
1731 " LANGUAGE_CODE):" 1743 " LANGUAGE_CODE):"
1740 ) 1752 )
1741 else: 1753 else:
1742 templateText = "{% get_language_info for LANGUAGE_CODE as lang %}" 1754 templateText = "{% get_language_info for LANGUAGE_CODE as lang %}"
1743 elif tag == "get_language_info_list": 1755 elif tag == "get_language_info_list":
1744 data, ok = DjangoTagInputDialog.getText( 1756 data, ok = DjangoTagInputDialog.getText(
1745 None, 1757 self.__ui,
1746 self.tr("Language Information for a list of languages"), 1758 self.tr("Language Information for a list of languages"),
1747 [self.tr("Enter language list variable (empty for LANGUAGES):")], 1759 [self.tr("Enter language list variable (empty for LANGUAGES):")],
1748 ["available_languages"], 1760 ["available_languages"],
1749 ) 1761 )
1750 if ok: 1762 if ok:
1803 templateText = "{{% localtime off %}}{0}{{% endlocaltime %}}".format( 1815 templateText = "{{% localtime off %}}{0}{{% endlocaltime %}}".format(
1804 selectedText 1816 selectedText
1805 ) 1817 )
1806 replace = True 1818 replace = True
1807 elif tag == "timezone_set": 1819 elif tag == "timezone_set":
1808 timezone, ok = TimezoneSelectionDialog.getTimezone() 1820 timezone, ok = TimezoneSelectionDialog.getTimezone(parent=self.__ui)
1809 if ok: 1821 if ok:
1810 templateText = '{{% timezone "{0}" %}}{1}{{% endtimezone %}}'.format( 1822 templateText = '{{% timezone "{0}" %}}{1}{{% endtimezone %}}'.format(
1811 timezone, selectedText 1823 timezone, selectedText
1812 ) 1824 )
1813 replace = True 1825 replace = True
1822 elif tag == "localtime": 1834 elif tag == "localtime":
1823 templateText = "|localtime" 1835 templateText = "|localtime"
1824 elif tag == "utc": 1836 elif tag == "utc":
1825 templateText = "|utc" 1837 templateText = "|utc"
1826 elif tag == "timezone": 1838 elif tag == "timezone":
1827 timezone, ok = TimezoneSelectionDialog.getTimezone() 1839 timezone, ok = TimezoneSelectionDialog.getTimezone(parent=self.__ui)
1828 if ok: 1840 if ok:
1829 templateText = '|timezone:"{0}"'.format(timezone) 1841 templateText = '|timezone:"{0}"'.format(timezone)
1830 1842
1831 #################################################### 1843 ####################################################
1832 ## Fallback: return just the tag name ## 1844 ## Fallback: return just the tag name ##

eric ide

mercurial