mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 05:37:14 +00:00
cookie and logon working nicely together: cave & entrance
This commit is contained in:
@@ -45,6 +45,7 @@ todo = """
|
|||||||
class CaveForm(ModelForm):
|
class CaveForm(ModelForm):
|
||||||
"""Only those fields for which we want to override defaults are listed here
|
"""Only those fields for which we want to override defaults are listed here
|
||||||
the other fields of the class Cave are present on the form, but use the default presentation style
|
the other fields of the class Cave are present on the form, but use the default presentation style
|
||||||
|
Extra fields, not in the model Cave, are also created here, e.g. who_are_you
|
||||||
|
|
||||||
see https://docs.djangoproject.com/en/5.1/topics/forms/modelforms/
|
see https://docs.djangoproject.com/en/5.1/topics/forms/modelforms/
|
||||||
"""
|
"""
|
||||||
@@ -106,6 +107,7 @@ class CaveForm(ModelForm):
|
|||||||
subarea = forms.CharField(required=False, label="Subarea (do not use for new caves)", widget=forms.TextInput(attrs={"placeholder": "usually blank, archaic"}))
|
subarea = forms.CharField(required=False, label="Subarea (do not use for new caves)", widget=forms.TextInput(attrs={"placeholder": "usually blank, archaic"}))
|
||||||
|
|
||||||
#cave_slug = forms.CharField()
|
#cave_slug = forms.CharField()
|
||||||
|
identified_login = forms.BooleanField(required=False,widget=forms.CheckboxInput(attrs={"onclick":"return false"})) # makes it readonly
|
||||||
who_are_you = forms.CharField(
|
who_are_you = forms.CharField(
|
||||||
widget=forms.TextInput(
|
widget=forms.TextInput(
|
||||||
attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Becka' or 'Animal <mta@gasthof.expo>'",
|
attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Becka' or 'Animal <mta@gasthof.expo>'",
|
||||||
@@ -119,7 +121,7 @@ class CaveForm(ModelForm):
|
|||||||
field_order = ['unofficial_number', 'kataster_number', 'official_name', 'underground_description', 'survey',
|
field_order = ['unofficial_number', 'kataster_number', 'official_name', 'underground_description', 'survey',
|
||||||
'underground_centre_line', 'explorers', 'equipment', 'notes', 'references', 'description_file', 'survex_file',
|
'underground_centre_line', 'explorers', 'equipment', 'notes', 'references', 'description_file', 'survex_file',
|
||||||
'areacode', 'subarea', 'length', 'depth', 'extent',
|
'areacode', 'subarea', 'length', 'depth', 'extent',
|
||||||
'kataster_code', 'kataster_status', 'fully_explored', 'non_public', 'who_are_you']
|
'kataster_code', 'kataster_status', 'fully_explored', 'non_public', 'identified_login', 'who_are_you']
|
||||||
|
|
||||||
def clean_cave_slug(self):
|
def clean_cave_slug(self):
|
||||||
if self.cleaned_data["cave_slug"] == "":
|
if self.cleaned_data["cave_slug"] == "":
|
||||||
@@ -232,6 +234,7 @@ class EntranceForm(ModelForm):
|
|||||||
)
|
)
|
||||||
alt = forms.CharField(required=False, label="Altitude (m) - from GPS if you have it, but let it settle.")
|
alt = forms.CharField(required=False, label="Altitude (m) - from GPS if you have it, but let it settle.")
|
||||||
# url = forms.CharField(required=False, label="URL [usually blank]", widget=forms.TextInput(attrs={"size": "45"}))
|
# url = forms.CharField(required=False, label="URL [usually blank]", widget=forms.TextInput(attrs={"size": "45"}))
|
||||||
|
identified_login = forms.BooleanField(required=False,widget=forms.CheckboxInput(attrs={"onclick":"return false"})) # makes it readonly
|
||||||
who_are_you = forms.CharField(
|
who_are_you = forms.CharField(
|
||||||
widget=forms.TextInput(
|
widget=forms.TextInput(
|
||||||
attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Becka' or 'Animal <mta@gasthof.expo>'",
|
attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Becka' or 'Animal <mta@gasthof.expo>'",
|
||||||
@@ -241,7 +244,7 @@ class EntranceForm(ModelForm):
|
|||||||
|
|
||||||
field_order = ['name', 'entrance_description', 'explorers', 'map_description', 'location_description', 'lastvisit', 'non_public',
|
field_order = ['name', 'entrance_description', 'explorers', 'map_description', 'location_description', 'lastvisit', 'non_public',
|
||||||
'findability', 'marking', 'approach', 'underground_description', 'photo', 'marking_comment', 'findability_description', 'other_description',
|
'findability', 'marking', 'approach', 'underground_description', 'photo', 'marking_comment', 'findability_description', 'other_description',
|
||||||
'bearings', 'tag_station', 'other_station', 'easting', 'northing', 'lat_wgs84', 'long_wgs84', 'alt', 'who_are_you']
|
'bearings', 'tag_station', 'other_station', 'easting', 'northing', 'lat_wgs84', 'long_wgs84', 'alt', 'identified_login', 'who_are_you']
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Entrance
|
model = Entrance
|
||||||
@@ -274,6 +277,8 @@ class EntranceLetterForm(ModelForm):
|
|||||||
to only one Cave.
|
to only one Cave.
|
||||||
|
|
||||||
see https://docs.djangoproject.com/en/5.1/topics/forms/modelforms/
|
see https://docs.djangoproject.com/en/5.1/topics/forms/modelforms/
|
||||||
|
|
||||||
|
To be re-written when we move the 'letter' field into Entrance
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# This only needs to be required=True for the second and subsequent entrances, not the first. Tricky.
|
# This only needs to be required=True for the second and subsequent entrances, not the first. Tricky.
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ from troggle.core.utils import (
|
|||||||
COOKIE_MAX_AGE,
|
COOKIE_MAX_AGE,
|
||||||
WriteAndCommitError,
|
WriteAndCommitError,
|
||||||
current_expo,
|
current_expo,
|
||||||
get_cookie,
|
get_editor,
|
||||||
git_string,
|
|
||||||
write_and_commit,
|
write_and_commit,
|
||||||
|
is_identified_user,
|
||||||
)
|
)
|
||||||
from troggle.core.views import expo
|
from troggle.core.views import expo
|
||||||
from troggle.parsers.caves import read_cave, read_entrance
|
from troggle.parsers.caves import read_cave, read_entrance
|
||||||
@@ -493,7 +493,8 @@ def edit_cave(request, path="", slug=None):
|
|||||||
if not (cave:= get_cave_from_slug(slug)): # walrus operator
|
if not (cave:= get_cave_from_slug(slug)): # walrus operator
|
||||||
return render(request, "errors/badslug.html", {"badslug": f"for cave {slug} - from edit_cave()"})
|
return render(request, "errors/badslug.html", {"badslug": f"for cave {slug} - from edit_cave()"})
|
||||||
|
|
||||||
editor = get_cookie(request)
|
identified_login = is_identified_user(request.user)
|
||||||
|
editor = get_editor(request)
|
||||||
|
|
||||||
if request.POST:
|
if request.POST:
|
||||||
form = CaveForm(request.POST, instance=cave)
|
form = CaveForm(request.POST, instance=cave)
|
||||||
@@ -554,9 +555,9 @@ def edit_cave(request, path="", slug=None):
|
|||||||
print(f"edit_cave(): EXCEPTION attempting to read_cave({cave.filename})\n{e}")
|
print(f"edit_cave(): EXCEPTION attempting to read_cave({cave.filename})\n{e}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
form = CaveForm(instance=cave, initial={'cave_slug': cave.slug(), "who_are_you":editor})
|
form = CaveForm(instance=cave, initial={'cave_slug': cave.slug(), "identified_login": identified_login, "who_are_you":editor})
|
||||||
else:
|
else:
|
||||||
form = CaveForm(initial={"who_are_you":editor})
|
form = CaveForm(initial={"identified_login": identified_login, "who_are_you":editor})
|
||||||
|
|
||||||
# The way formsets are rendered changed between Django 4 and Django 5
|
# The way formsets are rendered changed between Django 4 and Django 5
|
||||||
major, _, _, _, _ = django.VERSION
|
major, _, _, _, _ = django.VERSION
|
||||||
@@ -565,6 +566,9 @@ def edit_cave(request, path="", slug=None):
|
|||||||
else:
|
else:
|
||||||
tabletype = "div"
|
tabletype = "div"
|
||||||
|
|
||||||
|
if identified_login:
|
||||||
|
# disable editing the git id string as we get it from the logged-on user data
|
||||||
|
form.fields["who_are_you"].widget.attrs["readonly"]="readonly"
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"editcave.html",
|
"editcave.html",
|
||||||
@@ -662,7 +666,8 @@ def edit_entrance(request, path="", caveslug=None, entslug=None):
|
|||||||
imgpath = Path(path) / cave.areacode / cave.number()
|
imgpath = Path(path) / cave.areacode / cave.number()
|
||||||
print(f"Edit Entrance {imgpath=}")
|
print(f"Edit Entrance {imgpath=}")
|
||||||
|
|
||||||
editor = get_cookie(request)
|
identified_login = is_identified_user(request.user)
|
||||||
|
editor = get_editor(request)
|
||||||
|
|
||||||
if request.POST:
|
if request.POST:
|
||||||
print(f"POST Online edit of entrance: '{entrance}' where {cave=}")
|
print(f"POST Online edit of entrance: '{entrance}' where {cave=}")
|
||||||
@@ -771,7 +776,7 @@ def edit_entrance(request, path="", caveslug=None, entslug=None):
|
|||||||
# ent only in db not on file. Interesting, let's run with it using whatever we have in the db
|
# ent only in db not on file. Interesting, let's run with it using whatever we have in the db
|
||||||
print(f"ENTRANCE NOT read from file: entranceletter = '{ce.entranceletter}'")
|
print(f"ENTRANCE NOT read from file: entranceletter = '{ce.entranceletter}'")
|
||||||
|
|
||||||
entform = EntranceForm(instance=entrance, initial={"who_are_you":editor})
|
entform = EntranceForm(instance=entrance, initial={"identified_login": identified_login, "who_are_you":editor})
|
||||||
if entslug is None:
|
if entslug is None:
|
||||||
entletterform = EntranceLetterForm()
|
entletterform = EntranceLetterForm()
|
||||||
# print(f" Getting entletter from EntranceLetterForm")
|
# print(f" Getting entletter from EntranceLetterForm")
|
||||||
@@ -782,9 +787,12 @@ def edit_entrance(request, path="", caveslug=None, entslug=None):
|
|||||||
print(f" Blank value: getting entletter from EntranceLetterForm")
|
print(f" Blank value: getting entletter from EntranceLetterForm")
|
||||||
print(f"{entletter=} ")
|
print(f"{entletter=} ")
|
||||||
else:
|
else:
|
||||||
entform = EntranceForm(initial={"who_are_you":editor})
|
entform = EntranceForm(initial={"identified_login": identified_login, "who_are_you":editor})
|
||||||
entletterform = EntranceLetterForm()
|
entletterform = EntranceLetterForm()
|
||||||
|
|
||||||
|
if identified_login:
|
||||||
|
# disable editing the git id string as we get it from the logged-on user data
|
||||||
|
entform.fields["who_are_you"].widget.attrs["readonly"]="readonly"
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"editentrance.html",
|
"editentrance.html",
|
||||||
|
|||||||
@@ -35,16 +35,19 @@ at troggle/core/forms.py ass this uses a Django magic form creation thinggy. -->
|
|||||||
<li>Read the <a href="/handbook/survey/coord2.html#summary">brief explanation</a> of location data in the handbook.
|
<li>Read the <a href="/handbook/survey/coord2.html#summary">brief explanation</a> of location data in the handbook.
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
{% if ent.bearings %}
|
||||||
|
<br />
|
||||||
|
<label for="id_bearings">Bearings (obsolete):</label>
|
||||||
|
{{ent.bearings|safe}}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if entlettereditable %}
|
{% if entlettereditable %}
|
||||||
<table>{{ entletterform }}</table>
|
<table>{{ entletterform }}</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<table><tr><th>Entrance Letter</th><td>{{ entletter }}</td></table>
|
<table><tr><th>Entrance Letter</th><td>{{ entletter }}</td></table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<table>{{ entform }}
|
<table>{{ entform }}
|
||||||
{% if ent.bearings %}
|
|
||||||
<tr><th><label for="id_bearings">Bearings (obsolete):</label></th><td>
|
|
||||||
{{ent.bearings|safe}}</td></tr>
|
|
||||||
{% endif %}
|
|
||||||
</table>
|
</table>
|
||||||
<p><input style="font-weight: bold; font-size: 200%; font-variant-caps: small-caps; margin-left: 40%;" type="submit" value="Submit" /></p>
|
<p><input style="font-weight: bold; font-size: 200%; font-variant-caps: small-caps; margin-left: 40%;" type="submit" value="Submit" /></p>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user