Ticket #3268: __init__.diff
File __init__.diff, 6.4 KB (added by , 18 years ago) |
---|
-
__init__.py
337 337 def formfield(self, initial=None): 338 338 "Returns a django.newforms.Field instance for this database Field." 339 339 # TODO: This is just a temporary default during development. 340 return forms.CharField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 340 if self.choices: 341 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 342 else: 343 return forms.CharField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 341 344 342 345 def value_from_object(self, obj): 343 346 "Returns the value of this field in the given model instance." … … 397 400 return [oldforms.CheckboxField] 398 401 399 402 def formfield(self, initial=None): 400 return forms.BooleanField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 403 if self.choices: 404 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 405 else: 406 return forms.BooleanField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 401 407 402 408 class CharField(Field): 403 409 def get_manipulator_field_objs(self): … … 414 420 return str(value) 415 421 416 422 def formfield(self, initial=None): 417 return forms.CharField(max_length=self.maxlength, required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 423 if self.choices: 424 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 425 else: 426 return forms.CharField(max_length=self.maxlength, required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 418 427 419 428 # TODO: Maybe move this into contrib, because it's specialized. 420 429 class CommaSeparatedIntegerField(CharField): … … 488 497 return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or '')} 489 498 490 499 def formfield(self, initial=None): 491 return forms.DateField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 500 if self.choices: 501 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 502 else: 503 return forms.DateField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 492 504 493 505 class DateTimeField(DateField): 494 506 def to_python(self, value): … … 549 561 time_field: (val is not None and val.strftime("%H:%M:%S") or '')} 550 562 551 563 def formfield(self, initial=None): 552 return forms.DateTimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 564 if self.choices: 565 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 566 else: 567 return forms.DateTimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 553 568 554 569 class EmailField(CharField): 555 570 def __init__(self, *args, **kwargs): … … 566 581 validators.isValidEmail(field_data, all_data) 567 582 568 583 def formfield(self, initial=None): 569 return forms.EmailField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 584 if self.choices: 585 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 586 else: 587 return forms.EmailField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 570 588 571 589 class FileField(Field): 572 590 def __init__(self, verbose_name=None, name=None, upload_to='', **kwargs): … … 701 719 return [oldforms.IntegerField] 702 720 703 721 def formfield(self, initial=None): 704 return forms.IntegerField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 722 if self.choices: 723 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 724 else: 725 return forms.IntegerField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 705 726 706 727 class IPAddressField(Field): 707 728 def __init__(self, *args, **kwargs): … … 758 779 return [oldforms.LargeTextField] 759 780 760 781 def formfield(self, initial=None): 761 return forms.CharField(required=not self.blank, widget=forms.Textarea, label=capfirst(self.verbose_name), initial=initial) 782 if self.choices: 783 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 784 else: 785 return forms.CharField(required=not self.blank, widget=forms.Textarea, label=capfirst(self.verbose_name), initial=initial) 762 786 763 787 class TimeField(Field): 764 788 empty_strings_allowed = False … … 801 825 return {self.attname: (val is not None and val.strftime("%H:%M:%S") or '')} 802 826 803 827 def formfield(self, initial=None): 804 return forms.TimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 828 if self.choices: 829 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 830 else: 831 return forms.TimeField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial) 805 832 806 833 class URLField(CharField): 807 834 def __init__(self, verbose_name=None, name=None, verify_exists=True, **kwargs): … … 818 845 return "CharField" 819 846 820 847 def formfield(self, initial=None): 821 return forms.URLField(required=not self.blank, verify_exists=self.verify_exists, label=capfirst(self.verbose_name), initial=initial) 848 if self.choices: 849 return forms.ChoiceField(required=not self.blank, label=capfirst(self.verbose_name), initial=initial, choices=self.choices) 850 else: 851 return forms.URLField(required=not self.blank, verify_exists=self.verify_exists, label=capfirst(self.verbose_name), initial=initial) 822 852 823 853 class USStateField(Field): 824 854 def get_manipulator_field_objs(self):