2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-15 18:47:18 +00:00

Cookie/ git author now working on Wallet updates

This commit is contained in:
2024-12-29 17:05:08 +00:00
parent ace2325773
commit a3c7f165b9
3 changed files with 40 additions and 22 deletions

View File

@@ -228,7 +228,7 @@ class SvxForm(forms.Form):
fout.write("\n")
fout.close()
comment = f"Online survex edit: {self.data['filename']}.svx"
comment = f"Online edit: {self.data['filename']}.svx"
add_commit(fname, comment, editor)
msg = f"SAVED and committed to git (if there were differences)\nEdited by:{editor}"

View File

@@ -19,7 +19,7 @@ from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry
from troggle.core.models.survex import SurvexBlock, SurvexFile, SurvexPersonRole
from troggle.core.models.troggle import DataIssue, Expedition
from troggle.core.models.wallets import YEAR_RANGE, Wallet, make_valid_date
from troggle.core.utils import current_expo, sanitize_name
from troggle.core.utils import COOKIE_MAX_AGE, WriteAndCommitError, current_expo, get_cookie, git_string, sanitize_name, write_and_commit
from troggle.core.views.auth import login_required_if_public
from troggle.core.views.caves import get_cave_leniently, getCave
from troggle.core.views.scans import caveifywallet, oldwallet
@@ -80,9 +80,13 @@ class WalletForm(forms.Form): # not a model-form, just a form-form
electronic = forms.CharField(strip=True, required=False)
pland = forms.CharField(strip=True, required=False)
elevd = forms.CharField(strip=True, required=False)
# url = forms.CharField(strip=True, required=False)
survex = forms.CharField(strip=True, required=False)
who_are_you = forms.CharField(strip=True,
widget=forms.TextInput( # We are not using auto form rendering for this form, so this widget is not used.
attrs={"size": 100, "placeholder": "You are editing this page, who are you ? e.g. 'Becka' or 'Animal <mta@gasthof.expo>'",
"style": "vertical-align: text-top;"}
)
)
xlate = {
# "url": "description url",
@@ -102,6 +106,7 @@ xlate = {
"psg": "name", # a name for this wallet
"freetext": "free text",
"survex": "survex file",
"who_are_you": "editor of this commit",
}
@@ -499,6 +504,7 @@ def walletedit(request, path=None):
return w
def commit_json(waldata):
# CHANGE THIS to use git_commit() from troggle.utils
destfolder = contents_path.parent
dr_add = subprocess.run([git, "add", contentsjson], cwd=destfolder, capture_output=True, text=True)
if dr_add.returncode != 0:
@@ -704,6 +710,7 @@ def walletedit(request, path=None):
fresh_wallet = False
editor = get_cookie(request)
form = FilesForm()
if request.method == "POST":
@@ -716,6 +723,9 @@ def walletedit(request, path=None):
# Unset checkboxes do not return any value, checked ones return "True".
# So all need initialising to False
if formj.is_valid():
editor = formj.cleaned_data["who_are_you"]
editor = git_string(editor)
posted = request.POST.copy()
posted.pop("csrfmiddlewaretoken") # discard this
wd = WALLET_BLANK_JSON.copy()
@@ -745,7 +755,7 @@ def walletedit(request, path=None):
for i, elem in enumerate(wd["survex file"]):
wd["survex file"][i] = elem.strip()
wd.pop("editor of this commit") # discard this
save_json(wd)
# walletobject will already exist as creation does not happen here anymore
walletobject = make_wallet(wallet)
@@ -969,22 +979,24 @@ def walletedit(request, path=None):
"peoplesize": str(len(str(people))),
"filesaved": filesaved,
"actual_saved": actual_saved,
"who_are_you": editor,
}
return render(
request,
"walletform.html",
{
"form": form,
"wallet": wallet,
**context,
"date": waldata["date"],
#'url': waldata["description url"], 'urlsize': str(len(str(waldata["description url"]))),
"cave": cave,
"psg": psg,
"freetext": freetext,
"psgsize": str(max(12, len(str(psg)))),
"freetextsize": str(max(60, len(str(freetext)))),
},
)
edit_response = render(request,
"walletform.html",
{
"form": form,
"wallet": wallet,
**context,
"date": waldata["date"],
#'url': waldata["description url"], 'urlsize': str(len(str(waldata["description url"]))),
"cave": cave,
"psg": psg,
"freetext": freetext,
"psgsize": str(max(12, len(str(psg)))),
"freetextsize": str(max(60, len(str(freetext)))),
},
)
edit_response.set_cookie('editor_id', editor, max_age=COOKIE_MAX_AGE) # cookie expires after COOKIE_MAX_AGE seconds
return edit_response

View File

@@ -234,13 +234,19 @@ and <em>also</em> the exported files in standard formats: svx, svg etc. See why
label = "People" name = "people" size ="{{peoplesize}}"
title="List of people on the survey trip"
placeholder="{{people}}" value="{{people}}" />
<br>
<label for="survex">List of survex files</label>
<input {% if not user.username %} disabled{% endif %}
label = "survex" name = "survex" size ="{{survexsize}}"
title="List of survex files using this data"
placeholder="['caves-1623/148/148-2007.svx']" value="{{survex}}" />
<br>
<label for="who_are_you">Who are you:</label>
<input {% if not user.username %} disabled{% endif %}
label = "Who are you" name = "who_are_you" size ="{{freetextsize}}"
title="Who are you:"
placeholder="You who are editing this page e.g. Animal <mta@gasthof.expo>" value="{{who_are_you}}" required/>
<br><br>{% if user.username %}
<button class="fancybutton" style="padding: 0.5em 25px; margin-left: 155px; font-size: 90%; "
type = "submit" value = "Edit" >