2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

Dedicated 'Create' button for a new wallet

This commit is contained in:
Philip Sargent 2023-02-01 17:21:33 +00:00
parent e38d29f33d
commit 8e51f3aff8
3 changed files with 86 additions and 52 deletions

View File

@ -252,19 +252,20 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
# @login_required_if_public # @login_required_if_public
def walletedit(request, path=None): def walletedit(request, path=None):
"""Upload scanned image files into a wallet on /expofiles """Create a new wallet or upload scanned image files into a wallet on /expofiles
Also display AND EDIT the contents.json data in the wallet. Also display AND EDIT the contents.json data in the wallet.
This is the main wallet display and edit page. This is the main wallet display and edit page.
The Wallet object and the contents.json file are created when the user The Wallet object and the contents.json file are created when the user
first uploads files. creates the wallet AND THEN SAVES IT WITH A DATE.
This does NOT use a Django model linked to a Django form. Just a simple Django form. This does NOT use a Django model linked to a Django form. Just a simple Django form.
You will find the Django documentation on forms very confusing, You will find the Django documentation on forms very confusing,
as it covers many very differnet things we do not need. This is simpler. as it covers many very differnet things we do not need. This is simpler.
This subsumes much of the code which was in the old wallets.py script and so this function is very long indeed and needs refactoring. This subsumes much of the code which was in the pre-2022 non-troggle wallets.py script
and so this function is very long indeed and needs refactoring.
REWRITE bits using the ticklist, dateify, caveify, populate etc utility functions in core.view.scans.py REWRITE bits using the ticklist, dateify, caveify, populate etc utility functions in core.view.scans.py
""" """
@ -300,7 +301,8 @@ def walletedit(request, path=None):
if int(year) < 1977: if int(year) < 1977:
year = "1977" year = "1977"
if int(year) > 2050: if int(year) > 2050:
year = "2050" return (None, get_next_empty() )
wallet = f"{year}:{wnumber:02d}" wallet = f"{year}:{wnumber:02d}"
return (None, wallet) return (None, wallet)
@ -447,6 +449,8 @@ def walletedit(request, path=None):
wallet = wallet.replace(":", "#") wallet = wallet.replace(":", "#")
dirpath = Path(settings.SCANS_ROOT, year, wallet) dirpath = Path(settings.SCANS_ROOT, year, wallet)
contents_path = Path(settings.DRAWINGS_DATA, "walletjson") / year / wallet / contentsjson contents_path = Path(settings.DRAWINGS_DATA, "walletjson") / year / wallet / contentsjson
fresh_wallet = False
form = FilesForm() form = FilesForm()
@ -500,9 +504,17 @@ def walletedit(request, path=None):
return HttpResponseRedirect(f'/walletedit/{walletgoto.replace("#",":")}') return HttpResponseRedirect(f'/walletedit/{walletgoto.replace("#",":")}')
else: # not editing wallet data, uploading a file. But should not overwrite metadata at all. else: # not editing wallet data, creating a wallet or uploading a file. Should not overwrite metadata at all.
if "submitbutton" in request.POST:
print(f"--- Submit button value {request.POST['submitbutton']}")
if request.POST['submitbutton']=="Create":
w = WALLET_BLANK_JSON.copy()
save_json(w)
walletobject = make_wallet(wallet)
commit_json(w)
fresh_wallet = True
form = FilesForm(request.POST, request.FILES) form = FilesForm(request.POST, request.FILES)
if form.is_valid(): if form.is_valid():
# print(f'--- FORM walletedit multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}') # print(f'--- FORM walletedit multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
multiple = request.FILES.getlist("uploadfiles") multiple = request.FILES.getlist("uploadfiles")
@ -525,6 +537,9 @@ def walletedit(request, path=None):
save_json(waldata) save_json(waldata)
walletobject = make_wallet(wallet) walletobject = make_wallet(wallet)
commit_json(waldata) commit_json(waldata)
fresh_wallet = True
else:
print("--- Upload files form invalid")
# #
# Not a POST, so a GET starts here. And also control gets here after a POST is processed. # Not a POST, so a GET starts here. And also control gets here after a POST is processed.
# #
@ -545,7 +560,10 @@ def walletedit(request, path=None):
"(No wallet yet. It would be created if you upload a scan and then save the form with a date.)" "(No wallet yet. It would be created if you upload a scan and then save the form with a date.)"
) )
else: else:
create = True if fresh_wallet:
create = False
else:
create = True
if len(files) > 0: if len(files) > 0:
files = sorted(files) files = sorted(files)

View File

@ -1,7 +1,12 @@
<h4>When you only have a survexfile</h4>
<p>To create a wallet, if you have only a survex file and nothing to upload into the wallet, <p>To create a wallet, if you have only a survex file but no notes to scan, you should upload the survexfile first. But before you can do that you will need to login (use the menu item at top-right of page).
you currently need to got to <a href="/walletedit/">Upload Scans</a>, navigate to the new wallet number <p>
and then upload a dummy file, e.g. 'nothingyet.txt'. You can then edit the wallet details: the date, Upload the survexfile using e.g.
the people involved, and the url of the survexfile which you will already have uploaded using e.g.
<a href="/survexfile/caves-1623/290/mynewsurvex.svx">/survexfile/caves-1623/290/mynewsurvex.svx</a> <a href="/survexfile/caves-1623/290/mynewsurvex.svx">/survexfile/caves-1623/290/mynewsurvex.svx</a>
(for a survex file for cave 1623-290). (for a survex file for cave 1623-290). You will cut and paste the survex file data into the window on the form.
<p>While still logged-in, go to this page <a href="/walletedit/0000:00">Create Wallet</a> which will take you to the next unused wallet number page, and click the 'Create' button. This will not actually complete
the creation of the wallet until you have also set the date for the wallet in the wallet edit form (which will appear when you press 'Create').
<p>
While editing the wallet you should enter in the form the url of the survexfile which you have just created at e.g. <a href="/survexfile/caves-1623/290/mynewsurvex.svx">/survexfile/caves-1623/290/mynewsurvex.svx</a> (see above).

View File

@ -18,7 +18,7 @@
<input <input
label = "WalletGoto" name = "walletgoto" size="7" label = "WalletGoto" name = "walletgoto" size="7"
title="Wallet name to go to directly" title="Wallet name to go to directly"
placeholder="2023#nn" value="2023#" /> placeholder="{% now 'Y' %}#nn" value="{% now 'Y' %}#" />
</form> </form>
@ -37,11 +37,18 @@
<form method ='post' enctype ="multipart/form-data"> <form method ='post' enctype ="multipart/form-data">
{% csrf_token %} {% csrf_token %}
<br>{% if user.username %} <br>{% if user.username %}
{% if not create %}
<input class="fancybutton" type = "file" multiple="multiple" <input class="fancybutton" type = "file" multiple="multiple"
name = "uploadfiles" id="uploadfiles" /> name = "uploadfiles" id="uploadfiles" />
<br><br><br> <br><br><br>
<button class="fancybutton" style="padding: 0.5em 25px; margin-left: 155px" type = "submit" value = "Upload" > {% endif %}
Upload
<button class="fancybutton" style="padding: 0.5em 25px; margin-left: 155px" name="submitbutton" type = "submit"
{% if not create %}
value = "Upload" > Upload
{% else %}
value = "Create" > Create Wallet
{% endif %}
</button> </button>
{% endif %} {% endif %}
</form> </form>
@ -69,47 +76,51 @@
<a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{d}}"><em>{{d}}</em></a><br /> <a href="/expofiles/surveyscans/{{year}}/{{wallet|urlencode}}/{{d}}"><em>{{d}}</em></a><br />
{% endfor %} {% endfor %}
</ul> </ul>
</div>
</p> </p>
{% if create %} {% if create %}
This online wallet does not yet exist. This online wallet does not yet exist.
{% if user.username %} {% if user.username %}
<br>It will be created and initialised automatically when you upload a file, and then edit the date in the form below and save it. <br><br>It will be created when you click the Create button, <em>and then edit the date in the form below and save it</em>.
{% else %} {% else %}
<br>It will be created and initialised automatically when you upload a file, and then edit the date in the form below and save it. <br><br>To create a wallet, you need to <a href=/accounts/login/>Log In </a> first and then return to this page.
<br>But you need to log in first <a href=/accounts/login/>Log In </a>
{% endif %} {% endif %}
{% include 'wallet_new.html' %} {% include 'wallet_new.html' %}
{% endif %} {% endif %}
<p><em> <p><em>
<a href="/wallets/year/{{year}}">Wallet index for {{year}}</a> <a href="/wallets/year/{{year}}">Wallet index for {{year}}</a>
<br /> <br />
<a href="/expedition/{{year}}">Logbook entries, people, Survex files for {{year}}</a> <a href="/expedition/{{year}}">Logbook entries, People, Survex files for {{year}}</a>
<br /><br /> <br /><br />
<a href="/handbook/survey/newwallet.html#onlinew">HELP with using this form</a> {% if user.username %}
<a href="/handbook/survey/newwallet.html#onlinew">HELP with using this form</a>
{% else %}
<a href="/handbook/survey/newwallet.html#onlinew">HELP with editing a wallet and uploading scans</a>
{% endif %}
</em> </em>
{% if not create %}
</div> {% if complaints %}
{% if complaints %} <h3 style="text-align: left; color: red">Complaints</h3>
<h3 style="text-align: left; color: red">Complaints</h3> <ul style="list-style-type: disc; color: red">
<ul style="list-style-type: disc; color: red"> {% for cmp in complaints%}
{% for cmp in complaints%} <li>{{cmp}}
<li>{{cmp}} {% endfor %}
{% endfor %} </ul>
</ul>
{% if user.username %} {% if user.username %}
{% else %} {% else %}
<p>You will need to log in to the website (top right menu bar) to be able to edit the settings on this wallet. <p>You will need to log in to the website (top right menu bar) to be able to edit the settings on this wallet.
{% endif %} {% endif %}
{% endif %} {% endif %}
{% include 'wallet_table.html' %} {% include 'wallet_table.html' %}
{% if not create %}
<br> <br>
<span style="font-family: monospace; font-size: 150%; "> <span style="font-family: monospace; font-size: 150%; ">
{% if cave %}<u>Cave ID</u>: {% if cave %}<u>Cave ID</u>:
@ -138,65 +149,65 @@
<form method ='post'> <form method ='post'>
{% csrf_token %} {% csrf_token %}
<label for="date">Date of the survey trip</label> <label for="date">Date of the survey trip</label>
<input <input {% if not user.username %} disabled{% endif %}
label = "Date" name = "date" size="12" label = "Date" name = "date" size="12"
title="Date of the trip in ISO format: 2020-08-17" title="Date of the trip in ISO format: 2020-08-17"
placeholder="{{date}}" value="{{date}}" required /> placeholder="{{date}}" value="{{date}}" required />
<br> <br>
<label for="cave">Cave ID (only needed if no survex file yet)</label> <label for="cave">Cave ID (only needed if no survex file yet)</label>
<input <input {% if not user.username %} disabled{% endif %}
label = "Cave" name = "cave" size="12" label = "Cave" name = "cave" size="12"
title="Single cave id e.g. 2017-DM-01 or 1623-256. Not a list. " title="Single cave id e.g. 2017-DM-01 or 1623-256. Not a list. "
placeholder="{{cave}}" value="{{cave}}" /> placeholder="{{cave}}" value="{{cave}}" />
<br> <br>
<label for="psg">Survey area (wallet name)</label> <label for="psg">Survey area (wallet name)</label>
<input <input {% if not user.username %} disabled{% endif %}
label = "Survey area" name = "psg" size ="{{psgsize}}" label = "Survey area" name = "psg" size ="{{psgsize}}"
title="Survey area, e.g. White Elephant or Nieder Augst Eck" title="Survey area, e.g. White Elephant or Nieder Augst Eck"
placeholder="{{psg}}" value="{{psg}}" /> placeholder="{{psg}}" value="{{psg}}" />
<br> <br>
<label for="freetext">Free text for comments</label> <label for="freetext">Free text for comments</label>
<input <input {% if not user.username %} disabled{% endif %}
label = "Free text" name = "freetext" size ="{{freetextsize}}" label = "Free text" name = "freetext" size ="{{freetextsize}}"
title="e.g. scans for plan are in another wallet #99" title="e.g. scans for plan are in another wallet #99"
placeholder="{{freetext}}" value="{{freetext}}" /> placeholder="{{freetext}}" value="{{freetext}}" />
<br> <br>
<label for="plannr">Plan not required ?</label> <label for="plannr">Plan not required ?</label>
<input type="checkbox" name="plannr" id="plannr" value=" True" {% if "plan not required" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="plannr" id="plannr" value=" True" {% if "plan not required" in checked %}checked{% endif %}>
<br> <br>
<label for="elevnr">Elevation not required ?</label> <label for="elevnr">Elevation not required ?</label>
<input type="checkbox" name="elevnr" id="elevnr" value="True" {% if "elev not required" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="elevnr" id="elevnr" value="True" {% if "elev not required" in checked %}checked{% endif %}>
<br> <br>
<label for="survexnr">Survex file not required ?</label> <label for="survexnr">Survex file not required ?</label>
<input type="checkbox" name="survexnr" id="survexnr" value="True" {% if "survex not required" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="survexnr" id="survexnr" value="True" {% if "survex not required" in checked %}checked{% endif %}>
<br> <br>
<label for="pland">Plan drawn ?</label> <label for="pland">Plan drawn ?</label>
<input type="checkbox" name="pland" id="pland" value="True" {{chkpland}} {% if "plan drawn" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="pland" id="pland" value="True" {{chkpland}} {% if "plan drawn" in checked %}checked{% endif %}>
<br> <br>
<label for="elevd">Elevation drawn ?</label> <label for="elevd">Elevation drawn ?</label>
<input type="checkbox" name="elevd" id="elevd" value="True" {% if "elev drawn" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="elevd" id="elevd" value="True" {% if "elev drawn" in checked %}checked{% endif %}>
<br> <br>
<label for="descriptionw">Cave description written (or nothing recorded) ?</label> <label for="descriptionw">Cave description written (or nothing recorded) ?</label>
<input type="checkbox" name="descriptionw" id="descriptionw" value="True" {% if "description written" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="descriptionw" id="descriptionw" value="True" {% if "description written" in checked %}checked{% endif %}>
<br> <br>
<label for="qmsw">QMs written (or none seen) ?</label> <label for="qmsw">QMs written (or none seen) ?</label>
<input type="checkbox" name="qmsw" id="qmsw" value="True" {% if "qms written" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="qmsw" id="qmsw" value="True" {% if "qms written" in checked %}checked{% endif %}>
<br> <br>
<label for="websiteupt">Website updated ?</label> <label for="websiteupt">Website updated ?</label>
<input type="checkbox" name="websiteupt" id="websiteupt" value="True" {% if "website updated" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="websiteupt" id="websiteupt" value="True" {% if "website updated" in checked %}checked{% endif %}>
<br> <br>
<label for="electronic">Electronic survey ?</label> <label for="electronic">Electronic survey ?</label>
<input type="checkbox" name="electronic" id="electronic" value="True" {% if "electronic survey" in checked %}checked{% endif %}> <input {% if not user.username %} disabled{% endif %} type="checkbox" name="electronic" id="electronic" value="True" {% if "electronic survey" in checked %}checked{% endif %}>
<br> <br>
<label for="people">List of people on the survey trip(s)</label> <label for="people">List of people on the survey trip(s)</label>
<input <input {% if not user.username %} disabled{% endif %}
label = "People" name = "people" size ="{{peoplesize}}" label = "People" name = "people" size ="{{peoplesize}}"
title="List of people on the survey trip" title="List of people on the survey trip"
placeholder="{{people}}" value="{{people}}" /> placeholder="{{people}}" value="{{people}}" />
<br> <br>
<label for="survex">List of survex files</label> <label for="survex">List of survex files</label>
<input <input {% if not user.username %} disabled{% endif %}
label = "survex" name = "survex" size ="{{survexsize}}" label = "survex" name = "survex" size ="{{survexsize}}"
title="List of survex files using this data" title="List of survex files using this data"
placeholder="caves-1623/264/side_balkon/siriuscyberlift.svx" value="{{survex}}" /> placeholder="caves-1623/264/side_balkon/siriuscyberlift.svx" value="{{survex}}" />