diff --git a/core/models/logbooks.py b/core/models/logbooks.py index b594945..361fb96 100644 --- a/core/models/logbooks.py +++ b/core/models/logbooks.py @@ -150,8 +150,8 @@ class QM(TroggleModel): blockname = models.TextField(blank=True, null=True) # NB truncated copy of survexblock name with last char added expoyear = models.CharField(max_length=4, blank=True, null=True) ticked = models.BooleanField(default=False) - location_description = models.TextField(blank=True) - completion_description = models.TextField(blank=True) + location_description = models.TextField(blank=True, null=True) + completion_description = models.TextField(blank=True, null=True) completion_date = models.DateField(blank=True, null=True) nearest_station_name = models.CharField(max_length=200, blank=True, null=True) resolution_station_name = models.CharField(max_length=200, blank=True, null=True) @@ -177,17 +177,17 @@ class QM(TroggleModel): blocknamestr = "" return f"{cavestr}-{expoyearstr}-{self.number}{self.grade}{blocknamestr}" - def get_completion_url(self): - """assumes html file named is in same folder as cave description file - WRONG - needs rewriting!""" - cd = None - if self.completion_description: - try: - dir = Path(self.cave.url).parent - cd = dir / self.completion_description - except: - cd = None - return cd + # def get_completion_url(self): + # """assumes html file named is in same folder as cave description file + # WRONG - needs rewriting!""" + # cd = None + # if self.completion_description: + # try: + # dir = Path(self.cave.url).parent + # cd = dir / self.completion_description + # except: + # cd = None + # return cd def newslug(self): qmslug = f"{str(self.cave)}-{self.expoyear}-{self.blockname}{self.number}{self.grade}" diff --git a/core/views/caves.py b/core/views/caves.py index c866718..2f5a0ce 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -550,7 +550,7 @@ def qm(request, cave_id, qm_id, year, grade=None, blockname=None): try: c = getCave(cave_id) manyqms = c.get_open_QMs() | c.get_ticked_QMs() # set union operation - qm = manyqms.get(number=qm_id, expoyear=year) + qm = manyqms.get(number=qm_id, expoyear=year, grade=grade) return render(request, "qm.html", {"qm": qm}) except QM.DoesNotExist: # raise @@ -561,6 +561,16 @@ def qm(request, cave_id, qm_id, year, grade=None, blockname=None): "badslug": f"QM.DoesNotExist blockname is empty string: {cave_id=} {year=} {qm_id=} {grade=} {blockname=}" }, ) + except QM.MultipleObjectsReturned: + # raise + qms = manyqms.filter(number=qm_id, expoyear=year) + return render( + request, + "errors/badslug.html", + { + "badslug": f"QM.MultipleObjectsReturned {cave_id=} {year=} {qm_id=} {grade=} {blockname=} {qms=}" + }, + ) else: try: diff --git a/parsers/QMs.py b/parsers/QMs.py index 5a0be79..56c97e4 100644 --- a/parsers/QMs.py +++ b/parsers/QMs.py @@ -147,20 +147,32 @@ def parse_KH_QMs(kh, inputFile, ticked): #
C1997-161-27 A
Sib: pitch at end of Fuzzy Logic [Paradox Rift - continues] [sep.fuzzy.13] line += 1 res = re.search( - r"name=\"[CB](?P\d*)-(?P\d*)-(?P\d*).*\s*(?P[ABCDX?V])
(?P.*)(\[(?P.*)\])?", + r"name=\"[CB](?P\d*)-(?P\d*)-(?P\d*).*\s*(?P[ABCDX?V])
(?P[^[]*)(\[\s*(?P[^]]*)\s*\])?\s*(\[\s*(?P[^]]*)\s*\])?", dataline, ) if res: res = res.groupdict() year = int(res["year"]) + completion = res["completion"] + station_name = res["station_name"] + if not completion and station_name: + if station_name.startswith("{% for QM in cave.get_open_QMs %}
  • {{QM}} {% if QM.nearest_station_name %}§{{QM.nearest_station_name|safe}}§{% endif %} -{{QM.location_description}} {{QM.grade}} - {% if QM.block %} {{QM.block}}.svx {{QM.block.date}} {% endif %}
  • +{{QM.location_description|safe}} {{QM.grade}} + {% if QM.block %} {{QM.block}}.svx {{QM.block.date|date:'Y-m-d'}} {% endif %} + {% if QM.comment %} + {{QM.comment}}{% endif %} {% empty %}
  • No open leads. {% endfor %} @@ -43,14 +45,15 @@ {% if QM.nearest_station_name %}§{{QM.nearest_station_name|safe}}§{% endif %} {% if QM.resolution_station_name %}{{QM.resolution_station_name|safe}}{% endif %} {{QM.location_description|safe}} {{QM.grade}} - {% if QM.block %} {{QM.block}}.svx {{QM.block.date}} {% endif %} - + + + {% if QM.block %} {{QM.block}}.svx {{QM.block.date|date:'Y-m-d'}} {% endif %} {% if QM.completion_description %} - Completion page: {{QM.completion_description}} + ⋮{{QM.completion_description|safe}}⋮ {% endif %} + {% if QM.page_ref %}☉{{QM.page_ref}}☉{% endif %} {% if QM.comment %} - Comment: {{QM.comment}} - {% endif %} + {{QM.comment}}{% endif %} {% empty %}
  • No ticked leads. {% endfor %} @@ -58,4 +61,7 @@

    § QM.nearest_station_name
    ☆ QM.resolution_station_name - when ticked.
    +☉ QM.page_ref
    +⋮ QM.completion_description
    QM.comment
    {% endblock %} \ No newline at end of file diff --git a/templates/qm.html b/templates/qm.html index d10e742..0679452 100644 --- a/templates/qm.html +++ b/templates/qm.html @@ -26,12 +26,11 @@ {% if qm.resolution_station_name %} The survey station which record the continuation of the cave past this QM is {{qm.resolution_station_name}}.
    {%endif %} -Tick off comment: '{{qm.comment}}'
    -Tick off completion description: '{{qm.completion_description}}'
    -Tick off url: {{qm.get_completion_url}} WRONG
    -Tick off date: '{{qm.completion_date}}' [For survex file ticks. not implemented yet]
    +Tick off comment: '{{qm.comment|safe}}'
    +Tick off completion description: '{{qm.completion_description|safe}}'
    +Tick off date: '{{qm.completion_date|date:'Y-m-d'}}' [For survex file ticks. not implemented yet]
    {% endif %} -QM page_ref: '{{qm.page_ref}}'
    +QM page_ref: '{{qm.page_ref|safe}}'
    {% if qm.cave %}

    Cave: {{qm.cave|safe }}

    @@ -50,7 +49,7 @@ Comment: '{{qm.comment}}'
    {% if qm.block %}

    Survexfile

    -{{qm.block.date}} {{qm.block}}.svx +{{qm.block.date|date:'Y-m-d'}} {{qm.block}}.svx {% endif %}