ProjectDjango/Project.py

changeset 82
fc196e739797
parent 80
34b6482eb9f6
child 85
7c79dead3a86
equal deleted inserted replaced
81:3f801cc29e9f 82:fc196e739797
304 304
305 def __initDatabaseActions(self): 305 def __initDatabaseActions(self):
306 """ 306 """
307 Private method to define the database related actions. 307 Private method to define the database related actions.
308 """ 308 """
309 self.syncDatabaseAct = E5Action(
310 self.tr('Synchronize'),
311 self.tr('&Synchronize'),
312 0, 0,
313 self, 'django_database_syncdb')
314 self.syncDatabaseAct.setStatusTip(self.tr(
315 'Synchronizes the database'))
316 self.syncDatabaseAct.setWhatsThis(self.tr(
317 """<b>Synchronize</b>"""
318 """<p>Synchronizes the database.</p>"""
319 ))
320 self.syncDatabaseAct.triggered.connect(self.__databaseSynchronize)
321 self.actions.append(self.syncDatabaseAct)
322
323 self.inspectDatabaseAct = E5Action( 309 self.inspectDatabaseAct = E5Action(
324 self.tr('Introspect'), 310 self.tr('Introspect'),
325 self.tr('&Introspect'), 311 self.tr('&Introspect'),
326 0, 0, 312 0, 0,
327 self, 'django_database_inspect') 313 self, 'django_database_inspect')
860 @rtype QMenu 846 @rtype QMenu
861 """ 847 """
862 menu = QMenu(self.tr("&Database"), self.__ui) 848 menu = QMenu(self.tr("&Database"), self.__ui)
863 menu.setTearOffEnabled(True) 849 menu.setTearOffEnabled(True)
864 850
865 if self.getDjangoVersion() < (1, 7, 0):
866 menu.addAction(self.syncDatabaseAct)
867 menu.addSeparator()
868 menu.addAction(self.inspectDatabaseAct) 851 menu.addAction(self.inspectDatabaseAct)
869 menu.addSeparator() 852 menu.addSeparator()
870 menu.addAction(self.flushDatabaseAct) 853 menu.addAction(self.flushDatabaseAct)
871 menu.addSeparator() 854 menu.addSeparator()
872 menu.addAction(self.databaseClientAct) 855 menu.addAction(self.databaseClientAct)
1436 def __djangoInfo(self): 1419 def __djangoInfo(self):
1437 """ 1420 """
1438 Private slot to show some info about Django. 1421 Private slot to show some info about Django.
1439 """ 1422 """
1440 version = self.getDjangoVersionString() 1423 version = self.getDjangoVersionString()
1441 url = "http://www.djangoproject.com" 1424 url = "https://www.djangoproject.com"
1442 1425
1443 msgBox = E5MessageBox.E5MessageBox( 1426 msgBox = E5MessageBox.E5MessageBox(
1444 E5MessageBox.Question, 1427 E5MessageBox.Question,
1445 self.tr("About Django"), 1428 self.tr("About Django"),
1446 self.tr( 1429 self.tr(
1614 break 1597 break
1615 1598
1616 ################################################################## 1599 ##################################################################
1617 ## slots below implement creation functions 1600 ## slots below implement creation functions
1618 ################################################################## 1601 ##################################################################
1602
1603 def newProjectCreated(self):
1604 """
1605 Public slot to finish up the newly generated project.
1606 """
1607 if self.__e5project.getProjectType() == "Django":
1608 ppath = self.__e5project.getProjectPath()
1609
1610 # get rid of an __init__.py file because it would be in our way
1611 initModule = os.path.join(ppath, "__init__.py")
1612 if os.path.exists(initModule):
1613 self.__e5project.deleteFile("__init__.py")
1614 self.__e5project.saveProject()
1619 1615
1620 def startProjectOrApplication(self): 1616 def startProjectOrApplication(self):
1621 """ 1617 """
1622 Public slot to start a new Django project or application. 1618 Public slot to start a new Django project or application.
1623 """ 1619 """
2016 2012
2017 ################################################################## 2013 ##################################################################
2018 ## slots below implement database related functions 2014 ## slots below implement database related functions
2019 ################################################################## 2015 ##################################################################
2020 2016
2021 def __databaseSynchronize(self):
2022 """
2023 Private slot to synchronize the database.
2024 """
2025 consoleCmd = self.__isSpawningConsole(
2026 self.__plugin.getPreferences("ConsoleCommandNoClose"))[1]
2027 if consoleCmd:
2028 args = Utilities.parseOptionString(consoleCmd)
2029 args[0] = Utilities.getExecutablePath(args[0])
2030 args.append(self.__getPythonExecutable())
2031 args.append("manage.py")
2032 args.append("syncdb")
2033 try:
2034 wd = self.__sitePath()
2035 self.__adjustWorkingDirectory(args, wd)
2036 started, pid = QProcess.startDetached(args[0], args[1:], wd)
2037 if not started:
2038 E5MessageBox.critical(
2039 None,
2040 self.tr('Process Generation Error'),
2041 self.tr('The Django process could not be'
2042 ' started.'))
2043 except DjangoNoSiteSelectedException:
2044 pass
2045
2046 def __databaseInspect(self): 2017 def __databaseInspect(self):
2047 """ 2018 """
2048 Private slot to introspect the database and output a Django model 2019 Private slot to introspect the database and output a Django model
2049 module. 2020 module.
2050 """ 2021 """
2162 2133
2163 def __databaseSqlCreateTables(self): 2134 def __databaseSqlCreateTables(self):
2164 """ 2135 """
2165 Private slot to print the CREATE TABLE SQL statements for one 2136 Private slot to print the CREATE TABLE SQL statements for one
2166 or more applications. 2137 or more applications.
2138
2139 Note: available before Django v1.9.0
2167 """ 2140 """
2168 self.__sqlCommand(self.tr("Create Tables"), "sql") 2141 self.__sqlCommand(self.tr("Create Tables"), "sql")
2169 2142
2170 def __databaseSqlCreateIndexes(self): 2143 def __databaseSqlCreateIndexes(self):
2171 """ 2144 """
2172 Private slot to print the CREATE INDEX SQL statements for one 2145 Private slot to print the CREATE INDEX SQL statements for one
2173 or more applications. 2146 or more applications.
2147
2148 Note: available before Django v1.9.0
2174 """ 2149 """
2175 self.__sqlCommand(self.tr("Create Indexes"), "sqlindexes") 2150 self.__sqlCommand(self.tr("Create Indexes"), "sqlindexes")
2176 2151
2177 def __databaseSqlCreateEverything(self): 2152 def __databaseSqlCreateEverything(self):
2178 """ 2153 """
2179 Private slot to print the CREATE TABLE, custom SQL and 2154 Private slot to print the CREATE TABLE, custom SQL and
2180 CREATE INDEX SQL statements for one or more applications. 2155 CREATE INDEX SQL statements for one or more applications.
2156
2157 Note: available before Django v1.9.0
2181 """ 2158 """
2182 self.__sqlCommand(self.tr("Create Everything"), "sqlall") 2159 self.__sqlCommand(self.tr("Create Everything"), "sqlall")
2183 2160
2184 def __databaseSqlCustom(self): 2161 def __databaseSqlCustom(self):
2185 """ 2162 """
2186 Private slot to print the custom table modifying SQL statements 2163 Private slot to print the custom table modifying SQL statements
2187 for one or more applications. 2164 for one or more applications.
2165
2166 Note: available before Django v1.9.0
2188 """ 2167 """
2189 self.__sqlCommand(self.tr("Custom Statements"), "sqlcustom") 2168 self.__sqlCommand(self.tr("Custom Statements"), "sqlcustom")
2190 2169
2191 def __databaseSqlDropTables(self): 2170 def __databaseSqlDropTables(self):
2192 """ 2171 """
2193 Private slot to print the DROP TABLE SQL statements for one or 2172 Private slot to print the DROP TABLE SQL statements for one or
2194 more applications. 2173 more applications.
2174
2175 Note: available before Django v1.9.0
2195 """ 2176 """
2196 self.__sqlCommand(self.tr("Drop Tables"), "sqlclear") 2177 self.__sqlCommand(self.tr("Drop Tables"), "sqlclear")
2197 2178
2198 def __databaseSqlDropIndexes(self): 2179 def __databaseSqlDropIndexes(self):
2199 """ 2180 """
2200 Private slot to print the DROP INDEX SQL statements for one or 2181 Private slot to print the DROP INDEX SQL statements for one or
2201 more applications. 2182 more applications.
2183
2184 Note: available before Django v1.9.0
2202 """ 2185 """
2203 self.__sqlCommand(self.tr("Drop Indexes"), "sqldropindexes") 2186 self.__sqlCommand(self.tr("Drop Indexes"), "sqldropindexes")
2204 2187
2205 def __databaseSqlFlushDatabase(self): 2188 def __databaseSqlFlushDatabase(self):
2206 """ 2189 """

eric ide

mercurial