Ejemplo n.º 1
0
    def test_creation_form_on_signage(self):
        self.login()

        signa = SignageFactory.create()
        signage = "%s" % signa

        response = self.client.get(Blade.get_add_url() + '?signage=%s' % signa.pk)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, signage)
        form = response.context['form']
        self.assertEqual(form.initial['signage'], signa)
        # Should be able to save form successfully
        data = self.get_good_data()
        data['signage'] = signa.pk
        response = self.client.post(Blade.get_add_url() + '?signage=%s' % signa.pk, data)
        self.assertEqual(response.status_code, 302)
Ejemplo n.º 2
0
    def test_creation_form_on_signage(self):
        self.login()

        signa = SignageFactory.create()
        signage = u"%s" % signa

        response = self.client.get(Blade.get_add_url() + '?signage=%s' % signa.pk)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, signage)
        form = response.context['form']
        self.assertEqual(form.initial['signage'], signa)
        # Should be able to save form successfully
        data = self.get_good_data()
        data['signage'] = signa.pk
        response = self.client.post(Blade.get_add_url() + '?signage=%s' % signa.pk, data)
        self.assertEqual(response.status_code, 302)
Ejemplo n.º 3
0
    def test_delete_redirection(self):
        self.login()
        signage = SignageFactory.create()
        blade = BladeFactory.create(signage=signage)

        response = self.client.post(Blade.get_delete_url(blade))
        self.assertEqual(response.status_code, 302)
        self.assertRedirects(response, signage.get_detail_url(), status_code=302)
Ejemplo n.º 4
0
 def test_set_structure_with_permission(self):
     # The structure do not change because it changes with the signage form.
     # Need to check blade structure and line
     self.login()
     perm = Permission.objects.get(codename='can_bypass_structure')
     self.user.user_permissions.add(perm)
     structure = StructureFactory()
     self.assertNotEqual(structure, self.user.profile.structure)
     signage = SignageFactory(structure=structure)
     data = self.get_good_data()
     data['signage'] = signage.pk
     data['structure'] = self.user.profile.structure.pk
     response = self.client.post('%s?signage=%s' % (Blade.get_add_url(), signage.pk), data)
     self.assertEqual(response.status_code, 302)
     obj = self.model.objects.last()
     self.assertEqual(obj.structure, structure)
     self.logout()
Ejemplo n.º 5
0
 def test_set_structure_with_permission(self):
     # The structure do not change because it changes with the signage form.
     # Need to check blade structure and line
     self.login()
     perm = Permission.objects.get(codename='can_bypass_structure')
     self.user.user_permissions.add(perm)
     structure = StructureFactory()
     self.assertNotEqual(structure, self.user.profile.structure)
     signage = SignageFactory(structure=structure)
     data = self.get_good_data()
     data['signage'] = signage.pk
     data['structure'] = self.user.profile.structure.pk
     response = self.client.post('%s?signage=%s' % (Blade.get_add_url(), signage.pk), data)
     self.assertEqual(response.status_code, 302)
     obj = self.model.objects.last()
     self.assertEqual(obj.structure, structure)
     self.logout()
Ejemplo n.º 6
0
    def signages(self):
        if self.target_type == ContentType.objects.get_for_model(Signage):
            return [self.target]
        return []

    @property
    def infrastructures(self):
        if self.target_type == ContentType.objects.get_for_model(Infrastructure):
            return [self.target]
        return []


Path.add_property('interventions', lambda self: Intervention.path_interventions(self), _("Interventions"))
Topology.add_property('interventions', lambda self: Intervention.topology_interventions(self), _("Interventions"))
if 'geotrek.signage' in settings.INSTALLED_APPS:
    Blade.add_property('interventions', lambda self: Intervention.blade_interventions(self), _("Interventions"))


class InterventionStatus(StructureOrNoneRelated):

    status = models.CharField(verbose_name=_("Status"), max_length=128)
    order = models.PositiveSmallIntegerField(default=None, null=True, blank=True, verbose_name=_("Display order"))

    class Meta:
        verbose_name = _("Intervention's status")
        verbose_name_plural = _("Intervention's statuses")
        ordering = ['order', 'status']

    def __str__(self):
        if self.structure:
            return "{} ({})".format(self.status, self.structure.name)
Ejemplo n.º 7
0
    'areas', lambda self: intersecting(RestrictedArea, self, distance=0),
    _("Restricted areas"))
TouristicEvent.add_property(
    'areas', lambda self: intersecting(RestrictedArea, self, distance=0),
    _("Restricted areas"))
if 'geotrek.diving' in settings.INSTALLED_APPS:
    Dive.add_property(
        'areas',
        lambda self: uniquify(intersecting(RestrictedArea, self, distance=0)),
        _("Restricted areas"))
    Dive.add_property(
        'published_areas',
        lambda self: [area for area in self.areas if area.published],
        _("Published areas"))
if 'geotrek.signage' in settings.INSTALLED_APPS:
    Blade.add_property('areas', lambda self: self.signage.areas,
                       _("Restricted areas"))
    Blade.add_property(
        'published_areas',
        lambda self: [area for area in self.areas if area.published],
        _("Published areas"))

Topology.add_property(
    'published_areas',
    lambda self: [area for area in self.areas if area.published],
    _("Published areas"))
Project.add_property(
    'published_areas',
    lambda self: [area for area in self.areas if area.published],
    _("Published areas"))
Intervention.add_property(
    'published_areas',
Ejemplo n.º 8
0
        return cls.overlapping(topology).select_related('physical_type')


Path.add_property('physical_edges', PhysicalEdge.path_physicals,
                  _("Physical edges"))
Topology.add_property('physical_edges', PhysicalEdge.topology_physicals,
                      _("Physical edges"))
Intervention.add_property(
    'physical_edges', lambda self: self.target.physical_edges
    if self.target else [], _("Physical edges"))
Project.add_property('physical_edges',
                     lambda self: self.edges_by_attr('physical_edges'),
                     _("Physical edges"))
if 'geotrek.signage' in settings.INSTALLED_APPS:
    Blade.add_property('physical_edges',
                       lambda self: self.signage.physical_edges,
                       _("Physical edges"))


class LandType(StructureOrNoneRelated):
    name = models.CharField(max_length=128, verbose_name=_("Name"))
    right_of_way = models.BooleanField(default=False,
                                       verbose_name=_("Right of way"))

    class Meta:
        verbose_name = _("Land type")
        verbose_name_plural = _("Land types")
        ordering = ['name']

    def __str__(self):
        if self.structure:
Ejemplo n.º 9
0

Path.add_property('treks', Trek.path_treks, _("Treks"))
Topology.add_property('treks', Trek.topology_treks, _("Treks"))
if settings.HIDE_PUBLISHED_TREKS_IN_TOPOLOGIES:
    Topology.add_property('published_treks', lambda self: [], _("Published treks"))
else:
    Topology.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _("Published treks"))
Intervention.add_property('treks', lambda self: self.target.treks if self.target else [], _("Treks"))
Project.add_property('treks', lambda self: self.edges_by_attr('treks'), _("Treks"))
tourism_models.TouristicContent.add_property('treks', lambda self: intersecting(Trek, self), _("Treks"))
tourism_models.TouristicContent.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _("Published treks"))
tourism_models.TouristicEvent.add_property('treks', lambda self: intersecting(Trek, self), _("Treks"))
tourism_models.TouristicEvent.add_property('published_treks', lambda self: intersecting(Trek, self).filter(published=True), _("Published treks"))
if 'geotrek.signage' in settings.INSTALLED_APPS:
    Blade.add_property('treks', lambda self: self.signage.treks, _("Treks"))
    Blade.add_property('published_treks', lambda self: self.signage.published_treks, _("Published treks"))


class TrekRelationshipManager(models.Manager):
    use_for_related_fields = True

    def get_queryset(self):
        # Select treks foreign keys by default
        qs = super(TrekRelationshipManager, self).get_queryset().select_related('trek_a', 'trek_b')
        # Exclude deleted treks
        return qs.exclude(trek_a__deleted=True).exclude(trek_b__deleted=True)


class TrekRelationship(models.Model):
    """