Django - Mac OSX Workflow - Questions on efficient development methodologies

后端 未结 4 1800
独厮守ぢ
独厮守ぢ 2021-02-02 04:31

I am going to outline my workflow and I would like some suggestions on how to improve the efficiency of this. It seems right now a bit cumbersome and repetitive (something I ha

相关标签:
4条回答
  • 2021-02-02 04:39

    First of all, no need to do a ./manage.py runserver until your models are in place.

    Second, clear the database/rebuild the database should be done after fixing the code, and can be done in one fell swoop with ./manage.py reset perforce

    Third, the things that you are typing out in the shell each time (import models, try creating an object) should be written in a test suite instead. Then you can do ./manage.py test perforce instead of firing up the shell and typing it again. Actually, if you're using the test suite, you won't need to, because it will create a clean dummy db each time, and break it down for you when it's done.

    Fourth, Instead of "PRAY...", try "Watch tests pass."

    0 讨论(0)
  • 2021-02-02 04:46

    I find it smoother to write unit tests more often and only use the shell when something is failing and it's not obvious why and you want to poke around to figure it out. It is a little more inefficient at the very beginning, but quickly becomes a wonderful way to work.

    I also tend to concentrate on getting the model more or less stable and complete (at least as far as what will affect table structure) before I work on the views and need to run the server. That tends to front-load as many resets as possible so you're doing them when it's cheap.

    0 讨论(0)
  • 2021-02-02 04:49

    Thanks to everyone who read this and is looking for a better way. I think unit tests are definately the simpler approach.

    So according to the docs you simply need to create a file tests.py parallel to models.py and put tests in there.

    from django.test import TestCase
    from perforce.models import P4User, P4Client
    
    class ModelTests(TestCase):
      def setUp(self):
        self.p4 = P4.P4()
        self.p4.connect()
    
      def test_BasicP4(self):
        """
        Make sure we are running 2009.1 == 65
        """
        self.failUnlessEqual(self.p4.api_level, 65)
    
      def test_P4User_get_or_retrieve(self):
        """
        This will simply verify we can get a user and push it into the model
        """
        user = self.p4.run(("users"))[0]
        dbuser = P4User.objects.get_or_retrieve(user.get('User'))
    
        # Did it get loaded into the db?
        self.assertEqual(dbuser[1], True)
    
        # Do it again but hey it already exists..
        dbuser = P4User.objects.get_or_retrieve(user.get('User'))
        # Did it get loaded into the db?
        self.assertEqual(dbuser[1], False)
    
        # Verify one field of the data matches
        dbuser = dbuser[0]
        self.assertEqual(dbuser.email, user.get("Email"))
    

    Now you can simply fire up the terminal and do python manage.py test and that will run the tests but again that's a pretty limited view and still requires you to swap in/out of programs.. So here is how you do this directly from Textmate using ⌘R.

    Add an import line at the top and a few line at the bottom.

    from django.test.simple import run_tests
    #
    # Unit tests from above
    #
    if __name__ == '__main__':
      run_tests(None, verbosity=1, interactive=False)
    

    And now ⌘R will work directly from TextMate.

    0 讨论(0)
  • 2021-02-02 04:51

    OK, I'll bite :-) Here's what I use:

    • MAMP. You get a fully functional Apache + MySQL + PHP + phpMyAdmin stack to manage the web and DB layers. It's great for apps that go beyond basic SQLite. Basic version is free but I went ahead and popped for Pro because I use it so much and wanted to support the devs. A good way to test and make sure everything works is start with the Django test server, then deploy and test under MAMP on your own machine, and finally push it out to your deployment site. (You could try to automate the process with something like Fabric).

    • Eclipse + PyDev + PyDev extensions. Once configured properly you get Python code completion, a nice development environment, and full debugging. You can configure it so it runs the Django test server for you and you can set breakpoints on any line in Django source or your own code. The thing I like about Eclipse is that once you get used to the environment, you can also it for C/C++, Java, JavaScript, Python, and Flex coding.

    • Aptana for Eclipse. It helps when developing AJAX front-ends and editing Django templates to have a decent Javascript + HTML editor/debugger.

    • TextMate. I've created a TextMate project that includes all of Django sources and saved it in the Django source directory. This way, I can quickly do project searches through Django source and single-click open the source file. You can also set it up so you can go back and forth between Eclipse and TextMate editors and have them auto-reload.

    • A decent MySQL or SQLite editor. phpMySQLAdmin is OK but sometimes it's good to have a standalone tool. SequelPro (formerly CocoaMySQL) and Navicat are all pretty good for MySQL. One advantage is that once your app is deployed, you can use these tools to remotely access the deployment DB server and tweak it from your desktop. On the SQLite side SQLiteManager and Base are good commercial tools, as is the freebie FireFox SQLite Manager. At the very least you can watch what Django's doing under the hood.

    • I use Subversion for version control mostly because it runs on a standalone Mac Mini which saves to a Drobo RAID array plus auto-backups everything to a couple other external drives. This on top of Time Machine (yes, I'm paranoid :-) I used to use Eclipse's SVN support but now I'm a big fan of Versions. At some point when I can figure out a good mirroring scheme I'll switch to Mercurial, Git, or Bazaar, but for now this works pretty well.

    • Terminal plus a bunch of shell scripts. Everyone has their own version of this. I'm pretty lazy when it comes to these things so I set up a bunch of bash shortcuts to help speed up repetitive Django admin tasks. I posted these up a while back.

    Most of these can be had for free or a moderate fee (< $100). But if I had to pick the 'must have' items for Django development on the Mac, it would be Eclipse and PyDev.

    I'm sure there are some I've missed. Be great to hear what tools everyone else is using.

    0 讨论(0)
提交回复
热议问题