Django

Code

Changeset 981

Show
Ignore:
Timestamp:
10/20/05 10:55:45 (3 years ago)
Author:
rjwittams
Message:

Cleanups of whitespace changes and errors after big merge

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/new-admin/django/contrib/admin/views/main.py

    r966 r981  
    928928        request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr)) 
    929929        return HttpResponseRedirect("../../") 
    930     return render_to_response('admin/delete_confirmation_generic', { 
     930    return render_to_response('admin/delete_confirmation', { 
    931931        "title": "Are you sure?", 
    932932        "object_name": opts.verbose_name, 
  • django/branches/new-admin/django/contrib/admin/views/template.py

    r933 r981  
    2424        if not errors: 
    2525            request.user.add_message('The template is valid.') 
    26     return render_to_response('template_validator', { 
     26    return render_to_response('admin/template_validator', { 
    2727        'title': 'Template validator', 
    2828        'form': formfields.FormWrapper(manipulator, new_data, errors), 
  • django/branches/new-admin/django/core/formfields.py

    r939 r981  
    245245                            data = field.extract_data(self.data) 
    246246                            errors = self.errors.get(full_field_name, []) 
    247 #                           if(errors):raise full_field_name + " " + repr(errors) 
    248247                            collection[field_name] = FormFieldWrapper(field, data, errors) 
    249248                wrapper.append(FormFieldCollection(collection)) 
     
    289288 
    290289    def extract_data(self, data_dict): 
    291        if hasattr(self, 'requires_data_list') and hasattr(data_dict, 'getlist'): 
     290        if hasattr(self, 'requires_data_list') and hasattr(data_dict, 'getlist'): 
    292291            data = data_dict.getlist(self.get_member_name()) 
    293292        else: 
     
    295294        if data is None: 
    296295            data = '' 
    297         self.data_dict = data_dict   
    298         return data 
     296            return data 
    299297 
    300298    def convert_post_data(self, new_data): 
    301        name = self.get_member_name() 
     299        name = self.get_member_name() 
    302300        if new_data.has_key(self.field_name): 
    303             d = new_data.getlist(self.field_name) 
    304             #del new_data[self.field_name] 
     301            d = new_data.getlist(self.field_name) 
    305302            try: 
    306303                converted_data = [self.__class__.html2python(data)  
     
    309306                converted_data = d 
    310307            new_data.setlist(name, converted_data) 
    311           
    312308        else: 
    313309            try: 
  • django/branches/new-admin/django/core/management.py

    r966 r981  
    634634    from django.utils import autoreload 
    635635    autoreload.main(inner_run) 
    636     #inner_run() 
    637636runserver.args = '[optional port number, or ipaddr:port]' 
    638637 
  • django/branches/new-admin/django/core/meta/fields.py

    r975 r981  
    259259            return val 
    260260 
    261  
    262261    def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH): 
    263262        "Returns a list of tuples used as SelectField choices for this field." 
     
    267266            return first_choice + list(self.choices) 
    268267        rel_obj = self.rel.to 
    269         choices = first_choice + [(getattr(x, rel_obj.pk.column), repr(x)) for x in rel_obj.get_model_module().get_list(**self.rel.limit_choices_to)] 
    270   
    271         return choices 
    272  
     268        return first_choice + [(getattr(x, rel_obj.pk.column), repr(x)) for x in rel_obj.get_model_module().get_list(**self.rel.limit_choices_to)] 
    273269 
    274270    def get_choices_default(self): 
     
    285281 
    286282    def flatten_data(self, follow, obj = None): 
    287          """ 
    288              Returns a dictionary mapping the field's manipulator field names to its 
    289              "flattened" string values for the admin view. Obj is the instance to extract the  
    290              values from.  
    291          """ 
    292       
    293          return { self.get_db_column(): self._get_val_from_obj(obj)} 
     283        """ 
     284        Returns a dictionary mapping the field's manipulator field names to its 
     285        "flattened" string values for the admin view. Obj is the instance to extract the  
     286        values from.  
     287        """ 
     288        return { self.get_db_column(): self._get_val_from_obj(obj)} 
    294289 
    295290    def get_follow(self, override=None): 
     
    307302    def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False): 
    308303        if not rel: 
    309             return [] # Don't add a FormField unless it's in a related change context. 
     304            return [] # Don't add a FormField unless it's in a related context. 
    310305        return Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel) 
    311306 
     
    399394        val = self._get_val_from_obj(obj)  
    400395        date_field, time_field = self.get_manipulator_field_names('') 
    401        return {date_field: (val is not None and val.strftime("%Y-%m-%d") or ''), 
    402                 time_field: (val is not None and val.strftime("%H:%M:%S") or '')} 
     396        return {date_field: (val is not None and val.strftime("%Y-%m-%d") or ''), 
     397                    time_field: (val is not None and val.strftime("%H:%M:%S") or '')} 
    403398 
    404399class EmailField(Field): 
     
    595590    def flatten_data(self,follow, obj = None): 
    596591        val = self._get_val_from_obj(obj)  
    597        return {self.get_db_column(): (val is not None and val.strftime("%H:%M:%S") or '')}  
     592        return {self.get_db_column(): (val is not None and val.strftime("%H:%M:%S") or '')}  
    598593 
    599594class URLField(Field): 
     
    909904        the dict has attribs 'fields' and maybe 'classes'.  
    910905        fields is a list of subclasses of Field.  
    911  
    912         TODO:Return value needs to be encapsulated. 
    913906        """ 
    914907        if self.fields is None: 
  • django/branches/new-admin/django/core/meta/__init__.py

    r939 r981  
    925925        if cursor.fetchone(): 
    926926            db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column), False)) for f in non_pks] 
    927            cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % (opts.db_table,  
    928                 ','.join(['%s=%%s' % f.column for f in non_pks]), opts.pk.column), 
     927            cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % (opts.db_table,  
     928                    ','.join(['%s=%%s' % f.column for f in non_pks]), opts.pk.column), 
    929929                db_values + [pk_val]) 
    930930        else: 
     
    15811581    for f in opts.fields + opts.many_to_many: 
    15821582        if self.follow.get(f.name, False):    
    1583         # if f.editable and not (f.primary_key and change) and (not f.rel or not f.rel.edit_inline): 
    15841583            self.fields.extend(f.get_manipulator_fields(opts, self, change)) 
    15851584 
     
    15901589            self.fields.extend(f.get_manipulator_fields(opts, self, change, fol)) 
    15911590 
    1592    # for obj in opts.get_inline_related_objects_wrapped(): 
    1593    #     if change: 
    1594    #         count = getattr(self.original_object, 'get_%s_count' % opts.get_rel_object_method_name(obj.opts, obj.field))() 
    1595    #         count += obj.field.rel.num_extra_on_change 
    1596    #         if obj.field.rel.min_num_in_admin: 
    1597    #             count = max(count, obj.field.rel.min_num_in_admin) 
    1598    #         if obj.field.rel.max_num_in_admin: 
    1599    #             count = min(count, obj.field.rel.max_num_in_admin) 
    1600    #     else: 
    1601    #         count = obj.field.rel.num_in_admin 
    1602    #     for f in obj.opts.fields + obj.opts.many_to_many: 
    1603    #         if f.editable and f != obj.field : 
    1604    #             for i in range(count): 
    1605    #                self.fields.extend(f.get_manipulator_fields(obj.opts, self, change, name_prefix='%s.%d.' % (obj.opts.object_name.lower(), i), rel=True)) 
    1606  
    16071591    # Add field for ordering. 
    16081592    if change and opts.get_ordered_objects(): 
     
    16131597    from django.utils.datastructures import DotExpandedDict 
    16141598    params = {} 
    1615     for f in opts.fields: 
     1599    for f in opts.fields:         
     1600        # Fields with auto_now_add should keep their original value in the change stage. 
    16161601        auto_now_add = change and getattr(f, 'auto_now_add', False) 
    16171602        if self.follow.get(f.name, None) and not auto_now_add: 
     
    16241609        params[f.column] = param     
    16251610     
    1626         # Fields with auto_now_add are another special case; they should keep 
    1627         # their original value in the change stage. 
    1628         #if change and getattr(f, 'auto_now_add', False): 
    1629         #    params[f.column] = getattr(self.original_object, f.name) 
    1630         #else: 
    1631         #    params[f.column] = f.get_manipulator_new_data(new_data) 
    16321611 
    16331612    if change: 
  • django/branches/new-admin/django/core/template/defaulttags.py

    r876 r981  
    228228        return output 
    229229 
    230  
    231230class LoadNode(Node): 
    232231    def __init__(self, taglib): 
  • django/branches/new-admin/django/core/template/__init__.py

    r947 r981  
    7575ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.' 
    7676 
    77 #What to report as the origin of templates that come from non file sources (eg strings) 
     77#What to report as the origin of templates that come from non loader sources (ie strings) 
    7878UNKNOWN_SOURCE="<unknown source>" 
    7979 
     
    141141        "Display stage -- can be called many times" 
    142142        return self.nodelist.render(context) 
    143          
    144143 
    145144def compile_string(template_string, origin): 
     
    226225    def tokenize(self): 
    227226        "Return a list of tokens from a given template_string" 
     227        # remove all empty strings, because the regex has a tendency to add them 
    228228        bits = filter(None, tag_re.split(self.template_string)) 
    229229        return map(self.create_token, bits) 
     
    277277    def __init__(self, tokens): 
    278278        self.tokens = tokens 
    279          
     279 
    280280    def parse(self, parse_until=[]): 
    281281        nodelist = self.create_nodelist() 
     
    297297                except IndexError: 
    298298                    self.empty_block_tag(token) 
    299                  
    300299                # execute callback function for this tag and append resulting node 
    301300                self.enter_command(command, token); 
     
    303302                    compile_func = registered_tags[command] 
    304303                except KeyError: 
    305                     self.invalid_block_tag(token, command) 
    306                  
     304                    self.invalid_block_tag(token, command)  
    307305                try: 
    308306                    compiled_result = compile_func(self, token) 
     
    310308                    if not self.compile_function_error(token, e): 
    311309                       raise 
    312                      
    313310                self.extend_nodelist(nodelist, compiled_result, token) 
    314311                self.exit_command(); 
    315                  
    316312        if parse_until: 
    317313            self.unclosed_block_tag(token, parse_until) 
    318              
    319314        return nodelist 
    320315 
  • django/branches/new-admin/django/core/template/loader.py

    r966 r981  
    4242        template_source_loaders.append(func) 
    4343 
    44  
    45  
    46  
    4744class LoaderOrigin(Origin): 
    48     def __init__(self, name, loader): 
     45    def __init__(self, name, loader, name, dirs): 
     46        def reload(): 
     47                return loader(name, dirs)[0] 
    4948        super(LoaderOrigin, self).__init__(name) 
    50         self.loader = loader 
     49        self._reload = reload 
    5150     
    5251    def reload(self): 
    53         if self.loader: 
    54             return self.loader() 
    55         else: 
    56             raise NotImplementedException 
    57  
     52        return self._reload() 
    5853 
    5954def find_template_source(name, dirs=None): 
     
    6257            source, display_name  = loader(name, dirs)  
    6358             
    64             def reload(): 
    65                 return loader(name, dirs)[0] 
    6659             
    67             return (source, LoaderOrigin(display_name, reload)) 
     60             
     61            return (source, LoaderOrigin(display_name, loader, name, dirs)) 
    6862        except TemplateDoesNotExist: 
    6963            pass 
     
    217211             return '' # Fail silently for invalid included templates. 
    218212 
    219  
    220213def do_block(parser, token): 
    221214    """ 
  • django/branches/new-admin/django/core/validators.py

    r975 r981  
    1313_datere = r'\d{4}-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[12][0-9])|(?:3[0-1]))' 
    1414_timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?' 
    15 alnum_re = re.compile(r'^[\w-]+$') 
     15alnum_re = re.compile(r'^\w+$') 
    1616alnumurl_re = re.compile(r'^[\w/]+$') 
    1717ansi_date_re = re.compile('^%s$' % _datere) 
     
    5555def isAlphaNumeric(field_data, all_data): 
    5656    if not alnum_re.search(field_data): 
    57         raise ValidationError, "This value must contain only letters, numbers, dashes and underscores." 
     57        raise ValidationError, "This value must contain only letters, numbers and underscores." 
    5858 
    5959def isAlphaNumericURL(field_data, all_data): 
  • django/branches/new-admin/django/views/generic/create_update.py

    r773 r981  
    1010def create_object(request, app_label, module_name, template_name=None,  
    1111                 template_loader=template_loader, extra_context={},  
    12                  post_save_redirect=None, login_required=False): 
     12                 post_save_redirect=None, login_required=False, follow=None): 
    1313    """ 
    1414    Generic object-creation function. 
     
    2323         
    2424    mod = models.get_module(app_label, module_name) 
    25     manipulator = mod.AddManipulator(
     25    manipulator = mod.AddManipulator(follow=follow
    2626    if request.POST: 
    2727        # If data was POSTed, we're trying to create a new object 
     
    3030        # Check for errors 
    3131        errors = manipulator.get_validation_errors(new_data) 
     32        manipulator.do_html2python(new_data) 
    3233         
    3334        if not errors: 
    3435            # No errors -- this means we can save the data! 
    35             manipulator.do_html2python(new_data) 
    3636            new_object = manipulator.save(new_data) 
    3737             
     
    4949    else: 
    5050        # No POST, so we want a brand new form without any data or errors 
    51         errors = new_data = {} 
     51        errors = {} 
     52        new_data = manipulator.flatten_data() 
    5253     
    5354    # Create the FormWrapper, template, context, response