--- a/ProjectDjango/Project.py Thu Dec 26 14:24:34 2024 +0100 +++ b/ProjectDjango/Project.py Fri Dec 27 14:17:37 2024 +0100 @@ -33,6 +33,7 @@ from eric7.EricGui.EricAction import EricAction from eric7.EricWidgets import EricFileDialog, EricMessageBox from eric7.EricWidgets.EricApplication import ericApp +from eric7.EricWidgets.EricComboSelectionDialog import EricComboSelectionDialog try: from eric7.SystemUtilities.OSUtilities import isWindowsPlatform @@ -1263,7 +1264,7 @@ ) if not fname: - # user aborted or didn't enter a filename + # user aborted or did not enter a filename return ext = QFileInfo(fname).suffix() @@ -1284,38 +1285,89 @@ # user selected to not overwrite return - try: - with open(fname, "w") as f: - f.write("<!DOCTYPE html>") - f.write("<html>\n") - f.write(" <head>\n") - f.write(' <meta content="" />\n') - f.write(" <title></title>\n") - f.write(' <link rel="stylesheet" type="text/css" href="style.css"/>') - f.write(" <!--[if lte IE 7]>") - f.write(' <link rel="stylesheet" type="text/css" href="ie.css"/>') - f.write(" <![endif]-->") - f.write(" </head>\n") - f.write("\n") - f.write(' <body class="bodyclass">\n') - f.write(' <div id="container">') - f.write(" </div>") - f.write(" </body>\n") - f.close() - f.write("</html>\n") - except OSError as e: - EricMessageBox.critical( - self.__ui, - self.tr("New Form"), - self.tr( - "<p>The new form file <b>{0}</b> could not be" - " created.<br> Problem: {1}</p>" - ).format(fname, str(e)), - ) - return - - self.__ericProject.appendFile(fname) - self.__formsBrowser.sourceFile.emit(fname) + templateTypes = [ + (self.tr("Base Template"), "base"), + (self.tr("Extending Template"), "extend"), + (self.tr("Standalone Template"), "standalone"), + (self.tr("Empty Template"), "empty"), + ] + dlg = EricComboSelectionDialog( + templateTypes, + title=self.tr("New Form"), + message=self.tr("Select a template type:"), + parent=self.__ui, + ) + if dlg.exec() == QDialog.DialogCode.Accepted: + selectedType = dlg.getSelection()[1] # only the type is needed + + try: + with open(fname, "w") as f: + if selectedType == "base": + f.write( + """{% load static %} + +<!DOCTYPE html> +<html> +<head> + <title>{% block title %}{% endblock %}</title> + <link href="{% static "css/style.css" %}" rel="stylesheet" type="text/css" /> +</head> + +<body class="bodyclass"> + <div id="content"> + {% block content %} + {% endblock %} + </div> + <div id="sidebar"> + </div> +</body> +</html> +""" + ) + + elif selectedType == "extend": + f.write( + """{% extends "base.html" %} + +{% block title %}{% endblock %} + +{% block content %} +{% endblock %} +""" + ) + + elif selectedType == "standalone": + f.write( + """<!DOCTYPE html> +<html> +<head> + <meta content="" /> + <title></title> + <link href="style.css" rel="stylesheet" type="text/css" /> +</head> + +<body class="bodyclass"> + <div id="content"> + </div> +</body> +</html> +""" + ) + elif selectedType == "empty": + f.write("\n") + except OSError as e: + EricMessageBox.critical( + self.__ui, + self.tr("New Form"), + self.tr( + "<p>The new form file <b>{0}</b> could not be" + " created.<br> Problem: {1}</p>" + ).format(fname, str(e)), + ) + return + + self.__ericProject.appendFile(fname) + self.__formsBrowser.sourceFile.emit(fname) ################################################################## ## slots below implement general functionality