Ticket #18296: ticket18296.diff

File ticket18296.diff, 3.1 KB (added by vanessagomes, 12 years ago)

I'm sorry guys, it was another ticket that I was soluting, and it came together. Now is the right patch.

  • django/core/management/commands/startapp.py

    diff --git a/django/core/management/commands/startapp.py b/django/core/management/commands/startapp.py
    index 5581331..8c5d3ea 100644
    a b from django.core.management.base import CommandError  
    22from django.core.management.templates import TemplateCommand
    33from django.utils.importlib import import_module
    44
     5import os
     6from os import path
     7
    58
    69class Command(TemplateCommand):
    710    help = ("Creates a Django app directory structure for the given app "
    class Command(TemplateCommand):  
    2124            raise CommandError("%r conflicts with the name of an existing "
    2225                               "Python module and cannot be used as an app "
    2326                               "name. Please try another name." % app_name)
    24 
     27       
    2528        super(Command, self).handle('app', app_name, target, **options)
     29       
     30    def get_target_dir(self, target, name):
     31        top_dir = super(Command, self).get_target_dir(target, name)
     32        top_dir = os.path.abspath(path.expanduser(target))
     33        top_dir = os.path.join(top_dir, name)
     34         
     35        if not os.path.exists(top_dir):
     36            os.mkdir(top_dir)
     37       
     38        return top_dir
  • django/core/management/templates.py

    diff --git a/django/core/management/templates.py b/django/core/management/templates.py
    index 623aa69..5e81588 100644
    a b class TemplateCommand(BaseCommand):  
    5959    # The supported URL schemes
    6060    url_schemes = ['http', 'https', 'ftp']
    6161
     62    def get_target_dir(self, target, name):
     63        """
     64        Creates a directory for when location of the app or project
     65        are specified.
     66        """
     67        top_dir = os.path.abspath(path.expanduser(target))
     68        if not os.path.exists(top_dir):
     69            raise CommandError("Destination directory '%s' does not "
     70                       "exist, please create it first." % top_dir)
     71             
     72        return top_dir
     73       
     74
    6275    def handle(self, app_or_project, name, target=None, **options):
    6376        self.app_or_project = app_or_project
    6477        self.paths_to_remove = []
    class TemplateCommand(BaseCommand):  
    87100                    message = e
    88101                raise CommandError(message)
    89102        else:
    90             top_dir = os.path.abspath(path.expanduser(target))
    91             if not os.path.exists(top_dir):
    92                 raise CommandError("Destination directory '%s' does not "
    93                                    "exist, please create it first." % top_dir)
     103            top_dir = self.get_target_dir(target, name)
     104
    94105
    95106        extensions = tuple(
    96107            handle_extensions(options.get('extensions'), ignored=()))
    class TemplateCommand(BaseCommand):  
    141152                    # Ignore some files as they cause various breakages.
    142153                    continue
    143154                old_path = path.join(root, filename)
     155               
    144156                new_path = path.join(top_dir, relative_dir,
    145157                                     filename.replace(base_name, name))
    146158                if path.exists(new_path):
Back to Top