Changeset 981
- Timestamp:
- 10/20/05 10:55:45 (3 years ago)
- Files:
-
- django/branches/new-admin/django/conf/urls/admin.py (deleted)
- django/branches/new-admin/django/contrib/admin/views/main.py (modified) (1 diff)
- django/branches/new-admin/django/contrib/admin/views/template.py (modified) (1 diff)
- django/branches/new-admin/django/core/formfields.py (modified) (4 diffs)
- django/branches/new-admin/django/core/management.py (modified) (1 diff)
- django/branches/new-admin/django/core/meta/fields.py (modified) (7 diffs)
- django/branches/new-admin/django/core/meta/__init__.py (modified) (5 diffs)
- django/branches/new-admin/django/core/template/defaulttags.py (modified) (1 diff)
- django/branches/new-admin/django/core/template/__init__.py (modified) (7 diffs)
- django/branches/new-admin/django/core/template/loader.py (modified) (3 diffs)
- django/branches/new-admin/django/core/validators.py (modified) (2 diffs)
- django/branches/new-admin/django/views/generic/create_update.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/new-admin/django/contrib/admin/views/main.py
r966 r981 928 928 request.user.add_message('The %s "%s" was deleted successfully.' % (opts.verbose_name, obj_repr)) 929 929 return HttpResponseRedirect("../../") 930 return render_to_response('admin/delete_confirmation _generic', {930 return render_to_response('admin/delete_confirmation', { 931 931 "title": "Are you sure?", 932 932 "object_name": opts.verbose_name, django/branches/new-admin/django/contrib/admin/views/template.py
r933 r981 24 24 if not errors: 25 25 request.user.add_message('The template is valid.') 26 return render_to_response(' template_validator', {26 return render_to_response('admin/template_validator', { 27 27 'title': 'Template validator', 28 28 'form': formfields.FormWrapper(manipulator, new_data, errors), django/branches/new-admin/django/core/formfields.py
r939 r981 245 245 data = field.extract_data(self.data) 246 246 errors = self.errors.get(full_field_name, []) 247 # if(errors):raise full_field_name + " " + repr(errors)248 247 collection[field_name] = FormFieldWrapper(field, data, errors) 249 248 wrapper.append(FormFieldCollection(collection)) … … 289 288 290 289 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'): 292 291 data = data_dict.getlist(self.get_member_name()) 293 292 else: … … 295 294 if data is None: 296 295 data = '' 297 self.data_dict = data_dict 298 return data 296 return data 299 297 300 298 def convert_post_data(self, new_data): 301 name = self.get_member_name()299 name = self.get_member_name() 302 300 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) 305 302 try: 306 303 converted_data = [self.__class__.html2python(data) … … 309 306 converted_data = d 310 307 new_data.setlist(name, converted_data) 311 312 308 else: 313 309 try: django/branches/new-admin/django/core/management.py
r966 r981 634 634 from django.utils import autoreload 635 635 autoreload.main(inner_run) 636 #inner_run()637 636 runserver.args = '[optional port number, or ipaddr:port]' 638 637 django/branches/new-admin/django/core/meta/fields.py
r975 r981 259 259 return val 260 260 261 262 261 def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH): 263 262 "Returns a list of tuples used as SelectField choices for this field." … … 267 266 return first_choice + list(self.choices) 268 267 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)] 273 269 274 270 def get_choices_default(self): … … 285 281 286 282 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)} 294 289 295 290 def get_follow(self, override=None): … … 307 302 def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False): 308 303 if not rel: 309 return [] # Don't add a FormField unless it's in a related c hange context.304 return [] # Don't add a FormField unless it's in a related context. 310 305 return Field.get_manipulator_fields(self, opts, manipulator, change, name_prefix, rel) 311 306 … … 399 394 val = self._get_val_from_obj(obj) 400 395 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 '')} 403 398 404 399 class EmailField(Field): … … 595 590 def flatten_data(self,follow, obj = None): 596 591 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 '')} 598 593 599 594 class URLField(Field): … … 909 904 the dict has attribs 'fields' and maybe 'classes'. 910 905 fields is a list of subclasses of Field. 911 912 TODO:Return value needs to be encapsulated.913 906 """ 914 907 if self.fields is None: django/branches/new-admin/django/core/meta/__init__.py
r939 r981 925 925 if cursor.fetchone(): 926 926 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), 929 929 db_values + [pk_val]) 930 930 else: … … 1581 1581 for f in opts.fields + opts.many_to_many: 1582 1582 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):1584 1583 self.fields.extend(f.get_manipulator_fields(opts, self, change)) 1585 1584 … … 1590 1589 self.fields.extend(f.get_manipulator_fields(opts, self, change, fol)) 1591 1590 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_change1596 # 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_admin1602 # 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 1607 1591 # Add field for ordering. 1608 1592 if change and opts.get_ordered_objects(): … … 1613 1597 from django.utils.datastructures import DotExpandedDict 1614 1598 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. 1616 1601 auto_now_add = change and getattr(f, 'auto_now_add', False) 1617 1602 if self.follow.get(f.name, None) and not auto_now_add: … … 1624 1609 params[f.column] = param 1625 1610 1626 # Fields with auto_now_add are another special case; they should keep1627 # 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)1632 1611 1633 1612 if change: django/branches/new-admin/django/core/template/defaulttags.py
r876 r981 228 228 return output 229 229 230 231 230 class LoadNode(Node): 232 231 def __init__(self, taglib): django/branches/new-admin/django/core/template/__init__.py
r947 r981 75 75 ALLOWED_VARIABLE_CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.' 76 76 77 #What to report as the origin of templates that come from non file sources (egstrings)77 #What to report as the origin of templates that come from non loader sources (ie strings) 78 78 UNKNOWN_SOURCE="<unknown source>" 79 79 … … 141 141 "Display stage -- can be called many times" 142 142 return self.nodelist.render(context) 143 144 143 145 144 def compile_string(template_string, origin): … … 226 225 def tokenize(self): 227 226 "Return a list of tokens from a given template_string" 227 # remove all empty strings, because the regex has a tendency to add them 228 228 bits = filter(None, tag_re.split(self.template_string)) 229 229 return map(self.create_token, bits) … … 277 277 def __init__(self, tokens): 278 278 self.tokens = tokens 279 279 280 280 def parse(self, parse_until=[]): 281 281 nodelist = self.create_nodelist() … … 297 297 except IndexError: 298 298 self.empty_block_tag(token) 299 300 299 # execute callback function for this tag and append resulting node 301 300 self.enter_command(command, token); … … 303 302 compile_func = registered_tags[command] 304 303 except KeyError: 305 self.invalid_block_tag(token, command) 306 304 self.invalid_block_tag(token, command) 307 305 try: 308 306 compiled_result = compile_func(self, token) … … 310 308 if not self.compile_function_error(token, e): 311 309 raise 312 313 310 self.extend_nodelist(nodelist, compiled_result, token) 314 311 self.exit_command(); 315 316 312 if parse_until: 317 313 self.unclosed_block_tag(token, parse_until) 318 319 314 return nodelist 320 315 django/branches/new-admin/django/core/template/loader.py
r966 r981 42 42 template_source_loaders.append(func) 43 43 44 45 46 47 44 class 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] 49 48 super(LoaderOrigin, self).__init__(name) 50 self. loader = loader49 self._reload = reload 51 50 52 51 def reload(self): 53 if self.loader: 54 return self.loader() 55 else: 56 raise NotImplementedException 57 52 return self._reload() 58 53 59 54 def find_template_source(name, dirs=None): … … 62 57 source, display_name = loader(name, dirs) 63 58 64 def reload():65 return loader(name, dirs)[0]66 59 67 return (source, LoaderOrigin(display_name, reload)) 60 61 return (source, LoaderOrigin(display_name, loader, name, dirs)) 68 62 except TemplateDoesNotExist: 69 63 pass … … 217 211 return '' # Fail silently for invalid included templates. 218 212 219 220 213 def do_block(parser, token): 221 214 """ django/branches/new-admin/django/core/validators.py
r975 r981 13 13 _datere = r'\d{4}-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[12][0-9])|(?:3[0-1]))' 14 14 _timere = r'(?:[01]?[0-9]|2[0-3]):[0-5][0-9](?::[0-5][0-9])?' 15 alnum_re = re.compile(r'^ [\w-]+$')15 alnum_re = re.compile(r'^\w+$') 16 16 alnumurl_re = re.compile(r'^[\w/]+$') 17 17 ansi_date_re = re.compile('^%s$' % _datere) … … 55 55 def isAlphaNumeric(field_data, all_data): 56 56 if not alnum_re.search(field_data): 57 raise ValidationError, "This value must contain only letters, numbers , dashesand underscores."57 raise ValidationError, "This value must contain only letters, numbers and underscores." 58 58 59 59 def isAlphaNumericURL(field_data, all_data): django/branches/new-admin/django/views/generic/create_update.py
r773 r981 10 10 def create_object(request, app_label, module_name, template_name=None, 11 11 template_loader=template_loader, extra_context={}, 12 post_save_redirect=None, login_required=False ):12 post_save_redirect=None, login_required=False, follow=None): 13 13 """ 14 14 Generic object-creation function. … … 23 23 24 24 mod = models.get_module(app_label, module_name) 25 manipulator = mod.AddManipulator( )25 manipulator = mod.AddManipulator(follow=follow) 26 26 if request.POST: 27 27 # If data was POSTed, we're trying to create a new object … … 30 30 # Check for errors 31 31 errors = manipulator.get_validation_errors(new_data) 32 manipulator.do_html2python(new_data) 32 33 33 34 if not errors: 34 35 # No errors -- this means we can save the data! 35 manipulator.do_html2python(new_data)36 36 new_object = manipulator.save(new_data) 37 37 … … 49 49 else: 50 50 # 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() 52 53 53 54 # Create the FormWrapper, template, context, response
