Changeset 521
- Timestamp:
- 02/01/10 19:36:22 (7 months ago)
- Location:
- trunk/telemeta
- Files:
-
- 3 modified
-
models/crem.py (modified) (2 diffs)
-
models/cremquery.py (modified) (2 diffs)
-
tests/model_tests.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/telemeta/models/crem.py
r520 r521 557 557 558 558 name = CharField(_('name'), unique=True, max_length=150, required=True) 559 type = IntegerField(_('type'), choices=TYPE_CHOICES, required=True, db_index=True)559 type = IntegerField(_('type'), choices=TYPE_CHOICES, default=OTHER_TYPE, db_index=True) 560 560 complete_type = ForeignKey('LocationType', related_name="locations", verbose_name=_('complete type')) 561 561 current_location = WeakForeignKey('self', related_name="past_names", … … 577 577 return Location.objects.filter(ancestor_relations__ancestor_location=self) 578 578 579 def add_child(self, other): 580 LocationRelation.objects.create(location=other, ancestor_location=self, is_direct=True) 581 for location in self.ancestors(): 582 #FIXME: might raise Duplicate Entry 583 LocationRelation.objects.create(location=other, ancestor_location=location) 584 585 def add_parent(self, other): 586 LocationRelation.objects.create(location=self, ancestor_location=other, is_direct=True) 587 for location in self.descendants(): 588 #FIXME: might raise Duplicate Entry 589 LocationRelation.objects.create(location=location, ancestor_location=other) 590 579 591 def countries(self): 580 592 if self.type == self.COUNTRY: 581 593 return Location.objects.filter(pk=self.id) 582 594 return self.ancestors().filter(type=self.COUNTRY) 595 596 def continents(self): 597 if self.type == self.CONTINENT: 598 return Location.objects.filter(pk=self.id) 599 return self.ancestors().filter(type=self.CONTINENT) 583 600 584 601 class Meta(MetaCore): -
trunk/telemeta/models/cremquery.py
r520 r521 181 181 for lid in MediaItem.objects.filter(location__isnull=False).values_list('location', flat=True).distinct(): 182 182 location = Location.objects.get(pk=lid) 183 if not only_continent or (only_continent in location. ancestors().filter(type=Location.CONTINENT)):183 if not only_continent or (only_continent in location.continents()): 184 184 for l in location.countries(): 185 185 if not l in countries: … … 190 190 for country in countries: 191 191 count = country.collections().count() 192 for continent in country. ancestors().filter(type=Location.CONTINENT):192 for continent in country.continents(): 193 193 if not stat.has_key(continent): 194 194 stat[continent] = {} -
trunk/telemeta/tests/model_tests.py
r513 r521 46 46 self.olivier = User.objects.create(username="olivier", level="admin") 47 47 48 self.country = LocationType.objects.create(id="country", name="Country") 49 self.continent = LocationType.objects.create(id="continent", name="Continent") 50 self.city = LocationType.objects.create(id="city", name="City") 51 52 self.paris = Location.objects.create(name="Paris", type="other", complete_type=self.city) 53 self.france = Location.objects.create(name="France", type="country", complete_type=self.country) 54 self.europe = Location.objects.create(name="Europe", type="continent", complete_type=self.continent) 55 self.belgique = Location.objects.create(name="Belgique", type="country", complete_type=self.country) 56 57 LocationRelation.objects.create(location=self.paris, parent_location=self.france) 58 LocationRelation.objects.create(location=self.france, parent_location=self.europe) 48 self.country = LocationType.objects.create(code="country", name="Country") 49 self.continent = LocationType.objects.create(code="continent", name="Continent") 50 self.city = LocationType.objects.create(code="city", name="City") 51 52 self.paris = Location.objects.create(name="Paris", type=Location.OTHER_TYPE, complete_type=self.city) 53 self.france = Location.objects.create(name="France", type=Location.COUNTRY, complete_type=self.country) 54 self.europe = Location.objects.create(name="Europe", type=Location.CONTINENT, complete_type=self.continent) 55 self.belgique = Location.objects.create(name="Belgique", type=Location.COUNTRY, complete_type=self.country) 56 57 self.europe.add_child(self.france) 58 self.france.add_child(self.paris) 59 self.europe.add_child(self.belgique) 59 60 60 61 self.a = EthnicGroup.objects.create(name="a") … … 166 167 def testLocationSearch(self): 167 168 "Test by_country and by_continent properties of MediaCollection class" 168 self.assertEquals(self.collections.by_ country("France")[0], self.persepolis)169 self.assertEquals(self.collections.by_ continent("Europe")[0], self.persepolis)170 self.assertEquals(self.collections.by_ country("Belgique").order_by("title")[0], self.nicolas)171 self.assertEquals(self.collections.by_ country("Belgique").order_by("title")[1], self.volonte)169 self.assertEquals(self.collections.by_location(self.france)[0], self.persepolis) 170 self.assertEquals(self.collections.by_location(self.europe)[0], self.persepolis) 171 self.assertEquals(self.collections.by_location(self.belgique).order_by("title")[0], self.nicolas) 172 self.assertEquals(self.collections.by_location(self.belgique).order_by("title")[1], self.volonte) 172 173 173 174 def testRecordingYear(self): … … 270 271 def testLocationRelation(self): 271 272 "Test location country and continent resolving" 272 self.assertEquals(self.france, self.item_1.location.countr y())273 self.assertEquals(self.europe, self.item_1.location.continent ())274 self.assertEquals(self.france, self.item_2.location.countr y())275 self.assertEquals(self.europe, self.item_2.location.continent ())273 self.assertEquals(self.france, self.item_1.location.countries()[0]) 274 self.assertEquals(self.europe, self.item_1.location.continents()[0]) 275 self.assertEquals(self.france, self.item_2.location.countries()[0]) 276 self.assertEquals(self.europe, self.item_2.location.continents()[0]) 276 277 277 278 def testCollectionCountries(self):
