Django

Code

Changeset 6095

Show
Ignore:
Timestamp:
09/11/07 06:46:34 (1 year ago)
Author:
russellm
Message:

newforms-admin: Merged to [6094]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin

    • Property svnmerge-integrated changed from /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6081 to /django/trunk:1-4345,4350-4357,4359-4365,4371-4372,4374-4377,4380-4386,4388,4390-4391,4400-4402,4404-4408,4410,4412-4419,4426-4427,4430-4432,4434,4441,4443-4444,4446-4447,4450,4452-4453,4455-4458,4476,4503,4546,4564-4569,4580-4586,4617,4630,4641-6094
  • django/branches/newforms-admin/django/core/management/base.py

    r6082 r6095  
    66import sys 
    77import os 
    8 from traceback import print_exc 
    98 
    109class CommandError(Exception): 
     
    3736        return django.get_version() 
    3837 
    39     def usage(self): 
    40         usage = '%prog [options] ' + self.args 
     38    def usage(self, subcommand): 
     39        usage = '%%prog %s [options] %s' % (subcommand, self.args) 
    4140        if self.help: 
    4241            return '%s\n\n%s' % (usage, self.help) 
     
    4443            return usage 
    4544 
    46     def create_parser(self, prog_name): 
     45    def create_parser(self, prog_name, subcommand): 
    4746        return OptionParser(prog=prog_name, 
    48                             usage=self.usage(), 
     47                            usage=self.usage(subcommand), 
    4948                            version=self.get_version(), 
    5049                            option_list=self.option_list) 
    5150 
    52     def print_help(self, args): 
    53         parser = self.create_parser(args[0]
     51    def print_help(self, prog_name, subcommand): 
     52        parser = self.create_parser(prog_name, subcommand
    5453        parser.print_help() 
    5554 
    56     def run(self, args): 
    57         parser = self.create_parser(args[0]) 
    58         (options, args) = parser.parse_args(args[1:]) 
     55    def run_from_argv(self, argv): 
     56        parser = self.create_parser(argv[0], argv[1]) 
     57        options, args = parser.parse_args(argv[2:]) 
    5958        if options.settings: 
    6059            os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 
    6160        if options.pythonpath: 
    6261            sys.path.insert(0, options.pythonpath) 
    63         try: 
    64             self.execute(*args, **options.__dict__) 
    65         except Exception, e: 
    66             print_exc() 
    67             parser.print_usage() 
     62        self.execute(*args, **options.__dict__) 
    6863 
    6964    def execute(self, *args, **options): 
  • django/branches/newforms-admin/django/core/management/commands/runfcgi.py

    r6082 r6095  
    1616        runfastcgi(args) 
    1717         
    18     def usage(self): 
     18    def usage(self, subcommand): 
    1919        from django.core.servers.fastcgi import FASTCGI_HELP 
    2020        return FASTCGI_HELP 
  • django/branches/newforms-admin/django/core/management/__init__.py

    r6082 r6095  
    33import os 
    44import sys 
    5 import textwrap 
    65 
    76# For backwards compatibility: get_version() used to be in this module. 
     
    3736    by editing the self.commands dictionary. 
    3837    """ 
    39     def __init__(self): 
     38    def __init__(self, argv=None): 
     39        self.argv = argv or sys.argv[:] 
     40        self.prog_name = os.path.basename(self.argv[0]) 
    4041        self.commands = self.default_commands() 
    4142 
     
    5354        return dict([(name, load_command_class(name)) for name in names]) 
    5455 
    55     def print_help(self, argv): 
     56    def main_help_text(self): 
    5657        """ 
    57         Returns the help message, as a string. 
     58        Returns the script's main help text, as a string. 
    5859        """ 
    59         prog_name = os.path.basename(argv[0]) 
    60         usage = ['%s <subcommand> [options] [args]' % prog_name] 
     60        usage = ['%s <subcommand> [options] [args]' % self.prog_name] 
    6161        usage.append('Django command line tool, version %s' % django.get_version()) 
    62         usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % prog_name) 
     62        usage.append("Type '%s help <subcommand>' for help on a specific subcommand." % self.prog_name) 
    6363        usage.append('Available subcommands:') 
    6464        commands = self.commands.keys() 
     
    6666        for cmd in commands: 
    6767            usage.append('  %s' % cmd) 
    68         print '\n'.join(usage) 
     68        return '\n'.join(usage) 
    6969 
    70     def fetch_command(self, subcommand, command_name): 
     70    def fetch_command(self, subcommand): 
    7171        """ 
    7272        Tries to fetch the given subcommand, printing a message with the 
     
    7777            return self.commands[subcommand] 
    7878        except KeyError: 
    79             sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % (subcommand, command_name)) 
     79            sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" % (subcommand, self.prog_name)) 
    8080            sys.exit(1) 
    8181 
    82     def execute(self, argv=None): 
     82    def execute(self): 
    8383        """ 
    84         Figures out which command is being run (the first arg), creates a parser 
    85         appropriate to that command, and runs it. 
     84        Given the command-line arguments, this figures out which subcommand is 
     85        being run, creates a parser appropriate to that command, and runs it. 
    8686        """ 
    87         if argv is None: 
    88             argv = sys.argv 
    8987        try: 
    90             command_name = argv[1] 
     88            subcommand = self.argv[1] 
    9189        except IndexError: 
    92             sys.stderr.write("Type '%s help' for usage.\n" % os.path.basename(argv[0])
     90            sys.stderr.write("Type '%s help' for usage.\n" % self.prog_name
    9391            sys.exit(1) 
    9492 
    95         if command_name == 'help': 
    96             if len(argv) > 2: 
    97                 self.fetch_command(argv[2], argv[0]).print_help(argv[2:]) 
     93        if subcommand == 'help': 
     94            if len(self.argv) > 2: 
     95                self.fetch_command(self.argv[2]).print_help(self.prog_name, self.argv[2]) 
    9896            else: 
    99                 self.print_help(argv) 
     97                sys.stderr.write(self.main_help_text() + '\n') 
     98                sys.exit(1) 
    10099        # Special-cases: We want 'django-admin.py --version' and 
    101100        # 'django-admin.py --help' to work, for backwards compatibility. 
    102         elif argv[1:] == ['--version']: 
     101        elif self.argv[1:] == ['--version']: 
    103102            print django.get_version() 
    104         elif argv[1:] == ['--help']: 
    105             self.print_help(argv
     103        elif self.argv[1:] == ['--help']: 
     104            sys.stderr.write(self.main_help_text() + '\n'
    106105        else: 
    107             self.fetch_command(command_name, argv[0]).run(argv[1:]
     106            self.fetch_command(subcommand).run_from_argv(self.argv
    108107 
    109108class ProjectManagementUtility(ManagementUtility): 
     
    116115    represents django-admin.py. 
    117116    """ 
    118     def __init__(self, project_directory): 
    119         super(ProjectManagementUtility, self).__init__(
     117    def __init__(self, argv, project_directory): 
     118        super(ProjectManagementUtility, self).__init__(argv
    120119 
    121120        # Remove the "startproject" command from self.commands, because 
     
    151150    A simple method that runs a ManagementUtility. 
    152151    """ 
    153     utility = ManagementUtility(
    154     utility.execute(argv
     152    utility = ManagementUtility(argv
     153    utility.execute(
    155154 
    156155def execute_manager(settings_mod, argv=None): 
     
    160159    """ 
    161160    project_directory = setup_environ(settings_mod) 
    162     utility = ProjectManagementUtility(project_directory) 
    163     utility.execute(argv
     161    utility = ProjectManagementUtility(argv, project_directory) 
     162    utility.execute(
  • django/branches/newforms-admin/django/db/models/loading.py

    r5984 r6095  
    5353                if app_name in self.handled: 
    5454                    continue 
    55                 try: 
    56                     self.load_app(app_name, True) 
    57                 except Exception, e: 
    58                     # Problem importing the app 
    59                     self.app_errors[app_name] = e 
     55                self.load_app(app_name, True) 
    6056            if not self.nesting_level: 
    6157                for app_name in self.postponed: 
  • django/branches/newforms-admin/docs/contributing.txt

    r6082 r6095  
    417417We place a high importance on consistency and readability of documentation. 
    418418(After all, Django was created in a journalism environment!) 
     419 
     420How to document new features 
     421---------------------------- 
     422 
     423We treat our documentation like we treat our code: we aim to improve it as 
     424often as possible. This section explains how writers can craft their 
     425documentation changes in the most useful and least error-prone ways. 
     426 
     427Documentation changes come in two forms: 
     428 
     429    * General improvements -- Typo corrections, error fixes and better 
     430      explanations through clearer writing and more examples. 
     431 
     432    * New features -- Documentation of features that have been added to the 
     433      framework since the last release. 
     434 
     435Our philosophy is that "general improvements" are something that *all* current 
     436Django users should benefit from, including users of trunk *and* users of the 
     437latest release. Hence, the documentation section on djangoproject.com points 
     438people by default to the newest versions of the docs, because they have the 
     439latest and greatest content. (In fact, the Web site pulls directly from the 
     440Subversion repository, converting to HTML on the fly.) 
     441 
     442But this decision to feature bleeding-edge documentation has one large caveat: 
     443any documentation of *new* features will be seen by Django users who don't 
     444necessarily have access to those features yet, because they're only using the 
     445latest release. Thus, our policy is: 
     446 
     447    **All documentation of new features should be written in a way that clearly 
     448    designates the features are only available in the Django development 
     449    version. Assume documentation readers are using the latest release, not the 
     450    development version.** 
     451 
     452Our traditional way of marking new features is by prefacing the features' 
     453documentation with: "New in Django development version." Changes aren't 
     454*required* to include this exact text, but all documentation of new features 
     455should include the phrase "development version," so we can find and remove 
     456those phrases for the next release. 
    419457 
    420458Guidelines for ReST files 
  • django/branches/newforms-admin/tests/regressiontests/forms/regressions.py

    r5918 r6095  
    7474>>> f.cleaned_data 
    7575{'data': u'xyzzy'} 
    76  
    77 ####################### 
    78 # Miscellaneous Tests # 
    79 ####################### 
    80  
    81 There once was a problem with Form fields called "data". Let's make sure that 
    82 doesn't come back. 
    83 >>> class DataForm(Form): 
    84 ...     data = CharField(max_length=10) 
    85 >>> f = DataForm({'data': 'xyzzy'}) 
    86 >>> f.is_valid() 
    87 True 
    88 >>> f.cleaned_data 
    89 {'data': u'xyzzy'} 
    9076"""