def test_add_trail_from_existing_topology_does_not_use_pk(self): import bs4 self.login() trail = TrailFactory(offset=3.14) response = self.client.get(Trail.get_add_url() + '?topology=%s' % trail.pk) soup = bs4.BeautifulSoup(response.content, 'lxml') textarea_field = soup.find(id="id_topology") self.assertIn('"kind": "TOPOLOGY"', textarea_field.text) self.assertIn('"offset": 3.14', textarea_field.text) self.assertNotIn('"pk": %s' % trail.pk, textarea_field.text)
def test_add_trail_from_existing_topology_does_not_use_pk(self): import bs4 self.login() trail = TrailFactory(offset=3.14) response = self.client.get(Trail.get_add_url() + '?topology=%s' % trail.pk) soup = bs4.BeautifulSoup(response.content) textarea_field = soup.find(id="id_topology") self.assertIn('"kind": "TOPOLOGY"', textarea_field.text) self.assertIn('"offset": 3.14', textarea_field.text) self.assertNotIn('"pk": %s' % trail.pk, textarea_field.text)
def test_add_trail_from_existing_topology(self): self.login() trail = TrailFactory() form_data = self.get_good_data() form_data['topology'] = trail.serialize(with_pk=False) response = self.client.post(Trail.get_add_url(), form_data) self.assertEqual(response.status_code, 302) # success, redirects to detail view p = re.compile(r"/trail/(\d+)/") m = p.match(response['Location']) new_pk = int(m.group(1)) new_trail = Trail.objects.get(pk=new_pk) self.assertIn(trail, new_trail.trails.all())
def test_add_trail_from_existing_topology(self): self.login() trail = TrailFactory() form_data = self.get_good_data() form_data['topology'] = trail.serialize(with_pk=False) response = self.client.post(Trail.get_add_url(), form_data) self.assertEqual(response.status_code, 302) # success, redirects to detail view p = re.compile(r"http://testserver/trail/(\d+)/") m = p.match(response['Location']) new_pk = int(m.group(1)) new_trail = Trail.objects.get(pk=new_pk) self.assertIn(trail, new_trail.trails.all())
@classmethod def path_interventions(cls, path): return cls.objects.existing().filter(topology__aggregations__path=path) @classmethod def trail_interventions(cls, trail): """ Interventions of a trail is the union of interventions on all its paths """ return cls.objects.existing().filter(topology__aggregations__path__trail=trail) @classmethod def topology_interventions(cls, topology): topos = Topology.overlapping(topology).values_list('pk', flat=True) return cls.objects.existing().filter(topology__in=topos).distinct('pk') Path.add_property('interventions', lambda self: Intervention.path_interventions(self)) Trail.add_property('interventions', lambda self: Intervention.trail_interventions(self)) Topology.add_property('interventions', lambda self: Intervention.topology_interventions(self)) class InterventionStatus(StructureRelated): status = models.CharField(verbose_name=_(u"Status"), max_length=128, db_column='status') class Meta: db_table = 'm_b_suivi' verbose_name = _(u"Intervention's status") verbose_name_plural = _(u"Intervention's statuses") ordering = ['id'] def __unicode__(self): return self.status
@classmethod def trail_interventions(cls, trail): """ Interventions of a trail is the union of interventions on all its paths """ return cls.objects.existing().filter( topology__aggregations__path__trail=trail) @classmethod def topology_interventions(cls, topology): topos = Topology.overlapping(topology).values_list('pk', flat=True) return cls.objects.existing().filter(topology__in=topos).distinct('pk') Path.add_property('interventions', lambda self: Intervention.path_interventions(self)) Trail.add_property('interventions', lambda self: Intervention.trail_interventions(self)) Topology.add_property('interventions', lambda self: Intervention.topology_interventions(self)) class InterventionStatus(StructureRelated): status = models.CharField(verbose_name=_(u"Status"), max_length=128, db_column='status') class Meta: db_table = 'm_b_suivi' verbose_name = _(u"Intervention's status") verbose_name_plural = _(u"Intervention's statuses") ordering = ['id']