--- a/ProjectDjango/Project.py Tue Nov 08 19:07:58 2016 +0100 +++ b/ProjectDjango/Project.py Sat Dec 17 19:07:02 2016 +0100 @@ -272,6 +272,7 @@ self.__initDatabaseActions() self.__initDatabaseSqlActions() + self.__initMigrationActions() self.__initToolsActions() self.__initTestingActions() self.__initAuthorizationActions() @@ -430,6 +431,23 @@ self.__databaseSqlDropTables) self.actions.append(self.databaseSqlDropTablesAct) + self.databaseSqlDropIndexesAct = E5Action( + self.tr('Drop Indexes'), + self.tr('&Drop Indexes'), + 0, 0, + self, 'django_database_sql_drop_indexes') + self.databaseSqlDropIndexesAct.setStatusTip(self.tr( + 'Prints the DROP INDEX SQL statements for ' + 'one or more applications')) + self.databaseSqlDropIndexesAct.setWhatsThis(self.tr( + """<b>Drop Indexes</b>""" + """<p>Prints the DROP INDEX SQL statements """ + """for one or more applications.</p>""" + )) + self.databaseSqlDropIndexesAct.triggered.connect( + self.__databaseSqlDropIndexes) + self.actions.append(self.databaseSqlDropIndexesAct) + self.databaseSqlFlushAct = E5Action( self.tr('Flush Database'), self.tr('&Flush Database'), @@ -635,11 +653,51 @@ self.clearSessionsAct.triggered.connect(self.__clearSessions) self.actions.append(self.clearSessionsAct) + def __initMigrationActions(self): + """ + Private method to define the migration actions. + """ + # TODO: showmigrations + self.showMigrationsAct = E5Action( + self.tr('Show Migrations'), + self.tr('&Show Migrations'), + 0, 0, + self, 'django_migration_show') + self.showMigrationsAct.setStatusTip(self.tr( + 'Show a list of available migrations')) + self.showMigrationsAct.setWhatsThis(self.tr( + """<b>Show Migrations</b>""" + """<p>This shows a list of available migrations of the Django""" + """ project and their status.</p>""" + )) + self.showMigrationsAct.triggered.connect(self.__showMigrationsList) + self.actions.append(self.showMigrationsAct) + + self.showMigrationsPlanAct = E5Action( + self.tr('Show Migrations Plan'), + self.tr('Show Migrations &Plan'), + 0, 0, + self, 'django_migration_show_plan') + self.showMigrationsPlanAct.setStatusTip(self.tr( + 'Show a list with the migrations plan')) + self.showMigrationsPlanAct.setWhatsThis(self.tr( + """<b>Show Migrations Plan</b>""" + """<p>This shows a list with the migrations plan of the Django""" + """ project.</p>""" + )) + self.showMigrationsPlanAct.triggered.connect(self.__showMigrationsPlan) + self.actions.append(self.showMigrationsPlanAct) + + # TODO: makemigrations + # TODO: migrate + # TODO: squashmigrations + def initMenu(self): """ - Public slot to initialize the Django menu. + Public method to initialize the Django menu. - @return the menu generated (QMenu) + @return the menu generated + @rtype QMenu """ self.__menus = {} # clear menus references @@ -656,6 +714,7 @@ menu.addAction(self.startLocalApplicationAct) menu.addSeparator() menu.addMenu(self.__initDatabaseMenu()) + menu.addMenu(self.__initMigrationsMenu()) menu.addSeparator() menu.addMenu(self.__initToolsMenu()) menu.addSeparator() @@ -677,9 +736,10 @@ def __initDatabaseMenu(self): """ - Private slot to initialize the database menu. + Private method to initialize the database menu. - @return the menu generated (QMenu) + @return the menu generated + @rtype QMenu """ menu = QMenu(self.tr("&Database"), self.__ui) menu.setTearOffEnabled(True) @@ -700,21 +760,24 @@ def __initDatabaseSqlMenu(self): """ - Private slot to initialize the database SQL submenu. + Private method to initialize the database SQL submenu. - @return the menu generated (QMenu) + @return the menu generated + @rtype QMenu """ menu = QMenu(self.tr("Show &SQL"), self.__ui) menu.setTearOffEnabled(True) - menu.addAction(self.databaseSqlCreateTablesAct) - menu.addAction(self.databaseSqlCreateIndexesAct) - menu.addAction(self.databaseSqlCreateEverythingAct) - menu.addSeparator() - menu.addAction(self.databaseSqlCustomAct) - menu.addSeparator() - menu.addAction(self.databaseSqlDropTablesAct) - menu.addSeparator() + if self.getDjangoVersion() < (1, 9, 0): + menu.addAction(self.databaseSqlCreateTablesAct) + menu.addAction(self.databaseSqlCreateIndexesAct) + menu.addAction(self.databaseSqlCreateEverythingAct) + menu.addSeparator() + menu.addAction(self.databaseSqlCustomAct) + menu.addSeparator() + menu.addAction(self.databaseSqlDropTablesAct) + menu.addAction(self.databaseSqlDropIndexesAct) + menu.addSeparator() menu.addAction(self.databaseSqlFlushAct) menu.addAction(self.databaseSqlResetSeqAct) @@ -722,11 +785,29 @@ return menu + def __initMigrationsMenu(self): + """ + Private method to initialize the Migrations submenu. + + @return the menu generated + @rtype QMenu + """ + menu = QMenu(self.tr("&Migrations"), self.__ui) + menu.setTearOffEnabled(True) + + menu.addAction(self.showMigrationsAct) + menu.addAction(self.showMigrationsPlanAct) + + self.__menus["migrations"] = menu + + return menu + def __initToolsMenu(self): """ - Private slot to initialize the tools menu. + Private method to initialize the tools menu. - @return the menu generated (QMenu) + @return the menu generated + @rtype QMenu """ menu = QMenu(self.tr("&Tools"), self.__ui) menu.setTearOffEnabled(True) @@ -743,9 +824,10 @@ def __initTestingMenu(self): """ - Private slot to initialize the testing menu. + Private method to initialize the testing menu. - @return the menu generated (QMenu) + @return the menu generated + @rtype QMenu """ menu = QMenu(self.tr("T&esting"), self.__ui) menu.setTearOffEnabled(True) @@ -762,9 +844,10 @@ def __initAuthorizationMenu(self): """ - Private slot to initialize the authorization menu. + Private method to initialize the authorization menu. - @return the menu generated (QMenu) + @return the menu generated + @rtype QMenu """ menu = QMenu(self.tr("&Authorization"), self.__ui) menu.setTearOffEnabled(True) @@ -778,9 +861,10 @@ def __initSessionMenu(self): """ - Private slot to initialize the authorization menu. + Private method to initialize the authorization menu. - @return the menu generated (QMenu) + @return the menu generated + @rtype QMenu """ menu = QMenu(self.tr("&Session"), self.__ui) menu.setTearOffEnabled(True) @@ -1224,7 +1308,7 @@ """ Private slot to show some info about Django. """ - version = self.getDjangoVersion() + version = self.getDjangoVersionString() url = "http://www.djangoproject.com" msgBox = E5MessageBox.E5MessageBox( @@ -1246,9 +1330,9 @@ os.path.join("ProjectDjango", "icons", "django64.png"))) msgBox.exec_() - def getDjangoVersion(self): + def getDjangoVersionString(self): """ - Public method to get the Django version. + Public method to get the Django version as a string. @return Django version (string) """ @@ -1273,6 +1357,24 @@ return djangoVersion + def getDjangoVersion(self): + """ + Public method to get the Django version as a tuple. + + @return Django version + @rtype tuple of int + """ + djangoVersionStr = self.getDjangoVersionString() + djangoVersionList = [] + if djangoVersionStr: + for part in djangoVersionStr.split("."): + try: + djangoVersionList.append(int(part)) + except ValueError: + djangoVersionList.append(part) + + return tuple(djangoVersionList) + def __getApplications(self): """ Private method to ask the user for a list of application names. @@ -1753,14 +1855,17 @@ addr = "[::1]" else: addr = "127.0.0.1" - url = QUrl("http://{0}:{1}".format(addr, port)) - res = QDesktopServices.openUrl(url) - if not res: - E5MessageBox.critical( - None, - self.tr('Run Web-Browser'), - self.tr('Could not start the web-browser for the' - ' url "{0}".').format(url.toString())) + url = "http://{0}:{1}".format(addr, port) + if self.__plugin.getPreferences("UseExternalBrowser"): + res = QDesktopServices.openUrl(QUrl(url)) + if not res: + E5MessageBox.critical( + None, + self.tr('Run Web-Browser'), + self.tr('Could not start the web-browser for the' + ' url "{0}".').format(url.toString())) + else: + self.__ui.launchHelpViewer(url) ################################################################## ## slots below implement database related functions @@ -1941,6 +2046,13 @@ """ self.__sqlCommand(self.tr("Drop Tables"), "sqlclear") + def __databaseSqlDropIndexes(self): + """ + Private slot to print the DROP INDEX SQL statements for one or + more applications. + """ + self.__sqlCommand(self.tr("Drop Indexes"), "sqldropindexes") + def __databaseSqlFlushDatabase(self): """ Private slot to print a list of statements to return all database @@ -1956,6 +2068,40 @@ self.__sqlCommand(self.tr("Reset Sequences"), "sqlsequencereset") ################################################################## + ## slots below implement migration related functions + ################################################################## + + def __showMigrationsList(self): + """ + Private slot to show the available migrations and their status. + """ + try: + path = self.__sitePath() + except DjangoNoSiteSelectedException: + return + + from .DjangoMigrationsListDialog import DjangoMigrationsListDialog + self.__migrationsListDialog = DjangoMigrationsListDialog( + DjangoMigrationsListDialog.MigrationsListMode, self.__ui) + self.__migrationsListDialog.show() + self.__migrationsListDialog.start(self.__getPythonExecutable(), path) + + def __showMigrationsPlan(self): + """ + Private slot to show the migrations plan. + """ + try: + path = self.__sitePath() + except DjangoNoSiteSelectedException: + return + + from .DjangoMigrationsListDialog import DjangoMigrationsListDialog + self.__migrationsPlanDialog = DjangoMigrationsListDialog( + DjangoMigrationsListDialog.MigrationsPlanMode, self.__ui) + self.__migrationsPlanDialog.show() + self.__migrationsPlanDialog.start(self.__getPythonExecutable(), path) + + ################################################################## ## slots below implement some tool functions ##################################################################