8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Fix room_name problem with building

This commit is contained in:
detraz 2019-02-18 22:13:34 +01:00
parent 8d799ed92d
commit 87730a3ad2
3 changed files with 14 additions and 5 deletions

View file

@ -39,6 +39,7 @@ from .models import (
AccessPoint, AccessPoint,
SwitchBay, SwitchBay,
Building, Building,
Dormitory,
PortProfile, PortProfile,
) )
@ -87,6 +88,12 @@ class BuildingAdmin(VersionAdmin):
"""Administration d'un batiment""" """Administration d'un batiment"""
pass pass
class DormitoryAdmin(VersionAdmin):
"""Administration d'une residence"""
pass
class PortProfileAdmin(VersionAdmin): class PortProfileAdmin(VersionAdmin):
"""Administration of a port profile""" """Administration of a port profile"""
pass pass
@ -99,5 +106,6 @@ admin.site.register(Stack, StackAdmin)
admin.site.register(ModelSwitch, ModelSwitchAdmin) admin.site.register(ModelSwitch, ModelSwitchAdmin)
admin.site.register(ConstructorSwitch, ConstructorSwitchAdmin) admin.site.register(ConstructorSwitch, ConstructorSwitchAdmin)
admin.site.register(Building, BuildingAdmin) admin.site.register(Building, BuildingAdmin)
admin.site.register(Dormitory, DormitoryAdmin)
admin.site.register(SwitchBay, SwitchBayAdmin) admin.site.register(SwitchBay, SwitchBayAdmin)
admin.site.register(PortProfile, PortProfileAdmin) admin.site.register(PortProfile, PortProfileAdmin)

View file

@ -558,6 +558,10 @@ class Building(AclMixin, RevMixin, models.Model):
"""Returns all ap of the building""" """Returns all ap of the building"""
return AccessPoint.all_ap_in(self) return AccessPoint.all_ap_in(self)
@cached_property
def cached_name(self):
return self.__str__()
def __str__(self): def __str__(self):
if Dormitory.objects.count() > 1: if Dormitory.objects.count() > 1:
return self.dormitory.name + " : " + self.name return self.dormitory.name + " : " + self.name
@ -749,10 +753,7 @@ class Room(AclMixin, RevMixin, models.Model):
unique_together = ('name', 'building') unique_together = ('name', 'building')
def __str__(self): def __str__(self):
if Dormitory.objects.count() > 1: return self.building.cached_name + self.name
return self.building.dormitory.name + " : " + self.building.name + self.name
else:
return self.building.name + self.name
class PortProfile(AclMixin, RevMixin, models.Model): class PortProfile(AclMixin, RevMixin, models.Model):

View file

@ -42,7 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for dormitory in dormitory_list %} {% for dormitory in dormitory_list %}
<tr> <tr>
<td>{{ dormitory.name }}</td> <td>{{ dormitory.name }}</td>
<td>{% for building in dormitory.building_set.all %} {{ building }} {% endfor %}</td> <td>{% for building in dormitory.building_set.all %} {{ building.name }} {% endfor %}</td>
<td class="text-right"> <td class="text-right">
{% can_edit dormitory %} {% can_edit dormitory %}
{% include 'buttons/edit.html' with href='topologie:edit-dormitory' id=dormitory.id %} {% include 'buttons/edit.html' with href='topologie:edit-dormitory' id=dormitory.id %}