Django

Code

Show
Ignore:
Timestamp:
08/05/08 12:15:33 (4 months ago)
Author:
jbronn
Message:

gis: Merged revisions 7981-8001,8003-8011,8013-8033,8035-8036,8038-8039,8041-8063,8065-8076,8078-8139,8141-8154,8156-8214 via svnmerge from trunk.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis

    • Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
  • django/branches/gis/tests/modeltests/choices/models.py

    r6018 r8215  
    3737>>> s.get_gender_display() 
    3838u'Female' 
     39 
     40# If the value for the field doesn't correspond to a valid choice, 
     41# the value itself is provided as a display value. 
     42>>> a.gender = '' 
     43>>> a.get_gender_display() 
     44u'' 
     45 
     46>>> a.gender = 'U' 
     47>>> a.get_gender_display() 
     48u'U' 
     49 
    3950"""} 
  • django/branches/gis/tests/modeltests/custom_methods/models.py

    r6018 r8215  
    3232            FROM custom_methods_article 
    3333            WHERE pub_date = %s 
    34                 AND id != %s""", [str(self.pub_date), self.id]) 
     34                AND id != %s""", [connection.ops.value_to_db_date(self.pub_date), 
     35                                  self.id]) 
    3536        # The asterisk in "(*row)" tells Python to expand the list into 
    3637        # positional arguments to Article(). 
  • django/branches/gis/tests/modeltests/delete/models.py

    r7768 r8215  
    4343 
    4444__test__ = {'API_TESTS': """ 
    45 # First, some tests for the datastructure we use 
     45### Tests for models A,B,C,D ### 
     46 
     47## First, test the CollectedObjects data structure directly 
    4648 
    4749>>> from django.db.models.query import CollectedObjects 
     
    7375 
    7476 
     77## Second, test the usage of CollectedObjects by Model.delete() 
    7578 
    7679# Due to the way that transactions work in the test harness, 
     
    8588# access to internals here :-) 
    8689 
     90# If implementation changes, then the tests may need to be simplified: 
     91#  - remove the lines that set the .keyOrder and clear the related 
     92#    object caches 
     93#  - remove the second set of tests (with a2, b2 etc) 
     94 
    8795>>> from django.db.models.loading import cache 
     96 
     97>>> def clear_rel_obj_caches(models): 
     98...     for m in models: 
     99...         if hasattr(m._meta, '_related_objects_cache'):  
     100...             del m._meta._related_objects_cache 
    88101 
    89102# Nice order 
    90103>>> cache.app_models['delete'].keyOrder = ['a', 'b', 'c', 'd'] 
    91 >>> del A._meta._related_objects_cache 
    92 >>> del B._meta._related_objects_cache 
    93 >>> del C._meta._related_objects_cache 
    94 >>> del D._meta._related_objects_cache 
     104>>> clear_rel_obj_caches([A, B, C, D]) 
    95105 
    96106>>> a1 = A() 
     
    111121# Same again with a known bad order 
    112122>>> cache.app_models['delete'].keyOrder = ['d', 'c', 'b', 'a'] 
    113 >>> del A._meta._related_objects_cache 
    114 >>> del B._meta._related_objects_cache 
    115 >>> del C._meta._related_objects_cache 
    116 >>> del D._meta._related_objects_cache 
     123>>> clear_rel_obj_caches([A, B, C, D]) 
    117124 
    118125>>> a2 = A() 
     
    131138>>> a2.delete() 
    132139 
    133 # Tests for nullable related fields 
     140### Tests for models E,F - nullable related fields ### 
     141 
     142## First, test the CollectedObjects data structure directly 
    134143 
    135144>>> g = CollectedObjects() 
     
    142151>>> g.ordered_keys() 
    143152['key1', 'key2'] 
     153 
     154## Second, test the usage of CollectedObjects by Model.delete() 
    144155 
    145156>>> e1 = E() 
  • django/branches/gis/tests/modeltests/generic_relations/models.py

    r6920 r8215  
    2828        return self.tag 
    2929 
     30class Comparison(models.Model): 
     31    """ 
     32    A model that tests having multiple GenericForeignKeys 
     33    """ 
     34    comparative = models.CharField(max_length=50) 
     35     
     36    content_type1 = models.ForeignKey(ContentType, related_name="comparative1_set") 
     37    object_id1 = models.PositiveIntegerField() 
     38 
     39    content_type2 = models.ForeignKey(ContentType,  related_name="comparative2_set") 
     40    object_id2 = models.PositiveIntegerField() 
     41 
     42    first_obj = generic.GenericForeignKey(ct_field="content_type1", fk_field="object_id1") 
     43    other_obj = generic.GenericForeignKey(ct_field="content_type2", fk_field="object_id2") 
     44 
     45    def __unicode__(self): 
     46        return u"%s is %s than %s" % (self.first_obj, self.comparative, self.other_obj) 
     47 
    3048class Animal(models.Model): 
    3149    common_name = models.CharField(max_length=150) 
     
    3351 
    3452    tags = generic.GenericRelation(TaggedItem) 
     53    comparisons = generic.GenericRelation(Comparison,  
     54                                          object_id_field="object_id1", 
     55                                          content_type_field="content_type1") 
    3556 
    3657    def __unicode__(self): 
     
    137158[<Animal: Platypus>] 
    138159 
     160# Simple tests for multiple GenericForeignKeys 
     161# only uses one model, since the above tests should be sufficient. 
     162>>> tiger, cheetah, bear = Animal(common_name="tiger"), Animal(common_name="cheetah"), Animal(common_name="bear") 
     163>>> for o in [tiger, cheetah, bear]: o.save() 
     164 
     165# Create directly 
     166>>> Comparison(first_obj=cheetah, other_obj=tiger, comparative="faster").save() 
     167>>> Comparison(first_obj=tiger, other_obj=cheetah, comparative="cooler").save() 
     168 
     169# Create using GenericRelation 
     170>>> tiger.comparisons.create(other_obj=bear, comparative="cooler") 
     171<Comparison: tiger is cooler than bear> 
     172>>> tiger.comparisons.create(other_obj=cheetah, comparative="stronger") 
     173<Comparison: tiger is stronger than cheetah> 
     174 
     175>>> cheetah.comparisons.all() 
     176[<Comparison: cheetah is faster than tiger>] 
     177 
     178# Filtering works 
     179>>> tiger.comparisons.filter(comparative="cooler") 
     180[<Comparison: tiger is cooler than cheetah>, <Comparison: tiger is cooler than bear>] 
     181 
     182# Filtering and deleting works 
     183>>> subjective = ["cooler"] 
     184>>> tiger.comparisons.filter(comparative__in=subjective).delete() 
     185>>> Comparison.objects.all() 
     186[<Comparison: cheetah is faster than tiger>, <Comparison: tiger is stronger than cheetah>] 
     187 
     188# If we delete cheetah, Comparisons with cheetah as 'first_obj' will be deleted 
     189# since Animal has an explicit GenericRelation to Comparison through first_obj. 
     190# Comparisons with cheetah as 'other_obj' will not be deleted. 
     191>>> cheetah.delete() 
     192>>> Comparison.objects.all() 
     193[<Comparison: tiger is stronger than None>] 
    139194"""} 
  • django/branches/gis/tests/modeltests/invalid_models/models.py

    r7979 r8215  
    111111    rel1 = models.ForeignKey("Rel1") 
    112112    rel2 = models.ManyToManyField("Rel2") 
     113     
     114class MissingManualM2MModel(models.Model): 
     115    name = models.CharField(max_length=5) 
     116    missing_m2m = models.ManyToManyField(Model, through="MissingM2MModel") 
     117     
     118class Person(models.Model): 
     119    name = models.CharField(max_length=5) 
     120 
     121class Group(models.Model): 
     122    name = models.CharField(max_length=5) 
     123    primary = models.ManyToManyField(Person, through="Membership", related_name="primary") 
     124    secondary = models.ManyToManyField(Person, through="Membership", related_name="secondary") 
     125    tertiary = models.ManyToManyField(Person, through="RelationshipDoubleFK", related_name="tertiary") 
     126 
     127class GroupTwo(models.Model): 
     128    name = models.CharField(max_length=5) 
     129    primary = models.ManyToManyField(Person, through="Membership") 
     130    secondary = models.ManyToManyField(Group, through="MembershipMissingFK") 
     131 
     132class Membership(models.Model): 
     133    person = models.ForeignKey(Person) 
     134    group = models.ForeignKey(Group) 
     135    not_default_or_null = models.CharField(max_length=5) 
     136 
     137class MembershipMissingFK(models.Model): 
     138    person = models.ForeignKey(Person) 
     139 
     140class PersonSelfRefM2M(models.Model): 
     141    name = models.CharField(max_length=5) 
     142    friends = models.ManyToManyField('self', through="Relationship") 
     143    too_many_friends = models.ManyToManyField('self', through="RelationshipTripleFK") 
     144 
     145class PersonSelfRefM2MExplicit(models.Model): 
     146    name = models.CharField(max_length=5) 
     147    friends = models.ManyToManyField('self', through="ExplicitRelationship", symmetrical=True) 
     148 
     149class Relationship(models.Model): 
     150    first = models.ForeignKey(PersonSelfRefM2M, related_name="rel_from_set") 
     151    second = models.ForeignKey(PersonSelfRefM2M, related_name="rel_to_set") 
     152    date_added = models.DateTimeField() 
     153 
     154class ExplicitRelationship(models.Model): 
     155    first = models.ForeignKey(PersonSelfRefM2MExplicit, related_name="rel_from_set") 
     156    second = models.ForeignKey(PersonSelfRefM2MExplicit, related_name="rel_to_set") 
     157    date_added = models.DateTimeField() 
     158 
     159class RelationshipTripleFK(models.Model): 
     160    first = models.ForeignKey(PersonSelfRefM2M, related_name="rel_from_set_2") 
     161    second = models.ForeignKey(PersonSelfRefM2M, related_name="rel_to_set_2") 
     162    third = models.ForeignKey(PersonSelfRefM2M, related_name="too_many_by_far") 
     163    date_added = models.DateTimeField() 
     164 
     165class RelationshipDoubleFK(models.Model): 
     166    first = models.ForeignKey(Person, related_name="first_related_name") 
     167    second = models.ForeignKey(Person, related_name="second_related_name") 
     168    third = models.ForeignKey(Group, related_name="rel_to_set") 
     169    date_added = models.DateTimeField() 
    113170 
    114171model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute. 
     
    196253invalid_models.missingrelations: 'rel2' has m2m relation with model Rel2, which has not been installed 
    197254invalid_models.missingrelations: 'rel1' has relation with model Rel1, which has not been installed 
     255invalid_models.grouptwo: 'primary' has a manually-defined m2m relation through model Membership, which does not have foreign keys to Person and GroupTwo 
     256invalid_models.grouptwo: 'secondary' has a manually-defined m2m relation through model MembershipMissingFK, which does not have foreign keys to Group and GroupTwo 
     257invalid_models.missingmanualm2mmodel: 'missing_m2m' specifies an m2m relation through model MissingM2MModel, which has not been installed 
     258invalid_models.group: The model Group has two manually-defined m2m relations through the model Membership, which is not permitted. Please consider using an extra field on your intermediary model instead. 
     259invalid_models.group: Intermediary model RelationshipDoubleFK has more than one foreign key to Person, which is ambiguous and is not permitted. 
     260invalid_models.personselfrefm2m: Many-to-many fields with intermediate tables cannot be symmetrical. 
     261invalid_models.personselfrefm2m: Intermediary model RelationshipTripleFK has more than two foreign keys to PersonSelfRefM2M, which is ambiguous and is not permitted. 
     262invalid_models.personselfrefm2mexplicit: Many-to-many fields with intermediate tables cannot be symmetrical. 
    198263""" 
  • django/branches/gis/tests/modeltests/many_to_one/models.py

    r7979 r8215  
    4747# Article objects have access to their related Reporter objects. 
    4848>>> r = a.reporter 
     49 
     50# These are strings instead of unicode strings because that's what was used in 
     51# the creation of this reporter (and we haven't refreshed the data from the 
     52# database, which always returns unicode strings). 
    4953>>> r.first_name, r.last_name 
    50 (u'John', u'Smith') 
     54('John', 'Smith') 
    5155 
    5256# Create an Article via the Reporter object. 
     
    177181 
    178182# You can also use a queryset instead of a literal list of instances. 
    179 # The queryset must be reduced to a list of values using values(),  
     183# The queryset must be reduced to a list of values using values(), 
    180184# then converted into a query 
    181185>>> Article.objects.filter(reporter__in=Reporter.objects.filter(first_name='John').values('pk').query).distinct() 
  • django/branches/gis/tests/modeltests/model_formsets/models.py

    r7979 r8215  
    11from django.db import models 
     2 
     3try: 
     4    sorted 
     5except NameError: 
     6    from django.utils.itercompat import sorted 
    27 
    38class Author(models.Model): 
    49    name = models.CharField(max_length=100) 
     10 
     11    class Meta: 
     12        ordering = ('name',) 
    513 
    614    def __unicode__(self): 
     
    1826    authors = models.ManyToManyField(Author) 
    1927    created = models.DateField(editable=False) 
    20      
     28 
    2129    def __unicode__(self): 
    2230        return self.name 
     31 
     32class CustomPrimaryKey(models.Model): 
     33    my_pk = models.CharField(max_length=10, primary_key=True) 
     34    some_field = models.CharField(max_length=100) 
    2335 
    2436 
     
    4254...     'form-TOTAL_FORMS': '3', # the number of forms rendered 
    4355...     'form-INITIAL_FORMS': '0', # the number of forms with initial data 
    44 ...     'form-MAX_FORMS': '0', # the max number of forms 
    4556...     'form-0-name': 'Charles Baudelaire', 
    4657...     'form-1-name': 'Arthur Rimbaud', 
     
    8091...     'form-TOTAL_FORMS': '3', # the number of forms rendered 
    8192...     'form-INITIAL_FORMS': '2', # the number of forms with initial data 
    82 ...     'form-MAX_FORMS': '0', # the max number of forms 
    8393...     'form-0-id': '2', 
    8494...     'form-0-name': 'Arthur Rimbaud', 
     
    124134...     'form-TOTAL_FORMS': '4', # the number of forms rendered 
    125135...     'form-INITIAL_FORMS': '3', # the number of forms with initial data 
    126 ...     'form-MAX_FORMS': '0', # the max number of forms 
    127136...     'form-0-id': '2', 
    128137...     'form-0-name': 'Arthur Rimbaud', 
     
    154163...     'form-TOTAL_FORMS': '4', # the number of forms rendered 
    155164...     'form-INITIAL_FORMS': '3', # the number of forms with initial data 
    156 ...     'form-MAX_FORMS': '0', # the max number of forms 
    157165...     'form-0-id': '2', 
    158166...     'form-0-name': 'Walt Whitman', 
     
    185193...     'form-TOTAL_FORMS': '2', # the number of forms rendered 
    186194...     'form-INITIAL_FORMS': '1', # the number of forms with initial data 
    187 ...     'form-MAX_FORMS': '0', # the max number of forms 
    188195...     'form-0-id': '1', 
    189196...     'form-0-name': '2nd Tuesday of the Week Meeting', 
     
    202209>>> formset.save_m2m() 
    203210>>> instances[0].authors.all() 
    204 [<Author: Charles Baudelaire>, <Author: Walt Whitman>, <Author: Paul Verlaine>, <Author: John Steinbeck>] 
     211[<Author: Charles Baudelaire>, <Author: John Steinbeck>, <Author: Paul Verlaine>, <Author: Walt Whitman>] 
    205212 
    206213# delete the author we created to allow later tests to continue working. 
     
    215222>>> AuthorFormSet = modelformset_factory(Author, max_num=2) 
    216223>>> formset = AuthorFormSet(queryset=qs) 
    217 >>> formset.initial 
    218 [{'id': 1, 'name': u'Charles Baudelaire'}, {'id': 3, 'name': u'Paul Verlaine'}
     224>>> [sorted(x.items()) for x in formset.initial] 
     225[[('id', 1), ('name', u'Charles Baudelaire')], [('id', 3), ('name', u'Paul Verlaine')]
    219226 
    220227>>> AuthorFormSet = modelformset_factory(Author, max_num=3) 
    221228>>> formset = AuthorFormSet(queryset=qs) 
    222 >>> formset.initial 
    223 [{'id': 1, 'name': u'Charles Baudelaire'}, {'id': 3, 'name': u'Paul Verlaine'}, {'id': 2, 'name': u'Walt Whitman'}] 
     229>>> [sorted(x.items()) for x in formset.initial] 
     230[[('id', 1), ('name', u'Charles Baudelaire')], [('id', 3), ('name', u'Paul Verlaine')], [('id', 2), ('name', u'Walt Whitman')]] 
     231 
    224232 
    225233# Inline Formsets ############################################################ 
     
    243251...     'book_set-TOTAL_FORMS': '3', # the number of forms rendered 
    244252...     'book_set-INITIAL_FORMS': '0', # the number of forms with initial data 
    245 ...     'book_set-MAX_FORMS': '0', # the max number of forms 
    246253...     'book_set-0-title': 'Les Fleurs du Mal', 
    247254...     'book_set-1-title': '', 
     
    278285...     'book_set-TOTAL_FORMS': '3', # the number of forms rendered 
    279286...     'book_set-INITIAL_FORMS': '1', # the number of forms with initial data 
    280 ...     'book_set-MAX_FORMS': '0', # the max number of forms 
    281287...     'book_set-0-id': '1', 
    282288...     'book_set-0-title': 'Les Fleurs du Mal', 
     
    294300As you can see, 'Le Spleen de Paris' is now a book belonging to Charles Baudelaire. 
    295301 
    296 >>> for book in author.book_set.order_by('title'): 
     302>>> for book in author.book_set.order_by('id'): 
    297303...     print book.title 
     304Les Fleurs du Mal 
    298305Le Spleen de Paris 
    299 Les Fleurs du Mal 
    300306 
    301307The save_as_new parameter lets you re-associate the data to a new instance. 
     
    305311...     'book_set-TOTAL_FORMS': '3', # the number of forms rendered 
    306312...     'book_set-INITIAL_FORMS': '2', # the number of forms with initial data 
    307 ...     'book_set-MAX_FORMS': '0', # the max number of forms 
    308313...     'book_set-0-id': '1', 
    309314...     'book_set-0-title': 'Les Fleurs du Mal', 
     
    322327[<Book: Les Fleurs du Mal>, <Book: Le Spleen de Paris>] 
    323328 
     329Test using a custom prefix on an inline formset. 
     330 
     331>>> formset = AuthorBooksFormSet(prefix="test") 
     332>>> for form in formset.forms: 
     333...     print form.as_p() 
     334<p><label for="id_test-0-title">Title:</label> <input id="id_test-0-title" type="text" name="test-0-title" maxlength="100" /><input type="hidden" name="test-0-id" id="id_test-0-id" /></p> 
     335<p><label for="id_test-1-title">Title:</label> <input id="id_test-1-title" type="text" name="test-1-title" maxlength="100" /><input type="hidden" name="test-1-id" id="id_test-1-id" /></p> 
     336 
     337# Test a custom primary key ################################################### 
     338 
     339We need to ensure that it is displayed 
     340 
     341>>> CustomPrimaryKeyFormSet = modelformset_factory(CustomPrimaryKey) 
     342>>> formset = CustomPrimaryKeyFormSet() 
     343>>> for form in formset.forms: 
     344...     print form.as_p() 
     345<p><label for="id_form-0-my_pk">My pk:</label> <input id="id_form-0-my_pk" type="text" name="form-0-my_pk" maxlength="10" /></p> 
     346<p><label for="id_form-0-some_field">Some field:</label> <input id="id_form-0-some_field" type="text" name="form-0-some_field" maxlength="100" /></p> 
     347 
    324348"""} 
  • django/branches/gis/tests/modeltests/model_forms/models.py

    r7979 r8215  
    7070    try: 
    7171        # If PIL is available, try testing PIL. 
    72         # Otherwise, it's equivalent to TextFile above. 
    73         import Image 
     72        # Checking for the existence of Image is enough for CPython, but 
     73        # for PyPy, you need to check for the underlying modules 
     74        # If PIL is not available, this test is equivalent to TextFile above. 
     75        import Image, _imaging 
    7476        image = models.ImageField(upload_to=tempfile.gettempdir()) 
    7577    except ImportError: 
  • django/branches/gis/tests/modeltests/pagination/models.py

    r7918 r8215  
    55of code. This is often useful for dividing search results or long lists of 
    66objects into easily readable pages. 
    7  
    8 In Django 0.96 and earlier, a single ObjectPaginator class implemented this 
    9 functionality. In the Django development version, the behavior is split across 
    10 two classes -- Paginator and Page -- that are more easier to use. The legacy 
    11 ObjectPaginator class is deprecated. 
    127""" 
    138 
     
    2823...     a.save() 
    2924 
    30 #################################### 
    31 # New/current API (Paginator/Page)
    32 #################################### 
     25################## 
     26# Paginator/Page
     27################## 
    3328 
    3429>>> from django.core.paginator import Paginator 
     
    1411365 
    142137 
    143 ################################ 
    144 # Legacy API (ObjectPaginator) # 
    145 ################################ 
     138# Paginator can be passed other objects with a count() method. 
     139>>> class CountContainer: 
     140...     def count(self): 
     141...         return 42 
     142>>> paginator = Paginator(CountContainer(), 10) 
     143>>> paginator.count 
     14442 
     145>>> paginator.num_pages 
     146
     147>>> paginator.page_range 
     148[1, 2, 3, 4, 5] 
    146149 
    147 # Don't print out the deprecation warnings during testing. 
    148 >>> from warnings import filterwarnings 
    149 >>> filterwarnings("ignore") 
    150  
    151 >>> from django.core.paginator import ObjectPaginator, EmptyPage 
    152 >>> paginator = ObjectPaginator(Article.objects.all(), 5) 
    153 >>> paginator.hits 
    154 
    155 >>> paginator.pages 
    156 
    157 >>> paginator.page_range 
    158 [1, 2] 
    159  
    160 # Get the first page. 
    161 >>> paginator.get_page(0) 
    162 [<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: Article 4>, <Article: Article 5>] 
    163 >>> paginator.has_next_page(0) 
    164 True 
    165 >>> paginator.has_previous_page(0) 
    166 False 
    167 >>> paginator.first_on_page(0) 
    168 
    169 >>> paginator.last_on_page(0) 
    170 
    171  
    172 # Get the second page. 
    173 >>> paginator.get_page(1) 
    174 [<Article: Article 6>, <Article: Article 7>, <Article: Article 8>, <Article: Article 9>] 
    175 >>> paginator.has_next_page(1) 
    176 False 
    177 >>> paginator.has_previous_page(1) 
    178 True 
    179 >>> paginator.first_on_page(1) 
    180 
    181 >>> paginator.last_on_page(1) 
    182 
    183  
    184 # Invalid pages raise EmptyPage. 
    185 >>> paginator.get_page(-1) 
    186 Traceback (most recent call last): 
    187 ... 
    188 EmptyPage: ... 
    189 >>> paginator.get_page(2) 
    190 Traceback (most recent call last): 
    191 ... 
    192 EmptyPage: ... 
    193  
    194 # Empty paginators with allow_empty_first_page=True. 
    195 >>> paginator = ObjectPaginator(Article.objects.filter(id=0), 5) 
    196 >>> paginator.count 
    197 
    198 >>> paginator.num_pages 
    199 
    200 >>> paginator.page_range 
    201 [1] 
    202  
    203 # ObjectPaginator can be passed lists too. 
    204 >>> paginator = ObjectPaginator([1, 2, 3], 5) 
    205 >>> paginator.hits 
    206 
    207 >>> paginator.pages 
    208 
    209 >>> paginator.page_range 
    210 [1] 
    211  
    212  
    213 # ObjectPaginator can be passed other objects with a count() method. 
    214 >>> class Container: 
     150# Paginator can be passed other objects that implement __len__. 
     151>>> class LenContainer: 
    215152...     def __len__(self): 
    216153...         return 42 
    217 >>> paginator = ObjectPaginator(Container(), 10) 
    218 >>> paginator.hits 
     154>>> paginator = Paginator(LenContainer(), 10) 
     155>>> paginator.count 
    21915642 
    220 >>> paginator.pages 
     157>>> paginator.num_pages 
    2211585 
    222159>>> paginator.page_range 
     
    238175 
    239176# With orphans only set to 1, we should get two pages. 
    240 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=1) 
     177>>> paginator = Paginator(Article.objects.all(), 10, orphans=1) 
    241178>>> paginator.num_pages 
    2421792 
    243  
    244 # LEGACY: With orphans set to 3 and 10 items per page, we should get all 12 items on a single page. 
    245 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=3) 
    246 >>> paginator.pages 
    247 1 
    248  
    249 # LEGACY: With orphans only set to 1, we should get two pages. 
    250 >>> paginator = ObjectPaginator(Article.objects.all(), 10, orphans=1) 
    251 >>> paginator.pages 
    252 2 
    253180"""} 
  • django/branches/gis/tests/modeltests/validation/models.py

    r7354 r8215  
    1717    favorite_moment = models.DateTimeField() 
    1818    email = models.EmailField() 
     19    best_time = models.TimeField() 
    1920 
    2021    def __unicode__(self): 
     
    2930...     'birthdate': datetime.date(2000, 5, 3), 
    3031...     'favorite_moment': datetime.datetime(2002, 4, 3, 13, 23), 
    31 ...     'email': 'john@example.com' 
     32...     'email': 'john@example.com', 
     33...     'best_time': datetime.time(16, 20), 
    3234... } 
    3335>>> p = Person(**valid_params) 
     
    131133datetime.datetime(2002, 4, 3, 0, 0) 
    132134 
     135>>> p = Person(**dict(valid_params, best_time='16:20:00')) 
     136>>> p.validate() 
     137{} 
     138>>> p.best_time 
     139datetime.time(16, 20) 
     140 
     141>>> p = Person(**dict(valid_params, best_time='16:20')) 
     142>>> p.validate() 
     143{} 
     144>>> p.best_time 
     145datetime.time(16, 20) 
     146 
     147>>> p = Person(**dict(valid_params, best_time='bar')) 
     148>>> p.validate()['best_time'] 
     149[u'Enter a valid time in HH:MM[:ss[.uuuuuu]] format.'] 
     150 
    133151>>> p = Person(**dict(valid_params, email='john@example.com')) 
    134152>>> p.validate() 
     
    154172>>> errors['birthdate'] 
    155173[u'This field is required.'] 
     174>>> errors['best_time'] 
     175[u'This field is required.'] 
    156176 
    157177"""} 
  • django/branches/gis/tests/regressiontests/admin_scripts/tests.py

    r7979 r8215  
    11""" 
    2 A series of tests to establish that the command-line managment tools work as  
     2A series of tests to establish that the command-line managment tools work as 
    33advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE 
    44and default settings.py files. 
     
    77import unittest 
    88import shutil 
     9import sys 
     10import re 
    911 
    1012from django import conf, bin, get_version 
     
    1315class AdminScriptTestCase(unittest.TestCase): 
    1416    def write_settings(self, filename, apps=None): 
    15         test_dir = os.path.dirname(os.path.dirname(__file__))  
     17        test_dir = os.path.dirname(os.path.dirname(__file__)) 
    1618        settings_file = open(os.path.join(test_dir,filename), 'w') 
    1719        settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n') 
     
    2830            if hasattr(settings,s): 
    2931                settings_file.write("%s = '%s'\n" % (s, str(getattr(settings,s)))) 
    30                  
     32 
    3133        if apps is None: 
    3234            apps = ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts'] 
     
    3436        if apps: 
    3537            settings_file.write("INSTALLED_APPS = %s\n" % apps) 
     38 
     39        settings_file.close() 
     40 
     41    def remove_settings(self, filename): 
     42        test_dir = os.path.dirname(os.path.dirname(__file__)) 
     43        full_name = os.path.join(test_dir, filename) 
     44        os.remove(full_name) 
    3645         
    37         settings_file.close() 
    38          
    39     def remove_settings(self, filename): 
    40         test_dir = os.path.dirname(os.path.dirname(__file__))  
    41         os.remove(os.path.join(test_dir, filename)) 
    42         # Also try to remove the pyc file; if it exists, it could 
     46        # Also try to remove the compiled file; if it exists, it could 
    4347        # mess up later tests that depend upon the .py file not existing 
    4448        try: 
    45             os.remove(os.path.join(test_dir, filename + 'c')) 
     49            if sys.platform.startswith('java'): 
     50                # Jython produces module$py.class files 
     51                os.remove(re.sub(r'\.py$', '$py.class', full_name)) 
     52            else: 
     53                # CPython produces module.pyc files 
     54                os.remove(full_name + 'c') 
    4655        except OSError: 
    4756            pass 
    48              
     57         
     58    def _sys_executable(self): 
     59        """ 
     60        Returns the command line needed to run a python interpreter, including 
     61        the options for setting sys.path on Jython, which doesn't recognize 
     62        PYTHONPATH. 
     63        """ 
     64        if sys.platform.startswith('java'): 
     65            return "%s -J-Dpython.path=%s" % \ 
     66                   (sys.executable, os.environ['PYTHONPATH']) 
     67        else: 
     68            return sys.executable 
     69 
    4970    def run_test(self, script, args, settings_file=None, apps=None): 
    5071        test_dir = os.path.dirname(os.path.dirname(__file__)) 
    5172        project_dir = os.path.dirname(test_dir) 
    5273        base_dir = os.path.dirname(project_dir) 
    53          
    54         # Build the command line 
    55         cmd = 'python "%s"' % script 
    56         cmd += ''.join([' %s' % arg for arg in args]) 
    57          
     74 
    5875        # Remember the old environment 
    5976        old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None) 
    6077        old_python_path = os.environ.get('PYTHONPATH', None) 
    6178        old_cwd = os.getcwd() 
    62          
     79 
    6380        # Set the test environment 
    6481        if settings_file: 
     
    6683        elif 'DJANGO_SETTINGS_MODULE' in os.environ: 
    6784            del os.environ['DJANGO_SETTINGS_MODULE'] 
    68&nbs