Django - Mac OSX工作流程 - 有关高效开发方法的问题 [英] Django - Mac OSX Workflow - Questions on efficient development methodologies

查看:144
本文介绍了Django - Mac OSX工作流程 - 有关高效开发方法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要概述我的工作流程,我想提出一些关于如何提高效率的建议。现在似乎有点麻烦和重复(我讨厌的东西),所以我正在寻找一些改进。记住,我还是django的新手,它是如何工作的,但我是一个非常流畅的编码器(IMHO)。所以这里...



工具(我每天都使用这些,所以我不会倾向于转移)




  • Mac OSX Leopard

  • TextMate

  • 带有选项卡的终端

  • Perforce



假设




  • Django基础知识(教程/购买书籍)

  • Python流利(运行2.6,支持IDLE)

  • 启动我的第一个应用程序在models.py上工作



开始




  • 创建一个TextMate项目,其中包含整个django Tree。



TextMate Project http://img.skitch.com/20090821-g48cpt38pyfwk4u95mf4gk1m7d.jpg




  • 在终端的第一个选项卡中启动服务器



    python ./manage.py runserver


  • 在终端的第二个选项卡中窗口启动shell



    python ./manage.py shell


  • 这产生了iPython,让我开始开发工作流程




工作流程




  • 创建并构建一个名为models.py的基本模型


  • 构建一个基本的模型







 类P4Change(models.Model):
这只是展开'p4描述'
change = models.IntegerField(primary_key = True)
client = models.ForeignKey( P4Client)
user = models.ForeignKey(P4User)
files = models.ManyToManyField(P4Document)
desc = models.TextField()
status = models.CharField(max_length = 128 )
time = models.DateField(auto_now_add = True)


def __unicode __(self):
return str(self.change)

admin.site.register(P4Change)




  • 在第一个终端(运行服务器)中停止它^ C和syncdb启动服务器






 > python ./manage.py syncdb 
创建表perforce_p4change
安装perforce.P4Change模型的索引




  • 在shell终端窗口中加载它..






 > python ./manage.py shell 
Python 2.6.2(r262:71600,2009年4月23日,14:22:01)
有关详细信息,请输入copyright,credit或license。

IPython 0.10 - 增强的交互式Python。
? - >介绍和概述IPython的功能。
%quickref - >快速参考。
帮助 - > Python自己的帮助系统。
对象? - >有关对象的详细信息。 ?对象也可以,??打印更多。

在[1]:from perforce.models import *

在[2]中:c = P4Client.objects.get_or_create(nellie)




  • 如果它不工作,那么它是否打破yes / no:


    • 停止shell

    • 清除数据库

    • 重建数据库

    • 修复代码

    • 重新加载shell

    • 重新加载模块

    • PRAY ..




问题/评论/想法




  • 是我还是这样看起来效率低下?

  • 好像我应该能够重新加载(模块),但是不知道该怎么做..任何人?

  • 看起来我应该能够在TextMate内测试?任何人??

  • 即使刚刚离开shell,我必须验证我要离开..



这个点是为了让所有的天才都能在更有效的工作方式上向我展示。我完全乐意提出合理的建议。我不倾向于转移工具,但我可以批评。



谢谢!!

解决方案

正在寻找更好的方式。我认为单元测试肯定是更简单的方法。



根据文档,您只需要创建一个与models.py并行的文件tests.py并将测试放在那里。

  from django.test import TestCase 
from perforce.models import P4User,P4Client

class TestTests(TestCase):
def setUp(self):
self.p4 = P4.P4()
self.p4.connect()

def test_BasicP4 (self):

确保我们正在运行2009.1 == 65

self.failUnlessEqual(self.p4.api_level,65)

def test_P4User_get_or_retrieve(self):

这将简单地验证我们可以得到一个用户并将其推入模型

user = self.p4.run((users))[0]
dbuser = P4User.objects.get_or_retrieve(user.get('User'))

#将其加载到db?
self.assertEqual(dbuser [1],True)

#再次执行,但是它已经存在..
dbuser = P4User.objects.get_or_retrieve(user.get 'User'))
#它被加载到数据库吗?
self.assertEqual(dbuser [1],False)

#验证数据匹配的一个字段
dbuser = dbuser [0]
self.assertEqual(dbuser .email,user.get(Email))

现在,您可以简单地启动终端做python manage.py测试,这将运行测试,但再次是一个非常有限的视图,仍然需要你交换进出程序..所以这里是如何直接从Textmate使用⌘R。



在顶部添加一个导入行,底部添加几行。

  from django.test.simple import run_tests 

#单元测试从

如果__name__ =='__main__':
run_tests(无,verbosity = 1,interactive = False)

现在⌘R将直接从TextMate工作。 p>

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 hate), so I am looking for some improvements. Keep in mind I'm still new to django and how it works but I'm a pretty fluent coder (IMHO). So here goes...

Tools (I use these everyday so I'm not inclined to shift):

  • Mac OSX Leopard
  • TextMate
  • Terminal w/tabs
  • Perforce

Assumptions

  • Django Basics (Did the tutorials/bought the books)
  • Python Fluent (running 2.6 with IDLE Support)
  • Starting my first Application working on models.py

Starting out

  • Create a TextMate Project with the entire django Tree inside of it.

TextMate Project http://img.skitch.com/20090821-g48cpt38pyfwk4u95mf4gk1m7d.jpg

  • In the first tab of the terminal start the server

    python ./manage.py runserver

  • In the second tab of the terminal window start the shell

    python ./manage.py shell

  • This spawns up iPython and let's me start the development workflow

Workflow

  • Create and build a basic Model called models.py

  • Build a basic Model


class P4Change(models.Model):
  """This simply expands out 'p4 describe' """
  change        = models.IntegerField(primary_key=True)
  client        = models.ForeignKey(P4Client)
  user          = models.ForeignKey(P4User)
  files         = models.ManyToManyField(P4Document)
  desc          = models.TextField()
  status        = models.CharField(max_length=128)
  time          = models.DateField(auto_now_add=True)


  def __unicode__(self):
    return str(self.change)

admin.site.register(P4Change)

  • In the first terminal (Running server) stop it ^C and syncdb start server

>  python ./manage.py syncdb
Creating table perforce_p4change
Installing index for perforce.P4Change model

  • In the shell terminal window load it..

> python ./manage.py shell
Python 2.6.2 (r262:71600, Apr 23 2009, 14:22:01) 
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from perforce.models import *

In [2]: c = P4Client.objects.get_or_create("nellie")

  • Did it break yes/no if it did not work then do this:
    • Stop the shell
    • Clear the database
    • Rebuild the database
    • Fix the code
    • Reload the shell
    • Reload the modules
    • PRAY...

Issues / Comments / Thoughts

  • Is it me or does this seem terribly inefficient?
  • It seems like I should be able to do a reload(module) but I can't figure out how to do this.. Anyone?
  • It would seem as though I should be able to test this from within TextMate?? Anyone??
  • Even to just get out of the shell I have to verify I want to leave..

The point of this is for all of you geniuses out there to show me the light on a more productive way to work. I am completely open to reasonable suggestions. I'm not inclined to shift tools but I am open to criticisms.

Thanks!!

解决方案

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.

这篇关于Django - Mac OSX工作流程 - 有关高效开发方法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆