ProjectDjango/Project.py

changeset 72
0f95786f7868
parent 70
77f58dfc7eaa
child 73
8a4ccc4f1359
equal deleted inserted replaced
71:a250660cc153 72:0f95786f7868
270 self.aboutDjangoAct.triggered.connect(self.__djangoInfo) 270 self.aboutDjangoAct.triggered.connect(self.__djangoInfo)
271 self.actions.append(self.aboutDjangoAct) 271 self.actions.append(self.aboutDjangoAct)
272 272
273 self.__initDatabaseActions() 273 self.__initDatabaseActions()
274 self.__initDatabaseSqlActions() 274 self.__initDatabaseSqlActions()
275 self.__initMigrationActions()
275 self.__initToolsActions() 276 self.__initToolsActions()
276 self.__initTestingActions() 277 self.__initTestingActions()
277 self.__initAuthorizationActions() 278 self.__initAuthorizationActions()
278 self.__initSessionActions() 279 self.__initSessionActions()
279 280
428 )) 429 ))
429 self.databaseSqlDropTablesAct.triggered.connect( 430 self.databaseSqlDropTablesAct.triggered.connect(
430 self.__databaseSqlDropTables) 431 self.__databaseSqlDropTables)
431 self.actions.append(self.databaseSqlDropTablesAct) 432 self.actions.append(self.databaseSqlDropTablesAct)
432 433
434 self.databaseSqlDropIndexesAct = E5Action(
435 self.tr('Drop Indexes'),
436 self.tr('&Drop Indexes'),
437 0, 0,
438 self, 'django_database_sql_drop_indexes')
439 self.databaseSqlDropIndexesAct.setStatusTip(self.tr(
440 'Prints the DROP INDEX SQL statements for '
441 'one or more applications'))
442 self.databaseSqlDropIndexesAct.setWhatsThis(self.tr(
443 """<b>Drop Indexes</b>"""
444 """<p>Prints the DROP INDEX SQL statements """
445 """for one or more applications.</p>"""
446 ))
447 self.databaseSqlDropIndexesAct.triggered.connect(
448 self.__databaseSqlDropIndexes)
449 self.actions.append(self.databaseSqlDropIndexesAct)
450
433 self.databaseSqlFlushAct = E5Action( 451 self.databaseSqlFlushAct = E5Action(
434 self.tr('Flush Database'), 452 self.tr('Flush Database'),
435 self.tr('&Flush Database'), 453 self.tr('&Flush Database'),
436 0, 0, 454 0, 0,
437 self, 'django_database_sql_flush_database') 455 self, 'django_database_sql_flush_database')
633 """<p>Clear expired sessions of the Django project.</p>""" 651 """<p>Clear expired sessions of the Django project.</p>"""
634 )) 652 ))
635 self.clearSessionsAct.triggered.connect(self.__clearSessions) 653 self.clearSessionsAct.triggered.connect(self.__clearSessions)
636 self.actions.append(self.clearSessionsAct) 654 self.actions.append(self.clearSessionsAct)
637 655
656 def __initMigrationActions(self):
657 """
658 Private method to define the migration actions.
659 """
660 # TODO: showmigrations
661 self.showMigrationsAct = E5Action(
662 self.tr('Show Migrations'),
663 self.tr('&Show Migrations'),
664 0, 0,
665 self, 'django_migration_show')
666 self.showMigrationsAct.setStatusTip(self.tr(
667 'Show a list of available migrations'))
668 self.showMigrationsAct.setWhatsThis(self.tr(
669 """<b>Show Migrations</b>"""
670 """<p>This shows a list of available migrations of the Django"""
671 """ project and their status.</p>"""
672 ))
673 self.showMigrationsAct.triggered.connect(self.__showMigrationsList)
674 self.actions.append(self.showMigrationsAct)
675
676 self.showMigrationsPlanAct = E5Action(
677 self.tr('Show Migrations Plan'),
678 self.tr('Show Migrations &Plan'),
679 0, 0,
680 self, 'django_migration_show_plan')
681 self.showMigrationsPlanAct.setStatusTip(self.tr(
682 'Show a list with the migrations plan'))
683 self.showMigrationsPlanAct.setWhatsThis(self.tr(
684 """<b>Show Migrations Plan</b>"""
685 """<p>This shows a list with the migrations plan of the Django"""
686 """ project.</p>"""
687 ))
688 self.showMigrationsPlanAct.triggered.connect(self.__showMigrationsPlan)
689 self.actions.append(self.showMigrationsPlanAct)
690
691 # TODO: makemigrations
692 # TODO: migrate
693 # TODO: squashmigrations
694
638 def initMenu(self): 695 def initMenu(self):
639 """ 696 """
640 Public slot to initialize the Django menu. 697 Public method to initialize the Django menu.
641 698
642 @return the menu generated (QMenu) 699 @return the menu generated
700 @rtype QMenu
643 """ 701 """
644 self.__menus = {} # clear menus references 702 self.__menus = {} # clear menus references
645 703
646 menu = QMenu(self.tr('D&jango'), self.__ui) 704 menu = QMenu(self.tr('D&jango'), self.__ui)
647 menu.setTearOffEnabled(True) 705 menu.setTearOffEnabled(True)
654 menu.addAction(self.startProjectAct) 712 menu.addAction(self.startProjectAct)
655 menu.addAction(self.startGlobalApplicationAct) 713 menu.addAction(self.startGlobalApplicationAct)
656 menu.addAction(self.startLocalApplicationAct) 714 menu.addAction(self.startLocalApplicationAct)
657 menu.addSeparator() 715 menu.addSeparator()
658 menu.addMenu(self.__initDatabaseMenu()) 716 menu.addMenu(self.__initDatabaseMenu())
717 menu.addMenu(self.__initMigrationsMenu())
659 menu.addSeparator() 718 menu.addSeparator()
660 menu.addMenu(self.__initToolsMenu()) 719 menu.addMenu(self.__initToolsMenu())
661 menu.addSeparator() 720 menu.addSeparator()
662 menu.addAction(self.createCacheTableAct) 721 menu.addAction(self.createCacheTableAct)
663 menu.addSeparator() 722 menu.addSeparator()
675 734
676 return menu 735 return menu
677 736
678 def __initDatabaseMenu(self): 737 def __initDatabaseMenu(self):
679 """ 738 """
680 Private slot to initialize the database menu. 739 Private method to initialize the database menu.
681 740
682 @return the menu generated (QMenu) 741 @return the menu generated
742 @rtype QMenu
683 """ 743 """
684 menu = QMenu(self.tr("&Database"), self.__ui) 744 menu = QMenu(self.tr("&Database"), self.__ui)
685 menu.setTearOffEnabled(True) 745 menu.setTearOffEnabled(True)
686 746
687 menu.addAction(self.syncDatabaseAct) 747 menu.addAction(self.syncDatabaseAct)
698 758
699 return menu 759 return menu
700 760
701 def __initDatabaseSqlMenu(self): 761 def __initDatabaseSqlMenu(self):
702 """ 762 """
703 Private slot to initialize the database SQL submenu. 763 Private method to initialize the database SQL submenu.
704 764
705 @return the menu generated (QMenu) 765 @return the menu generated
766 @rtype QMenu
706 """ 767 """
707 menu = QMenu(self.tr("Show &SQL"), self.__ui) 768 menu = QMenu(self.tr("Show &SQL"), self.__ui)
708 menu.setTearOffEnabled(True) 769 menu.setTearOffEnabled(True)
709 770
710 menu.addAction(self.databaseSqlCreateTablesAct) 771 if self.getDjangoVersion() < (1, 9, 0):
711 menu.addAction(self.databaseSqlCreateIndexesAct) 772 menu.addAction(self.databaseSqlCreateTablesAct)
712 menu.addAction(self.databaseSqlCreateEverythingAct) 773 menu.addAction(self.databaseSqlCreateIndexesAct)
713 menu.addSeparator() 774 menu.addAction(self.databaseSqlCreateEverythingAct)
714 menu.addAction(self.databaseSqlCustomAct) 775 menu.addSeparator()
715 menu.addSeparator() 776 menu.addAction(self.databaseSqlCustomAct)
716 menu.addAction(self.databaseSqlDropTablesAct) 777 menu.addSeparator()
717 menu.addSeparator() 778 menu.addAction(self.databaseSqlDropTablesAct)
779 menu.addAction(self.databaseSqlDropIndexesAct)
780 menu.addSeparator()
718 menu.addAction(self.databaseSqlFlushAct) 781 menu.addAction(self.databaseSqlFlushAct)
719 menu.addAction(self.databaseSqlResetSeqAct) 782 menu.addAction(self.databaseSqlResetSeqAct)
720 783
721 self.__menus["sql"] = menu 784 self.__menus["sql"] = menu
722 785
723 return menu 786 return menu
724 787
788 def __initMigrationsMenu(self):
789 """
790 Private method to initialize the Migrations submenu.
791
792 @return the menu generated
793 @rtype QMenu
794 """
795 menu = QMenu(self.tr("&Migrations"), self.__ui)
796 menu.setTearOffEnabled(True)
797
798 menu.addAction(self.showMigrationsAct)
799 menu.addAction(self.showMigrationsPlanAct)
800
801 self.__menus["migrations"] = menu
802
803 return menu
804
725 def __initToolsMenu(self): 805 def __initToolsMenu(self):
726 """ 806 """
727 Private slot to initialize the tools menu. 807 Private method to initialize the tools menu.
728 808
729 @return the menu generated (QMenu) 809 @return the menu generated
810 @rtype QMenu
730 """ 811 """
731 menu = QMenu(self.tr("&Tools"), self.__ui) 812 menu = QMenu(self.tr("&Tools"), self.__ui)
732 menu.setTearOffEnabled(True) 813 menu.setTearOffEnabled(True)
733 814
734 menu.addAction(self.diffSettingsAct) 815 menu.addAction(self.diffSettingsAct)
741 822
742 return menu 823 return menu
743 824
744 def __initTestingMenu(self): 825 def __initTestingMenu(self):
745 """ 826 """
746 Private slot to initialize the testing menu. 827 Private method to initialize the testing menu.
747 828
748 @return the menu generated (QMenu) 829 @return the menu generated
830 @rtype QMenu
749 """ 831 """
750 menu = QMenu(self.tr("T&esting"), self.__ui) 832 menu = QMenu(self.tr("T&esting"), self.__ui)
751 menu.setTearOffEnabled(True) 833 menu.setTearOffEnabled(True)
752 834
753 menu.addAction(self.dumpDataAct) 835 menu.addAction(self.dumpDataAct)
760 842
761 return menu 843 return menu
762 844
763 def __initAuthorizationMenu(self): 845 def __initAuthorizationMenu(self):
764 """ 846 """
765 Private slot to initialize the authorization menu. 847 Private method to initialize the authorization menu.
766 848
767 @return the menu generated (QMenu) 849 @return the menu generated
850 @rtype QMenu
768 """ 851 """
769 menu = QMenu(self.tr("&Authorization"), self.__ui) 852 menu = QMenu(self.tr("&Authorization"), self.__ui)
770 menu.setTearOffEnabled(True) 853 menu.setTearOffEnabled(True)
771 854
772 menu.addAction(self.changePasswordAct) 855 menu.addAction(self.changePasswordAct)
776 859
777 return menu 860 return menu
778 861
779 def __initSessionMenu(self): 862 def __initSessionMenu(self):
780 """ 863 """
781 Private slot to initialize the authorization menu. 864 Private method to initialize the authorization menu.
782 865
783 @return the menu generated (QMenu) 866 @return the menu generated
867 @rtype QMenu
784 """ 868 """
785 menu = QMenu(self.tr("&Session"), self.__ui) 869 menu = QMenu(self.tr("&Session"), self.__ui)
786 menu.setTearOffEnabled(True) 870 menu.setTearOffEnabled(True)
787 871
788 menu.addAction(self.clearSessionsAct) 872 menu.addAction(self.clearSessionsAct)
1222 1306
1223 def __djangoInfo(self): 1307 def __djangoInfo(self):
1224 """ 1308 """
1225 Private slot to show some info about Django. 1309 Private slot to show some info about Django.
1226 """ 1310 """
1227 version = self.getDjangoVersion() 1311 version = self.getDjangoVersionString()
1228 url = "http://www.djangoproject.com" 1312 url = "http://www.djangoproject.com"
1229 1313
1230 msgBox = E5MessageBox.E5MessageBox( 1314 msgBox = E5MessageBox.E5MessageBox(
1231 E5MessageBox.Question, 1315 E5MessageBox.Question,
1232 self.tr("About Django"), 1316 self.tr("About Django"),
1244 buttons=E5MessageBox.Ok) 1328 buttons=E5MessageBox.Ok)
1245 msgBox.setIconPixmap(UI.PixmapCache.getPixmap( 1329 msgBox.setIconPixmap(UI.PixmapCache.getPixmap(
1246 os.path.join("ProjectDjango", "icons", "django64.png"))) 1330 os.path.join("ProjectDjango", "icons", "django64.png")))
1247 msgBox.exec_() 1331 msgBox.exec_()
1248 1332
1249 def getDjangoVersion(self): 1333 def getDjangoVersionString(self):
1250 """ 1334 """
1251 Public method to get the Django version. 1335 Public method to get the Django version as a string.
1252 1336
1253 @return Django version (string) 1337 @return Django version (string)
1254 """ 1338 """
1255 djangoVersion = "" 1339 djangoVersion = ""
1256 1340
1270 output = str(process.readAllStandardOutput(), ioEncoding, 1354 output = str(process.readAllStandardOutput(), ioEncoding,
1271 'replace') 1355 'replace')
1272 djangoVersion = output.splitlines()[0].strip() 1356 djangoVersion = output.splitlines()[0].strip()
1273 1357
1274 return djangoVersion 1358 return djangoVersion
1359
1360 def getDjangoVersion(self):
1361 """
1362 Public method to get the Django version as a tuple.
1363
1364 @return Django version
1365 @rtype tuple of int
1366 """
1367 djangoVersionStr = self.getDjangoVersionString()
1368 djangoVersionList = []
1369 if djangoVersionStr:
1370 for part in djangoVersionStr.split("."):
1371 try:
1372 djangoVersionList.append(int(part))
1373 except ValueError:
1374 djangoVersionList.append(part)
1375
1376 return tuple(djangoVersionList)
1275 1377
1276 def __getApplications(self): 1378 def __getApplications(self):
1277 """ 1379 """
1278 Private method to ask the user for a list of application names. 1380 Private method to ask the user for a list of application names.
1279 1381
1751 port = "8000" 1853 port = "8000"
1752 if ipv6: 1854 if ipv6:
1753 addr = "[::1]" 1855 addr = "[::1]"
1754 else: 1856 else:
1755 addr = "127.0.0.1" 1857 addr = "127.0.0.1"
1756 url = QUrl("http://{0}:{1}".format(addr, port)) 1858 url = "http://{0}:{1}".format(addr, port)
1757 res = QDesktopServices.openUrl(url) 1859 if self.__plugin.getPreferences("UseExternalBrowser"):
1758 if not res: 1860 res = QDesktopServices.openUrl(QUrl(url))
1759 E5MessageBox.critical( 1861 if not res:
1760 None, 1862 E5MessageBox.critical(
1761 self.tr('Run Web-Browser'), 1863 None,
1762 self.tr('Could not start the web-browser for the' 1864 self.tr('Run Web-Browser'),
1763 ' url "{0}".').format(url.toString())) 1865 self.tr('Could not start the web-browser for the'
1866 ' url "{0}".').format(url.toString()))
1867 else:
1868 self.__ui.launchHelpViewer(url)
1764 1869
1765 ################################################################## 1870 ##################################################################
1766 ## slots below implement database related functions 1871 ## slots below implement database related functions
1767 ################################################################## 1872 ##################################################################
1768 1873
1939 Private slot to print the DROP TABLE SQL statements for one or 2044 Private slot to print the DROP TABLE SQL statements for one or
1940 more applications. 2045 more applications.
1941 """ 2046 """
1942 self.__sqlCommand(self.tr("Drop Tables"), "sqlclear") 2047 self.__sqlCommand(self.tr("Drop Tables"), "sqlclear")
1943 2048
2049 def __databaseSqlDropIndexes(self):
2050 """
2051 Private slot to print the DROP INDEX SQL statements for one or
2052 more applications.
2053 """
2054 self.__sqlCommand(self.tr("Drop Indexes"), "sqldropindexes")
2055
1944 def __databaseSqlFlushDatabase(self): 2056 def __databaseSqlFlushDatabase(self):
1945 """ 2057 """
1946 Private slot to print a list of statements to return all database 2058 Private slot to print a list of statements to return all database
1947 tables to their initial state. 2059 tables to their initial state.
1948 """ 2060 """
1952 """ 2064 """
1953 Private slot to print the SQL statements for resetting sequences for 2065 Private slot to print the SQL statements for resetting sequences for
1954 one or more applications. 2066 one or more applications.
1955 """ 2067 """
1956 self.__sqlCommand(self.tr("Reset Sequences"), "sqlsequencereset") 2068 self.__sqlCommand(self.tr("Reset Sequences"), "sqlsequencereset")
2069
2070 ##################################################################
2071 ## slots below implement migration related functions
2072 ##################################################################
2073
2074 def __showMigrationsList(self):
2075 """
2076 Private slot to show the available migrations and their status.
2077 """
2078 try:
2079 path = self.__sitePath()
2080 except DjangoNoSiteSelectedException:
2081 return
2082
2083 from .DjangoMigrationsListDialog import DjangoMigrationsListDialog
2084 self.__migrationsListDialog = DjangoMigrationsListDialog(
2085 DjangoMigrationsListDialog.MigrationsListMode, self.__ui)
2086 self.__migrationsListDialog.show()
2087 self.__migrationsListDialog.start(self.__getPythonExecutable(), path)
2088
2089 def __showMigrationsPlan(self):
2090 """
2091 Private slot to show the migrations plan.
2092 """
2093 try:
2094 path = self.__sitePath()
2095 except DjangoNoSiteSelectedException:
2096 return
2097
2098 from .DjangoMigrationsListDialog import DjangoMigrationsListDialog
2099 self.__migrationsPlanDialog = DjangoMigrationsListDialog(
2100 DjangoMigrationsListDialog.MigrationsPlanMode, self.__ui)
2101 self.__migrationsPlanDialog.show()
2102 self.__migrationsPlanDialog.start(self.__getPythonExecutable(), path)
1957 2103
1958 ################################################################## 2104 ##################################################################
1959 ## slots below implement some tool functions 2105 ## slots below implement some tool functions
1960 ################################################################## 2106 ##################################################################
1961 2107

eric ide

mercurial