summaryrefslogtreecommitdiffstats
path: root/core/views
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-02-01 17:21:33 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2023-02-01 17:21:33 +0000
commit8e51f3aff859d5c45c5bfb2a159879c25dee6215 (patch)
tree9d459b0ce4c6fc1f7aa5b7f11a2a61d598f01235 /core/views
parente38d29f33d8924679c7d393fbebbcc927d751b1f (diff)
downloadtroggle-8e51f3aff859d5c45c5bfb2a159879c25dee6215.tar.gz
troggle-8e51f3aff859d5c45c5bfb2a159879c25dee6215.tar.bz2
troggle-8e51f3aff859d5c45c5bfb2a159879c25dee6215.zip
Dedicated 'Create' button for a new wallet
Diffstat (limited to 'core/views')
-rw-r--r--core/views/wallets.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/core/views/wallets.py b/core/views/wallets.py
index 738c2cb..9779b83 100644
--- a/core/views/wallets.py
+++ b/core/views/wallets.py
@@ -252,19 +252,20 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
# @login_required_if_public
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.
This is the main wallet display and edit page.
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.
You will find the Django documentation on forms very confusing,
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
"""
@@ -300,7 +301,8 @@ def walletedit(request, path=None):
if int(year) < 1977:
year = "1977"
if int(year) > 2050:
- year = "2050"
+ return (None, get_next_empty() )
+
wallet = f"{year}:{wnumber:02d}"
return (None, wallet)
@@ -447,6 +449,8 @@ def walletedit(request, path=None):
wallet = wallet.replace(":", "#")
dirpath = Path(settings.SCANS_ROOT, year, wallet)
contents_path = Path(settings.DRAWINGS_DATA, "walletjson") / year / wallet / contentsjson
+
+ fresh_wallet = False
form = FilesForm()
@@ -500,9 +504,17 @@ def walletedit(request, path=None):
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)
-
if form.is_valid():
# print(f'--- FORM walletedit multiple BUT EMPTY METADATA supposedly {WALLET_BLANK_JSON["date"]=}')
multiple = request.FILES.getlist("uploadfiles")
@@ -525,6 +537,9 @@ def walletedit(request, path=None):
save_json(waldata)
walletobject = make_wallet(wallet)
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.
#
@@ -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.)"
)
else:
- create = True
+ if fresh_wallet:
+ create = False
+ else:
+ create = True
if len(files) > 0:
files = sorted(files)