forked from expo/troggle
Compare commits
559 Commits
RW_rebuild
...
Faster-sur
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e77aa9fb84 | ||
|
|
f5fe2d9e33 | ||
|
|
5006342b7b | ||
|
|
3ce8b67b4f | ||
|
|
52cec290d9 | ||
|
|
a559151c57 | ||
|
|
2fc60f9f74 | ||
|
|
3b1fcb7feb | ||
|
|
2838f540d1 | ||
|
|
f5ec5a61a9 | ||
|
|
44caf35fd8 | ||
|
|
c5055e7f34 | ||
|
|
de14ecea22 | ||
|
|
f5174a3248 | ||
|
|
f0889ce0f8 | ||
|
|
b6dc711c14 | ||
|
|
04fb2e8701 | ||
|
|
c1439bed8d | ||
|
|
a88f326ee6 | ||
| 56618dbe65 | |||
|
|
71ef710d09 | ||
|
|
c74852b60b | ||
|
|
a26109cb30 | ||
|
|
6b5b9a5315 | ||
|
|
4ebf3d8a0e | ||
| 37d02b298d | |||
|
|
d6053322e8 | ||
|
|
5b5f385b67 | ||
|
|
04428c45c9 | ||
| a7f605ced9 | |||
|
|
0adb8e528d | ||
|
|
f4280f9907 | ||
| 2d7892e3b1 | |||
|
|
8edeb2f622 | ||
|
|
d157a081b1 | ||
|
|
fcc57cf365 | ||
| 12c8ab41bf | |||
|
|
9266e5460e | ||
|
|
ad45859071 | ||
|
|
ee759980c4 | ||
|
|
18b371bc15 | ||
|
|
9e77b8bb75 | ||
|
|
e6acd4bdbd | ||
|
|
424219fb6f | ||
|
|
2ebb37552f | ||
|
|
822359fe51 | ||
|
|
97426a0ddb | ||
|
|
3f78382d45 | ||
|
|
8a1be45aac | ||
|
|
b5cca8be3b | ||
|
|
4d2f9a2b39 | ||
|
|
8fe02e5c89 | ||
|
|
b2dd905f0e | ||
|
|
c06d372984 | ||
|
|
7a9aef6faf | ||
|
|
6889ae9fa3 | ||
|
|
02d3cc84d5 | ||
|
|
768ec83037 | ||
|
|
b42249890e | ||
|
|
2f9870644b | ||
|
|
cc313246bb | ||
|
|
4e187581b3 | ||
|
|
bfe018cde6 | ||
|
|
dc479b33c5 | ||
|
|
ae284a1f30 | ||
|
|
f1736c53c4 | ||
|
|
23df89cf31 | ||
|
|
05c5e26e99 | ||
|
|
d1d0c24ed8 | ||
|
|
c4301cf6df | ||
|
|
b3089fafe9 | ||
|
|
de7d68b1eb | ||
|
|
e913a56a6b | ||
|
|
bb8dbb381f | ||
|
|
39c61bd526 | ||
|
|
144610d6c2 | ||
|
|
10f1cdb458 | ||
|
|
40f413ba47 | ||
|
|
a588221524 | ||
|
|
9cd8734947 | ||
|
|
9df91b221b | ||
|
|
c8551991b2 | ||
|
|
64a4842dcb | ||
|
|
f666b9c396 | ||
|
|
a4532a29da | ||
|
|
5469794159 | ||
|
|
705dd51f30 | ||
|
|
1e26578305 | ||
|
|
ddb62f2897 | ||
|
|
8b5f81c8f8 | ||
|
|
f8be510509 | ||
|
|
27af84da65 | ||
|
|
121f0a6aac | ||
|
|
9646c32819 | ||
|
|
8932bdc466 | ||
|
|
c3ab5c6096 | ||
|
|
9fa93fdd15 | ||
|
|
7a7433bc84 | ||
|
|
b4296f1736 | ||
|
|
ff8c5ef0c1 | ||
|
|
1bac650aee | ||
|
|
a22b42e832 | ||
|
|
9fc80bed35 | ||
|
|
afa5a8b940 | ||
|
|
59f8647e0f | ||
|
|
f593104c04 | ||
|
|
384b0438b4 | ||
|
|
dc6d89b0ca | ||
|
|
e01507d541 | ||
| b505a26ce4 | |||
| a5e1529514 | |||
|
|
6f42bd51e1 | ||
|
|
42d10cf43d | ||
|
|
4e27c90f77 | ||
|
|
2226aa34d5 | ||
|
|
0268ff46b3 | ||
| 1d7cf3f41a | |||
| 32c186afd7 | |||
| 54a9f7a37c | |||
| e4e8cc5993 | |||
| 8703ed5d94 | |||
| a4118261e1 | |||
| 6392c1f238 | |||
| 4148ece133 | |||
| c724f292ca | |||
| 53513b812b | |||
| beffdbd89d | |||
| 8bd0df1bab | |||
| 4ae43e94f4 | |||
| da88771fd4 | |||
| b6b7d2aa12 | |||
| c733b0f2eb | |||
| 9712bf6dfd | |||
| 5e4c1493a1 | |||
| 41b1334257 | |||
| a2fcbae129 | |||
| e9077542c9 | |||
| 79595521a9 | |||
| 38b658fd3f | |||
| a89123755c | |||
| 0fb9accd05 | |||
| f87df707ab | |||
| a2cb771fc1 | |||
| c888f59ff0 | |||
| 43ff6e09be | |||
| 810ab3ea4f | |||
| cb5978237b | |||
| 622d523c98 | |||
| ee7d2529e7 | |||
| 82de967f97 | |||
| 466e667e14 | |||
| 3c563ce665 | |||
| 19a061efa8 | |||
| a397eb9d00 | |||
| e5d864359a | |||
| b2adc285b6 | |||
| 8af604262d | |||
| b33ca2b290 | |||
| c4455168c6 | |||
| 1b4674acde | |||
| 4fac4317a3 | |||
| 78bf9986b7 | |||
| 5154c0d8e5 | |||
| b01fcc3a6d | |||
| e8585bec42 | |||
| 521f0241f8 | |||
| 0394becdac | |||
| e5fa636776 | |||
| 6beaf4afdd | |||
| 822812525e | |||
| a4a92483bd | |||
| 3254ba1443 | |||
| 4c3d0ce7fa | |||
| a99afe07c6 | |||
| 73bb60eff9 | |||
| 0a214c5d4b | |||
| 29c53f35ab | |||
| 3746dab5de | |||
| 18dbadd675 | |||
| ee2cd0d391 | |||
| 0cc4e7c7d3 | |||
|
|
478065786f | ||
|
|
e64d82cd92 | ||
|
|
12a991920a | ||
| 0758efb3ec | |||
| 54b782c67e | |||
| 78a5f656b9 | |||
| 6e23853759 | |||
| becfaa1504 | |||
|
|
77a6015ad6 | ||
|
|
7c15a7439d | ||
|
|
b4f4db5754 | ||
|
|
c6656e6642 | ||
|
|
e6fa54d0e5 | ||
|
|
f16b4e3f47 | ||
|
|
4ad5b68433 | ||
|
|
552730f0a3 | ||
|
|
a1f02e575f | ||
|
|
f58b1db920 | ||
|
|
3d2ac06a72 | ||
|
|
9802f45452 | ||
|
|
1ad58d6b5d | ||
|
|
6805bcb690 | ||
|
|
c162411f0b | ||
|
|
10a05d686e | ||
|
|
89ef5c19ff | ||
|
|
4385ce86c1 | ||
|
|
46124a770f | ||
|
|
6f6327d267 | ||
|
|
6710a469ee | ||
|
|
174c475ec7 | ||
|
|
d3b42a125d | ||
|
|
2f2f4d396d | ||
|
|
e1eea7088f | ||
|
|
760fa3114f | ||
|
|
798ae591c6 | ||
|
|
7877efba0a | ||
|
|
cfa888fde6 | ||
|
|
cedcb0988a | ||
|
|
c939013b14 | ||
|
|
458d0e1ebc | ||
|
|
776152ef47 | ||
|
|
9f285a9f34 | ||
|
|
302ad0632e | ||
|
|
ffb5d7bdda | ||
|
|
242cf4741a | ||
|
|
41a14f161d | ||
|
|
f0e1406c5f | ||
|
|
d7c6676c49 | ||
|
|
5e9dfc6ea6 | ||
|
|
27fca090fc | ||
|
|
716131f005 | ||
|
|
496280f3e6 | ||
|
|
0dd0951b28 | ||
|
|
b9597fbb57 | ||
|
|
edc6591554 | ||
|
|
560b9bf985 | ||
|
|
6652e3f160 | ||
|
|
b0f1f73ce4 | ||
|
|
214d887c57 | ||
|
|
6b16724c2a | ||
|
|
f1bb927063 | ||
|
|
eeda1bed73 | ||
|
|
751ec9517f | ||
|
|
228814be33 | ||
|
|
cebcbeb73a | ||
|
|
057b09dca9 | ||
|
|
480541ae54 | ||
|
|
60303d041c | ||
|
|
5a911ecec7 | ||
|
|
7056f9a8b2 | ||
|
|
34036581f2 | ||
|
|
dcc67fddda | ||
|
|
03cad0a37f | ||
|
|
a4651eaa0a | ||
|
|
7aed3d3b30 | ||
|
|
4771f52b20 | ||
|
|
77ad85b05c | ||
|
|
01d877d26e | ||
|
|
e84d990366 | ||
|
|
e06be10f7f | ||
|
|
fe6750e824 | ||
|
|
d29fe2ee1c | ||
|
|
1156b1d3ea | ||
|
|
126a10cf94 | ||
|
|
4560e0da84 | ||
|
|
f9c2e0e170 | ||
|
|
cf413dd03c | ||
|
|
4965678443 | ||
|
|
67f94f9436 | ||
|
|
1186662960 | ||
|
|
3010961383 | ||
|
|
806fd41130 | ||
|
|
af07161f05 | ||
|
|
5ff759db93 | ||
|
|
7f292d402b | ||
|
|
c180780da9 | ||
|
|
d75862bc41 | ||
|
|
7cdb603d75 | ||
|
|
94c44b0d7b | ||
|
|
4a3d181097 | ||
|
|
d8863dca48 | ||
|
|
e0c439e850 | ||
|
|
f4f1b3ca6d | ||
|
|
4a93790c7e | ||
|
|
5265acd9dc | ||
|
|
9f69bb5fca | ||
|
|
b1d6e1c3d5 | ||
|
|
659703b221 | ||
|
|
3869bd536e | ||
|
|
408d154d3f | ||
|
|
44e3eb8a18 | ||
|
|
51a3cecc02 | ||
|
|
6b4ea7b83e | ||
|
|
da71cca22f | ||
|
|
5c945e3431 | ||
|
|
ba5bc365c1 | ||
|
|
c362b1b529 | ||
|
|
f90b6dc7ab | ||
|
|
a6a9016548 | ||
|
|
5351108ec1 | ||
|
|
7759e481d4 | ||
|
|
69c3a06c98 | ||
|
|
d1ad8730d7 | ||
|
|
f3a570a21d | ||
|
|
f626d3304d | ||
|
|
7eb4c89bf0 | ||
|
|
9435be0f19 | ||
|
|
7f108f6d9a | ||
|
|
3f98470af8 | ||
|
|
e58b69782c | ||
|
|
e49e22b37c | ||
|
|
82e69b4f05 | ||
|
|
ea9266ecf9 | ||
|
|
99ea6778ad | ||
|
|
ccd80e74f8 | ||
|
|
3057d2a232 | ||
|
|
d1ac659d4f | ||
|
|
bb1989d0f0 | ||
|
|
418e5e1d3f | ||
|
|
3b12e6d975 | ||
|
|
54d7f1d097 | ||
|
|
cfc90deb83 | ||
|
|
1a0e577606 | ||
|
|
a05fe94d90 | ||
|
|
8e64062214 | ||
|
|
8c1882eec8 | ||
|
|
8dd51096cf | ||
|
|
ecd5bbcb1d | ||
|
|
6d5babd331 | ||
|
|
79b7d32664 | ||
|
|
dd66ad835a | ||
|
|
a29fd964bd | ||
|
|
1ef274ec1d | ||
|
|
0f5627505f | ||
|
|
c0782e1cca | ||
|
|
ed1d273e03 | ||
|
|
9654e5da1c | ||
|
|
8040b746b4 | ||
|
|
05004aa874 | ||
|
|
4a21720745 | ||
|
|
13cb2e9b0f | ||
|
|
0259947cda | ||
|
|
080684e56f | ||
|
|
4b269bb234 | ||
|
|
1a62931202 | ||
|
|
c2029df3c9 | ||
|
|
4a074295ad | ||
|
|
711fefb0da | ||
|
|
fd12e70f78 | ||
|
|
fac89bae30 | ||
|
|
ab97e367cb | ||
|
|
ae693ca4c5 | ||
|
|
77dea07b40 | ||
|
|
77dcf7f759 | ||
|
|
59e7c4d5df | ||
|
|
0b5e57b85e | ||
|
|
c623acf832 | ||
|
|
36b1888f46 | ||
|
|
c09a668620 | ||
|
|
e85c386375 | ||
|
|
c66ecc4d7f | ||
|
|
13fe89af9f | ||
|
|
d8fe39ae86 | ||
|
|
5f5359f933 | ||
|
|
e820a516de | ||
|
|
e9fdea80c0 | ||
|
|
9534bd8881 | ||
|
|
5be508620e | ||
|
|
82e968d5c7 | ||
|
|
b4b060a962 | ||
|
|
64e5e9d45c | ||
|
|
881215e815 | ||
|
|
35cd983cc9 | ||
|
|
0a70039dee | ||
|
|
18ccc57f87 | ||
|
|
c23fcc5b06 | ||
|
|
21ff3b8b5d | ||
|
|
97c388dba0 | ||
|
|
10799e2ce3 | ||
|
|
7ef6b1fcc2 | ||
|
|
7a220b4c87 | ||
|
|
dc1327674c | ||
|
|
c8ff8e3ef6 | ||
|
|
f766df597c | ||
|
|
bab92cb88c | ||
|
|
5d8a5494cd | ||
|
|
129d93dfa7 | ||
|
|
65c55f0f21 | ||
|
|
8578a3097a | ||
|
|
de5f68e42c | ||
|
|
f44b0be459 | ||
|
|
a128401d49 | ||
|
|
5075ded032 | ||
|
|
47c2e87979 | ||
|
|
53352e7987 | ||
|
|
44f86a7d6f | ||
|
|
c37124d9c4 | ||
|
|
69ab1e0249 | ||
|
|
2fd8052ac2 | ||
|
|
28924db9f8 | ||
|
|
50545af223 | ||
|
|
30829ff9c8 | ||
|
|
ede9e4a9bd | ||
|
|
04d0e80430 | ||
|
|
366d4736ca | ||
|
|
f3391a912e | ||
|
|
52eb4030d0 | ||
|
|
835680f0ee | ||
|
|
cdf54e0f9b | ||
|
|
b439d40120 | ||
|
|
cb744ddeef | ||
|
|
872ffe5882 | ||
|
|
671e946c6d | ||
|
|
3928609c29 | ||
|
|
e942c839a1 | ||
|
|
bff34aafb9 | ||
|
|
7623943f3e | ||
|
|
6d7691791a | ||
|
|
b001df1f53 | ||
|
|
1cc7f2d92e | ||
|
|
7a0a898bc6 | ||
|
|
41aca4e2d7 | ||
|
|
7e89b12004 | ||
|
|
7bac9f829e | ||
|
|
2435639498 | ||
|
|
2be3e4ce9d | ||
|
|
1294444026 | ||
|
|
7578b65573 | ||
|
|
ced45c92f7 | ||
|
|
f21cddb2d0 | ||
|
|
735b729a41 | ||
|
|
c5b933f922 | ||
|
|
ce6fe2590d | ||
|
|
7509a76eb0 | ||
|
|
41eaa06e55 | ||
|
|
7429749004 | ||
|
|
709f9954f4 | ||
|
|
29adaa03c6 | ||
|
|
9f169fb2b9 | ||
|
|
6b8294d9dc | ||
|
|
0ea70273fe | ||
|
|
c66b5e2dad | ||
|
|
9077462893 | ||
|
|
7158a79a34 | ||
|
|
68060d6118 | ||
|
|
ddbdc73e7e | ||
|
|
263b640641 | ||
|
|
84ad39f24a | ||
|
|
408a4c79aa | ||
|
|
b9bbccfe00 | ||
|
|
05d262e42b | ||
|
|
18e61d19f5 | ||
|
|
4a073ea161 | ||
|
|
2993ca74cc | ||
|
|
1566923d5c | ||
|
|
b0073caf5f | ||
|
|
8ad044cb2c | ||
|
|
8a9eb32aaf | ||
|
|
7f2199405d | ||
|
|
38a545e174 | ||
|
|
4f0271ad49 | ||
|
|
7fc1602f7a | ||
|
|
aa26690e33 | ||
|
|
09581829d1 | ||
|
|
3afb94f5d2 | ||
|
|
29f084613d | ||
|
|
dd76a1a0be | ||
|
|
c132477f80 | ||
|
|
92635f6f68 | ||
|
|
65ef255b99 | ||
|
|
854fe85132 | ||
|
|
4da6203828 | ||
|
|
7db1aae5ee | ||
|
|
b4388d838e | ||
|
|
8446047ab2 | ||
|
|
dc19150eba | ||
|
|
a89139763f | ||
|
|
dab138c731 | ||
|
|
205a73917d | ||
|
|
ae3fe8cd42 | ||
|
|
c0b274767b | ||
|
|
620040bde1 | ||
|
|
22aa9990a5 | ||
|
|
16b7404d9b | ||
|
|
db5e315db0 | ||
|
|
4c87ce59d3 | ||
|
|
ca7bc171c9 | ||
|
|
b55b17ccc1 | ||
|
|
59830c80af | ||
|
|
b4a63eca02 | ||
|
|
0306723c95 | ||
|
|
af9743026e | ||
|
|
9b44731c33 | ||
|
|
5946e159bc | ||
|
|
327ea9cacf | ||
|
|
6d6991e266 | ||
|
|
e4ea57932e | ||
|
|
484a17d496 | ||
|
|
1d421b2d7c | ||
|
|
4ce282b88b | ||
|
|
85ada36973 | ||
|
|
a3e42d3b19 | ||
|
|
542f55d43e | ||
|
|
d87f221a2b | ||
|
|
6237a19d17 | ||
|
|
17175637dc | ||
|
|
32b5c7fbb0 | ||
|
|
ef47d092e6 | ||
|
|
8648c85b67 | ||
|
|
657c37d45c | ||
|
|
006becf6ca | ||
|
|
012d948193 | ||
|
|
a048adcdac | ||
|
|
b091e8eb09 | ||
|
|
14b39d906c | ||
|
|
0508ba299c | ||
|
|
02db5a9170 | ||
|
|
93a68ff43e | ||
|
|
97e423ba86 | ||
|
|
3033f1eecd | ||
|
|
f4405a16f1 | ||
|
|
025b743070 | ||
|
|
e27f5565cb | ||
|
|
7fe5cd6ede | ||
|
|
7052355596 | ||
|
|
1e6d1a9f2f | ||
|
|
a776c6ba13 | ||
|
|
75f782ab71 | ||
|
|
832f56a6d0 | ||
|
|
f6d3a7c84e | ||
|
|
7769a35f07 | ||
|
|
c38dfd20a1 | ||
|
|
83634fe95a | ||
|
|
e336e9c770 | ||
|
|
3ac1169aa7 | ||
|
|
3d8a6fb55a | ||
|
|
891b3abb44 | ||
|
|
01b0980c44 | ||
|
|
2c2f11be39 | ||
|
|
d71078d03d | ||
|
|
12009e36df | ||
|
|
21c39f70de | ||
|
|
7566faf77b | ||
|
|
f27d5988f0 | ||
|
|
d8a215a575 | ||
|
|
118d132797 | ||
|
|
06487e5534 | ||
|
|
c0b73d4777 | ||
|
|
e9e755b517 | ||
|
|
191619e6d8 | ||
|
|
0f64e786b5 | ||
|
|
7164296c9d | ||
|
|
787445c071 | ||
|
|
d9d119c0c9 | ||
|
|
c45eb31e8f | ||
|
|
b31d022c1a | ||
|
|
919c7e932a | ||
|
|
9489fe56d9 |
0
.hgignore → .gitignore
vendored
0
.hgignore → .gitignore
vendored
12
README.txt
12
README.txt
@@ -1,6 +1,6 @@
|
|||||||
Troggle is an application for caving expedition data management, originally created for use on Cambridge University Caving Club (CUCC)expeditions and licensed under the GNU Lesser General Public License.
|
Troggle is an application for caving expedition data management, originally created for use on Cambridge University Caving Club (CUCC)expeditions and licensed under the GNU Lesser General Public License.
|
||||||
|
|
||||||
Troggle has been forked into two projects. The original one is maintained by Aron Curtis and is used for Erebus caves. The CUCC variant uses files as the definitive data, not the database and lives at expo.sruvex.com/troggle.
|
Troggle has been forked into two projects. The original one is maintained by Aron Curtis and is used for Erebus caves. The CUCC variant uses files as the definitive data, not the database and lives at expo.survex.com/troggle.
|
||||||
|
|
||||||
Troggle setup
|
Troggle setup
|
||||||
==========
|
==========
|
||||||
@@ -18,12 +18,14 @@ If you want to use MySQL or Postgresql, download and install them. However, you
|
|||||||
|
|
||||||
Troggle itself
|
Troggle itself
|
||||||
-------------
|
-------------
|
||||||
Choose a directory where you will keep troggle, and svn check out Troggle into it using the following command:
|
Choose a directory where you will keep troggle, and git clone Troggle into it using the following command:
|
||||||
|
|
||||||
svn co http://troggle.googlecode.com/svn/
|
git clone git://expo.survex.com/troggle
|
||||||
|
or more reliably
|
||||||
|
git clone ssh://expo@expo.survex.com/home/expo/troggle
|
||||||
|
|
||||||
|
|
||||||
If you want to work on the source code and be able to commit, you will need to use https instead of http, and your google account will need to be added to the troggle project members list. Contact aaron dot curtis at cantab dot net to get this set up.
|
If you want to work on the source code and be able to commit, your account will need to be added to the troggle project members list. Contact wookey at wookware dot org to get this set up.
|
||||||
|
|
||||||
Next, you need to fill in your local settings. Copy either localsettingsubuntu.py or localsettingsserver.py to a new file called localsettings.py. Follow the instructions contained in the file to fill out your settings.
|
Next, you need to fill in your local settings. Copy either localsettingsubuntu.py or localsettingsserver.py to a new file called localsettings.py. Follow the instructions contained in the file to fill out your settings.
|
||||||
|
|
||||||
@@ -35,7 +37,7 @@ Run "python databaseReset.py reset" from the troggle directory.
|
|||||||
Once troggle is running, you can also log in and then go to "Import / export" data under "admin" on the menu.
|
Once troggle is running, you can also log in and then go to "Import / export" data under "admin" on the menu.
|
||||||
|
|
||||||
Adding a new year/expedition requires adding a column to the
|
Adding a new year/expedition requires adding a column to the
|
||||||
noinfo/folk.csv table - a year doesn't exist until that is done.
|
folk/folk.csv table - a year doesn't exist until that is done.
|
||||||
|
|
||||||
|
|
||||||
Running a Troggle server
|
Running a Troggle server
|
||||||
|
|||||||
@@ -74,11 +74,11 @@ class LogbookEntryAdmin(TroggleModelAdmin):
|
|||||||
}
|
}
|
||||||
actions=('export_logbook_entries_as_html','export_logbook_entries_as_txt')
|
actions=('export_logbook_entries_as_html','export_logbook_entries_as_txt')
|
||||||
|
|
||||||
def export_logbook_entries_as_html(modeladmin, request, queryset):
|
def export_logbook_entries_as_html(self, modeladmin, request, queryset):
|
||||||
response=downloadLogbook(request=request, queryset=queryset, extension='html')
|
response=downloadLogbook(request=request, queryset=queryset, extension='html')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def export_logbook_entries_as_txt(modeladmin, request, queryset):
|
def export_logbook_entries_as_txt(self, modeladmin, request, queryset):
|
||||||
response=downloadLogbook(request=request, queryset=queryset, extension='txt')
|
response=downloadLogbook(request=request, queryset=queryset, extension='txt')
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@@ -139,16 +139,17 @@ admin.site.register(SurvexStation)
|
|||||||
admin.site.register(SurvexScansFolder)
|
admin.site.register(SurvexScansFolder)
|
||||||
admin.site.register(SurvexScanSingle)
|
admin.site.register(SurvexScanSingle)
|
||||||
|
|
||||||
|
admin.site.register(DataIssue)
|
||||||
|
|
||||||
def export_as_json(modeladmin, request, queryset):
|
def export_as_json(modeladmin, request, queryset):
|
||||||
response = HttpResponse(mimetype="text/json")
|
response = HttpResponse(content_type="text/json")
|
||||||
response['Content-Disposition'] = 'attachment; filename=troggle_output.json'
|
response['Content-Disposition'] = 'attachment; filename=troggle_output.json'
|
||||||
serializers.serialize("json", queryset, stream=response)
|
serializers.serialize("json", queryset, stream=response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def export_as_xml(modeladmin, request, queryset):
|
def export_as_xml(modeladmin, request, queryset):
|
||||||
response = HttpResponse(mimetype="text/xml")
|
response = HttpResponse(content_type="text/xml")
|
||||||
response['Content-Disposition'] = 'attachment; filename=troggle_output.xml'
|
response['Content-Disposition'] = 'attachment; filename=troggle_output.xml'
|
||||||
serializers.serialize("xml", queryset, stream=response)
|
serializers.serialize("xml", queryset, stream=response)
|
||||||
return response
|
return response
|
||||||
|
|||||||
@@ -46,12 +46,12 @@ class EntranceForm(ModelForm):
|
|||||||
#underground_centre_line = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
|
#underground_centre_line = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
|
||||||
#notes = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
|
#notes = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
|
||||||
#references = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
|
#references = forms.CharField(required = False, widget=TinyMCE(attrs={'cols': 80, 'rows': 10}))
|
||||||
other_station = forms.CharField(required=False) # Trying to change this to a singl;e line entry
|
other_station = forms.CharField(required=False) # Trying to change this to a single line entry
|
||||||
tag_station = forms.CharField(required=False) # Trying to change this to a singl;e line entry
|
tag_station = forms.CharField(required=False) # Trying to change this to a single line entry
|
||||||
exact_station = forms.CharField(required=False) # Trying to change this to a singl;e line entry
|
exact_station = forms.CharField(required=False) # Trying to change this to a single line entry
|
||||||
northing = forms.CharField(required=False) # Trying to change this to a singl;e line entry
|
northing = forms.CharField(required=False) # Trying to change this to a single line entry
|
||||||
easting = forms.CharField(required=False) # Trying to change this to a singl;e line entry
|
easting = forms.CharField(required=False) # Trying to change this to a single line entry
|
||||||
alt = forms.CharField(required=False) # Trying to change this to a singl;e line entry
|
alt = forms.CharField(required=False) # Trying to change this to a single line entry
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Entrance
|
model = Entrance
|
||||||
exclude = ("cached_primary_slug", "filename",)
|
exclude = ("cached_primary_slug", "filename",)
|
||||||
@@ -123,7 +123,7 @@ def getTripForm(expedition):
|
|||||||
html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
print dir(self)
|
print(dir(self))
|
||||||
if self.cleaned_data.get("caveOrLocation") == "cave" and not self.cleaned_data.get("cave"):
|
if self.cleaned_data.get("caveOrLocation") == "cave" and not self.cleaned_data.get("cave"):
|
||||||
self._errors["cave"] = self.error_class(["This field is required"])
|
self._errors["cave"] = self.error_class(["This field is required"])
|
||||||
if self.cleaned_data.get("caveOrLocation") == "location" and not self.cleaned_data.get("location"):
|
if self.cleaned_data.get("caveOrLocation") == "location" and not self.cleaned_data.get("location"):
|
||||||
|
|||||||
@@ -2,6 +2,14 @@ from django.core.management.base import BaseCommand, CommandError
|
|||||||
from optparse import make_option
|
from optparse import make_option
|
||||||
from troggle.core.models import Cave
|
from troggle.core.models import Cave
|
||||||
import settings
|
import settings
|
||||||
|
import os
|
||||||
|
|
||||||
|
from django.db import connection
|
||||||
|
from django.core import management
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
from troggle.core.models import Cave, Entrance
|
||||||
|
import troggle.flatpages.models
|
||||||
|
|
||||||
databasename=settings.DATABASES['default']['NAME']
|
databasename=settings.DATABASES['default']['NAME']
|
||||||
expouser=settings.EXPOUSER
|
expouser=settings.EXPOUSER
|
||||||
@@ -12,22 +20,13 @@ class Command(BaseCommand):
|
|||||||
help = 'This is normal usage, clear database and reread everything'
|
help = 'This is normal usage, clear database and reread everything'
|
||||||
|
|
||||||
option_list = BaseCommand.option_list + (
|
option_list = BaseCommand.option_list + (
|
||||||
make_option('--foo',
|
make_option('--reset',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='foo',
|
dest='reset',
|
||||||
default=False,
|
default=False,
|
||||||
help='test'),
|
help='Reset the entier DB from files'),
|
||||||
)
|
)
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
'--foo',
|
|
||||||
action='store_true',
|
|
||||||
dest='foo',
|
|
||||||
help='Help text',
|
|
||||||
)
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
print(args)
|
print(args)
|
||||||
print(options)
|
print(options)
|
||||||
@@ -46,8 +45,8 @@ class Command(BaseCommand):
|
|||||||
self.import_QMs()
|
self.import_QMs()
|
||||||
elif "tunnel" in args:
|
elif "tunnel" in args:
|
||||||
self.import_tunnelfiles()
|
self.import_tunnelfiles()
|
||||||
elif "reset" in args:
|
elif options['reset']:
|
||||||
self.reset()
|
self.reset(self)
|
||||||
elif "survex" in args:
|
elif "survex" in args:
|
||||||
self.import_survex()
|
self.import_survex()
|
||||||
elif "survexpos" in args:
|
elif "survexpos" in args:
|
||||||
@@ -61,13 +60,15 @@ class Command(BaseCommand):
|
|||||||
self.dumplogbooks()
|
self.dumplogbooks()
|
||||||
elif "writeCaves" in args:
|
elif "writeCaves" in args:
|
||||||
self.writeCaves()
|
self.writeCaves()
|
||||||
elif "foo" in args:
|
elif options['foo']:
|
||||||
self.stdout.write('Tesing....')
|
self.stdout.write(self.style.WARNING('Tesing....'))
|
||||||
else:
|
else:
|
||||||
self.stdout.write("%s not recognised" % args)
|
#self.stdout.write("%s not recognised" % args)
|
||||||
self.usage(options)
|
#self.usage(options)
|
||||||
|
self.stdout.write("poo")
|
||||||
|
#print(args)
|
||||||
|
|
||||||
def reload_db():
|
def reload_db(obj):
|
||||||
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3':
|
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3':
|
||||||
try:
|
try:
|
||||||
os.remove(databasename)
|
os.remove(databasename)
|
||||||
@@ -86,22 +87,22 @@ class Command(BaseCommand):
|
|||||||
user.is_superuser = True
|
user.is_superuser = True
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
def make_dirs():
|
def make_dirs(obj):
|
||||||
"""Make directories that troggle requires"""
|
"""Make directories that troggle requires"""
|
||||||
# should also deal with permissions here.
|
# should also deal with permissions here.
|
||||||
if not os.path.isdir(settings.PHOTOS_ROOT):
|
if not os.path.isdir(settings.PHOTOS_ROOT):
|
||||||
os.mkdir(settings.PHOTOS_ROOT)
|
os.mkdir(settings.PHOTOS_ROOT)
|
||||||
|
|
||||||
def import_caves():
|
def import_caves(obj):
|
||||||
import parsers.caves
|
import parsers.caves
|
||||||
print("importing caves")
|
print("Importing Caves")
|
||||||
parsers.caves.readcaves()
|
parsers.caves.readcaves()
|
||||||
|
|
||||||
def import_people():
|
def import_people(obj):
|
||||||
import parsers.people
|
import parsers.people
|
||||||
parsers.people.LoadPersonsExpos()
|
parsers.people.LoadPersonsExpos()
|
||||||
|
|
||||||
def import_logbooks():
|
def import_logbooks(obj):
|
||||||
# The below line was causing errors I didn't understand (it said LOGFILE was a string), and I couldn't be bothered to figure
|
# The below line was causing errors I didn't understand (it said LOGFILE was a string), and I couldn't be bothered to figure
|
||||||
# what was going on so I just catch the error with a try. - AC 21 May
|
# what was going on so I just catch the error with a try. - AC 21 May
|
||||||
try:
|
try:
|
||||||
@@ -112,57 +113,57 @@ class Command(BaseCommand):
|
|||||||
import parsers.logbooks
|
import parsers.logbooks
|
||||||
parsers.logbooks.LoadLogbooks()
|
parsers.logbooks.LoadLogbooks()
|
||||||
|
|
||||||
def import_survex():
|
def import_survex(obj):
|
||||||
import parsers.survex
|
import parsers.survex
|
||||||
parsers.survex.LoadAllSurvexBlocks()
|
parsers.survex.LoadAllSurvexBlocks()
|
||||||
parsers.survex.LoadPos()
|
parsers.survex.LoadPos()
|
||||||
|
|
||||||
def import_QMs():
|
def import_QMs(obj):
|
||||||
import parsers.QMs
|
import parsers.QMs
|
||||||
|
|
||||||
def import_surveys():
|
def import_surveys(obj):
|
||||||
import parsers.surveys
|
import parsers.surveys
|
||||||
parsers.surveys.parseSurveys(logfile=settings.LOGFILE)
|
parsers.surveys.parseSurveys(logfile=settings.LOGFILE)
|
||||||
|
|
||||||
def import_surveyscans():
|
def import_surveyscans(obj):
|
||||||
import parsers.surveys
|
import parsers.surveys
|
||||||
parsers.surveys.LoadListScans()
|
parsers.surveys.LoadListScans()
|
||||||
|
|
||||||
def import_tunnelfiles():
|
def import_tunnelfiles(obj):
|
||||||
import parsers.surveys
|
import parsers.surveys
|
||||||
parsers.surveys.LoadTunnelFiles()
|
parsers.surveys.LoadTunnelFiles()
|
||||||
|
|
||||||
def reset():
|
def reset(self, mgmt_obj):
|
||||||
""" Wipe the troggle database and import everything from legacy data
|
""" Wipe the troggle database and import everything from legacy data
|
||||||
"""
|
"""
|
||||||
reload_db()
|
self.reload_db()
|
||||||
make_dirs()
|
self.make_dirs()
|
||||||
pageredirects()
|
self.pageredirects()
|
||||||
import_caves()
|
self.import_caves()
|
||||||
import_people()
|
self.import_people()
|
||||||
import_surveyscans()
|
self.import_surveyscans()
|
||||||
import_survex()
|
self.import_survex()
|
||||||
import_logbooks()
|
self.import_logbooks()
|
||||||
import_QMs()
|
self.import_QMs()
|
||||||
try:
|
try:
|
||||||
import_tunnelfiles()
|
self.import_tunnelfiles()
|
||||||
except:
|
except:
|
||||||
print("Tunnel files parser broken.")
|
print("Tunnel files parser broken.")
|
||||||
|
|
||||||
import_surveys()
|
self.import_surveys()
|
||||||
|
|
||||||
def pageredirects():
|
def pageredirects(obj):
|
||||||
for oldURL, newURL in [("indxal.htm", reverse("caveindex"))]:
|
for oldURL, newURL in [("indxal.htm", reverse("caveindex"))]:
|
||||||
f = troggle.flatpages.models.Redirect(originalURL=oldURL, newURL=newURL)
|
f = troggle.flatpages.models.Redirect(originalURL=oldURL, newURL=newURL)
|
||||||
f.save()
|
f.save()
|
||||||
|
|
||||||
def writeCaves():
|
def writeCaves(obj):
|
||||||
for cave in Cave.objects.all():
|
for cave in Cave.objects.all():
|
||||||
cave.writeDataFile()
|
cave.writeDataFile()
|
||||||
for entrance in Entrance.objects.all():
|
for entrance in Entrance.objects.all():
|
||||||
entrance.writeDataFile()
|
entrance.writeDataFile()
|
||||||
|
|
||||||
def usage(self, parser):
|
def troggle_usage(obj):
|
||||||
print("""Usage is 'manage.py reset_db <command>'
|
print("""Usage is 'manage.py reset_db <command>'
|
||||||
where command is:
|
where command is:
|
||||||
reset - this is normal usage, clear database and reread everything
|
reset - this is normal usage, clear database and reread everything
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
import utm
|
|
||||||
import math
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
def lat_lon_entrance(utmstring):
|
|
||||||
try:
|
|
||||||
x = float(utmstring.split()[0])
|
|
||||||
y = float(utmstring.split()[1])
|
|
||||||
#return ' '+str(x+y)+' '+str(y)
|
|
||||||
q = utm.to_latlon(x, y, 33, 'U')
|
|
||||||
return "{:.5f} {:.5f}".format(q[0],q[1])
|
|
||||||
except:
|
|
||||||
return 'Not found'
|
|
||||||
|
|
||||||
def top_camp_distance(utmstring):
|
|
||||||
try:
|
|
||||||
x = float(utmstring.split()[0])
|
|
||||||
y = float(utmstring.split()[1])
|
|
||||||
tx = settings.TOPCAMPX
|
|
||||||
ty = settings.TOPCAMPY
|
|
||||||
dist = math.sqrt( (tx-x)*(tx-x) + (ty-y)*(ty-y) )
|
|
||||||
return "{:.1f}".format(dist)
|
|
||||||
except:
|
|
||||||
return 'Not found'
|
|
||||||
866
core/models.py
866
core/models.py
@@ -15,8 +15,868 @@ from django.template import Context, loader
|
|||||||
import settings
|
import settings
|
||||||
getcontext().prec=2 #use 2 significant figures for decimal calculations
|
getcontext().prec=2 #use 2 significant figures for decimal calculations
|
||||||
|
|
||||||
from troggle.core.models_survex import * #ancient models for both survex and other things
|
from troggle.core.models_survex import *
|
||||||
from troggle.core.models_old import *
|
|
||||||
|
|
||||||
|
|
||||||
from troggle.core.models_millenial import * #updated models are here
|
def get_related_by_wikilinks(wiki_text):
|
||||||
|
found=re.findall(settings.QM_PATTERN,wiki_text)
|
||||||
|
res=[]
|
||||||
|
for wikilink in found:
|
||||||
|
qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
|
||||||
|
try:
|
||||||
|
cave_slugs = CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
|
||||||
|
qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
|
||||||
|
found_by__date__year = qmdict['year'],
|
||||||
|
number = qmdict['number'])
|
||||||
|
res.append(qm)
|
||||||
|
except QM.DoesNotExist:
|
||||||
|
print('fail on '+str(wikilink))
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
try:
|
||||||
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
|
filename=settings.LOGFILE,
|
||||||
|
filemode='w')
|
||||||
|
except:
|
||||||
|
subprocess.call(settings.FIX_PERMISSIONS)
|
||||||
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
|
filename=settings.LOGFILE,
|
||||||
|
filemode='w')
|
||||||
|
|
||||||
|
#This class is for adding fields and methods which all of our models will have.
|
||||||
|
class TroggleModel(models.Model):
|
||||||
|
new_since_parsing = models.BooleanField(default=False, editable=False)
|
||||||
|
non_public = models.BooleanField(default=False)
|
||||||
|
def object_name(self):
|
||||||
|
return self._meta.object_name
|
||||||
|
|
||||||
|
def get_admin_url(self):
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
class TroggleImageModel(models.Model):
|
||||||
|
new_since_parsing = models.BooleanField(default=False, editable=False)
|
||||||
|
|
||||||
|
def object_name(self):
|
||||||
|
return self._meta.object_name
|
||||||
|
|
||||||
|
def get_admin_url(self):
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
|
||||||
|
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
#
|
||||||
|
# single Expedition, usually seen by year
|
||||||
|
#
|
||||||
|
class Expedition(TroggleModel):
|
||||||
|
year = models.CharField(max_length=20, unique=True)
|
||||||
|
name = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.year
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('-year',)
|
||||||
|
get_latest_by = 'year'
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
|
||||||
|
|
||||||
|
# construction function. should be moved out
|
||||||
|
def get_expedition_day(self, date):
|
||||||
|
expeditiondays = self.expeditionday_set.filter(date=date)
|
||||||
|
if expeditiondays:
|
||||||
|
assert len(expeditiondays) == 1
|
||||||
|
return expeditiondays[0]
|
||||||
|
res = ExpeditionDay(expedition=self, date=date)
|
||||||
|
res.save()
|
||||||
|
return res
|
||||||
|
|
||||||
|
def day_min(self):
|
||||||
|
res = self.expeditionday_set.all()
|
||||||
|
return res and res[0] or None
|
||||||
|
|
||||||
|
def day_max(self):
|
||||||
|
res = self.expeditionday_set.all()
|
||||||
|
return res and res[len(res) - 1] or None
|
||||||
|
|
||||||
|
|
||||||
|
class ExpeditionDay(TroggleModel):
|
||||||
|
expedition = models.ForeignKey("Expedition")
|
||||||
|
date = models.DateField()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('date',)
|
||||||
|
|
||||||
|
def GetPersonTrip(self, personexpedition):
|
||||||
|
personexpeditions = self.persontrip_set.filter(expeditionday=self)
|
||||||
|
return personexpeditions and personexpeditions[0] or None
|
||||||
|
|
||||||
|
#
|
||||||
|
# single Person, can go on many years
|
||||||
|
#
|
||||||
|
class Person(TroggleModel):
|
||||||
|
first_name = models.CharField(max_length=100)
|
||||||
|
last_name = models.CharField(max_length=100)
|
||||||
|
fullname = models.CharField(max_length=200)
|
||||||
|
is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False)
|
||||||
|
mug_shot = models.CharField(max_length=100, blank=True,null=True)
|
||||||
|
blurb = models.TextField(blank=True,null=True)
|
||||||
|
|
||||||
|
#href = models.CharField(max_length=200)
|
||||||
|
orderref = models.CharField(max_length=200) # for alphabetic
|
||||||
|
user = models.OneToOneField(User, null=True, blank=True)
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name}))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = "People"
|
||||||
|
ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
if self.last_name:
|
||||||
|
return "%s %s" % (self.first_name, self.last_name)
|
||||||
|
return self.first_name
|
||||||
|
|
||||||
|
|
||||||
|
def notability(self):
|
||||||
|
notability = Decimal(0)
|
||||||
|
max_expo_val = 0
|
||||||
|
|
||||||
|
max_expo_year = Expedition.objects.all().aggregate(Max('year'))
|
||||||
|
max_expo_val = int(max_expo_year['year__max']) + 1
|
||||||
|
|
||||||
|
for personexpedition in self.personexpedition_set.all():
|
||||||
|
if not personexpedition.is_guest:
|
||||||
|
print(personexpedition.expedition.year)
|
||||||
|
notability += Decimal(1) / (max_expo_val - int(personexpedition.expedition.year))
|
||||||
|
return notability
|
||||||
|
|
||||||
|
def bisnotable(self):
|
||||||
|
return self.notability() > Decimal(1)/Decimal(3)
|
||||||
|
|
||||||
|
def surveyedleglength(self):
|
||||||
|
return sum([personexpedition.surveyedleglength() for personexpedition in self.personexpedition_set.all()])
|
||||||
|
|
||||||
|
def first(self):
|
||||||
|
return self.personexpedition_set.order_by('-expedition')[0]
|
||||||
|
def last(self):
|
||||||
|
return self.personexpedition_set.order_by('expedition')[0]
|
||||||
|
|
||||||
|
#def Sethref(self):
|
||||||
|
#if self.last_name:
|
||||||
|
#self.href = self.first_name.lower() + "_" + self.last_name.lower()
|
||||||
|
#self.orderref = self.last_name + " " + self.first_name
|
||||||
|
#else:
|
||||||
|
# self.href = self.first_name.lower()
|
||||||
|
#self.orderref = self.first_name
|
||||||
|
#self.notability = 0.0 # set temporarily
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Person's attenance to one Expo
|
||||||
|
#
|
||||||
|
class PersonExpedition(TroggleModel):
|
||||||
|
expedition = models.ForeignKey(Expedition)
|
||||||
|
person = models.ForeignKey(Person)
|
||||||
|
slugfield = models.SlugField(max_length=50,blank=True,null=True)
|
||||||
|
|
||||||
|
is_guest = models.BooleanField(default=False)
|
||||||
|
COMMITTEE_CHOICES = (
|
||||||
|
('leader','Expo leader'),
|
||||||
|
('medical','Expo medical officer'),
|
||||||
|
('treasurer','Expo treasurer'),
|
||||||
|
('sponsorship','Expo sponsorship coordinator'),
|
||||||
|
('research','Expo research coordinator'),
|
||||||
|
)
|
||||||
|
expo_committee_position = models.CharField(blank=True,null=True,choices=COMMITTEE_CHOICES,max_length=200)
|
||||||
|
nickname = models.CharField(max_length=100,blank=True,null=True)
|
||||||
|
|
||||||
|
def GetPersonroles(self):
|
||||||
|
res = [ ]
|
||||||
|
for personrole in self.personrole_set.order_by('survexblock'):
|
||||||
|
if res and res[-1]['survexpath'] == personrole.survexblock.survexpath:
|
||||||
|
res[-1]['roles'] += ", " + str(personrole.role)
|
||||||
|
else:
|
||||||
|
res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath, 'roles':str(personrole.role)})
|
||||||
|
return res
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('-expedition',)
|
||||||
|
#order_with_respect_to = 'expedition'
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "%s: (%s)" % (self.person, self.expedition)
|
||||||
|
|
||||||
|
|
||||||
|
#why is the below a function in personexpedition, rather than in person? - AC 14 Feb 09
|
||||||
|
def name(self):
|
||||||
|
if self.nickname:
|
||||||
|
return "%s (%s) %s" % (self.person.first_name, self.nickname, self.person.last_name)
|
||||||
|
if self.person.last_name:
|
||||||
|
return "%s %s" % (self.person.first_name, self.person.last_name)
|
||||||
|
return self.person.first_name
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT, reverse('personexpedition',kwargs={'first_name':self.person.first_name,'last_name':self.person.last_name,'year':self.expedition.year}))
|
||||||
|
|
||||||
|
def surveyedleglength(self):
|
||||||
|
survexblocks = [personrole.survexblock for personrole in self.personrole_set.all() ]
|
||||||
|
return sum([survexblock.totalleglength for survexblock in set(survexblocks)])
|
||||||
|
|
||||||
|
# would prefer to return actual person trips so we could link to first and last ones
|
||||||
|
def day_min(self):
|
||||||
|
res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
|
||||||
|
return res["day_min"]
|
||||||
|
|
||||||
|
def day_max(self):
|
||||||
|
res = self.persontrip_set.all().aggregate(day_max=Max("expeditionday__date"))
|
||||||
|
return res["day_max"]
|
||||||
|
|
||||||
|
#
|
||||||
|
# Single parsed entry from Logbook
|
||||||
|
#
|
||||||
|
class LogbookEntry(TroggleModel):
|
||||||
|
|
||||||
|
LOGBOOK_ENTRY_TYPES = (
|
||||||
|
("wiki", "Wiki style logbook"),
|
||||||
|
("html", "Html style logbook")
|
||||||
|
)
|
||||||
|
|
||||||
|
date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.ld()
|
||||||
|
expeditionday = models.ForeignKey("ExpeditionDay", null=True)#MJG wants to KILL THIS (redundant information)
|
||||||
|
expedition = models.ForeignKey(Expedition,blank=True,null=True) # yes this is double-
|
||||||
|
title = models.CharField(max_length=settings.MAX_LOGBOOK_ENTRY_TITLE_LENGTH)
|
||||||
|
cave_slug = models.SlugField(max_length=50)
|
||||||
|
place = models.CharField(max_length=100,blank=True,null=True,help_text="Only use this if you haven't chosen a cave")
|
||||||
|
text = models.TextField()
|
||||||
|
slug = models.SlugField(max_length=50)
|
||||||
|
filename = models.CharField(max_length=200,null=True)
|
||||||
|
entry_type = models.CharField(default="wiki",null=True,choices=LOGBOOK_ENTRY_TYPES,max_length=50)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = "Logbook Entries"
|
||||||
|
# several PersonTrips point in to this object
|
||||||
|
ordering = ('-date',)
|
||||||
|
|
||||||
|
def __getattribute__(self, item):
|
||||||
|
if item == "cave": #Allow a logbookentries cave to be directly accessed despite not having a proper foreignkey
|
||||||
|
return CaveSlug.objects.get(slug = self.cave_slug).cave
|
||||||
|
return super(LogbookEntry, self).__getattribute__(item)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
if "cave" in kwargs.keys():
|
||||||
|
if kwargs["cave"] is not None:
|
||||||
|
kwargs["cave_slug"] = CaveSlug.objects.get(cave=kwargs["cave"], primary=True).slug
|
||||||
|
kwargs.pop("cave")
|
||||||
|
return super(LogbookEntry, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def isLogbookEntry(self): # Function used in templates
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT, reverse('logbookentry',kwargs={'date':self.date,'slug':self.slug}))
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "%s: (%s)" % (self.date, self.title)
|
||||||
|
|
||||||
|
def get_next_by_id(self):
|
||||||
|
LogbookEntry.objects.get(id=self.id+1)
|
||||||
|
|
||||||
|
def get_previous_by_id(self):
|
||||||
|
LogbookEntry.objects.get(id=self.id-1)
|
||||||
|
|
||||||
|
def new_QM_number(self):
|
||||||
|
"""Returns """
|
||||||
|
if self.cave:
|
||||||
|
nextQMnumber=self.cave.new_QM_number(self.date.year)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
return nextQMnumber
|
||||||
|
|
||||||
|
def new_QM_found_link(self):
|
||||||
|
"""Produces a link to a new QM with the next number filled in and this LogbookEntry set as 'found by' """
|
||||||
|
return settings.URL_ROOT + r'/admin/core/qm/add/?' + r'found_by=' + str(self.pk) +'&number=' + str(self.new_QM_number())
|
||||||
|
|
||||||
|
def DayIndex(self):
|
||||||
|
return list(self.expeditionday.logbookentry_set.all()).index(self)
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Single Person going on a trip, which may or may not be written up (accounts for different T/U for people in same logbook entry)
|
||||||
|
#
|
||||||
|
class PersonTrip(TroggleModel):
|
||||||
|
personexpedition = models.ForeignKey("PersonExpedition",null=True)
|
||||||
|
|
||||||
|
#expeditionday = models.ForeignKey("ExpeditionDay")#MJG wants to KILL THIS (redundant information)
|
||||||
|
#date = models.DateField() #MJG wants to KILL THIS (redundant information)
|
||||||
|
time_underground = models.FloatField(help_text="In decimal hours")
|
||||||
|
logbook_entry = models.ForeignKey(LogbookEntry)
|
||||||
|
is_logbook_entry_author = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
|
||||||
|
# sequencing by person (difficult to solve locally)
|
||||||
|
#persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)#MJG wants to KILL THIS (and use funstion persontrip_next_auto)
|
||||||
|
#persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)#MJG wants to KILL THIS(and use funstion persontrip_prev_auto)
|
||||||
|
|
||||||
|
def persontrip_next(self):
|
||||||
|
futurePTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__gt = self.logbook_entry.date).order_by('logbook_entry__date').all()
|
||||||
|
if len(futurePTs) > 0:
|
||||||
|
return futurePTs[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def persontrip_prev(self):
|
||||||
|
pastPTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__lt = self.logbook_entry.date).order_by('-logbook_entry__date').all()
|
||||||
|
if len(pastPTs) > 0:
|
||||||
|
return pastPTs[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def place(self):
|
||||||
|
return self.logbook_entry.cave and self.logbook_entry.cave or self.logbook_entry.place
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return "%s (%s)" % (self.personexpedition, self.logbook_entry.date)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##########################################
|
||||||
|
# move following classes into models_cave
|
||||||
|
##########################################
|
||||||
|
|
||||||
|
class Area(TroggleModel):
|
||||||
|
short_name = models.CharField(max_length=100)
|
||||||
|
name = models.CharField(max_length=200, blank=True, null=True)
|
||||||
|
description = models.TextField(blank=True,null=True)
|
||||||
|
parent = models.ForeignKey('Area', blank=True, null=True)
|
||||||
|
def __unicode__(self):
|
||||||
|
if self.parent:
|
||||||
|
return unicode(self.parent) + u" - " + unicode(self.short_name)
|
||||||
|
else:
|
||||||
|
return unicode(self.short_name)
|
||||||
|
def kat_area(self):
|
||||||
|
if self.short_name in ["1623", "1626"]:
|
||||||
|
return self.short_name
|
||||||
|
elif self.parent:
|
||||||
|
return self.parent.kat_area()
|
||||||
|
|
||||||
|
class CaveAndEntrance(models.Model):
|
||||||
|
cave = models.ForeignKey('Cave')
|
||||||
|
entrance = models.ForeignKey('Entrance')
|
||||||
|
entrance_letter = models.CharField(max_length=20,blank=True,null=True)
|
||||||
|
def __unicode__(self):
|
||||||
|
return unicode(self.cave) + unicode(self.entrance_letter)
|
||||||
|
|
||||||
|
class CaveSlug(models.Model):
|
||||||
|
cave = models.ForeignKey('Cave')
|
||||||
|
slug = models.SlugField(max_length=50, unique = True)
|
||||||
|
primary = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
|
||||||
|
class Cave(TroggleModel):
|
||||||
|
# too much here perhaps,
|
||||||
|
official_name = models.CharField(max_length=160)
|
||||||
|
area = models.ManyToManyField(Area, blank=True, null=True)
|
||||||
|
kataster_code = models.CharField(max_length=20,blank=True,null=True)
|
||||||
|
kataster_number = models.CharField(max_length=10,blank=True, null=True)
|
||||||
|
unofficial_number = models.CharField(max_length=60,blank=True, null=True)
|
||||||
|
entrances = models.ManyToManyField('Entrance', through='CaveAndEntrance')
|
||||||
|
explorers = models.TextField(blank=True,null=True)
|
||||||
|
underground_description = models.TextField(blank=True,null=True)
|
||||||
|
equipment = models.TextField(blank=True,null=True)
|
||||||
|
references = models.TextField(blank=True,null=True)
|
||||||
|
survey = models.TextField(blank=True,null=True)
|
||||||
|
kataster_status = models.TextField(blank=True,null=True)
|
||||||
|
underground_centre_line = models.TextField(blank=True,null=True)
|
||||||
|
notes = models.TextField(blank=True,null=True)
|
||||||
|
length = models.CharField(max_length=100,blank=True,null=True)
|
||||||
|
depth = models.CharField(max_length=100,blank=True,null=True)
|
||||||
|
extent = models.CharField(max_length=100,blank=True,null=True)
|
||||||
|
survex_file = models.CharField(max_length=100,blank=True,null=True)
|
||||||
|
description_file = models.CharField(max_length=200,blank=True,null=True)
|
||||||
|
url = models.CharField(max_length=200,blank=True,null=True)
|
||||||
|
filename = models.CharField(max_length=200)
|
||||||
|
|
||||||
|
|
||||||
|
#class Meta:
|
||||||
|
# unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
|
||||||
|
# FIXME Kataster Areas and CUCC defined sub areas need seperating
|
||||||
|
|
||||||
|
|
||||||
|
#href = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('kataster_code', 'unofficial_number')
|
||||||
|
|
||||||
|
def hassurvey(self):
|
||||||
|
if not self.underground_centre_line:
|
||||||
|
return "No"
|
||||||
|
if (self.survey.find("<img") > -1 or self.survey.find("<a") > -1 or self.survey.find("<IMG") > -1 or self.survey.find("<A") > -1):
|
||||||
|
return "Yes"
|
||||||
|
return "Missing"
|
||||||
|
|
||||||
|
def hassurveydata(self):
|
||||||
|
if not self.underground_centre_line:
|
||||||
|
return "No"
|
||||||
|
if self.survex_file:
|
||||||
|
return "Yes"
|
||||||
|
return "Missing"
|
||||||
|
|
||||||
|
def slug(self):
|
||||||
|
primarySlugs = self.caveslug_set.filter(primary = True)
|
||||||
|
if primarySlugs:
|
||||||
|
return primarySlugs[0].slug
|
||||||
|
else:
|
||||||
|
slugs = self.caveslug_set.filter()
|
||||||
|
if slugs:
|
||||||
|
return slugs[0].slug
|
||||||
|
|
||||||
|
def ours(self):
|
||||||
|
return bool(re.search(r'CUCC', self.explorers))
|
||||||
|
|
||||||
|
def reference(self):
|
||||||
|
if self.kataster_number:
|
||||||
|
return "%s-%s" % (self.kat_area(), self.kataster_number)
|
||||||
|
else:
|
||||||
|
return "%s-%s" % (self.kat_area(), self.unofficial_number)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
if self.kataster_number:
|
||||||
|
href = self.kataster_number
|
||||||
|
elif self.unofficial_number:
|
||||||
|
href = self.unofficial_number
|
||||||
|
else:
|
||||||
|
href = self.official_name.lower()
|
||||||
|
#return settings.URL_ROOT + '/cave/' + href + '/'
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT, reverse('cave',kwargs={'cave_id':href,}))
|
||||||
|
|
||||||
|
def __unicode__(self, sep = u": "):
|
||||||
|
return unicode(self.slug())
|
||||||
|
|
||||||
|
def get_QMs(self):
|
||||||
|
return QM.objects.filter(found_by__cave_slug=self.caveslug_set.all())
|
||||||
|
|
||||||
|
def new_QM_number(self, year=datetime.date.today().year):
|
||||||
|
"""Given a cave and the current year, returns the next QM number."""
|
||||||
|
try:
|
||||||
|
res=QM.objects.filter(found_by__date__year=year, found_by__cave=self).order_by('-number')[0]
|
||||||
|
except IndexError:
|
||||||
|
return 1
|
||||||
|
return res.number+1
|
||||||
|
|
||||||
|
def kat_area(self):
|
||||||
|
for a in self.area.all():
|
||||||
|
if a.kat_area():
|
||||||
|
return a.kat_area()
|
||||||
|
|
||||||
|
def entrances(self):
|
||||||
|
return CaveAndEntrance.objects.filter(cave=self)
|
||||||
|
|
||||||
|
def singleentrance(self):
|
||||||
|
return len(CaveAndEntrance.objects.filter(cave=self)) == 1
|
||||||
|
|
||||||
|
def entrancelist(self):
|
||||||
|
rs = []
|
||||||
|
res = ""
|
||||||
|
for e in CaveAndEntrance.objects.filter(cave=self):
|
||||||
|
rs.append(e.entrance_letter)
|
||||||
|
rs.sort()
|
||||||
|
prevR = None
|
||||||
|
n = 0
|
||||||
|
for r in rs:
|
||||||
|
if prevR:
|
||||||
|
if chr(ord(prevR) + 1 ) == r:
|
||||||
|
prevR = r
|
||||||
|
n += 1
|
||||||
|
else:
|
||||||
|
if n == 0:
|
||||||
|
res += ", " + prevR
|
||||||
|
else:
|
||||||
|
res += "–" + prevR
|
||||||
|
else:
|
||||||
|
prevR = r
|
||||||
|
n = 0
|
||||||
|
res += r
|
||||||
|
if n == 0:
|
||||||
|
res += ", " + prevR
|
||||||
|
else:
|
||||||
|
res += "–" + prevR
|
||||||
|
return res
|
||||||
|
|
||||||
|
def writeDataFile(self):
|
||||||
|
try:
|
||||||
|
f = open(os.path.join(settings.CAVEDESCRIPTIONS, self.filename), "w")
|
||||||
|
except:
|
||||||
|
subprocess.call(settings.FIX_PERMISSIONS)
|
||||||
|
f = open(os.path.join(settings.CAVEDESCRIPTIONS, self.filename), "w")
|
||||||
|
t = loader.get_template('dataformat/cave.xml')
|
||||||
|
c = Context({'cave': self})
|
||||||
|
u = t.render(c)
|
||||||
|
u8 = u.encode("utf-8")
|
||||||
|
f.write(u8)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def getArea(self):
|
||||||
|
areas = self.area.all()
|
||||||
|
lowestareas = list(areas)
|
||||||
|
for area in areas:
|
||||||
|
if area.parent in areas:
|
||||||
|
try:
|
||||||
|
lowestareas.remove(area.parent)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return lowestareas[0]
|
||||||
|
|
||||||
|
def getCaveByReference(reference):
|
||||||
|
areaname, code = reference.split("-", 1)
|
||||||
|
#print(areaname, code)
|
||||||
|
area = Area.objects.get(short_name = areaname)
|
||||||
|
#print(area)
|
||||||
|
foundCaves = list(Cave.objects.filter(area = area, kataster_number = code).all()) + list(Cave.objects.filter(area = area, unofficial_number = code).all())
|
||||||
|
print(list(foundCaves))
|
||||||
|
if len(foundCaves) == 1:
|
||||||
|
return foundCaves[0]
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
class OtherCaveName(TroggleModel):
|
||||||
|
name = models.CharField(max_length=160)
|
||||||
|
cave = models.ForeignKey(Cave)
|
||||||
|
def __unicode__(self):
|
||||||
|
return unicode(self.name)
|
||||||
|
|
||||||
|
class EntranceSlug(models.Model):
|
||||||
|
entrance = models.ForeignKey('Entrance')
|
||||||
|
slug = models.SlugField(max_length=50, unique = True)
|
||||||
|
primary = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
class Entrance(TroggleModel):
|
||||||
|
name = models.CharField(max_length=100, blank=True,null=True)
|
||||||
|
entrance_description = models.TextField(blank=True,null=True)
|
||||||
|
explorers = models.TextField(blank=True,null=True)
|
||||||
|
map_description = models.TextField(blank=True,null=True)
|
||||||
|
location_description = models.TextField(blank=True,null=True)
|
||||||
|
approach = models.TextField(blank=True,null=True)
|
||||||
|
underground_description = models.TextField(blank=True,null=True)
|
||||||
|
photo = models.TextField(blank=True,null=True)
|
||||||
|
MARKING_CHOICES = (
|
||||||
|
('P', 'Paint'),
|
||||||
|
('P?', 'Paint (?)'),
|
||||||
|
('T', 'Tag'),
|
||||||
|
('T?', 'Tag (?)'),
|
||||||
|
('R', 'Needs Retag'),
|
||||||
|
('S', 'Spit'),
|
||||||
|
('S?', 'Spit (?)'),
|
||||||
|
('U', 'Unmarked'),
|
||||||
|
('?', 'Unknown'))
|
||||||
|
marking = models.CharField(max_length=2, choices=MARKING_CHOICES)
|
||||||
|
marking_comment = models.TextField(blank=True,null=True)
|
||||||
|
FINDABLE_CHOICES = (
|
||||||
|
('?', 'To be confirmed ...'),
|
||||||
|
('S', 'Coordinates'),
|
||||||
|
('L', 'Lost'),
|
||||||
|
('R', 'Refindable'))
|
||||||
|
findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True)
|
||||||
|
findability_description = models.TextField(blank=True,null=True)
|
||||||
|
alt = models.TextField(blank=True, null=True)
|
||||||
|
northing = models.TextField(blank=True, null=True)
|
||||||
|
easting = models.TextField(blank=True, null=True)
|
||||||
|
tag_station = models.TextField(blank=True, null=True)
|
||||||
|
exact_station = models.TextField(blank=True, null=True)
|
||||||
|
other_station = models.TextField(blank=True, null=True)
|
||||||
|
other_description = models.TextField(blank=True,null=True)
|
||||||
|
bearings = models.TextField(blank=True,null=True)
|
||||||
|
url = models.CharField(max_length=200,blank=True,null=True)
|
||||||
|
filename = models.CharField(max_length=200)
|
||||||
|
cached_primary_slug = models.CharField(max_length=200,blank=True,null=True)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return unicode(self.slug())
|
||||||
|
|
||||||
|
def exact_location(self):
|
||||||
|
return SurvexStation.objects.lookup(self.exact_station)
|
||||||
|
def other_location(self):
|
||||||
|
return SurvexStation.objects.lookup(self.other_station)
|
||||||
|
|
||||||
|
|
||||||
|
def find_location(self):
|
||||||
|
r = {'': 'To be entered ',
|
||||||
|
'?': 'To be confirmed:',
|
||||||
|
'S': '',
|
||||||
|
'L': 'Lost:',
|
||||||
|
'R': 'Refindable:'}[self.findability]
|
||||||
|
if self.tag_station:
|
||||||
|
try:
|
||||||
|
s = SurvexStation.objects.lookup(self.tag_station)
|
||||||
|
return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z)
|
||||||
|
except:
|
||||||
|
return r + "%s Tag Station not in dataset" % self.tag_station
|
||||||
|
if self.exact_station:
|
||||||
|
try:
|
||||||
|
s = SurvexStation.objects.lookup(self.exact_station)
|
||||||
|
return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z)
|
||||||
|
except:
|
||||||
|
return r + "%s Exact Station not in dataset" % self.tag_station
|
||||||
|
if self.other_station:
|
||||||
|
try:
|
||||||
|
s = SurvexStation.objects.lookup(self.other_station)
|
||||||
|
return r + "%0.0fE %0.0fN %0.0fAlt %s" % (s.x, s.y, s.z, self.other_description)
|
||||||
|
except:
|
||||||
|
return r + "%s Other Station not in dataset" % self.tag_station
|
||||||
|
if self.FINDABLE_CHOICES == "S":
|
||||||
|
r += "ERROR, Entrance has been surveyed but has no survex point"
|
||||||
|
if self.bearings:
|
||||||
|
return r + self.bearings
|
||||||
|
return r
|
||||||
|
|
||||||
|
def best_station(self):
|
||||||
|
if self.tag_station:
|
||||||
|
return self.tag_station
|
||||||
|
if self.exact_station:
|
||||||
|
return self.exact_station
|
||||||
|
if self.other_station:
|
||||||
|
return self.other_station
|
||||||
|
|
||||||
|
def has_photo(self):
|
||||||
|
if self.photo:
|
||||||
|
if (self.photo.find("<img") > -1 or self.photo.find("<a") > -1 or self.photo.find("<IMG") > -1 or self.photo.find("<A") > -1):
|
||||||
|
return "Yes"
|
||||||
|
else:
|
||||||
|
return "Missing"
|
||||||
|
else:
|
||||||
|
return "No"
|
||||||
|
|
||||||
|
def marking_val(self):
|
||||||
|
for m in self.MARKING_CHOICES:
|
||||||
|
if m[0] == self.marking:
|
||||||
|
return m[1]
|
||||||
|
def findability_val(self):
|
||||||
|
for f in self.FINDABLE_CHOICES:
|
||||||
|
if f[0] == self.findability:
|
||||||
|
return f[1]
|
||||||
|
|
||||||
|
def tag(self):
|
||||||
|
return SurvexStation.objects.lookup(self.tag_station)
|
||||||
|
|
||||||
|
def needs_surface_work(self):
|
||||||
|
return self.findability != "S" or not self.has_photo or self.marking != "T"
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
|
||||||
|
ancestor_titles='/'.join([subcave.title for subcave in self.get_ancestors()])
|
||||||
|
if ancestor_titles:
|
||||||
|
res = '/'.join((self.get_root().cave.get_absolute_url(), ancestor_titles, self.title))
|
||||||
|
|
||||||
|
else:
|
||||||
|
res = '/'.join((self.get_root().cave.get_absolute_url(), self.title))
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
def slug(self):
|
||||||
|
if not self.cached_primary_slug:
|
||||||
|
primarySlugs = self.entranceslug_set.filter(primary = True)
|
||||||
|
if primarySlugs:
|
||||||
|
self.cached_primary_slug = primarySlugs[0].slug
|
||||||
|
self.save()
|
||||||
|
else:
|
||||||
|
slugs = self.entranceslug_set.filter()
|
||||||
|
if slugs:
|
||||||
|
self.cached_primary_slug = slugs[0].slug
|
||||||
|
self.save()
|
||||||
|
return self.cached_primary_slug
|
||||||
|
|
||||||
|
def writeDataFile(self):
|
||||||
|
try:
|
||||||
|
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")
|
||||||
|
except:
|
||||||
|
subprocess.call(settings.FIX_PERMISSIONS)
|
||||||
|
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")
|
||||||
|
t = loader.get_template('dataformat/entrance.xml')
|
||||||
|
c = Context({'entrance': self})
|
||||||
|
u = t.render(c)
|
||||||
|
u8 = u.encode("utf-8")
|
||||||
|
f.write(u8)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
class CaveDescription(TroggleModel):
|
||||||
|
short_name = models.CharField(max_length=50, unique = True)
|
||||||
|
long_name = models.CharField(max_length=200, blank=True, null=True)
|
||||||
|
description = models.TextField(blank=True,null=True)
|
||||||
|
linked_subcaves = models.ManyToManyField("NewSubCave", blank=True,null=True)
|
||||||
|
linked_entrances = models.ManyToManyField("Entrance", blank=True,null=True)
|
||||||
|
linked_qms = models.ManyToManyField("QM", blank=True,null=True)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
if self.long_name:
|
||||||
|
return unicode(self.long_name)
|
||||||
|
else:
|
||||||
|
return unicode(self.short_name)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT, reverse('cavedescription', args=(self.short_name,)))
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
"""
|
||||||
|
Overridden save method which stores wikilinks in text as links in database.
|
||||||
|
"""
|
||||||
|
super(CaveDescription, self).save()
|
||||||
|
qm_list=get_related_by_wikilinks(self.description)
|
||||||
|
for qm in qm_list:
|
||||||
|
self.linked_qms.add(qm)
|
||||||
|
super(CaveDescription, self).save()
|
||||||
|
|
||||||
|
class NewSubCave(TroggleModel):
|
||||||
|
name = models.CharField(max_length=200, unique = True)
|
||||||
|
def __unicode__(self):
|
||||||
|
return unicode(self.name)
|
||||||
|
|
||||||
|
class QM(TroggleModel):
|
||||||
|
#based on qm.csv in trunk/expoweb/1623/204 which has the fields:
|
||||||
|
#"Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment"
|
||||||
|
found_by = models.ForeignKey(LogbookEntry, related_name='QMs_found',blank=True, null=True )
|
||||||
|
ticked_off_by = models.ForeignKey(LogbookEntry, related_name='QMs_ticked_off',null=True,blank=True)
|
||||||
|
#cave = models.ForeignKey(Cave)
|
||||||
|
#expedition = models.ForeignKey(Expedition)
|
||||||
|
|
||||||
|
number = models.IntegerField(help_text="this is the sequential number in the year", )
|
||||||
|
GRADE_CHOICES=(
|
||||||
|
('A', 'A: Large obvious lead'),
|
||||||
|
('B', 'B: Average lead'),
|
||||||
|
('C', 'C: Tight unpromising lead'),
|
||||||
|
('D', 'D: Dig'),
|
||||||
|
('X', 'X: Unclimbable aven')
|
||||||
|
)
|
||||||
|
grade = models.CharField(max_length=1, choices=GRADE_CHOICES)
|
||||||
|
location_description = models.TextField(blank=True)
|
||||||
|
nearest_station_description = models.CharField(max_length=400,null=True,blank=True)
|
||||||
|
nearest_station_name = models.CharField(max_length=200,blank=True,null=True)
|
||||||
|
nearest_station = models.ForeignKey(SurvexStation,null=True,blank=True)
|
||||||
|
area = models.CharField(max_length=100,blank=True,null=True)
|
||||||
|
completion_description = models.TextField(blank=True,null=True)
|
||||||
|
comment=models.TextField(blank=True,null=True)
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return u"%s %s" % (self.code(), self.grade)
|
||||||
|
|
||||||
|
def code(self):
|
||||||
|
return u"%s-%s-%s" % (unicode(self.found_by.cave)[6:], self.found_by.date.year, self.number)
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
#return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number
|
||||||
|
return urlparse.urljoin(settings.URL_ROOT, reverse('qm',kwargs={'cave_id':self.found_by.cave.kataster_number,'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}))
|
||||||
|
|
||||||
|
def get_next_by_id(self):
|
||||||
|
return QM.objects.get(id=self.id+1)
|
||||||
|
|
||||||
|
def get_previous_by_id(self):
|
||||||
|
return QM.objects.get(id=self.id-1)
|
||||||
|
|
||||||
|
def wiki_link(self):
|
||||||
|
return u"%s%s%s" % ('[[QM:',self.code(),']]')
|
||||||
|
|
||||||
|
photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL)
|
||||||
|
class DPhoto(TroggleImageModel):
|
||||||
|
caption = models.CharField(max_length=1000,blank=True,null=True)
|
||||||
|
contains_logbookentry = models.ForeignKey(LogbookEntry,blank=True,null=True)
|
||||||
|
contains_person = models.ManyToManyField(Person,blank=True,null=True)
|
||||||
|
file = models.ImageField(storage=photoFileStorage, upload_to='.',)
|
||||||
|
is_mugshot = models.BooleanField(default=False)
|
||||||
|
contains_cave = models.ForeignKey(Cave,blank=True,null=True)
|
||||||
|
contains_entrance = models.ForeignKey(Entrance, related_name="photo_file",blank=True,null=True)
|
||||||
|
#nearest_survey_point = models.ForeignKey(SurveyStation,blank=True,null=True)
|
||||||
|
nearest_QM = models.ForeignKey(QM,blank=True,null=True)
|
||||||
|
lon_utm = models.FloatField(blank=True,null=True)
|
||||||
|
lat_utm = models.FloatField(blank=True,null=True)
|
||||||
|
|
||||||
|
class IKOptions:
|
||||||
|
spec_module = 'core.imagekit_specs'
|
||||||
|
cache_dir = 'thumbs'
|
||||||
|
image_field = 'file'
|
||||||
|
|
||||||
|
#content_type = models.ForeignKey(ContentType)
|
||||||
|
#object_id = models.PositiveIntegerField()
|
||||||
|
#location = generic.GenericForeignKey('content_type', 'object_id')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.caption
|
||||||
|
|
||||||
|
scansFileStorage = FileSystemStorage(location=settings.SURVEY_SCANS, base_url=settings.SURVEYS_URL)
|
||||||
|
def get_scan_path(instance, filename):
|
||||||
|
year=instance.survey.expedition.year
|
||||||
|
#print("WN: ", type(instance.survey.wallet_number), instance.survey.wallet_number, instance.survey.wallet_letter)
|
||||||
|
number=str(instance.survey.wallet_number)
|
||||||
|
if str(instance.survey.wallet_letter) != "None":
|
||||||
|
number=str(instance.survey.wallet_letter) + number #two strings formatting because convention is 2009#01 or 2009#X01
|
||||||
|
return os.path.join('./',year,year+r'#'+number,str(instance.contents)+str(instance.number_in_wallet)+r'.jpg')
|
||||||
|
|
||||||
|
class ScannedImage(TroggleImageModel):
|
||||||
|
file = models.ImageField(storage=scansFileStorage, upload_to=get_scan_path)
|
||||||
|
scanned_by = models.ForeignKey(Person,blank=True, null=True)
|
||||||
|
scanned_on = models.DateField(null=True)
|
||||||
|
survey = models.ForeignKey('Survey')
|
||||||
|
contents = models.CharField(max_length=20,choices=(('notes','notes'),('plan','plan_sketch'),('elevation','elevation_sketch')))
|
||||||
|
number_in_wallet = models.IntegerField(null=True)
|
||||||
|
lon_utm = models.FloatField(blank=True,null=True)
|
||||||
|
lat_utm = models.FloatField(blank=True,null=True)
|
||||||
|
|
||||||
|
class IKOptions:
|
||||||
|
spec_module = 'core.imagekit_specs'
|
||||||
|
cache_dir = 'thumbs'
|
||||||
|
image_field = 'file'
|
||||||
|
#content_type = models.ForeignKey(ContentType)
|
||||||
|
#object_id = models.PositiveIntegerField()
|
||||||
|
#location = generic.GenericForeignKey('content_type', 'object_id')
|
||||||
|
|
||||||
|
#This is an ugly hack to deal with the #s in our survey scan paths. The correct thing is to write a custom file storage backend which calls urlencode on the name for making file.url but not file.path.
|
||||||
|
def correctURL(self):
|
||||||
|
return string.replace(self.file.url,r'#',r'%23')
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return get_scan_path(self,'')
|
||||||
|
|
||||||
|
class Survey(TroggleModel):
|
||||||
|
expedition = models.ForeignKey('Expedition') #REDUNDANT (logbook_entry)
|
||||||
|
wallet_number = models.IntegerField(blank=True,null=True)
|
||||||
|
wallet_letter = models.CharField(max_length=1,blank=True,null=True)
|
||||||
|
comments = models.TextField(blank=True,null=True)
|
||||||
|
location = models.CharField(max_length=400,blank=True,null=True) #REDUNDANT
|
||||||
|
subcave = models.ForeignKey('NewSubCave', blank=True, null=True)
|
||||||
|
#notes_scan = models.ForeignKey('ScannedImage',related_name='notes_scan',blank=True, null=True) #Replaced by contents field of ScannedImage model
|
||||||
|
survex_block = models.OneToOneField('SurvexBlock',blank=True, null=True)
|
||||||
|
logbook_entry = models.ForeignKey('LogbookEntry')
|
||||||
|
centreline_printed_on = models.DateField(blank=True, null=True)
|
||||||
|
centreline_printed_by = models.ForeignKey('Person',related_name='centreline_printed_by',blank=True,null=True)
|
||||||
|
#sketch_scan = models.ForeignKey(ScannedImage,blank=True, null=True) #Replaced by contents field of ScannedImage model
|
||||||
|
tunnel_file = models.FileField(upload_to='surveyXMLfiles',blank=True, null=True)
|
||||||
|
tunnel_main_sketch = models.ForeignKey('Survey',blank=True,null=True)
|
||||||
|
integrated_into_main_sketch_on = models.DateField(blank=True,null=True)
|
||||||
|
integrated_into_main_sketch_by = models.ForeignKey('Person' ,related_name='integrated_into_main_sketch_by', blank=True,null=True)
|
||||||
|
rendered_image = models.ImageField(upload_to='renderedSurveys',blank=True,null=True)
|
||||||
|
def __unicode__(self):
|
||||||
|
return self.expedition.year+"#"+"%02d" % int(self.wallet_number)
|
||||||
|
|
||||||
|
def notes(self):
|
||||||
|
return self.scannedimage_set.filter(contents='notes')
|
||||||
|
|
||||||
|
def plans(self):
|
||||||
|
return self.scannedimage_set.filter(contents='plan')
|
||||||
|
|
||||||
|
def elevations(self):
|
||||||
|
return self.scannedimage_set.filter(contents='elevation')
|
||||||
|
|
||||||
|
class DataIssue(TroggleModel):
|
||||||
|
date = models.DateTimeField(auto_now_add=True, blank=True)
|
||||||
|
parser = models.CharField(max_length=50, blank=True, null=True)
|
||||||
|
message = models.CharField(max_length=400, blank=True, null=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ['date']
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return u"%s - %s" % (self.parser, self.message)
|
||||||
|
|||||||
@@ -1,864 +0,0 @@
|
|||||||
import urllib, urlparse, string, os, datetime, logging, re
|
|
||||||
import subprocess
|
|
||||||
from django.forms import ModelForm
|
|
||||||
from django.db import models
|
|
||||||
from django.contrib import admin
|
|
||||||
from django.core.files.storage import FileSystemStorage
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
from django.db.models import Min, Max
|
|
||||||
from django.conf import settings
|
|
||||||
from decimal import Decimal, getcontext
|
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
from imagekit.models import ImageModel
|
|
||||||
from django.template import Context, loader
|
|
||||||
import settings
|
|
||||||
getcontext().prec=2 #use 2 significant figures for decimal calculations
|
|
||||||
|
|
||||||
from troggle.core.models_survex import *
|
|
||||||
|
|
||||||
from troggle.core.models_millenial import *
|
|
||||||
|
|
||||||
def get_related_by_wikilinks(wiki_text):
|
|
||||||
found=re.findall(settings.QM_PATTERN,wiki_text)
|
|
||||||
res=[]
|
|
||||||
for wikilink in found:
|
|
||||||
qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
|
|
||||||
try:
|
|
||||||
cave_slugs = CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
|
|
||||||
qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
|
|
||||||
found_by__date__year = qmdict['year'],
|
|
||||||
number = qmdict['number'])
|
|
||||||
res.append(qm)
|
|
||||||
except QM.DoesNotExist:
|
|
||||||
print('fail on '+str(wikilink))
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
try:
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
|
||||||
filename=settings.LOGFILE,
|
|
||||||
filemode='w')
|
|
||||||
except:
|
|
||||||
subprocess.call(settings.FIX_PERMISSIONS)
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
|
||||||
filename=settings.LOGFILE,
|
|
||||||
filemode='w')
|
|
||||||
|
|
||||||
#This class is for adding fields and methods which all of our models will have.
|
|
||||||
class TroggleModel(models.Model):
|
|
||||||
new_since_parsing = models.BooleanField(default=False, editable=False)
|
|
||||||
non_public = models.BooleanField(default=False)
|
|
||||||
def object_name(self):
|
|
||||||
return self._meta.object_name
|
|
||||||
|
|
||||||
def get_admin_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
class TroggleImageModel(ImageModel):
|
|
||||||
new_since_parsing = models.BooleanField(default=False, editable=False)
|
|
||||||
|
|
||||||
def object_name(self):
|
|
||||||
return self._meta.object_name
|
|
||||||
|
|
||||||
def get_admin_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
|
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
#
|
|
||||||
# single Expedition, usually seen by year
|
|
||||||
#
|
|
||||||
class Expedition(TroggleModel):
|
|
||||||
year = models.CharField(max_length=20, unique=True)
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.year
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('-year',)
|
|
||||||
get_latest_by = 'year'
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
|
|
||||||
|
|
||||||
# construction function. should be moved out
|
|
||||||
def get_expedition_day(self, date):
|
|
||||||
expeditiondays = self.expeditionday_set.filter(date=date)
|
|
||||||
if expeditiondays:
|
|
||||||
assert len(expeditiondays) == 1
|
|
||||||
return expeditiondays[0]
|
|
||||||
res = ExpeditionDay(expedition=self, date=date)
|
|
||||||
res.save()
|
|
||||||
return res
|
|
||||||
|
|
||||||
def day_min(self):
|
|
||||||
res = self.expeditionday_set.all()
|
|
||||||
return res and res[0] or None
|
|
||||||
|
|
||||||
def day_max(self):
|
|
||||||
res = self.expeditionday_set.all()
|
|
||||||
return res and res[len(res) - 1] or None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExpeditionDay(TroggleModel):
|
|
||||||
expedition = models.ForeignKey("Expedition")
|
|
||||||
date = models.DateField()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('date',)
|
|
||||||
|
|
||||||
def GetPersonTrip(self, personexpedition):
|
|
||||||
personexpeditions = self.persontrip_set.filter(expeditionday=self)
|
|
||||||
return personexpeditions and personexpeditions[0] or None
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# single Person, can go on many years
|
|
||||||
#
|
|
||||||
class Person(TroggleModel):
|
|
||||||
first_name = models.CharField(max_length=100)
|
|
||||||
last_name = models.CharField(max_length=100)
|
|
||||||
is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False)
|
|
||||||
mug_shot = models.CharField(max_length=100, blank=True,null=True)
|
|
||||||
blurb = models.TextField(blank=True,null=True)
|
|
||||||
|
|
||||||
#href = models.CharField(max_length=200)
|
|
||||||
orderref = models.CharField(max_length=200) # for alphabetic
|
|
||||||
|
|
||||||
#the below have been removed and made methods. I'm not sure what the b in bisnotable stands for. - AC 16 Feb
|
|
||||||
#notability = models.FloatField() # for listing the top 20 people
|
|
||||||
#bisnotable = models.BooleanField(default=False)
|
|
||||||
user = models.OneToOneField(User, null=True, blank=True)
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name}))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name_plural = "People"
|
|
||||||
ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name')
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
if self.last_name:
|
|
||||||
return "%s %s" % (self.first_name, self.last_name)
|
|
||||||
return self.first_name
|
|
||||||
|
|
||||||
|
|
||||||
def notability(self):
|
|
||||||
notability = Decimal(0)
|
|
||||||
for personexpedition in self.personexpedition_set.all():
|
|
||||||
if not personexpedition.is_guest:
|
|
||||||
notability += Decimal(1) / (2012 - int(personexpedition.expedition.year))
|
|
||||||
return notability
|
|
||||||
|
|
||||||
def bisnotable(self):
|
|
||||||
return self.notability() > Decimal(1)/Decimal(3)
|
|
||||||
|
|
||||||
def surveyedleglength(self):
|
|
||||||
return sum([personexpedition.surveyedleglength() for personexpedition in self.personexpedition_set.all()])
|
|
||||||
|
|
||||||
def first(self):
|
|
||||||
return self.personexpedition_set.order_by('-expedition')[0]
|
|
||||||
def last(self):
|
|
||||||
return self.personexpedition_set.order_by('expedition')[0]
|
|
||||||
|
|
||||||
#def Sethref(self):
|
|
||||||
#if self.last_name:
|
|
||||||
#self.href = self.first_name.lower() + "_" + self.last_name.lower()
|
|
||||||
#self.orderref = self.last_name + " " + self.first_name
|
|
||||||
#else:
|
|
||||||
# self.href = self.first_name.lower()
|
|
||||||
#self.orderref = self.first_name
|
|
||||||
#self.notability = 0.0 # set temporarily
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Person's attenance to one Expo
|
|
||||||
#
|
|
||||||
class PersonExpedition(TroggleModel):
|
|
||||||
expedition = models.ForeignKey(Expedition)
|
|
||||||
person = models.ForeignKey(Person)
|
|
||||||
slugfield = models.SlugField(max_length=50,blank=True,null=True)
|
|
||||||
|
|
||||||
is_guest = models.BooleanField(default=False)
|
|
||||||
COMMITTEE_CHOICES = (
|
|
||||||
('leader','Expo leader'),
|
|
||||||
('medical','Expo medical officer'),
|
|
||||||
('treasurer','Expo treasurer'),
|
|
||||||
('sponsorship','Expo sponsorship coordinator'),
|
|
||||||
('research','Expo research coordinator'),
|
|
||||||
)
|
|
||||||
expo_committee_position = models.CharField(blank=True,null=True,choices=COMMITTEE_CHOICES,max_length=200)
|
|
||||||
nickname = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
|
|
||||||
def GetPersonroles(self):
|
|
||||||
res = [ ]
|
|
||||||
for personrole in self.personrole_set.order_by('survexblock'):
|
|
||||||
if res and res[-1]['survexpath'] == personrole.survexblock.survexpath:
|
|
||||||
res[-1]['roles'] += ", " + str(personrole.role)
|
|
||||||
else:
|
|
||||||
res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath, 'roles':str(personrole.role)})
|
|
||||||
return res
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('-expedition',)
|
|
||||||
#order_with_respect_to = 'expedition'
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "%s: (%s)" % (self.person, self.expedition)
|
|
||||||
|
|
||||||
|
|
||||||
#why is the below a function in personexpedition, rather than in person? - AC 14 Feb 09
|
|
||||||
def name(self):
|
|
||||||
if self.nickname:
|
|
||||||
return "%s (%s) %s" % (self.person.first_name, self.nickname, self.person.last_name)
|
|
||||||
if self.person.last_name:
|
|
||||||
return "%s %s" % (self.person.first_name, self.person.last_name)
|
|
||||||
return self.person.first_name
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('personexpedition',kwargs={'first_name':self.person.first_name,'last_name':self.person.last_name,'year':self.expedition.year}))
|
|
||||||
|
|
||||||
def surveyedleglength(self):
|
|
||||||
survexblocks = [personrole.survexblock for personrole in self.personrole_set.all() ]
|
|
||||||
return sum([survexblock.totalleglength for survexblock in set(survexblocks)])
|
|
||||||
|
|
||||||
# would prefer to return actual person trips so we could link to first and last ones
|
|
||||||
def day_min(self):
|
|
||||||
res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
|
|
||||||
return res["day_min"]
|
|
||||||
|
|
||||||
def day_max(self):
|
|
||||||
res = self.persontrip_set.all().aggregate(day_max=Max("expeditionday__date"))
|
|
||||||
return res["day_max"]
|
|
||||||
|
|
||||||
#
|
|
||||||
# Single parsed entry from Logbook
|
|
||||||
#
|
|
||||||
class LogbookEntry(TroggleModel):
|
|
||||||
date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.
|
|
||||||
expeditionday = models.ForeignKey("ExpeditionDay", null=True)#MJG wants to KILL THIS (redundant information)
|
|
||||||
expedition = models.ForeignKey(Expedition,blank=True,null=True) # yes this is double-
|
|
||||||
#author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip.
|
|
||||||
# Re: the above- so this field should be "typist" or something, not "author". - AC 15 jun 09
|
|
||||||
#MJG wants to KILL THIS, as it is typically redundant with PersonTrip.is_logbook_entry_author, in the rare it was not redundanty and of actually interest it could be added to the text.
|
|
||||||
title = models.CharField(max_length=settings.MAX_LOGBOOK_ENTRY_TITLE_LENGTH)
|
|
||||||
cave_slug = models.SlugField(max_length=50)
|
|
||||||
place = models.CharField(max_length=100,blank=True,null=True,help_text="Only use this if you haven't chosen a cave")
|
|
||||||
text = models.TextField()
|
|
||||||
slug = models.SlugField(max_length=50)
|
|
||||||
filename = models.CharField(max_length=200,null=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name_plural = "Logbook Entries"
|
|
||||||
# several PersonTrips point in to this object
|
|
||||||
ordering = ('-date',)
|
|
||||||
|
|
||||||
def __getattribute__(self, item):
|
|
||||||
if item == "cave": #Allow a logbookentries cave to be directly accessed despite not having a proper foreignkey
|
|
||||||
return CaveSlug.objects.get(slug = self.cave_slug).cave
|
|
||||||
return super(LogbookEntry, self).__getattribute__(item)
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
if "cave" in kwargs.keys():
|
|
||||||
if kwargs["cave"] is not None:
|
|
||||||
kwargs["cave_slug"] = CaveSlug.objects.get(cave=kwargs["cave"], primary=True).slug
|
|
||||||
kwargs.pop("cave")
|
|
||||||
return super(LogbookEntry, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
def isLogbookEntry(self): # Function used in templates
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('logbookentry',kwargs={'date':self.date,'slug':self.slug}))
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "%s: (%s)" % (self.date, self.title)
|
|
||||||
|
|
||||||
def get_next_by_id(self):
|
|
||||||
LogbookEntry.objects.get(id=self.id+1)
|
|
||||||
|
|
||||||
def get_previous_by_id(self):
|
|
||||||
LogbookEntry.objects.get(id=self.id-1)
|
|
||||||
|
|
||||||
def new_QM_number(self):
|
|
||||||
"""Returns """
|
|
||||||
if self.cave:
|
|
||||||
nextQMnumber=self.cave.new_QM_number(self.date.year)
|
|
||||||
else:
|
|
||||||
return none
|
|
||||||
return nextQMnumber
|
|
||||||
|
|
||||||
def new_QM_found_link(self):
|
|
||||||
"""Produces a link to a new QM with the next number filled in and this LogbookEntry set as 'found by' """
|
|
||||||
return settings.URL_ROOT + r'/admin/core/qm/add/?' + r'found_by=' + str(self.pk) +'&number=' + str(self.new_QM_number())
|
|
||||||
|
|
||||||
def DayIndex(self):
|
|
||||||
return list(self.expeditionday.logbookentry_set.all()).index(self)
|
|
||||||
|
|
||||||
#
|
|
||||||
# Single Person going on a trip, which may or may not be written up (accounts for different T/U for people in same logbook entry)
|
|
||||||
#
|
|
||||||
class PersonTrip(TroggleModel):
|
|
||||||
personexpedition = models.ForeignKey("PersonExpedition",null=True)
|
|
||||||
|
|
||||||
#expeditionday = models.ForeignKey("ExpeditionDay")#MJG wants to KILL THIS (redundant information)
|
|
||||||
#date = models.DateField() #MJG wants to KILL THIS (redundant information)
|
|
||||||
time_underground = models.FloatField(help_text="In decimal hours")
|
|
||||||
logbook_entry = models.ForeignKey(LogbookEntry)
|
|
||||||
is_logbook_entry_author = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
|
|
||||||
# sequencing by person (difficult to solve locally)
|
|
||||||
#persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)#MJG wants to KILL THIS (and use funstion persontrip_next_auto)
|
|
||||||
#persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)#MJG wants to KILL THIS(and use funstion persontrip_prev_auto)
|
|
||||||
|
|
||||||
def persontrip_next(self):
|
|
||||||
futurePTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__gt = self.logbook_entry.date).order_by('logbook_entry__date').all()
|
|
||||||
if len(futurePTs) > 0:
|
|
||||||
return futurePTs[0]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def persontrip_prev(self):
|
|
||||||
pastPTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__lt = self.logbook_entry.date).order_by('-logbook_entry__date').all()
|
|
||||||
if len(pastPTs) > 0:
|
|
||||||
return pastPTs[0]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def place(self):
|
|
||||||
return self.logbook_entry.cave and self.logbook_entry.cave or self.logbook_entry.place
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "%s (%s)" % (self.personexpedition, self.logbook_entry.date)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##########################################
|
|
||||||
# move following classes into models_cave
|
|
||||||
##########################################
|
|
||||||
|
|
||||||
class Area(TroggleModel):
|
|
||||||
short_name = models.CharField(max_length=100)
|
|
||||||
name = models.CharField(max_length=200, blank=True, null=True)
|
|
||||||
description = models.TextField(blank=True,null=True)
|
|
||||||
parent = models.ForeignKey('Area', blank=True, null=True)
|
|
||||||
def __unicode__(self):
|
|
||||||
if self.parent:
|
|
||||||
return unicode(self.parent) + u" - " + unicode(self.short_name)
|
|
||||||
else:
|
|
||||||
return unicode(self.short_name)
|
|
||||||
def kat_area(self):
|
|
||||||
if self.short_name in ["1623", "1626"]:
|
|
||||||
return self.short_name
|
|
||||||
elif self.parent:
|
|
||||||
return self.parent.kat_area()
|
|
||||||
|
|
||||||
class CaveAndEntrance(models.Model):
|
|
||||||
cave = models.ForeignKey('Cave')
|
|
||||||
entrance = models.ForeignKey('Entrance')
|
|
||||||
entrance_letter = models.CharField(max_length=20,blank=True,null=True)
|
|
||||||
def __unicode__(self):
|
|
||||||
return unicode(self.cave) + unicode(self.entrance_letter)
|
|
||||||
|
|
||||||
class CaveSlug(models.Model):
|
|
||||||
cave = models.ForeignKey('Cave')
|
|
||||||
slug = models.SlugField(max_length=50, unique = True)
|
|
||||||
primary = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
|
|
||||||
class Cave(TroggleModel):
|
|
||||||
# too much here perhaps,
|
|
||||||
official_name = models.CharField(max_length=160)
|
|
||||||
area = models.ManyToManyField(Area, blank=True, null=True)
|
|
||||||
kataster_code = models.CharField(max_length=20,blank=True,null=True)
|
|
||||||
kataster_number = models.CharField(max_length=10,blank=True, null=True)
|
|
||||||
unofficial_number = models.CharField(max_length=60,blank=True, null=True)
|
|
||||||
entrances = models.ManyToManyField('Entrance', through='CaveAndEntrance')
|
|
||||||
explorers = models.TextField(blank=True,null=True)
|
|
||||||
underground_description = models.TextField(blank=True,null=True)
|
|
||||||
equipment = models.TextField(blank=True,null=True)
|
|
||||||
references = models.TextField(blank=True,null=True)
|
|
||||||
survey = models.TextField(blank=True,null=True)
|
|
||||||
kataster_status = models.TextField(blank=True,null=True)
|
|
||||||
underground_centre_line = models.TextField(blank=True,null=True)
|
|
||||||
notes = models.TextField(blank=True,null=True)
|
|
||||||
length = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
depth = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
extent = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
survex_file = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
description_file = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
url = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
filename = models.CharField(max_length=200)
|
|
||||||
|
|
||||||
|
|
||||||
#class Meta:
|
|
||||||
# unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
|
|
||||||
# FIXME Kataster Areas and CUCC defined sub areas need seperating
|
|
||||||
|
|
||||||
|
|
||||||
#href = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('kataster_code', 'unofficial_number')
|
|
||||||
|
|
||||||
def hassurvey(self):
|
|
||||||
if not self.underground_centre_line:
|
|
||||||
return "No"
|
|
||||||
if (self.survey.find("<img") > -1 or self.survey.find("<a") > -1 or self.survey.find("<IMG") > -1 or self.survey.find("<A") > -1):
|
|
||||||
return "Yes"
|
|
||||||
return "Missing"
|
|
||||||
|
|
||||||
def hassurveydata(self):
|
|
||||||
if not self.underground_centre_line:
|
|
||||||
return "No"
|
|
||||||
if self.survex_file:
|
|
||||||
return "Yes"
|
|
||||||
return "Missing"
|
|
||||||
|
|
||||||
def slug(self):
|
|
||||||
primarySlugs = self.caveslug_set.filter(primary = True)
|
|
||||||
if primarySlugs:
|
|
||||||
return primarySlugs[0].slug
|
|
||||||
else:
|
|
||||||
slugs = self.caveslug_set.filter()
|
|
||||||
if slugs:
|
|
||||||
return slugs[0].slug
|
|
||||||
|
|
||||||
def ours(self):
|
|
||||||
return bool(re.search(r'CUCC', self.explorers))
|
|
||||||
|
|
||||||
def reference(self):
|
|
||||||
if self.kataster_number:
|
|
||||||
return "%s-%s" % (self.kat_area(), self.kataster_number)
|
|
||||||
else:
|
|
||||||
return "%s-%s" % (self.kat_area(), self.unofficial_number)
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
if self.kataster_number:
|
|
||||||
href = self.kataster_number
|
|
||||||
elif self.unofficial_number:
|
|
||||||
href = self.unofficial_number
|
|
||||||
else:
|
|
||||||
href = official_name.lower()
|
|
||||||
#return settings.URL_ROOT + '/cave/' + href + '/'
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('cave',kwargs={'cave_id':href,}))
|
|
||||||
|
|
||||||
def __unicode__(self, sep = u": "):
|
|
||||||
return unicode(self.slug())
|
|
||||||
|
|
||||||
def get_QMs(self):
|
|
||||||
return QM.objects.filter(found_by__cave_slug=self.caveslug_set.all())
|
|
||||||
|
|
||||||
def new_QM_number(self, year=datetime.date.today().year):
|
|
||||||
"""Given a cave and the current year, returns the next QM number."""
|
|
||||||
try:
|
|
||||||
res=QM.objects.filter(found_by__date__year=year, found_by__cave=self).order_by('-number')[0]
|
|
||||||
except IndexError:
|
|
||||||
return 1
|
|
||||||
return res.number+1
|
|
||||||
|
|
||||||
def kat_area(self):
|
|
||||||
for a in self.area.all():
|
|
||||||
if a.kat_area():
|
|
||||||
return a.kat_area()
|
|
||||||
|
|
||||||
def entrances(self):
|
|
||||||
return CaveAndEntrance.objects.filter(cave=self)
|
|
||||||
|
|
||||||
def singleentrance(self):
|
|
||||||
return len(CaveAndEntrance.objects.filter(cave=self)) == 1
|
|
||||||
|
|
||||||
def entrancelist(self):
|
|
||||||
rs = []
|
|
||||||
res = ""
|
|
||||||
for e in CaveAndEntrance.objects.filter(cave=self):
|
|
||||||
rs.append(e.entrance_letter)
|
|
||||||
rs.sort()
|
|
||||||
prevR = None
|
|
||||||
n = 0
|
|
||||||
for r in rs:
|
|
||||||
if prevR:
|
|
||||||
if chr(ord(prevR) + 1 ) == r:
|
|
||||||
prevR = r
|
|
||||||
n += 1
|
|
||||||
else:
|
|
||||||
if n == 0:
|
|
||||||
res += ", " + prevR
|
|
||||||
else:
|
|
||||||
res += "–" + prevR
|
|
||||||
else:
|
|
||||||
prevR = r
|
|
||||||
n = 0
|
|
||||||
res += r
|
|
||||||
if n == 0:
|
|
||||||
res += ", " + prevR
|
|
||||||
else:
|
|
||||||
res += "–" + prevR
|
|
||||||
return res
|
|
||||||
|
|
||||||
def writeDataFile(self):
|
|
||||||
try:
|
|
||||||
f = open(os.path.join(settings.CAVEDESCRIPTIONS, self.filename), "w")
|
|
||||||
except:
|
|
||||||
subprocess.call(settings.FIX_PERMISSIONS)
|
|
||||||
f = open(os.path.join(settings.CAVEDESCRIPTIONS, self.filename), "w")
|
|
||||||
t = loader.get_template('dataformat/cave.xml')
|
|
||||||
c = Context({'cave': self})
|
|
||||||
u = t.render(c)
|
|
||||||
u8 = u.encode("utf-8")
|
|
||||||
f.write(u8)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def getArea(self):
|
|
||||||
areas = self.area.all()
|
|
||||||
lowestareas = list(areas)
|
|
||||||
for area in areas:
|
|
||||||
if area.parent in areas:
|
|
||||||
try:
|
|
||||||
lowestareas.remove(area.parent)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return lowestareas[0]
|
|
||||||
|
|
||||||
def getCaveByReference(reference):
|
|
||||||
areaname, code = reference.split("-", 1)
|
|
||||||
print(areaname, code)
|
|
||||||
area = Area.objects.get(short_name = areaname)
|
|
||||||
print(area)
|
|
||||||
foundCaves = list(Cave.objects.filter(area = area, kataster_number = code).all()) + list(Cave.objects.filter(area = area, unofficial_number = code).all())
|
|
||||||
print(list(foundCaves))
|
|
||||||
assert len(foundCaves) == 1
|
|
||||||
return foundCaves[0]
|
|
||||||
|
|
||||||
class OtherCaveName(TroggleModel):
|
|
||||||
name = models.CharField(max_length=160)
|
|
||||||
cave = models.ForeignKey(Cave)
|
|
||||||
def __unicode__(self):
|
|
||||||
return unicode(self.name)
|
|
||||||
|
|
||||||
class EntranceSlug(models.Model):
|
|
||||||
entrance = models.ForeignKey('Entrance')
|
|
||||||
slug = models.SlugField(max_length=50, unique = True)
|
|
||||||
primary = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
class Entrance(TroggleModel):
|
|
||||||
name = models.CharField(max_length=100, blank=True,null=True)
|
|
||||||
entrance_description = models.TextField(blank=True,null=True)
|
|
||||||
explorers = models.TextField(blank=True,null=True)
|
|
||||||
map_description = models.TextField(blank=True,null=True)
|
|
||||||
location_description = models.TextField(blank=True,null=True)
|
|
||||||
approach = models.TextField(blank=True,null=True)
|
|
||||||
underground_description = models.TextField(blank=True,null=True)
|
|
||||||
photo = models.TextField(blank=True,null=True)
|
|
||||||
MARKING_CHOICES = (
|
|
||||||
('P', 'Paint'),
|
|
||||||
('P?', 'Paint (?)'),
|
|
||||||
('T', 'Tag'),
|
|
||||||
('T?', 'Tag (?)'),
|
|
||||||
('R', 'Needs Retag'),
|
|
||||||
('S', 'Spit'),
|
|
||||||
('S?', 'Spit (?)'),
|
|
||||||
('U', 'Unmarked'),
|
|
||||||
('?', 'Unknown'))
|
|
||||||
marking = models.CharField(max_length=2, choices=MARKING_CHOICES)
|
|
||||||
marking_comment = models.TextField(blank=True,null=True)
|
|
||||||
FINDABLE_CHOICES = (
|
|
||||||
('?', 'To be confirmed ...'),
|
|
||||||
('S', 'Coordinates'),
|
|
||||||
('L', 'Lost'),
|
|
||||||
('R', 'Refindable'))
|
|
||||||
findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True)
|
|
||||||
findability_description = models.TextField(blank=True,null=True)
|
|
||||||
alt = models.TextField(blank=True, null=True)
|
|
||||||
northing = models.TextField(blank=True, null=True)
|
|
||||||
easting = models.TextField(blank=True, null=True)
|
|
||||||
tag_station = models.TextField(blank=True, null=True)
|
|
||||||
exact_station = models.TextField(blank=True, null=True)
|
|
||||||
other_station = models.TextField(blank=True, null=True)
|
|
||||||
other_description = models.TextField(blank=True,null=True)
|
|
||||||
bearings = models.TextField(blank=True,null=True)
|
|
||||||
url = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
filename = models.CharField(max_length=200)
|
|
||||||
cached_primary_slug = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return unicode(self.slug())
|
|
||||||
|
|
||||||
def exact_location(self):
|
|
||||||
return SurvexStation.objects.lookup(self.exact_station)
|
|
||||||
def other_location(self):
|
|
||||||
return SurvexStation.objects.lookup(self.other_station)
|
|
||||||
|
|
||||||
|
|
||||||
def find_location(self):
|
|
||||||
r = {'': 'To be entered ',
|
|
||||||
'?': 'To be confirmed:',
|
|
||||||
'S': '',
|
|
||||||
'L': 'Lost:',
|
|
||||||
'R': 'Refindable:'}[self.findability]
|
|
||||||
if self.tag_station:
|
|
||||||
try:
|
|
||||||
s = SurvexStation.objects.lookup(self.tag_station)
|
|
||||||
return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z)
|
|
||||||
except:
|
|
||||||
return r + "%s Tag Station not in dataset" % self.tag_station
|
|
||||||
if self.exact_station:
|
|
||||||
try:
|
|
||||||
s = SurvexStation.objects.lookup(self.exact_station)
|
|
||||||
return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z)
|
|
||||||
except:
|
|
||||||
return r + "%s Exact Station not in dataset" % self.tag_station
|
|
||||||
if self.other_station:
|
|
||||||
try:
|
|
||||||
s = SurvexStation.objects.lookup(self.other_station)
|
|
||||||
return r + "%0.0fE %0.0fN %0.0fAlt %s" % (s.x, s.y, s.z, self.other_description)
|
|
||||||
except:
|
|
||||||
return r + "%s Other Station not in dataset" % self.tag_station
|
|
||||||
if self.FINDABLE_CHOICES == "S":
|
|
||||||
r += "ERROR, Entrance has been surveyed but has no survex point"
|
|
||||||
if self.bearings:
|
|
||||||
return r + self.bearings
|
|
||||||
return r
|
|
||||||
|
|
||||||
def best_station(self):
|
|
||||||
if self.tag_station:
|
|
||||||
return self.tag_station
|
|
||||||
if self.exact_station:
|
|
||||||
return self.exact_station
|
|
||||||
if self.other_station:
|
|
||||||
return self.other_station
|
|
||||||
|
|
||||||
def has_photo(self):
|
|
||||||
if self.photo:
|
|
||||||
if (self.photo.find("<img") > -1 or self.photo.find("<a") > -1 or self.photo.find("<IMG") > -1 or self.photo.find("<A") > -1):
|
|
||||||
return "Yes"
|
|
||||||
else:
|
|
||||||
return "Missing"
|
|
||||||
else:
|
|
||||||
return "No"
|
|
||||||
|
|
||||||
def marking_val(self):
|
|
||||||
for m in self.MARKING_CHOICES:
|
|
||||||
if m[0] == self.marking:
|
|
||||||
return m[1]
|
|
||||||
def findability_val(self):
|
|
||||||
for f in self.FINDABLE_CHOICES:
|
|
||||||
if f[0] == self.findability:
|
|
||||||
return f[1]
|
|
||||||
|
|
||||||
def tag(self):
|
|
||||||
return SurvexStation.objects.lookup(self.tag_station)
|
|
||||||
|
|
||||||
def needs_surface_work(self):
|
|
||||||
return self.findability != "S" or not self.has_photo or self.marking != "T"
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
|
|
||||||
ancestor_titles='/'.join([subcave.title for subcave in self.get_ancestors()])
|
|
||||||
if ancestor_titles:
|
|
||||||
res = '/'.join((self.get_root().cave.get_absolute_url(), ancestor_titles, self.title))
|
|
||||||
|
|
||||||
else:
|
|
||||||
res = '/'.join((self.get_root().cave.get_absolute_url(), self.title))
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
def slug(self):
|
|
||||||
if not self.cached_primary_slug:
|
|
||||||
primarySlugs = self.entranceslug_set.filter(primary = True)
|
|
||||||
if primarySlugs:
|
|
||||||
self.cached_primary_slug = primarySlugs[0].slug
|
|
||||||
self.save()
|
|
||||||
else:
|
|
||||||
slugs = self.entranceslug_set.filter()
|
|
||||||
if slugs:
|
|
||||||
self.cached_primary_slug = slugs[0].slug
|
|
||||||
self.save()
|
|
||||||
return self.cached_primary_slug
|
|
||||||
|
|
||||||
def writeDataFile(self):
|
|
||||||
try:
|
|
||||||
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")
|
|
||||||
except:
|
|
||||||
subprocess.call(settings.FIX_PERMISSIONS)
|
|
||||||
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")
|
|
||||||
t = loader.get_template('dataformat/entrance.xml')
|
|
||||||
c = Context({'entrance': self})
|
|
||||||
u = t.render(c)
|
|
||||||
u8 = u.encode("utf-8")
|
|
||||||
f.write(u8)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
class CaveDescription(TroggleModel):
|
|
||||||
short_name = models.CharField(max_length=50, unique = True)
|
|
||||||
long_name = models.CharField(max_length=200, blank=True, null=True)
|
|
||||||
description = models.TextField(blank=True,null=True)
|
|
||||||
linked_subcaves = models.ManyToManyField("NewSubCave", blank=True,null=True)
|
|
||||||
linked_entrances = models.ManyToManyField("Entrance", blank=True,null=True)
|
|
||||||
linked_qms = models.ManyToManyField("QM", blank=True,null=True)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
if self.long_name:
|
|
||||||
return unicode(self.long_name)
|
|
||||||
else:
|
|
||||||
return unicode(self.short_name)
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('cavedescription', args=(self.short_name,)))
|
|
||||||
|
|
||||||
def save(self):
|
|
||||||
"""
|
|
||||||
Overridden save method which stores wikilinks in text as links in database.
|
|
||||||
"""
|
|
||||||
super(CaveDescription, self).save()
|
|
||||||
qm_list=get_related_by_wikilinks(self.description)
|
|
||||||
for qm in qm_list:
|
|
||||||
self.linked_qms.add(qm)
|
|
||||||
super(CaveDescription, self).save()
|
|
||||||
|
|
||||||
class NewSubCave(TroggleModel):
|
|
||||||
name = models.CharField(max_length=200, unique = True)
|
|
||||||
def __unicode__(self):
|
|
||||||
return unicode(self.name)
|
|
||||||
|
|
||||||
class QM(TroggleModel):
|
|
||||||
#based on qm.csv in trunk/expoweb/1623/204 which has the fields:
|
|
||||||
#"Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment"
|
|
||||||
found_by = models.ForeignKey(LogbookEntry, related_name='QMs_found',blank=True, null=True )
|
|
||||||
ticked_off_by = models.ForeignKey(LogbookEntry, related_name='QMs_ticked_off',null=True,blank=True)
|
|
||||||
#cave = models.ForeignKey(Cave)
|
|
||||||
#expedition = models.ForeignKey(Expedition)
|
|
||||||
|
|
||||||
number = models.IntegerField(help_text="this is the sequential number in the year", )
|
|
||||||
GRADE_CHOICES=(
|
|
||||||
('A', 'A: Large obvious lead'),
|
|
||||||
('B', 'B: Average lead'),
|
|
||||||
('C', 'C: Tight unpromising lead'),
|
|
||||||
('D', 'D: Dig'),
|
|
||||||
('X', 'X: Unclimbable aven')
|
|
||||||
)
|
|
||||||
grade = models.CharField(max_length=1, choices=GRADE_CHOICES)
|
|
||||||
location_description = models.TextField(blank=True)
|
|
||||||
#should be a foreignkey to surveystation
|
|
||||||
nearest_station_description = models.CharField(max_length=400,null=True,blank=True)
|
|
||||||
nearest_station = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
area = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
completion_description = models.TextField(blank=True,null=True)
|
|
||||||
comment=models.TextField(blank=True,null=True)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return u"%s %s" % (self.code(), self.grade)
|
|
||||||
|
|
||||||
def code(self):
|
|
||||||
return u"%s-%s-%s" % (unicode(self.found_by.cave)[6:], self.found_by.date.year, self.number)
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
#return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('qm',kwargs={'cave_id':self.found_by.cave.kataster_number,'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}))
|
|
||||||
|
|
||||||
def get_next_by_id(self):
|
|
||||||
return QM.objects.get(id=self.id+1)
|
|
||||||
|
|
||||||
def get_previous_by_id(self):
|
|
||||||
return QM.objects.get(id=self.id-1)
|
|
||||||
|
|
||||||
def wiki_link(self):
|
|
||||||
return u"%s%s%s" % ('[[QM:',self.code(),']]')
|
|
||||||
|
|
||||||
photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL)
|
|
||||||
class DPhoto(TroggleImageModel):
|
|
||||||
caption = models.CharField(max_length=1000,blank=True,null=True)
|
|
||||||
contains_logbookentry = models.ForeignKey(LogbookEntry,blank=True,null=True)
|
|
||||||
contains_person = models.ManyToManyField(Person,blank=True,null=True)
|
|
||||||
file = models.ImageField(storage=photoFileStorage, upload_to='.',)
|
|
||||||
is_mugshot = models.BooleanField(default=False)
|
|
||||||
contains_cave = models.ForeignKey(Cave,blank=True,null=True)
|
|
||||||
contains_entrance = models.ForeignKey(Entrance, related_name="photo_file",blank=True,null=True)
|
|
||||||
#nearest_survey_point = models.ForeignKey(SurveyStation,blank=True,null=True)
|
|
||||||
nearest_QM = models.ForeignKey(QM,blank=True,null=True)
|
|
||||||
lon_utm = models.FloatField(blank=True,null=True)
|
|
||||||
lat_utm = models.FloatField(blank=True,null=True)
|
|
||||||
|
|
||||||
class IKOptions:
|
|
||||||
spec_module = 'core.imagekit_specs'
|
|
||||||
cache_dir = 'thumbs'
|
|
||||||
image_field = 'file'
|
|
||||||
|
|
||||||
#content_type = models.ForeignKey(ContentType)
|
|
||||||
#object_id = models.PositiveIntegerField()
|
|
||||||
#location = generic.GenericForeignKey('content_type', 'object_id')
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.caption
|
|
||||||
|
|
||||||
scansFileStorage = FileSystemStorage(location=settings.SURVEY_SCANS, base_url=settings.SURVEYS_URL)
|
|
||||||
def get_scan_path(instance, filename):
|
|
||||||
year=instance.survey.expedition.year
|
|
||||||
#print("WN: ", type(instance.survey.wallet_number), instance.survey.wallet_number, instance.survey.wallet_letter)
|
|
||||||
number=str(instance.survey.wallet_number)
|
|
||||||
if str(instance.survey.wallet_letter) != "None":
|
|
||||||
number=str(instance.survey.wallet_letter) + number #two strings formatting because convention is 2009#01 or 2009#X01
|
|
||||||
return os.path.join('./',year,year+r'#'+number,str(instance.contents)+str(instance.number_in_wallet)+r'.jpg')
|
|
||||||
|
|
||||||
class ScannedImage(TroggleImageModel):
|
|
||||||
file = models.ImageField(storage=scansFileStorage, upload_to=get_scan_path)
|
|
||||||
scanned_by = models.ForeignKey(Person,blank=True, null=True)
|
|
||||||
scanned_on = models.DateField(null=True)
|
|
||||||
survey = models.ForeignKey('Survey')
|
|
||||||
contents = models.CharField(max_length=20,choices=(('notes','notes'),('plan','plan_sketch'),('elevation','elevation_sketch')))
|
|
||||||
number_in_wallet = models.IntegerField(null=True)
|
|
||||||
lon_utm = models.FloatField(blank=True,null=True)
|
|
||||||
lat_utm = models.FloatField(blank=True,null=True)
|
|
||||||
|
|
||||||
class IKOptions:
|
|
||||||
spec_module = 'core.imagekit_specs'
|
|
||||||
cache_dir = 'thumbs'
|
|
||||||
image_field = 'file'
|
|
||||||
#content_type = models.ForeignKey(ContentType)
|
|
||||||
#object_id = models.PositiveIntegerField()
|
|
||||||
#location = generic.GenericForeignKey('content_type', 'object_id')
|
|
||||||
|
|
||||||
#This is an ugly hack to deal with the #s in our survey scan paths. The correct thing is to write a custom file storage backend which calls urlencode on the name for making file.url but not file.path.
|
|
||||||
def correctURL(self):
|
|
||||||
return string.replace(self.file.url,r'#',r'%23')
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return get_scan_path(self,'')
|
|
||||||
|
|
||||||
class Survey(TroggleModel):
|
|
||||||
expedition = models.ForeignKey('Expedition') #REDUNDANT (logbook_entry)
|
|
||||||
wallet_number = models.IntegerField(blank=True,null=True)
|
|
||||||
wallet_letter = models.CharField(max_length=1,blank=True,null=True)
|
|
||||||
comments = models.TextField(blank=True,null=True)
|
|
||||||
location = models.CharField(max_length=400,blank=True,null=True) #REDUNDANT
|
|
||||||
subcave = models.ForeignKey('NewSubCave', blank=True, null=True)
|
|
||||||
#notes_scan = models.ForeignKey('ScannedImage',related_name='notes_scan',blank=True, null=True) #Replaced by contents field of ScannedImage model
|
|
||||||
survex_block = models.OneToOneField('SurvexBlock',blank=True, null=True)
|
|
||||||
logbook_entry = models.ForeignKey('LogbookEntry')
|
|
||||||
centreline_printed_on = models.DateField(blank=True, null=True)
|
|
||||||
centreline_printed_by = models.ForeignKey('Person',related_name='centreline_printed_by',blank=True,null=True)
|
|
||||||
#sketch_scan = models.ForeignKey(ScannedImage,blank=True, null=True) #Replaced by contents field of ScannedImage model
|
|
||||||
tunnel_file = models.FileField(upload_to='surveyXMLfiles',blank=True, null=True)
|
|
||||||
tunnel_main_sketch = models.ForeignKey('Survey',blank=True,null=True)
|
|
||||||
integrated_into_main_sketch_on = models.DateField(blank=True,null=True)
|
|
||||||
integrated_into_main_sketch_by = models.ForeignKey('Person' ,related_name='integrated_into_main_sketch_by', blank=True,null=True)
|
|
||||||
rendered_image = models.ImageField(upload_to='renderedSurveys',blank=True,null=True)
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.expedition.year+"#"+"%02d" % int(self.wallet_number)
|
|
||||||
|
|
||||||
def notes(self):
|
|
||||||
return self.scannedimage_set.filter(contents='notes')
|
|
||||||
|
|
||||||
def plans(self):
|
|
||||||
return self.scannedimage_set.filter(contents='plan')
|
|
||||||
|
|
||||||
def elevations(self):
|
|
||||||
return self.scannedimage_set.filter(contents='elevation')
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
import troggle.core.methods_millenial as methods_millenial
|
|
||||||
|
|
||||||
#
|
|
||||||
# This file was created in 2019
|
|
||||||
# It's a result of massive frustration with cluttered database of troggle
|
|
||||||
# Maximal clarity of code was primary goal (previous code had very little comments)
|
|
||||||
# Maximal speed of database rebuild was secondary goal
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# The following file will tell you what fields and methods are avaliable inside this database
|
|
||||||
# be carefull you might miss some! ManyToMany fields can be used from the far end as well
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Naming conventions:
|
|
||||||
# (Upper/lower convention)
|
|
||||||
# Class names are writen Udddd_ddd_dddM - they finish with M for backwards compatibility
|
|
||||||
# Fields/methods are written lower_lower_lower
|
|
||||||
#
|
|
||||||
|
|
||||||
class PersonM(models.Model): #instance of this class corresponds to one physical peson
|
|
||||||
name = models.CharField(max_length=100) #just name, talk to wookey if you diagree
|
|
||||||
surveys_made = models.ManyToManyField('SurveyM', related_name='people_surveyed') #links to survey objects that this person made (made=:survex says so)
|
|
||||||
expos_attended = models.ManyToManyField('ExpeditionM', related_name='people_attended') #expos attended by this person (attended=:folk.csv says so)
|
|
||||||
logbook_entries_written = models.ManyToManyField('Logbook_entryM', related_name='people_wrote') #links to logbook chuncks created by a person
|
|
||||||
|
|
||||||
class CaveM(models.Model): #instance of this class corresponds to one 'thing' that people call cave
|
|
||||||
entrance = models.CharField(max_length=100) #UTM string describing ONE(!) entrance. Purpose = findability
|
|
||||||
title = models.TextField() #title given to the topmost survey in survex, numeric name otherwise c.f. name (e.g. 'Fishface')
|
|
||||||
name = models.TextField() #name given to the topmost survey in survex (e.g. '2017-cucc-28')
|
|
||||||
surveys = models.ManyToManyField('SurveyM', related_name='cave_parent') #links to surveys objects that this cave contains
|
|
||||||
survex_file = models.TextField() #gives path to top level survex file
|
|
||||||
total_length = models.FloatField() #holds total length of this cave (as given by cavern)
|
|
||||||
total_depth = models.FloatField() #holds total depth of this cave (as given by cavern)
|
|
||||||
description = models.TextField() #holds link to description
|
|
||||||
date = models.TextField() #holds date of last visit
|
|
||||||
def top_camp_distance(self): #returns distance of this cave from topcamp
|
|
||||||
return methods_millenial.top_camp_distance(self.entrance)
|
|
||||||
def top_camp_bearing(self): #returns bearing to this cave from topcamp in format 235.5 (float north-based azimuth)
|
|
||||||
return methods_millenial.top_camp_bearing(self.entrance)
|
|
||||||
def top_camp_bearing_letter(self): #returns bearing to this cave from topcamp in format e.g. 'NE'
|
|
||||||
return methods_millenial.top_camp_bearing_letter(self.entrance)
|
|
||||||
def lat_lon_entrance(self): #lat_lon entrance location
|
|
||||||
return methods_millenial.lat_lon_entrance(self.entrance)
|
|
||||||
|
|
||||||
|
|
||||||
class Cave_descriptionM(models.Model): #instance of this class corresponds to each of the .html files in descriptions
|
|
||||||
#each of those holds one XML field
|
|
||||||
slug = models.TextField()
|
|
||||||
explorers = models.TextField()
|
|
||||||
underground_description = models.TextField()
|
|
||||||
equipment = models.TextField()
|
|
||||||
references = models.TextField()
|
|
||||||
survey = models.TextField()
|
|
||||||
kataster_status = models.TextField()
|
|
||||||
underground_centre_line = models.TextField()
|
|
||||||
survex_file = models.TextField() #as given in .html file
|
|
||||||
notes = models.TextField()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExpeditionM(models.Model): #instance of this class corresponds to one expo (usually one year)
|
|
||||||
date = models.CharField(max_length=100) #date in format YYYY.MM.DD-YYYY.MM.DD
|
|
||||||
|
|
||||||
|
|
||||||
class SurveyM(models.Model): #instance of this class corresponds to one .svx file - one trip
|
|
||||||
date = models.CharField(max_length=100) #date of the trip in format YYYY.MM.DD (dated:=date given by .svx file)
|
|
||||||
maxdepth = models.FloatField() #represents max depth of a node in this survey
|
|
||||||
|
|
||||||
class Logbook_entryM(models.Model): #instance of this class corresponds to one bit of logbook (c.f. expo.survex.com/years/2015/logbook.html or simil)
|
|
||||||
date = models.CharField(max_length=100) #date as typed into logbook
|
|
||||||
contents = models.TextField() #contents of the logbook chunk
|
|
||||||
|
|
||||||
class Parser_messageM(models.Model): #instance of this class contains one error or warining message produce by any of the parsers
|
|
||||||
parsername = models.CharField(max_length = 20) #name of parser
|
|
||||||
content = models.TextField() #content of message
|
|
||||||
message_type = models.CharField(max_length = 10) # [Error,Info] or similar
|
|
||||||
|
|
||||||
@@ -1,862 +0,0 @@
|
|||||||
import urllib, urlparse, string, os, datetime, logging, re
|
|
||||||
import subprocess
|
|
||||||
from django.forms import ModelForm
|
|
||||||
from django.db import models
|
|
||||||
from django.contrib import admin
|
|
||||||
from django.core.files.storage import FileSystemStorage
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
from django.db.models import Min, Max
|
|
||||||
from django.conf import settings
|
|
||||||
from decimal import Decimal, getcontext
|
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
from imagekit.models import ImageModel
|
|
||||||
from django.template import Context, loader
|
|
||||||
import settings
|
|
||||||
getcontext().prec=2 #use 2 significant figures for decimal calculations
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_related_by_wikilinks(wiki_text):
|
|
||||||
found=re.findall(settings.QM_PATTERN,wiki_text)
|
|
||||||
res=[]
|
|
||||||
for wikilink in found:
|
|
||||||
qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
|
|
||||||
try:
|
|
||||||
cave_slugs = CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
|
|
||||||
qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
|
|
||||||
found_by__date__year = qmdict['year'],
|
|
||||||
number = qmdict['number'])
|
|
||||||
res.append(qm)
|
|
||||||
except QM.DoesNotExist:
|
|
||||||
print('fail on '+str(wikilink))
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
try:
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
|
||||||
filename=settings.LOGFILE,
|
|
||||||
filemode='w')
|
|
||||||
except:
|
|
||||||
subprocess.call(settings.FIX_PERMISSIONS)
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
|
||||||
filename=settings.LOGFILE,
|
|
||||||
filemode='w')
|
|
||||||
|
|
||||||
#This class is for adding fields and methods which all of our models will have.
|
|
||||||
class TroggleModel(models.Model):
|
|
||||||
new_since_parsing = models.BooleanField(default=False, editable=False)
|
|
||||||
non_public = models.BooleanField(default=False)
|
|
||||||
def object_name(self):
|
|
||||||
return self._meta.object_name
|
|
||||||
|
|
||||||
def get_admin_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
class TroggleImageModel(ImageModel):
|
|
||||||
new_since_parsing = models.BooleanField(default=False, editable=False)
|
|
||||||
|
|
||||||
def object_name(self):
|
|
||||||
return self._meta.object_name
|
|
||||||
|
|
||||||
def get_admin_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk))
|
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
#
|
|
||||||
# single Expedition, usually seen by year
|
|
||||||
#
|
|
||||||
class Expedition(TroggleModel):
|
|
||||||
year = models.CharField(max_length=20, unique=True)
|
|
||||||
name = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.year
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('-year',)
|
|
||||||
get_latest_by = 'year'
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
|
|
||||||
|
|
||||||
# construction function. should be moved out
|
|
||||||
def get_expedition_day(self, date):
|
|
||||||
expeditiondays = self.expeditionday_set.filter(date=date)
|
|
||||||
if expeditiondays:
|
|
||||||
assert len(expeditiondays) == 1
|
|
||||||
return expeditiondays[0]
|
|
||||||
res = ExpeditionDay(expedition=self, date=date)
|
|
||||||
res.save()
|
|
||||||
return res
|
|
||||||
|
|
||||||
def day_min(self):
|
|
||||||
res = self.expeditionday_set.all()
|
|
||||||
return res and res[0] or None
|
|
||||||
|
|
||||||
def day_max(self):
|
|
||||||
res = self.expeditionday_set.all()
|
|
||||||
return res and res[len(res) - 1] or None
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExpeditionDay(TroggleModel):
|
|
||||||
expedition = models.ForeignKey("Expedition")
|
|
||||||
date = models.DateField()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('date',)
|
|
||||||
|
|
||||||
def GetPersonTrip(self, personexpedition):
|
|
||||||
personexpeditions = self.persontrip_set.filter(expeditionday=self)
|
|
||||||
return personexpeditions and personexpeditions[0] or None
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# single Person, can go on many years
|
|
||||||
#
|
|
||||||
class Person(TroggleModel):
|
|
||||||
first_name = models.CharField(max_length=100)
|
|
||||||
last_name = models.CharField(max_length=100)
|
|
||||||
is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False)
|
|
||||||
mug_shot = models.CharField(max_length=100, blank=True,null=True)
|
|
||||||
blurb = models.TextField(blank=True,null=True)
|
|
||||||
|
|
||||||
#href = models.CharField(max_length=200)
|
|
||||||
orderref = models.CharField(max_length=200) # for alphabetic
|
|
||||||
|
|
||||||
#the below have been removed and made methods. I'm not sure what the b in bisnotable stands for. - AC 16 Feb
|
|
||||||
#notability = models.FloatField() # for listing the top 20 people
|
|
||||||
#bisnotable = models.BooleanField(default=False)
|
|
||||||
user = models.OneToOneField(User, null=True, blank=True)
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name}))
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name_plural = "People"
|
|
||||||
ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name')
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
if self.last_name:
|
|
||||||
return "%s %s" % (self.first_name, self.last_name)
|
|
||||||
return self.first_name
|
|
||||||
|
|
||||||
|
|
||||||
def notability(self):
|
|
||||||
notability = Decimal(0)
|
|
||||||
for personexpedition in self.personexpedition_set.all():
|
|
||||||
if not personexpedition.is_guest:
|
|
||||||
notability += Decimal(1) / (2012 - int(personexpedition.expedition.year))
|
|
||||||
return notability
|
|
||||||
|
|
||||||
def bisnotable(self):
|
|
||||||
return self.notability() > Decimal(1)/Decimal(3)
|
|
||||||
|
|
||||||
def surveyedleglength(self):
|
|
||||||
return sum([personexpedition.surveyedleglength() for personexpedition in self.personexpedition_set.all()])
|
|
||||||
|
|
||||||
def first(self):
|
|
||||||
return self.personexpedition_set.order_by('-expedition')[0]
|
|
||||||
def last(self):
|
|
||||||
return self.personexpedition_set.order_by('expedition')[0]
|
|
||||||
|
|
||||||
#def Sethref(self):
|
|
||||||
#if self.last_name:
|
|
||||||
#self.href = self.first_name.lower() + "_" + self.last_name.lower()
|
|
||||||
#self.orderref = self.last_name + " " + self.first_name
|
|
||||||
#else:
|
|
||||||
# self.href = self.first_name.lower()
|
|
||||||
#self.orderref = self.first_name
|
|
||||||
#self.notability = 0.0 # set temporarily
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Person's attenance to one Expo
|
|
||||||
#
|
|
||||||
class PersonExpedition(TroggleModel):
|
|
||||||
expedition = models.ForeignKey(Expedition)
|
|
||||||
person = models.ForeignKey(Person)
|
|
||||||
slugfield = models.SlugField(max_length=50,blank=True,null=True)
|
|
||||||
|
|
||||||
is_guest = models.BooleanField(default=False)
|
|
||||||
COMMITTEE_CHOICES = (
|
|
||||||
('leader','Expo leader'),
|
|
||||||
('medical','Expo medical officer'),
|
|
||||||
('treasurer','Expo treasurer'),
|
|
||||||
('sponsorship','Expo sponsorship coordinator'),
|
|
||||||
('research','Expo research coordinator'),
|
|
||||||
)
|
|
||||||
expo_committee_position = models.CharField(blank=True,null=True,choices=COMMITTEE_CHOICES,max_length=200)
|
|
||||||
nickname = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
|
|
||||||
def GetPersonroles(self):
|
|
||||||
res = [ ]
|
|
||||||
for personrole in self.personrole_set.order_by('survexblock'):
|
|
||||||
if res and res[-1]['survexpath'] == personrole.survexblock.survexpath:
|
|
||||||
res[-1]['roles'] += ", " + str(personrole.role)
|
|
||||||
else:
|
|
||||||
res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath, 'roles':str(personrole.role)})
|
|
||||||
return res
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('-expedition',)
|
|
||||||
#order_with_respect_to = 'expedition'
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "%s: (%s)" % (self.person, self.expedition)
|
|
||||||
|
|
||||||
|
|
||||||
#why is the below a function in personexpedition, rather than in person? - AC 14 Feb 09
|
|
||||||
def name(self):
|
|
||||||
if self.nickname:
|
|
||||||
return "%s (%s) %s" % (self.person.first_name, self.nickname, self.person.last_name)
|
|
||||||
if self.person.last_name:
|
|
||||||
return "%s %s" % (self.person.first_name, self.person.last_name)
|
|
||||||
return self.person.first_name
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('personexpedition',kwargs={'first_name':self.person.first_name,'last_name':self.person.last_name,'year':self.expedition.year}))
|
|
||||||
|
|
||||||
def surveyedleglength(self):
|
|
||||||
survexblocks = [personrole.survexblock for personrole in self.personrole_set.all() ]
|
|
||||||
return sum([survexblock.totalleglength for survexblock in set(survexblocks)])
|
|
||||||
|
|
||||||
# would prefer to return actual person trips so we could link to first and last ones
|
|
||||||
def day_min(self):
|
|
||||||
res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
|
|
||||||
return res["day_min"]
|
|
||||||
|
|
||||||
def day_max(self):
|
|
||||||
res = self.persontrip_set.all().aggregate(day_max=Max("expeditionday__date"))
|
|
||||||
return res["day_max"]
|
|
||||||
|
|
||||||
#
|
|
||||||
# Single parsed entry from Logbook
|
|
||||||
#
|
|
||||||
class LogbookEntry(TroggleModel):
|
|
||||||
date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.
|
|
||||||
expeditionday = models.ForeignKey("ExpeditionDay", null=True)#MJG wants to KILL THIS (redundant information)
|
|
||||||
expedition = models.ForeignKey(Expedition,blank=True,null=True) # yes this is double-
|
|
||||||
#author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip.
|
|
||||||
# Re: the above- so this field should be "typist" or something, not "author". - AC 15 jun 09
|
|
||||||
#MJG wants to KILL THIS, as it is typically redundant with PersonTrip.is_logbook_entry_author, in the rare it was not redundanty and of actually interest it could be added to the text.
|
|
||||||
title = models.CharField(max_length=settings.MAX_LOGBOOK_ENTRY_TITLE_LENGTH)
|
|
||||||
cave_slug = models.SlugField(max_length=50)
|
|
||||||
place = models.CharField(max_length=100,blank=True,null=True,help_text="Only use this if you haven't chosen a cave")
|
|
||||||
text = models.TextField()
|
|
||||||
slug = models.SlugField(max_length=50)
|
|
||||||
filename = models.CharField(max_length=200,null=True)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
verbose_name_plural = "Logbook Entries"
|
|
||||||
# several PersonTrips point in to this object
|
|
||||||
ordering = ('-date',)
|
|
||||||
|
|
||||||
def __getattribute__(self, item):
|
|
||||||
if item == "cave": #Allow a logbookentries cave to be directly accessed despite not having a proper foreignkey
|
|
||||||
return CaveSlug.objects.get(slug = self.cave_slug).cave
|
|
||||||
return super(LogbookEntry, self).__getattribute__(item)
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
if "cave" in kwargs.keys():
|
|
||||||
if kwargs["cave"] is not None:
|
|
||||||
kwargs["cave_slug"] = CaveSlug.objects.get(cave=kwargs["cave"], primary=True).slug
|
|
||||||
kwargs.pop("cave")
|
|
||||||
return super(LogbookEntry, self).__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
def isLogbookEntry(self): # Function used in templates
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('logbookentry',kwargs={'date':self.date,'slug':self.slug}))
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "%s: (%s)" % (self.date, self.title)
|
|
||||||
|
|
||||||
def get_next_by_id(self):
|
|
||||||
LogbookEntry.objects.get(id=self.id+1)
|
|
||||||
|
|
||||||
def get_previous_by_id(self):
|
|
||||||
LogbookEntry.objects.get(id=self.id-1)
|
|
||||||
|
|
||||||
def new_QM_number(self):
|
|
||||||
"""Returns """
|
|
||||||
if self.cave:
|
|
||||||
nextQMnumber=self.cave.new_QM_number(self.date.year)
|
|
||||||
else:
|
|
||||||
return none
|
|
||||||
return nextQMnumber
|
|
||||||
|
|
||||||
def new_QM_found_link(self):
|
|
||||||
"""Produces a link to a new QM with the next number filled in and this LogbookEntry set as 'found by' """
|
|
||||||
return settings.URL_ROOT + r'/admin/core/qm/add/?' + r'found_by=' + str(self.pk) +'&number=' + str(self.new_QM_number())
|
|
||||||
|
|
||||||
def DayIndex(self):
|
|
||||||
return list(self.expeditionday.logbookentry_set.all()).index(self)
|
|
||||||
|
|
||||||
#
|
|
||||||
# Single Person going on a trip, which may or may not be written up (accounts for different T/U for people in same logbook entry)
|
|
||||||
#
|
|
||||||
class PersonTrip(TroggleModel):
|
|
||||||
personexpedition = models.ForeignKey("PersonExpedition",null=True)
|
|
||||||
|
|
||||||
#expeditionday = models.ForeignKey("ExpeditionDay")#MJG wants to KILL THIS (redundant information)
|
|
||||||
#date = models.DateField() #MJG wants to KILL THIS (redundant information)
|
|
||||||
time_underground = models.FloatField(help_text="In decimal hours")
|
|
||||||
logbook_entry = models.ForeignKey(LogbookEntry)
|
|
||||||
is_logbook_entry_author = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
|
|
||||||
# sequencing by person (difficult to solve locally)
|
|
||||||
#persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)#MJG wants to KILL THIS (and use funstion persontrip_next_auto)
|
|
||||||
#persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)#MJG wants to KILL THIS(and use funstion persontrip_prev_auto)
|
|
||||||
|
|
||||||
def persontrip_next(self):
|
|
||||||
futurePTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__gt = self.logbook_entry.date).order_by('logbook_entry__date').all()
|
|
||||||
if len(futurePTs) > 0:
|
|
||||||
return futurePTs[0]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def persontrip_prev(self):
|
|
||||||
pastPTs = PersonTrip.objects.filter(personexpedition = self.personexpedition, logbook_entry__date__lt = self.logbook_entry.date).order_by('-logbook_entry__date').all()
|
|
||||||
if len(pastPTs) > 0:
|
|
||||||
return pastPTs[0]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def place(self):
|
|
||||||
return self.logbook_entry.cave and self.logbook_entry.cave or self.logbook_entry.place
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return "%s (%s)" % (self.personexpedition, self.logbook_entry.date)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##########################################
|
|
||||||
# move following classes into models_cave
|
|
||||||
##########################################
|
|
||||||
|
|
||||||
class Area(TroggleModel):
|
|
||||||
short_name = models.CharField(max_length=100)
|
|
||||||
name = models.CharField(max_length=200, blank=True, null=True)
|
|
||||||
description = models.TextField(blank=True,null=True)
|
|
||||||
parent = models.ForeignKey('Area', blank=True, null=True)
|
|
||||||
def __unicode__(self):
|
|
||||||
if self.parent:
|
|
||||||
return unicode(self.parent) + u" - " + unicode(self.short_name)
|
|
||||||
else:
|
|
||||||
return unicode(self.short_name)
|
|
||||||
def kat_area(self):
|
|
||||||
if self.short_name in ["1623", "1626"]:
|
|
||||||
return self.short_name
|
|
||||||
elif self.parent:
|
|
||||||
return self.parent.kat_area()
|
|
||||||
|
|
||||||
class CaveAndEntrance(models.Model):
|
|
||||||
cave = models.ForeignKey('Cave')
|
|
||||||
entrance = models.ForeignKey('Entrance')
|
|
||||||
entrance_letter = models.CharField(max_length=20,blank=True,null=True)
|
|
||||||
def __unicode__(self):
|
|
||||||
return unicode(self.cave) + unicode(self.entrance_letter)
|
|
||||||
|
|
||||||
class CaveSlug(models.Model):
|
|
||||||
cave = models.ForeignKey('Cave')
|
|
||||||
slug = models.SlugField(max_length=50, unique = True)
|
|
||||||
primary = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
|
|
||||||
class Cave(TroggleModel):
|
|
||||||
# too much here perhaps,
|
|
||||||
official_name = models.CharField(max_length=160)
|
|
||||||
area = models.ManyToManyField(Area, blank=True, null=True)
|
|
||||||
kataster_code = models.CharField(max_length=20,blank=True,null=True)
|
|
||||||
kataster_number = models.CharField(max_length=10,blank=True, null=True)
|
|
||||||
unofficial_number = models.CharField(max_length=60,blank=True, null=True)
|
|
||||||
entrances = models.ManyToManyField('Entrance', through='CaveAndEntrance')
|
|
||||||
explorers = models.TextField(blank=True,null=True)
|
|
||||||
underground_description = models.TextField(blank=True,null=True)
|
|
||||||
equipment = models.TextField(blank=True,null=True)
|
|
||||||
references = models.TextField(blank=True,null=True)
|
|
||||||
survey = models.TextField(blank=True,null=True)
|
|
||||||
kataster_status = models.TextField(blank=True,null=True)
|
|
||||||
underground_centre_line = models.TextField(blank=True,null=True)
|
|
||||||
notes = models.TextField(blank=True,null=True)
|
|
||||||
length = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
depth = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
extent = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
survex_file = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
description_file = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
url = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
filename = models.CharField(max_length=200)
|
|
||||||
|
|
||||||
|
|
||||||
#class Meta:
|
|
||||||
# unique_together = (("area", "kataster_number"), ("area", "unofficial_number"))
|
|
||||||
# FIXME Kataster Areas and CUCC defined sub areas need seperating
|
|
||||||
|
|
||||||
|
|
||||||
#href = models.CharField(max_length=100)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('kataster_code', 'unofficial_number')
|
|
||||||
|
|
||||||
def hassurvey(self):
|
|
||||||
if not self.underground_centre_line:
|
|
||||||
return "No"
|
|
||||||
if (self.survey.find("<img") > -1 or self.survey.find("<a") > -1 or self.survey.find("<IMG") > -1 or self.survey.find("<A") > -1):
|
|
||||||
return "Yes"
|
|
||||||
return "Missing"
|
|
||||||
|
|
||||||
def hassurveydata(self):
|
|
||||||
if not self.underground_centre_line:
|
|
||||||
return "No"
|
|
||||||
if self.survex_file:
|
|
||||||
return "Yes"
|
|
||||||
return "Missing"
|
|
||||||
|
|
||||||
def slug(self):
|
|
||||||
primarySlugs = self.caveslug_set.filter(primary = True)
|
|
||||||
if primarySlugs:
|
|
||||||
return primarySlugs[0].slug
|
|
||||||
else:
|
|
||||||
slugs = self.caveslug_set.filter()
|
|
||||||
if slugs:
|
|
||||||
return slugs[0].slug
|
|
||||||
|
|
||||||
def ours(self):
|
|
||||||
return bool(re.search(r'CUCC', self.explorers))
|
|
||||||
|
|
||||||
def reference(self):
|
|
||||||
if self.kataster_number:
|
|
||||||
return "%s-%s" % (self.kat_area(), self.kataster_number)
|
|
||||||
else:
|
|
||||||
return "%s-%s" % (self.kat_area(), self.unofficial_number)
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
if self.kataster_number:
|
|
||||||
href = self.kataster_number
|
|
||||||
elif self.unofficial_number:
|
|
||||||
href = self.unofficial_number
|
|
||||||
else:
|
|
||||||
href = official_name.lower()
|
|
||||||
#return settings.URL_ROOT + '/cave/' + href + '/'
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('cave',kwargs={'cave_id':href,}))
|
|
||||||
|
|
||||||
def __unicode__(self, sep = u": "):
|
|
||||||
return unicode(self.slug())
|
|
||||||
|
|
||||||
def get_QMs(self):
|
|
||||||
return QM.objects.filter(found_by__cave_slug=self.caveslug_set.all())
|
|
||||||
|
|
||||||
def new_QM_number(self, year=datetime.date.today().year):
|
|
||||||
"""Given a cave and the current year, returns the next QM number."""
|
|
||||||
try:
|
|
||||||
res=QM.objects.filter(found_by__date__year=year, found_by__cave=self).order_by('-number')[0]
|
|
||||||
except IndexError:
|
|
||||||
return 1
|
|
||||||
return res.number+1
|
|
||||||
|
|
||||||
def kat_area(self):
|
|
||||||
for a in self.area.all():
|
|
||||||
if a.kat_area():
|
|
||||||
return a.kat_area()
|
|
||||||
|
|
||||||
def entrances(self):
|
|
||||||
return CaveAndEntrance.objects.filter(cave=self)
|
|
||||||
|
|
||||||
def singleentrance(self):
|
|
||||||
return len(CaveAndEntrance.objects.filter(cave=self)) == 1
|
|
||||||
|
|
||||||
def entrancelist(self):
|
|
||||||
rs = []
|
|
||||||
res = ""
|
|
||||||
for e in CaveAndEntrance.objects.filter(cave=self):
|
|
||||||
rs.append(e.entrance_letter)
|
|
||||||
rs.sort()
|
|
||||||
prevR = None
|
|
||||||
n = 0
|
|
||||||
for r in rs:
|
|
||||||
if prevR:
|
|
||||||
if chr(ord(prevR) + 1 ) == r:
|
|
||||||
prevR = r
|
|
||||||
n += 1
|
|
||||||
else:
|
|
||||||
if n == 0:
|
|
||||||
res += ", " + prevR
|
|
||||||
else:
|
|
||||||
res += "–" + prevR
|
|
||||||
else:
|
|
||||||
prevR = r
|
|
||||||
n = 0
|
|
||||||
res += r
|
|
||||||
if n == 0:
|
|
||||||
res += ", " + prevR
|
|
||||||
else:
|
|
||||||
res += "–" + prevR
|
|
||||||
return res
|
|
||||||
|
|
||||||
def writeDataFile(self):
|
|
||||||
try:
|
|
||||||
f = open(os.path.join(settings.CAVEDESCRIPTIONS, self.filename), "w")
|
|
||||||
except:
|
|
||||||
subprocess.call(settings.FIX_PERMISSIONS)
|
|
||||||
f = open(os.path.join(settings.CAVEDESCRIPTIONS, self.filename), "w")
|
|
||||||
t = loader.get_template('dataformat/cave.xml')
|
|
||||||
c = Context({'cave': self})
|
|
||||||
u = t.render(c)
|
|
||||||
u8 = u.encode("utf-8")
|
|
||||||
f.write(u8)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
def getArea(self):
|
|
||||||
areas = self.area.all()
|
|
||||||
lowestareas = list(areas)
|
|
||||||
for area in areas:
|
|
||||||
if area.parent in areas:
|
|
||||||
try:
|
|
||||||
lowestareas.remove(area.parent)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
return lowestareas[0]
|
|
||||||
|
|
||||||
def getCaveByReference(reference):
|
|
||||||
areaname, code = reference.split("-", 1)
|
|
||||||
print(areaname, code)
|
|
||||||
area = Area.objects.get(short_name = areaname)
|
|
||||||
print(area)
|
|
||||||
foundCaves = list(Cave.objects.filter(area = area, kataster_number = code).all()) + list(Cave.objects.filter(area = area, unofficial_number = code).all())
|
|
||||||
print(list(foundCaves))
|
|
||||||
assert len(foundCaves) == 1
|
|
||||||
return foundCaves[0]
|
|
||||||
|
|
||||||
class OtherCaveName(TroggleModel):
|
|
||||||
name = models.CharField(max_length=160)
|
|
||||||
cave = models.ForeignKey(Cave)
|
|
||||||
def __unicode__(self):
|
|
||||||
return unicode(self.name)
|
|
||||||
|
|
||||||
class EntranceSlug(models.Model):
|
|
||||||
entrance = models.ForeignKey('Entrance')
|
|
||||||
slug = models.SlugField(max_length=50, unique = True)
|
|
||||||
primary = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
class Entrance(TroggleModel):
|
|
||||||
name = models.CharField(max_length=100, blank=True,null=True)
|
|
||||||
entrance_description = models.TextField(blank=True,null=True)
|
|
||||||
explorers = models.TextField(blank=True,null=True)
|
|
||||||
map_description = models.TextField(blank=True,null=True)
|
|
||||||
location_description = models.TextField(blank=True,null=True)
|
|
||||||
approach = models.TextField(blank=True,null=True)
|
|
||||||
underground_description = models.TextField(blank=True,null=True)
|
|
||||||
photo = models.TextField(blank=True,null=True)
|
|
||||||
MARKING_CHOICES = (
|
|
||||||
('P', 'Paint'),
|
|
||||||
('P?', 'Paint (?)'),
|
|
||||||
('T', 'Tag'),
|
|
||||||
('T?', 'Tag (?)'),
|
|
||||||
('R', 'Needs Retag'),
|
|
||||||
('S', 'Spit'),
|
|
||||||
('S?', 'Spit (?)'),
|
|
||||||
('U', 'Unmarked'),
|
|
||||||
('?', 'Unknown'))
|
|
||||||
marking = models.CharField(max_length=2, choices=MARKING_CHOICES)
|
|
||||||
marking_comment = models.TextField(blank=True,null=True)
|
|
||||||
FINDABLE_CHOICES = (
|
|
||||||
('?', 'To be confirmed ...'),
|
|
||||||
('S', 'Coordinates'),
|
|
||||||
('L', 'Lost'),
|
|
||||||
('R', 'Refindable'))
|
|
||||||
findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True)
|
|
||||||
findability_description = models.TextField(blank=True,null=True)
|
|
||||||
alt = models.TextField(blank=True, null=True)
|
|
||||||
northing = models.TextField(blank=True, null=True)
|
|
||||||
easting = models.TextField(blank=True, null=True)
|
|
||||||
tag_station = models.TextField(blank=True, null=True)
|
|
||||||
exact_station = models.TextField(blank=True, null=True)
|
|
||||||
other_station = models.TextField(blank=True, null=True)
|
|
||||||
other_description = models.TextField(blank=True,null=True)
|
|
||||||
bearings = models.TextField(blank=True,null=True)
|
|
||||||
url = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
filename = models.CharField(max_length=200)
|
|
||||||
cached_primary_slug = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return unicode(self.slug())
|
|
||||||
|
|
||||||
def exact_location(self):
|
|
||||||
return SurvexStation.objects.lookup(self.exact_station)
|
|
||||||
def other_location(self):
|
|
||||||
return SurvexStation.objects.lookup(self.other_station)
|
|
||||||
|
|
||||||
|
|
||||||
def find_location(self):
|
|
||||||
r = {'': 'To be entered ',
|
|
||||||
'?': 'To be confirmed:',
|
|
||||||
'S': '',
|
|
||||||
'L': 'Lost:',
|
|
||||||
'R': 'Refindable:'}[self.findability]
|
|
||||||
if self.tag_station:
|
|
||||||
try:
|
|
||||||
s = SurvexStation.objects.lookup(self.tag_station)
|
|
||||||
return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z)
|
|
||||||
except:
|
|
||||||
return r + "%s Tag Station not in dataset" % self.tag_station
|
|
||||||
if self.exact_station:
|
|
||||||
try:
|
|
||||||
s = SurvexStation.objects.lookup(self.exact_station)
|
|
||||||
return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z)
|
|
||||||
except:
|
|
||||||
return r + "%s Exact Station not in dataset" % self.tag_station
|
|
||||||
if self.other_station:
|
|
||||||
try:
|
|
||||||
s = SurvexStation.objects.lookup(self.other_station)
|
|
||||||
return r + "%0.0fE %0.0fN %0.0fAlt %s" % (s.x, s.y, s.z, self.other_description)
|
|
||||||
except:
|
|
||||||
return r + "%s Other Station not in dataset" % self.tag_station
|
|
||||||
if self.FINDABLE_CHOICES == "S":
|
|
||||||
r += "ERROR, Entrance has been surveyed but has no survex point"
|
|
||||||
if self.bearings:
|
|
||||||
return r + self.bearings
|
|
||||||
return r
|
|
||||||
|
|
||||||
def best_station(self):
|
|
||||||
if self.tag_station:
|
|
||||||
return self.tag_station
|
|
||||||
if self.exact_station:
|
|
||||||
return self.exact_station
|
|
||||||
if self.other_station:
|
|
||||||
return self.other_station
|
|
||||||
|
|
||||||
def has_photo(self):
|
|
||||||
if self.photo:
|
|
||||||
if (self.photo.find("<img") > -1 or self.photo.find("<a") > -1 or self.photo.find("<IMG") > -1 or self.photo.find("<A") > -1):
|
|
||||||
return "Yes"
|
|
||||||
else:
|
|
||||||
return "Missing"
|
|
||||||
else:
|
|
||||||
return "No"
|
|
||||||
|
|
||||||
def marking_val(self):
|
|
||||||
for m in self.MARKING_CHOICES:
|
|
||||||
if m[0] == self.marking:
|
|
||||||
return m[1]
|
|
||||||
def findability_val(self):
|
|
||||||
for f in self.FINDABLE_CHOICES:
|
|
||||||
if f[0] == self.findability:
|
|
||||||
return f[1]
|
|
||||||
|
|
||||||
def tag(self):
|
|
||||||
return SurvexStation.objects.lookup(self.tag_station)
|
|
||||||
|
|
||||||
def needs_surface_work(self):
|
|
||||||
return self.findability != "S" or not self.has_photo or self.marking != "T"
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
|
|
||||||
ancestor_titles='/'.join([subcave.title for subcave in self.get_ancestors()])
|
|
||||||
if ancestor_titles:
|
|
||||||
res = '/'.join((self.get_root().cave.get_absolute_url(), ancestor_titles, self.title))
|
|
||||||
|
|
||||||
else:
|
|
||||||
res = '/'.join((self.get_root().cave.get_absolute_url(), self.title))
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
def slug(self):
|
|
||||||
if not self.cached_primary_slug:
|
|
||||||
primarySlugs = self.entranceslug_set.filter(primary = True)
|
|
||||||
if primarySlugs:
|
|
||||||
self.cached_primary_slug = primarySlugs[0].slug
|
|
||||||
self.save()
|
|
||||||
else:
|
|
||||||
slugs = self.entranceslug_set.filter()
|
|
||||||
if slugs:
|
|
||||||
self.cached_primary_slug = slugs[0].slug
|
|
||||||
self.save()
|
|
||||||
return self.cached_primary_slug
|
|
||||||
|
|
||||||
def writeDataFile(self):
|
|
||||||
try:
|
|
||||||
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")
|
|
||||||
except:
|
|
||||||
subprocess.call(settings.FIX_PERMISSIONS)
|
|
||||||
f = open(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename), "w")
|
|
||||||
t = loader.get_template('dataformat/entrance.xml')
|
|
||||||
c = Context({'entrance': self})
|
|
||||||
u = t.render(c)
|
|
||||||
u8 = u.encode("utf-8")
|
|
||||||
f.write(u8)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
class CaveDescription(TroggleModel):
|
|
||||||
short_name = models.CharField(max_length=50, unique = True)
|
|
||||||
long_name = models.CharField(max_length=200, blank=True, null=True)
|
|
||||||
description = models.TextField(blank=True,null=True)
|
|
||||||
linked_subcaves = models.ManyToManyField("NewSubCave", blank=True,null=True)
|
|
||||||
linked_entrances = models.ManyToManyField("Entrance", blank=True,null=True)
|
|
||||||
linked_qms = models.ManyToManyField("QM", blank=True,null=True)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
if self.long_name:
|
|
||||||
return unicode(self.long_name)
|
|
||||||
else:
|
|
||||||
return unicode(self.short_name)
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('cavedescription', args=(self.short_name,)))
|
|
||||||
|
|
||||||
def save(self):
|
|
||||||
"""
|
|
||||||
Overridden save method which stores wikilinks in text as links in database.
|
|
||||||
"""
|
|
||||||
super(CaveDescription, self).save()
|
|
||||||
qm_list=get_related_by_wikilinks(self.description)
|
|
||||||
for qm in qm_list:
|
|
||||||
self.linked_qms.add(qm)
|
|
||||||
super(CaveDescription, self).save()
|
|
||||||
|
|
||||||
class NewSubCave(TroggleModel):
|
|
||||||
name = models.CharField(max_length=200, unique = True)
|
|
||||||
def __unicode__(self):
|
|
||||||
return unicode(self.name)
|
|
||||||
|
|
||||||
class QM(TroggleModel):
|
|
||||||
#based on qm.csv in trunk/expoweb/1623/204 which has the fields:
|
|
||||||
#"Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment"
|
|
||||||
found_by = models.ForeignKey(LogbookEntry, related_name='QMs_found',blank=True, null=True )
|
|
||||||
ticked_off_by = models.ForeignKey(LogbookEntry, related_name='QMs_ticked_off',null=True,blank=True)
|
|
||||||
#cave = models.ForeignKey(Cave)
|
|
||||||
#expedition = models.ForeignKey(Expedition)
|
|
||||||
|
|
||||||
number = models.IntegerField(help_text="this is the sequential number in the year", )
|
|
||||||
GRADE_CHOICES=(
|
|
||||||
('A', 'A: Large obvious lead'),
|
|
||||||
('B', 'B: Average lead'),
|
|
||||||
('C', 'C: Tight unpromising lead'),
|
|
||||||
('D', 'D: Dig'),
|
|
||||||
('X', 'X: Unclimbable aven')
|
|
||||||
)
|
|
||||||
grade = models.CharField(max_length=1, choices=GRADE_CHOICES)
|
|
||||||
location_description = models.TextField(blank=True)
|
|
||||||
#should be a foreignkey to surveystation
|
|
||||||
nearest_station_description = models.CharField(max_length=400,null=True,blank=True)
|
|
||||||
nearest_station = models.CharField(max_length=200,blank=True,null=True)
|
|
||||||
area = models.CharField(max_length=100,blank=True,null=True)
|
|
||||||
completion_description = models.TextField(blank=True,null=True)
|
|
||||||
comment=models.TextField(blank=True,null=True)
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return u"%s %s" % (self.code(), self.grade)
|
|
||||||
|
|
||||||
def code(self):
|
|
||||||
return u"%s-%s-%s" % (unicode(self.found_by.cave)[6:], self.found_by.date.year, self.number)
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
#return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number
|
|
||||||
return urlparse.urljoin(settings.URL_ROOT, reverse('qm',kwargs={'cave_id':self.found_by.cave.kataster_number,'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}))
|
|
||||||
|
|
||||||
def get_next_by_id(self):
|
|
||||||
return QM.objects.get(id=self.id+1)
|
|
||||||
|
|
||||||
def get_previous_by_id(self):
|
|
||||||
return QM.objects.get(id=self.id-1)
|
|
||||||
|
|
||||||
def wiki_link(self):
|
|
||||||
return u"%s%s%s" % ('[[QM:',self.code(),']]')
|
|
||||||
|
|
||||||
photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL)
|
|
||||||
class DPhoto(TroggleImageModel):
|
|
||||||
caption = models.CharField(max_length=1000,blank=True,null=True)
|
|
||||||
contains_logbookentry = models.ForeignKey(LogbookEntry,blank=True,null=True)
|
|
||||||
contains_person = models.ManyToManyField(Person,blank=True,null=True)
|
|
||||||
file = models.ImageField(storage=photoFileStorage, upload_to='.',)
|
|
||||||
is_mugshot = models.BooleanField(default=False)
|
|
||||||
contains_cave = models.ForeignKey(Cave,blank=True,null=True)
|
|
||||||
contains_entrance = models.ForeignKey(Entrance, related_name="photo_file",blank=True,null=True)
|
|
||||||
#nearest_survey_point = models.ForeignKey(SurveyStation,blank=True,null=True)
|
|
||||||
nearest_QM = models.ForeignKey(QM,blank=True,null=True)
|
|
||||||
lon_utm = models.FloatField(blank=True,null=True)
|
|
||||||
lat_utm = models.FloatField(blank=True,null=True)
|
|
||||||
|
|
||||||
class IKOptions:
|
|
||||||
spec_module = 'core.imagekit_specs'
|
|
||||||
cache_dir = 'thumbs'
|
|
||||||
image_field = 'file'
|
|
||||||
|
|
||||||
#content_type = models.ForeignKey(ContentType)
|
|
||||||
#object_id = models.PositiveIntegerField()
|
|
||||||
#location = generic.GenericForeignKey('content_type', 'object_id')
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.caption
|
|
||||||
|
|
||||||
scansFileStorage = FileSystemStorage(location=settings.SURVEY_SCANS, base_url=settings.SURVEYS_URL)
|
|
||||||
def get_scan_path(instance, filename):
|
|
||||||
year=instance.survey.expedition.year
|
|
||||||
#print("WN: ", type(instance.survey.wallet_number), instance.survey.wallet_number, instance.survey.wallet_letter)
|
|
||||||
number=str(instance.survey.wallet_number)
|
|
||||||
if str(instance.survey.wallet_letter) != "None":
|
|
||||||
number=str(instance.survey.wallet_letter) + number #two strings formatting because convention is 2009#01 or 2009#X01
|
|
||||||
return os.path.join('./',year,year+r'#'+number,str(instance.contents)+str(instance.number_in_wallet)+r'.jpg')
|
|
||||||
|
|
||||||
class ScannedImage(TroggleImageModel):
|
|
||||||
file = models.ImageField(storage=scansFileStorage, upload_to=get_scan_path)
|
|
||||||
scanned_by = models.ForeignKey(Person,blank=True, null=True)
|
|
||||||
scanned_on = models.DateField(null=True)
|
|
||||||
survey = models.ForeignKey('Survey')
|
|
||||||
contents = models.CharField(max_length=20,choices=(('notes','notes'),('plan','plan_sketch'),('elevation','elevation_sketch')))
|
|
||||||
number_in_wallet = models.IntegerField(null=True)
|
|
||||||
lon_utm = models.FloatField(blank=True,null=True)
|
|
||||||
lat_utm = models.FloatField(blank=True,null=True)
|
|
||||||
|
|
||||||
class IKOptions:
|
|
||||||
spec_module = 'core.imagekit_specs'
|
|
||||||
cache_dir = 'thumbs'
|
|
||||||
image_field = 'file'
|
|
||||||
#content_type = models.ForeignKey(ContentType)
|
|
||||||
#object_id = models.PositiveIntegerField()
|
|
||||||
#location = generic.GenericForeignKey('content_type', 'object_id')
|
|
||||||
|
|
||||||
#This is an ugly hack to deal with the #s in our survey scan paths. The correct thing is to write a custom file storage backend which calls urlencode on the name for making file.url but not file.path.
|
|
||||||
def correctURL(self):
|
|
||||||
return string.replace(self.file.url,r'#',r'%23')
|
|
||||||
|
|
||||||
def __unicode__(self):
|
|
||||||
return get_scan_path(self,'')
|
|
||||||
|
|
||||||
class Survey(TroggleModel):
|
|
||||||
expedition = models.ForeignKey('Expedition') #REDUNDANT (logbook_entry)
|
|
||||||
wallet_number = models.IntegerField(blank=True,null=True)
|
|
||||||
wallet_letter = models.CharField(max_length=1,blank=True,null=True)
|
|
||||||
comments = models.TextField(blank=True,null=True)
|
|
||||||
location = models.CharField(max_length=400,blank=True,null=True) #REDUNDANT
|
|
||||||
subcave = models.ForeignKey('NewSubCave', blank=True, null=True)
|
|
||||||
#notes_scan = models.ForeignKey('ScannedImage',related_name='notes_scan',blank=True, null=True) #Replaced by contents field of ScannedImage model
|
|
||||||
survex_block = models.OneToOneField('SurvexBlock',blank=True, null=True)
|
|
||||||
logbook_entry = models.ForeignKey('LogbookEntry')
|
|
||||||
centreline_printed_on = models.DateField(blank=True, null=True)
|
|
||||||
centreline_printed_by = models.ForeignKey('Person',related_name='centreline_printed_by',blank=True,null=True)
|
|
||||||
#sketch_scan = models.ForeignKey(ScannedImage,blank=True, null=True) #Replaced by contents field of ScannedImage model
|
|
||||||
tunnel_file = models.FileField(upload_to='surveyXMLfiles',blank=True, null=True)
|
|
||||||
tunnel_main_sketch = models.ForeignKey('Survey',blank=True,null=True)
|
|
||||||
integrated_into_main_sketch_on = models.DateField(blank=True,null=True)
|
|
||||||
integrated_into_main_sketch_by = models.ForeignKey('Person' ,related_name='integrated_into_main_sketch_by', blank=True,null=True)
|
|
||||||
rendered_image = models.ImageField(upload_to='renderedSurveys',blank=True,null=True)
|
|
||||||
def __unicode__(self):
|
|
||||||
return self.expedition.year+"#"+"%02d" % int(self.wallet_number)
|
|
||||||
|
|
||||||
def notes(self):
|
|
||||||
return self.scannedimage_set.filter(contents='notes')
|
|
||||||
|
|
||||||
def plans(self):
|
|
||||||
return self.scannedimage_set.filter(contents='plan')
|
|
||||||
|
|
||||||
def elevations(self):
|
|
||||||
return self.scannedimage_set.filter(contents='elevation')
|
|
||||||
@@ -97,7 +97,7 @@ class SurvexBlockLookUpManager(models.Manager):
|
|||||||
blocknames = []
|
blocknames = []
|
||||||
else:
|
else:
|
||||||
blocknames = name.split(".")
|
blocknames = name.split(".")
|
||||||
block = SurvexBlock.objects.get(parent=None, survexfile__path="all")
|
block = SurvexBlock.objects.get(parent=None, survexfile__path=settings.SURVEX_TOPNAME)
|
||||||
for blockname in blocknames:
|
for blockname in blocknames:
|
||||||
block = SurvexBlock.objects.get(parent=block, name__iexact=blockname)
|
block = SurvexBlock.objects.get(parent=block, name__iexact=blockname)
|
||||||
return block
|
return block
|
||||||
@@ -225,4 +225,4 @@ class TunnelFile(models.Model):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('tunnelpath',)
|
ordering = ('tunnelpath',)
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,6 @@ def survex_to_html(value, autoescape=None):
|
|||||||
if autoescape:
|
if autoescape:
|
||||||
value = conditional_escape(value)
|
value = conditional_escape(value)
|
||||||
for regex, sub in regexes:
|
for regex, sub in regexes:
|
||||||
print sub
|
print(sub)
|
||||||
value = regex.sub(sub, value)
|
value = regex.sub(sub, value)
|
||||||
return mark_safe(value)
|
return mark_safe(value)
|
||||||
@@ -7,7 +7,6 @@ from troggle.core.models import QM, DPhoto, LogbookEntry, Cave
|
|||||||
import re, urlparse
|
import re, urlparse
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def plusone(n):
|
def plusone(n):
|
||||||
@@ -77,7 +76,7 @@ def wiki_to_html_short(value, autoescape=None):
|
|||||||
if number>1:
|
if number>1:
|
||||||
return '<h'+num+'>'+matchobj.groups()[1]+'</h'+num+'>'
|
return '<h'+num+'>'+matchobj.groups()[1]+'</h'+num+'>'
|
||||||
else:
|
else:
|
||||||
print 'morethanone'
|
print('morethanone')
|
||||||
return matchobj.group()
|
return matchobj.group()
|
||||||
value = re.sub(r"(?m)^(=+)([^=]+)(=+)$",headerrepl,value)
|
value = re.sub(r"(?m)^(=+)([^=]+)(=+)$",headerrepl,value)
|
||||||
|
|
||||||
@@ -143,13 +142,13 @@ def wiki_to_html_short(value, autoescape=None):
|
|||||||
value = re.sub(photoSrcPattern,photoSrcRepl, value, re.DOTALL)
|
value = re.sub(photoSrcPattern,photoSrcRepl, value, re.DOTALL)
|
||||||
|
|
||||||
#make cave links
|
#make cave links
|
||||||
value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%scave/\1/">\1</a>' % settings.URL_ROOT, value, re.DOTALL)
|
value = re.sub(r"\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%scave/\1/">\1</a>' % settings.URL_ROOT, value, re.DOTALL)
|
||||||
#make people links
|
#make people links
|
||||||
value = re.sub("\[\[\s*person:(.+)\|(.+)\]\]",r'<a href="%sperson/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
value = re.sub(r"\[\[\s*person:(.+)\|(.+)\]\]",r'<a href="%sperson/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
||||||
#make subcave links
|
#make subcave links
|
||||||
value = re.sub("\[\[\s*subcave:(.+)\|(.+)\]\]",r'<a href="%ssubcave/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
value = re.sub(r"\[\[\s*subcave:(.+)\|(.+)\]\]",r'<a href="%ssubcave/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
||||||
#make cavedescription links
|
#make cavedescription links
|
||||||
value = re.sub("\[\[\s*cavedescription:(.+)\|(.+)\]\]",r'<a href="%scavedescription/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
value = re.sub(r"\[\[\s*cavedescription:(.+)\|(.+)\]\]",r'<a href="%scavedescription/\1/">\2</a>' % settings.URL_ROOT, value, re.DOTALL)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from troggle.core.models import CaveSlug, Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, EntranceSlug, Entrance, Area, SurvexStation, CaveM, Cave_descriptionM
|
from troggle.core.models import CaveSlug, Cave, CaveAndEntrance, Survey, Expedition, QM, CaveDescription, EntranceSlug, Entrance, Area, SurvexStation
|
||||||
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
|
from troggle.core.forms import CaveForm, CaveAndEntranceFormSet, VersionControlCommentForm, EntranceForm, EntranceLetterForm
|
||||||
import troggle.core.models as models
|
import troggle.core.models as models
|
||||||
import troggle.settings as settings
|
import troggle.settings as settings
|
||||||
@@ -10,28 +10,16 @@ from troggle.helper import login_required_if_public
|
|||||||
from django.forms.models import modelformset_factory
|
from django.forms.models import modelformset_factory
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from utils import render_with_context # see views_logbooks for explanation on this.
|
|
||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
import re, urlparse
|
import re, urlparse
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404, render
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
import string, os, sys, subprocess
|
import string, os, sys, subprocess
|
||||||
|
|
||||||
def millenialcaves(request):
|
|
||||||
#RW messing around area
|
|
||||||
caves = CaveM.objects.all()
|
|
||||||
descr = Cave_descriptionM.objects.all()
|
|
||||||
return render_with_context(request,'millenialcaves.html',{'caves': caves,'descriptions' : descr})
|
|
||||||
|
|
||||||
def millenialdescription(request, slug):
|
|
||||||
desc = Cave_descriptionM.objects.get(slug=slug)
|
|
||||||
return render_with_context(request,'cave_uground_description.html', {'cave': desc})
|
|
||||||
|
|
||||||
|
|
||||||
def getCave(cave_id):
|
def getCave(cave_id):
|
||||||
"""Returns a cave object when given a cave name or number. It is used by views including cavehref, ent, and qm."""
|
"""Returns a cave object when given a cave name or number. It is used by views including cavehref, ent, and qm."""
|
||||||
try:
|
try:
|
||||||
@@ -65,16 +53,16 @@ def caveindex(request):
|
|||||||
caves = Cave.objects.all()
|
caves = Cave.objects.all()
|
||||||
notablecavehrefs = settings.NOTABLECAVESHREFS
|
notablecavehrefs = settings.NOTABLECAVESHREFS
|
||||||
notablecaves = [Cave.objects.get(kataster_number=kataster_number) for kataster_number in notablecavehrefs ]
|
notablecaves = [Cave.objects.get(kataster_number=kataster_number) for kataster_number in notablecavehrefs ]
|
||||||
#caves1623 = list(Cave.objects.filter(area__short_name = "1623"))
|
caves1623 = list(Cave.objects.filter(area__short_name = "1623"))
|
||||||
caves1623 = list(Cave.objects.all())
|
|
||||||
caves1626 = list(Cave.objects.filter(area__short_name = "1626"))
|
caves1626 = list(Cave.objects.filter(area__short_name = "1626"))
|
||||||
caves1623.sort(caveCmp)
|
caves1623.sort(caveCmp)
|
||||||
caves1626.sort(caveCmp)
|
caves1626.sort(caveCmp)
|
||||||
return render_with_context(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':notablecaves, 'cavepage': True})
|
return render(request,'caveindex.html', {'caves1623': caves1623, 'caves1626': caves1626, 'notablecaves':notablecaves, 'cavepage': True})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def millenialcaves(request):
|
||||||
|
#RW messing around area
|
||||||
|
return HttpResponse("Test text", content_type="text/plain")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def cave3d(request, cave_id=''):
|
def cave3d(request, cave_id=''):
|
||||||
@@ -94,43 +82,43 @@ def cave3d(request, cave_id=''):
|
|||||||
def cave(request, cave_id='', offical_name=''):
|
def cave(request, cave_id='', offical_name=''):
|
||||||
cave=getCave(cave_id)
|
cave=getCave(cave_id)
|
||||||
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
||||||
return render_with_context(request,'nonpublic.html', {'instance': cave, 'cavepage': True, 'cave_id': cave_id})
|
return render(request,'nonpublic.html', {'instance': cave, 'cavepage': True, 'cave_id': cave_id})
|
||||||
else:
|
else:
|
||||||
return render_with_context(request,'cave.html', {'settings': settings, 'cave': cave, 'cavepage': True, 'cave_id': cave_id})
|
return render(request,'cave.html', {'settings': settings, 'cave': cave, 'cavepage': True, 'cave_id': cave_id})
|
||||||
|
|
||||||
def caveEntrance(request, slug):
|
def caveEntrance(request, slug):
|
||||||
cave = Cave.objects.get(caveslug__slug = slug)
|
cave = Cave.objects.get(caveslug__slug = slug)
|
||||||
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
||||||
return render_with_context(request,'nonpublic.html', {'instance': cave})
|
return render(request,'nonpublic.html', {'instance': cave})
|
||||||
else:
|
else:
|
||||||
return render_with_context(request,'cave_entrances.html', {'cave': cave})
|
return render(request,'cave_entrances.html', {'cave': cave})
|
||||||
|
|
||||||
def caveDescription(request, slug):
|
def caveDescription(request, slug):
|
||||||
cave = Cave.objects.get(caveslug__slug = slug)
|
cave = Cave.objects.get(caveslug__slug = slug)
|
||||||
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
||||||
return render_with_context(request,'nonpublic.html', {'instance': cave})
|
return render(request,'nonpublic.html', {'instance': cave})
|
||||||
else:
|
else:
|
||||||
return render_with_context(request,'cave_uground_description.html', {'cave': cave})
|
return render(request,'cave_uground_description.html', {'cave': cave})
|
||||||
|
|
||||||
def caveQMs(request, slug):
|
def caveQMs(request, slug):
|
||||||
cave = Cave.objects.get(caveslug__slug = slug)
|
cave = Cave.objects.get(caveslug__slug = slug)
|
||||||
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
||||||
return render_with_context(request,'nonpublic.html', {'instance': cave})
|
return render(request,'nonpublic.html', {'instance': cave})
|
||||||
else:
|
else:
|
||||||
return render_with_context(request,'cave_qms.html', {'cave': cave})
|
return render(request,'cave_qms.html', {'cave': cave})
|
||||||
def caveLogbook(request, slug):
|
def caveLogbook(request, slug):
|
||||||
cave = Cave.objects.get(caveslug__slug = slug)
|
cave = Cave.objects.get(caveslug__slug = slug)
|
||||||
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
||||||
return render_with_context(request,'nonpublic.html', {'instance': cave})
|
return render(request,'nonpublic.html', {'instance': cave})
|
||||||
else:
|
else:
|
||||||
return render_with_context(request,'cave_logbook.html', {'cave': cave})
|
return render(request,'cave_logbook.html', {'cave': cave})
|
||||||
|
|
||||||
def caveSlug(request, slug):
|
def caveSlug(request, slug):
|
||||||
cave = Cave.objects.get(caveslug__slug = slug)
|
cave = Cave.objects.get(caveslug__slug = slug)
|
||||||
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated():
|
||||||
return render_with_context(request,'nonpublic.html', {'instance': cave, 'cave_editable': slug})
|
return render(request,'nonpublic.html', {'instance': cave, 'cave_editable': slug})
|
||||||
else:
|
else:
|
||||||
return render_with_context(request,'cave.html', {'cave': cave, 'cave_editable': slug})
|
return render(request,'cave.html', {'cave': cave, 'cave_editable': slug})
|
||||||
|
|
||||||
@login_required_if_public
|
@login_required_if_public
|
||||||
def edit_cave(request, slug=None):
|
def edit_cave(request, slug=None):
|
||||||
@@ -171,7 +159,7 @@ def edit_cave(request, slug=None):
|
|||||||
ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all())
|
ceFormSet = CaveAndEntranceFormSet(queryset=cave.caveandentrance_set.all())
|
||||||
versionControlForm = VersionControlCommentForm()
|
versionControlForm = VersionControlCommentForm()
|
||||||
|
|
||||||
return render_with_context(request,
|
return render(request,
|
||||||
'editcave2.html',
|
'editcave2.html',
|
||||||
{'form': form,
|
{'form': form,
|
||||||
'caveAndEntranceFormSet': ceFormSet,
|
'caveAndEntranceFormSet': ceFormSet,
|
||||||
@@ -215,7 +203,7 @@ def editEntrance(request, caveslug, slug=None):
|
|||||||
entletter = EntranceLetterForm(request.POST)
|
entletter = EntranceLetterForm(request.POST)
|
||||||
else:
|
else:
|
||||||
entletter = None
|
entletter = None
|
||||||
return render_with_context(request,
|
return render(request,
|
||||||
'editentrance.html',
|
'editentrance.html',
|
||||||
{'form': form,
|
{'form': form,
|
||||||
'versionControlForm': versionControlForm,
|
'versionControlForm': versionControlForm,
|
||||||
@@ -226,7 +214,7 @@ def qm(request,cave_id,qm_id,year,grade=None):
|
|||||||
year=int(year)
|
year=int(year)
|
||||||
try:
|
try:
|
||||||
qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year)
|
qm=getCave(cave_id).get_QMs().get(number=qm_id,found_by__date__year=year)
|
||||||
return render_with_context(request,'qm.html',locals())
|
return render(request,'qm.html',locals())
|
||||||
|
|
||||||
except QM.DoesNotExist:
|
except QM.DoesNotExist:
|
||||||
url=urlparse.urljoin(settings.URL_ROOT, r'/admin/core/qm/add/'+'?'+ r'number=' + qm_id)
|
url=urlparse.urljoin(settings.URL_ROOT, r'/admin/core/qm/add/'+'?'+ r'number=' + qm_id)
|
||||||
@@ -239,16 +227,16 @@ def qm(request,cave_id,qm_id,year,grade=None):
|
|||||||
def ent(request, cave_id, ent_letter):
|
def ent(request, cave_id, ent_letter):
|
||||||
cave = Cave.objects.filter(kataster_number = cave_id)[0]
|
cave = Cave.objects.filter(kataster_number = cave_id)[0]
|
||||||
cave_and_ent = CaveAndEntrance.objects.filter(cave = cave).filter(entrance_letter = ent_letter)[0]
|
cave_and_ent = CaveAndEntrance.objects.filter(cave = cave).filter(entrance_letter = ent_letter)[0]
|
||||||
return render_with_context(request,'entrance.html', {'cave': cave,
|
return render(request,'entrance.html', {'cave': cave,
|
||||||
'entrance': cave_and_ent.entrance,
|
'entrance': cave_and_ent.entrance,
|
||||||
'letter': cave_and_ent.entrance_letter,})
|
'letter': cave_and_ent.entrance_letter,})
|
||||||
|
|
||||||
def entranceSlug(request, slug):
|
def entranceSlug(request, slug):
|
||||||
entrance = Entrance.objects.get(entranceslug__slug = slug)
|
entrance = Entrance.objects.get(entranceslug__slug = slug)
|
||||||
if entrance.non_public and not request.user.is_authenticated():
|
if entrance.non_public and not request.user.is_authenticated():
|
||||||
return render_with_context(request,'nonpublic.html', {'instance': entrance})
|
return render(request,'nonpublic.html', {'instance': entrance})
|
||||||
else:
|
else:
|
||||||
return render_with_context(request,'entranceslug.html', {'entrance': entrance})
|
return render(request,'entranceslug.html', {'entrance': entrance})
|
||||||
|
|
||||||
def survexblock(request, survexpath):
|
def survexblock(request, survexpath):
|
||||||
survexpath = re.sub("/", ".", survexpath)
|
survexpath = re.sub("/", ".", survexpath)
|
||||||
@@ -256,12 +244,12 @@ def survexblock(request, survexpath):
|
|||||||
survexblock = models.SurvexBlock.objects.get(survexpath=survexpath)
|
survexblock = models.SurvexBlock.objects.get(survexpath=survexpath)
|
||||||
#ftext = survexblock.filecontents()
|
#ftext = survexblock.filecontents()
|
||||||
ftext = survexblock.text
|
ftext = survexblock.text
|
||||||
return render_with_context(request,'survexblock.html', {'survexblock':survexblock, 'ftext':ftext, })
|
return render(request,'survexblock.html', {'survexblock':survexblock, 'ftext':ftext, })
|
||||||
|
|
||||||
def surveyindex(request):
|
def surveyindex(request):
|
||||||
surveys=Survey.objects.all()
|
surveys=Survey.objects.all()
|
||||||
expeditions=Expedition.objects.order_by("-year")
|
expeditions=Expedition.objects.order_by("-year")
|
||||||
return render_with_context(request,'survey.html',locals())
|
return render(request,'survey.html',locals())
|
||||||
|
|
||||||
def survey(request,year,wallet_number):
|
def survey(request,year,wallet_number):
|
||||||
surveys=Survey.objects.all()
|
surveys=Survey.objects.all()
|
||||||
@@ -274,19 +262,19 @@ def survey(request,year,wallet_number):
|
|||||||
planSketches=current_survey.scannedimage_set.filter(contents='plan')
|
planSketches=current_survey.scannedimage_set.filter(contents='plan')
|
||||||
elevationSketches=current_survey.scannedimage_set.filter(contents='elevation')
|
elevationSketches=current_survey.scannedimage_set.filter(contents='elevation')
|
||||||
|
|
||||||
return render_with_context(request,'survey.html', locals())
|
return render(request,'survey.html', locals())
|
||||||
|
|
||||||
def cave_description(request, cavedescription_name):
|
def cave_description(request, cavedescription_name):
|
||||||
cave_description = get_object_or_404(CaveDescription, short_name = cavedescription_name)
|
cave_description = get_object_or_404(CaveDescription, short_name = cavedescription_name)
|
||||||
return render_with_context(request,'cave_description.html', locals())
|
return render(request,'cave_description.html', locals())
|
||||||
|
|
||||||
def get_entrances(request, caveslug):
|
def get_entrances(request, caveslug):
|
||||||
cave = Cave.objects.get(caveslug__slug = caveslug)
|
cave = Cave.objects.get(caveslug__slug = caveslug)
|
||||||
return render_with_context(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
|
return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
|
||||||
|
|
||||||
def get_qms(request, caveslug):
|
def get_qms(request, caveslug):
|
||||||
cave = Cave.objects.get(caveslug__slug = caveslug)
|
cave = Cave.objects.get(caveslug__slug = caveslug)
|
||||||
return render_with_context(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
|
return render(request,'options.html', {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]})
|
||||||
|
|
||||||
areanames = [
|
areanames = [
|
||||||
#('', 'Location unclear'),
|
#('', 'Location unclear'),
|
||||||
@@ -324,7 +312,7 @@ def prospecting(request):
|
|||||||
caves = list(a.cave_set.all())
|
caves = list(a.cave_set.all())
|
||||||
caves.sort(caveCmp)
|
caves.sort(caveCmp)
|
||||||
areas.append((name, a, caves))
|
areas.append((name, a, caves))
|
||||||
return render_with_context(request, 'prospecting.html', {"areas": areas})
|
return render(request, 'prospecting.html', {"areas": areas})
|
||||||
|
|
||||||
# Parameters for big map and zoomed subarea maps:
|
# Parameters for big map and zoomed subarea maps:
|
||||||
# big map first (zoom factor ignored)
|
# big map first (zoom factor ignored)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response, render
|
||||||
from troggle.core.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry, SurvexBlock
|
from troggle.core.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry, SurvexBlock
|
||||||
import troggle.core.models as models
|
import troggle.core.models as models
|
||||||
import troggle.settings as settings
|
import troggle.settings as settings
|
||||||
@@ -9,7 +9,6 @@ from troggle.core.forms import getTripForm#, get_name, PersonForm
|
|||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from django.http import HttpResponseRedirect, HttpResponse
|
from django.http import HttpResponseRedirect, HttpResponse
|
||||||
from django.template import Context, loader
|
from django.template import Context, loader
|
||||||
from utils import render_with_context
|
|
||||||
import os.path
|
import os.path
|
||||||
import troggle.parsers.logbooks as logbookparsers
|
import troggle.parsers.logbooks as logbookparsers
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
@@ -55,7 +54,7 @@ def personindex(request):
|
|||||||
if person.bisnotable():
|
if person.bisnotable():
|
||||||
notablepersons.append(person)
|
notablepersons.append(person)
|
||||||
|
|
||||||
return render_with_context(request,'personindex.html', {'persons': persons, 'personss':personss, 'notablepersons':notablepersons, })
|
return render(request,'personindex.html', {'persons': persons, 'personss':personss, 'notablepersons':notablepersons})
|
||||||
|
|
||||||
|
|
||||||
def expedition(request, expeditionname):
|
def expedition(request, expeditionname):
|
||||||
@@ -75,10 +74,9 @@ def expedition(request, expeditionname):
|
|||||||
prow.append(pcell)
|
prow.append(pcell)
|
||||||
personexpeditiondays.append({"personexpedition":personexpedition, "personrow":prow})
|
personexpeditiondays.append({"personexpedition":personexpedition, "personrow":prow})
|
||||||
|
|
||||||
message = ""
|
|
||||||
if "reload" in request.GET:
|
if "reload" in request.GET:
|
||||||
message = LoadLogbookForExpedition(this_expedition)
|
LoadLogbookForExpedition(this_expedition)
|
||||||
return render_with_context(request,'expedition.html', {'expedition': this_expedition, 'expeditions':expeditions, 'personexpeditiondays':personexpeditiondays, 'message':message, 'settings':settings, 'dateditems': dateditems })
|
return render(request,'expedition.html', {'expedition': this_expedition, 'expeditions':expeditions, 'personexpeditiondays':personexpeditiondays, 'settings':settings, 'dateditems': dateditems })
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return ('expedition', (expedition.year))
|
return ('expedition', (expedition.year))
|
||||||
@@ -103,13 +101,13 @@ def person(request, first_name='', last_name='', ):
|
|||||||
this_person.save()
|
this_person.save()
|
||||||
return HttpResponseRedirect(reverse('profiles_select_profile'))
|
return HttpResponseRedirect(reverse('profiles_select_profile'))
|
||||||
|
|
||||||
return render_with_context(request,'person.html', {'person': this_person, })
|
return render(request,'person.html', {'person': this_person, })
|
||||||
|
|
||||||
|
|
||||||
def GetPersonChronology(personexpedition):
|
def GetPersonChronology(personexpedition):
|
||||||
res = { }
|
res = { }
|
||||||
for persontrip in personexpedition.persontrip_set.all():
|
for persontrip in personexpedition.persontrip_set.all():
|
||||||
a = res.setdefault(persontrip.date, { })
|
a = res.setdefault(persontrip.logbook_entry.date, { })
|
||||||
a.setdefault("persontrips", [ ]).append(persontrip)
|
a.setdefault("persontrips", [ ]).append(persontrip)
|
||||||
|
|
||||||
for personrole in personexpedition.survexpersonrole_set.all():
|
for personrole in personexpedition.survexpersonrole_set.all():
|
||||||
@@ -136,17 +134,17 @@ def personexpedition(request, first_name='', last_name='', year=''):
|
|||||||
this_expedition = Expedition.objects.get(year=year)
|
this_expedition = Expedition.objects.get(year=year)
|
||||||
personexpedition = person.personexpedition_set.get(expedition=this_expedition)
|
personexpedition = person.personexpedition_set.get(expedition=this_expedition)
|
||||||
personchronology = GetPersonChronology(personexpedition)
|
personchronology = GetPersonChronology(personexpedition)
|
||||||
return render_with_context(request,'personexpedition.html', {'personexpedition': personexpedition, 'personchronology':personchronology})
|
return render(request,'personexpedition.html', {'personexpedition': personexpedition, 'personchronology':personchronology})
|
||||||
|
|
||||||
|
|
||||||
def logbookentry(request, date, slug):
|
def logbookentry(request, date, slug):
|
||||||
this_logbookentry = LogbookEntry.objects.filter(date=date, slug=slug)
|
this_logbookentry = LogbookEntry.objects.filter(date=date, slug=slug)
|
||||||
|
|
||||||
if len(this_logbookentry)>1:
|
if len(this_logbookentry)>1:
|
||||||
return render_with_context(request, 'object_list.html',{'object_list':this_logbookentry})
|
return render(request, 'object_list.html',{'object_list':this_logbookentry})
|
||||||
else:
|
else:
|
||||||
this_logbookentry=this_logbookentry[0]
|
this_logbookentry=this_logbookentry[0]
|
||||||
return render_with_context(request, 'logbookentry.html', {'logbookentry': this_logbookentry})
|
return render(request, 'logbookentry.html', {'logbookentry': this_logbookentry})
|
||||||
|
|
||||||
|
|
||||||
def logbookSearch(request, extra):
|
def logbookSearch(request, extra):
|
||||||
@@ -157,14 +155,14 @@ def logbookSearch(request, extra):
|
|||||||
entry_query = search.get_query(query_string, ['text','title',])
|
entry_query = search.get_query(query_string, ['text','title',])
|
||||||
found_entries = LogbookEntry.objects.filter(entry_query)
|
found_entries = LogbookEntry.objects.filter(entry_query)
|
||||||
|
|
||||||
return render_with_context(request,'logbooksearch.html',
|
return render(request,'logbooksearch.html',
|
||||||
{ 'query_string': query_string, 'found_entries': found_entries, })
|
{ 'query_string': query_string, 'found_entries': found_entries, })
|
||||||
#context_instance=RequestContext(request))
|
#context_instance=RequestContext(request))
|
||||||
|
|
||||||
def personForm(request,pk):
|
def personForm(request,pk):
|
||||||
person=Person.objects.get(pk=pk)
|
person=Person.objects.get(pk=pk)
|
||||||
form=PersonForm(instance=person)
|
form=PersonForm(instance=person)
|
||||||
return render_with_context(request,'personform.html', {'form':form,})
|
return render(request,'personform.html', {'form':form,})
|
||||||
|
|
||||||
|
|
||||||
def experimental(request):
|
def experimental(request):
|
||||||
@@ -181,7 +179,7 @@ def experimental(request):
|
|||||||
|
|
||||||
survexlegs = models.SurvexLeg.objects.all()
|
survexlegs = models.SurvexLeg.objects.all()
|
||||||
totalsurvexlength = sum([survexleg.tape for survexleg in survexlegs])
|
totalsurvexlength = sum([survexleg.tape for survexleg in survexlegs])
|
||||||
return render_with_context(request, 'experimental.html', { "nsurvexlegs":len(survexlegs), "totalsurvexlength":totalsurvexlength, "legsbyexpo":legsbyexpo })
|
return render(request, 'experimental.html', { "nsurvexlegs":len(survexlegs), "totalsurvexlength":totalsurvexlength, "legsbyexpo":legsbyexpo })
|
||||||
|
|
||||||
@login_required_if_public
|
@login_required_if_public
|
||||||
def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
|
def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
|
||||||
@@ -240,7 +238,7 @@ def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
|
|||||||
tripForm = TripForm() # An unbound form
|
tripForm = TripForm() # An unbound form
|
||||||
personTripFormSet = PersonTripFormSet()
|
personTripFormSet = PersonTripFormSet()
|
||||||
|
|
||||||
return render_with_context(request, 'newlogbookentry.html', {
|
return render(request, 'newlogbookentry.html', {
|
||||||
'tripForm': tripForm,
|
'tripForm': tripForm,
|
||||||
'personTripFormSet': personTripFormSet,
|
'personTripFormSet': personTripFormSet,
|
||||||
|
|
||||||
@@ -262,9 +260,8 @@ def delLogbookEntry(lbe):
|
|||||||
|
|
||||||
def get_people(request, expeditionslug):
|
def get_people(request, expeditionslug):
|
||||||
exp = Expedition.objects.get(year = expeditionslug)
|
exp = Expedition.objects.get(year = expeditionslug)
|
||||||
return render_with_context(request,'options.html', {"items": [(pe.slug, pe.name) for pe in exp.personexpedition_set.all()]})
|
return render(request,'options.html', {"items": [(pe.slug, pe.name) for pe in exp.personexpedition_set.all()]})
|
||||||
|
|
||||||
def get_logbook_entries(request, expeditionslug):
|
def get_logbook_entries(request, expeditionslug):
|
||||||
exp = Expedition.objects.get(year = expeditionslug)
|
exp = Expedition.objects.get(year = expeditionslug)
|
||||||
return render_with_context(request,'options.html', {"items": [(le.slug, "%s - %s" % (le.date, le.title)) for le in exp.logbookentry_set.all()]})
|
return render(request,'options.html', {"items": [(le.slug, "%s - %s" % (le.date, le.title)) for le in exp.logbookentry_set.all()]})
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ from django.conf import settings
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.template import loader, Context
|
from django.template import loader, Context
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
from django.shortcuts import render
|
||||||
import databaseReset
|
import databaseReset
|
||||||
import re
|
import re
|
||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
from utils import render_with_context
|
|
||||||
from troggle.core.models import *
|
from troggle.core.models import *
|
||||||
from troggle.helper import login_required_if_public
|
from troggle.helper import login_required_if_public
|
||||||
|
|
||||||
@@ -21,18 +21,18 @@ def stats(request):
|
|||||||
statsDict['caveCount'] = int(Cave.objects.count())
|
statsDict['caveCount'] = int(Cave.objects.count())
|
||||||
statsDict['personCount'] = int(Person.objects.count())
|
statsDict['personCount'] = int(Person.objects.count())
|
||||||
statsDict['logbookEntryCount'] = int(LogbookEntry.objects.count())
|
statsDict['logbookEntryCount'] = int(LogbookEntry.objects.count())
|
||||||
return render_with_context(request,'statistics.html', statsDict)
|
return render(request,'statistics.html', statsDict)
|
||||||
|
|
||||||
def frontpage(request):
|
def frontpage(request):
|
||||||
if request.user.is_authenticated():
|
if request.user.is_authenticated():
|
||||||
return render_with_context(request,'tasks.html')
|
return render(request,'tasks.html')
|
||||||
|
|
||||||
expeditions = Expedition.objects.order_by("-year")
|
expeditions = Expedition.objects.order_by("-year")
|
||||||
logbookentry = LogbookEntry
|
logbookentry = LogbookEntry
|
||||||
cave = Cave
|
cave = Cave
|
||||||
photo = DPhoto
|
photo = DPhoto
|
||||||
from django.contrib.admin.templatetags import log
|
from django.contrib.admin.templatetags import log
|
||||||
return render_with_context(request,'frontpage.html', locals())
|
return render(request,'frontpage.html', locals())
|
||||||
|
|
||||||
def todo(request):
|
def todo(request):
|
||||||
message = "no test message" #reverse('personn', kwargs={"name":"hkjhjh"})
|
message = "no test message" #reverse('personn', kwargs={"name":"hkjhjh"})
|
||||||
@@ -45,7 +45,7 @@ def todo(request):
|
|||||||
|
|
||||||
expeditions = Expedition.objects.order_by("-year")
|
expeditions = Expedition.objects.order_by("-year")
|
||||||
totallogbookentries = LogbookEntry.objects.count()
|
totallogbookentries = LogbookEntry.objects.count()
|
||||||
return render_with_context(request,'index.html', {'expeditions':expeditions, 'all':'all', 'totallogbookentries':totallogbookentries, "message":message})
|
return render(request,'index.html', {'expeditions':expeditions, 'all':'all', 'totallogbookentries':totallogbookentries, "message":message})
|
||||||
|
|
||||||
|
|
||||||
def controlPanel(request):
|
def controlPanel(request):
|
||||||
@@ -59,27 +59,27 @@ def controlPanel(request):
|
|||||||
databaseReset.make_dirs()
|
databaseReset.make_dirs()
|
||||||
for item in importlist:
|
for item in importlist:
|
||||||
if item in request.POST:
|
if item in request.POST:
|
||||||
print "running"+ " databaseReset."+item+"()"
|
print("running"+ " databaseReset."+item+"()")
|
||||||
exec "databaseReset."+item+"()"
|
exec("databaseReset."+item+"()")
|
||||||
jobs_completed.append(item)
|
jobs_completed.append(item)
|
||||||
else:
|
else:
|
||||||
if request.user.is_authenticated(): #The user is logged in, but is not a superuser.
|
if request.user.is_authenticated(): #The user is logged in, but is not a superuser.
|
||||||
return render_with_context(request,'controlPanel.html', {'caves':Cave.objects.all(),'error':'You must be a superuser to use that feature.'})
|
return render(request,'controlPanel.html', {'caves':Cave.objects.all(),'error':'You must be a superuser to use that feature.'})
|
||||||
else:
|
else:
|
||||||
return HttpResponseRedirect(reverse('auth_login'))
|
return HttpResponseRedirect(reverse('auth_login'))
|
||||||
|
|
||||||
return render_with_context(request,'controlPanel.html', {'caves':Cave.objects.all(),'expeditions':Expedition.objects.all(),'jobs_completed':jobs_completed})
|
return render(request,'controlPanel.html', {'caves':Cave.objects.all(),'expeditions':Expedition.objects.all(),'jobs_completed':jobs_completed})
|
||||||
|
|
||||||
def downloadCavetab(request):
|
def downloadCavetab(request):
|
||||||
from export import tocavetab
|
from export import tocavetab
|
||||||
response = HttpResponse(mimetype='text/csv')
|
response = HttpResponse(content_type='text/csv')
|
||||||
response['Content-Disposition'] = 'attachment; filename=CAVETAB2.CSV'
|
response['Content-Disposition'] = 'attachment; filename=CAVETAB2.CSV'
|
||||||
tocavetab.writeCaveTab(response)
|
tocavetab.writeCaveTab(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def downloadSurveys(request):
|
def downloadSurveys(request):
|
||||||
from export import tosurveys
|
from export import tosurveys
|
||||||
response = HttpResponse(mimetype='text/csv')
|
response = HttpResponse(content_type='text/csv')
|
||||||
response['Content-Disposition'] = 'attachment; filename=Surveys.csv'
|
response['Content-Disposition'] = 'attachment; filename=Surveys.csv'
|
||||||
tosurveys.writeCaveTab(response)
|
tosurveys.writeCaveTab(response)
|
||||||
return response
|
return response
|
||||||
@@ -94,20 +94,19 @@ def downloadLogbook(request,year=None,extension=None,queryset=None):
|
|||||||
logbook_entries=queryset
|
logbook_entries=queryset
|
||||||
filename='logbook'
|
filename='logbook'
|
||||||
else:
|
else:
|
||||||
|
response = HttpResponse(content_type='text/plain')
|
||||||
return response(r"Error: Logbook downloader doesn't know what year you want")
|
return response(r"Error: Logbook downloader doesn't know what year you want")
|
||||||
|
|
||||||
if 'year' in request.GET:
|
if 'year' in request.GET:
|
||||||
year=request.GET['year']
|
year=request.GET['year']
|
||||||
if 'extension' in request.GET:
|
if 'extension' in request.GET:
|
||||||
extension=request.GET['extension']
|
extension=request.GET['extension']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if extension =='txt':
|
if extension =='txt':
|
||||||
response = HttpResponse(mimetype='text/plain')
|
response = HttpResponse(content_type='text/plain')
|
||||||
style='2008'
|
style='2008'
|
||||||
elif extension == 'html':
|
elif extension == 'html':
|
||||||
response = HttpResponse(mimetype='text/html')
|
response = HttpResponse(content_type='text/html')
|
||||||
style='2005'
|
style='2005'
|
||||||
|
|
||||||
template='logbook'+style+'style.'+extension
|
template='logbook'+style+'style.'+extension
|
||||||
@@ -124,11 +123,11 @@ def downloadQMs(request):
|
|||||||
try:
|
try:
|
||||||
cave=Cave.objects.get(kataster_number=request.GET['cave_id'])
|
cave=Cave.objects.get(kataster_number=request.GET['cave_id'])
|
||||||
except Cave.DoesNotExist:
|
except Cave.DoesNotExist:
|
||||||
cave=Cave.objects.get(name=cave_id)
|
cave=Cave.objects.get(name=request.GET['cave_id'])
|
||||||
|
|
||||||
from export import toqms
|
from export import toqms
|
||||||
|
|
||||||
response = HttpResponse(mimetype='text/csv')
|
response = HttpResponse(content_type='text/csv')
|
||||||
response['Content-Disposition'] = 'attachment; filename=qm.csv'
|
response['Content-Disposition'] = 'attachment; filename=qm.csv'
|
||||||
toqms.writeQmTable(response,cave)
|
toqms.writeQmTable(response,cave)
|
||||||
return response
|
return response
|
||||||
@@ -136,7 +135,7 @@ def downloadQMs(request):
|
|||||||
def ajax_test(request):
|
def ajax_test(request):
|
||||||
post_text = request.POST['post_data']
|
post_text = request.POST['post_data']
|
||||||
return HttpResponse("{'response_text': '"+post_text+" recieved.'}",
|
return HttpResponse("{'response_text': '"+post_text+" recieved.'}",
|
||||||
mimetype="application/json")
|
content_type="application/json")
|
||||||
|
|
||||||
def eyecandy(request):
|
def eyecandy(request):
|
||||||
return
|
return
|
||||||
@@ -144,9 +143,9 @@ def eyecandy(request):
|
|||||||
def ajax_QM_number(request):
|
def ajax_QM_number(request):
|
||||||
if request.method=='POST':
|
if request.method=='POST':
|
||||||
cave=Cave.objects.get(id=request.POST['cave'])
|
cave=Cave.objects.get(id=request.POST['cave'])
|
||||||
print cave
|
print(cave)
|
||||||
exp=Expedition.objects.get(pk=request.POST['year'])
|
exp=Expedition.objects.get(pk=request.POST['year'])
|
||||||
print exp
|
print(exp)
|
||||||
res=cave.new_QM_number(exp.year)
|
res=cave.new_QM_number(exp.year)
|
||||||
|
|
||||||
return HttpResponse(res)
|
return HttpResponse(res)
|
||||||
@@ -167,7 +166,7 @@ def logbook_entry_suggestions(request):
|
|||||||
#unwiki_QMs=re.findall(unwiki_QM_pattern,lbo.text)
|
#unwiki_QMs=re.findall(unwiki_QM_pattern,lbo.text)
|
||||||
unwiki_QMs=[m.groupdict() for m in unwiki_QM_pattern.finditer(lbo.text)]
|
unwiki_QMs=[m.groupdict() for m in unwiki_QM_pattern.finditer(lbo.text)]
|
||||||
|
|
||||||
print unwiki_QMs
|
print(unwiki_QMs)
|
||||||
for qm in unwiki_QMs:
|
for qm in unwiki_QMs:
|
||||||
#try:
|
#try:
|
||||||
if len(qm['year'])==2:
|
if len(qm['year'])==2:
|
||||||
@@ -180,7 +179,7 @@ def logbook_entry_suggestions(request):
|
|||||||
try:
|
try:
|
||||||
lbo=LogbookEntry.objects.get(date__year=qm['year'],title__icontains="placeholder for QMs in")
|
lbo=LogbookEntry.objects.get(date__year=qm['year'],title__icontains="placeholder for QMs in")
|
||||||
except:
|
except:
|
||||||
print "failed to get placeholder for year "+str(qm['year'])
|
print("failed to get placeholder for year "+str(qm['year']))
|
||||||
|
|
||||||
temp_QM=QM(found_by=lbo,number=qm['number'],grade=qm['grade'])
|
temp_QM=QM(found_by=lbo,number=qm['number'],grade=qm['grade'])
|
||||||
temp_QM.grade=qm['grade']
|
temp_QM.grade=qm['grade']
|
||||||
@@ -188,7 +187,7 @@ def logbook_entry_suggestions(request):
|
|||||||
#except:
|
#except:
|
||||||
#print 'failed'
|
#print 'failed'
|
||||||
|
|
||||||
print unwiki_QMs
|
print(unwiki_QMs)
|
||||||
|
|
||||||
|
|
||||||
#wikilink_QMs=re.findall(wikilink_QM_pattern,lbo.text)
|
#wikilink_QMs=re.findall(wikilink_QM_pattern,lbo.text)
|
||||||
@@ -199,10 +198,10 @@ def logbook_entry_suggestions(request):
|
|||||||
#for qm in wikilink_QMs:
|
#for qm in wikilink_QMs:
|
||||||
#Try to look up the QM.
|
#Try to look up the QM.
|
||||||
|
|
||||||
print 'got 208'
|
print('got 208')
|
||||||
any_suggestions=True
|
any_suggestions=True
|
||||||
print 'got 210'
|
print('got 210')
|
||||||
return render_with_context(request,'suggestions.html',
|
return render(request,'suggestions.html',
|
||||||
{
|
{
|
||||||
'unwiki_QMs':unwiki_QMs,
|
'unwiki_QMs':unwiki_QMs,
|
||||||
'any_suggestions':any_suggestions
|
'any_suggestions':any_suggestions
|
||||||
@@ -262,7 +261,7 @@ def newFile(request, pslug = None):
|
|||||||
# else:
|
# else:
|
||||||
# fileform = UploadFileForm() # An unbound form
|
# fileform = UploadFileForm() # An unbound form
|
||||||
|
|
||||||
return render_with_context(request, 'editfile.html', {
|
return render(request, 'editfile.html', {
|
||||||
'fileForm': fileform,
|
'fileForm': fileform,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.http import HttpResponseRedirect, HttpResponse
|
from django.http import HttpResponseRedirect, HttpResponse
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response, render
|
||||||
|
from django.core.context_processors import csrf
|
||||||
from django.http import HttpResponse, Http404
|
from django.http import HttpResponse, Http404
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@@ -40,62 +41,6 @@ survextemplatefile = """; Locn: Totes Gebirge, Austria - Loser/Augst-Eck Plateau
|
|||||||
|
|
||||||
*end [surveyname]"""
|
*end [surveyname]"""
|
||||||
|
|
||||||
|
|
||||||
def millenialcaves(request):
|
|
||||||
cavesdir = os.path.join(settings.SURVEX_DATA, "caves-1623")
|
|
||||||
#cavesdircontents = { }
|
|
||||||
|
|
||||||
onefilecaves = [ ]
|
|
||||||
multifilecaves = [ ]
|
|
||||||
subdircaves = [ ]
|
|
||||||
|
|
||||||
millenialcaves = [ ]
|
|
||||||
|
|
||||||
|
|
||||||
# go through the list and identify the contents of each cave directory
|
|
||||||
for cavedir in os.listdir(cavesdir):
|
|
||||||
if cavedir in ["144", "40"]: #????? RW
|
|
||||||
continue
|
|
||||||
|
|
||||||
gcavedir = os.path.join(cavesdir, cavedir) #directory od 'large' cave
|
|
||||||
|
|
||||||
if os.path.isdir(gcavedir) and cavedir[0] != ".":
|
|
||||||
subdirs, subsvx = identifycavedircontents(gcavedir)
|
|
||||||
survdirobj = [ ]
|
|
||||||
|
|
||||||
for lsubsvx in subsvx:
|
|
||||||
survdirobj.append(("caves-1623/"+cavedir+"/"+lsubsvx, lsubsvx))
|
|
||||||
|
|
||||||
# caves with subdirectories
|
|
||||||
if subdirs:
|
|
||||||
subsurvdirs = [ ]
|
|
||||||
for subdir in subdirs:
|
|
||||||
dsubdirs, dsubsvx = identifycavedircontents(os.path.join(gcavedir, subdir))
|
|
||||||
assert not dsubdirs
|
|
||||||
lsurvdirobj = [ ]
|
|
||||||
for lsubsvx in dsubsvx:
|
|
||||||
lsurvdirobj.append(("caves-1623/"+cavedir+"/"+subdir+"/"+lsubsvx, lsubsvx))
|
|
||||||
subsurvdirs.append((lsurvdirobj[0], lsurvdirobj[1:]))
|
|
||||||
subdircaves.append((cavedir, (survdirobj[0], survdirobj[1:]), subsurvdirs))
|
|
||||||
|
|
||||||
# multifile caves
|
|
||||||
elif len(survdirobj) > 1:
|
|
||||||
multifilecaves.append((survdirobj[0], survdirobj[1:]))
|
|
||||||
# single file caves
|
|
||||||
else:
|
|
||||||
#print("survdirobj = ")
|
|
||||||
#print(survdirobj)
|
|
||||||
onefilecaves.append(survdirobj[0])
|
|
||||||
|
|
||||||
caves = Cave.objects.all()
|
|
||||||
|
|
||||||
return render_to_response('millenialcaves.html', {'settings': settings , 'caves':caves , "onefilecaves":onefilecaves, "multifilecaves":multifilecaves, "subdircaves":subdircaves })
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ReplaceTabs(stext):
|
def ReplaceTabs(stext):
|
||||||
res = [ ]
|
res = [ ]
|
||||||
@@ -228,13 +173,14 @@ def svx(request, survex_file):
|
|||||||
'difflist': difflist,
|
'difflist': difflist,
|
||||||
'logmessage':logmessage,
|
'logmessage':logmessage,
|
||||||
'form':form}
|
'form':form}
|
||||||
|
vmap.update(csrf(request))
|
||||||
if outputtype == "ajax":
|
if outputtype == "ajax":
|
||||||
return render_to_response('svxfiledifflistonly.html', vmap)
|
return render_to_response('svxfiledifflistonly.html', vmap)
|
||||||
return render_to_response('svxfile.html', vmap)
|
return render_to_response('svxfile.html', vmap)
|
||||||
|
|
||||||
def svxraw(request, survex_file):
|
def svxraw(request, survex_file):
|
||||||
svx = open(os.path.join(settings.SURVEX_DATA, survex_file+".svx"), "rb")
|
svx = open(os.path.join(settings.SURVEX_DATA, survex_file+".svx"), "rb")
|
||||||
return HttpResponse(svx, mimetype="text")
|
return HttpResponse(svx, content_type="text")
|
||||||
|
|
||||||
|
|
||||||
# The cavern running function
|
# The cavern running function
|
||||||
@@ -249,20 +195,20 @@ def threed(request, survex_file):
|
|||||||
process(survex_file)
|
process(survex_file)
|
||||||
try:
|
try:
|
||||||
threed = open(settings.SURVEX_DATA + survex_file + ".3d", "rb")
|
threed = open(settings.SURVEX_DATA + survex_file + ".3d", "rb")
|
||||||
return HttpResponse(threed, mimetype="model/3d")
|
return HttpResponse(threed, content_type="model/3d")
|
||||||
except:
|
except:
|
||||||
log = open(settings.SURVEX_DATA + survex_file + ".log", "rb")
|
log = open(settings.SURVEX_DATA + survex_file + ".log", "rb")
|
||||||
return HttpResponse(log, mimetype="text")
|
return HttpResponse(log, content_type="text")
|
||||||
|
|
||||||
def log(request, survex_file):
|
def log(request, survex_file):
|
||||||
process(survex_file)
|
process(survex_file)
|
||||||
log = open(settings.SURVEX_DATA + survex_file + ".log", "rb")
|
log = open(settings.SURVEX_DATA + survex_file + ".log", "rb")
|
||||||
return HttpResponse(log, mimetype="text")
|
return HttpResponse(log, content_type="text")
|
||||||
|
|
||||||
def err(request, survex_file):
|
def err(request, survex_file):
|
||||||
process(survex_file)
|
process(survex_file)
|
||||||
err = open(settings.SURVEX_DATA + survex_file + ".err", "rb")
|
err = open(settings.SURVEX_DATA + survex_file + ".err", "rb")
|
||||||
return HttpResponse(err, mimetype="text")
|
return HttpResponse(err, content_type="text")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ def make_dirs():
|
|||||||
|
|
||||||
def import_caves():
|
def import_caves():
|
||||||
import parsers.caves
|
import parsers.caves
|
||||||
print("importing caves")
|
print("Importing Caves")
|
||||||
parsers.caves.readcaves()
|
parsers.caves.readcaves()
|
||||||
|
|
||||||
def import_people():
|
def import_people():
|
||||||
@@ -81,6 +81,15 @@ def import_tunnelfiles():
|
|||||||
parsers.surveys.LoadTunnelFiles()
|
parsers.surveys.LoadTunnelFiles()
|
||||||
|
|
||||||
|
|
||||||
|
def rebuild():
|
||||||
|
""" Wipe the troggle database and sets up structure but imports nothing
|
||||||
|
"""
|
||||||
|
reload_db()
|
||||||
|
make_dirs()
|
||||||
|
pageredirects()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def reset():
|
def reset():
|
||||||
""" Wipe the troggle database and import everything from legacy data
|
""" Wipe the troggle database and import everything from legacy data
|
||||||
"""
|
"""
|
||||||
@@ -90,9 +99,9 @@ def reset():
|
|||||||
import_caves()
|
import_caves()
|
||||||
import_people()
|
import_people()
|
||||||
import_surveyscans()
|
import_surveyscans()
|
||||||
import_survex()
|
|
||||||
import_logbooks()
|
import_logbooks()
|
||||||
import_QMs()
|
import_QMs()
|
||||||
|
import_survex()
|
||||||
try:
|
try:
|
||||||
import_tunnelfiles()
|
import_tunnelfiles()
|
||||||
except:
|
except:
|
||||||
@@ -109,10 +118,10 @@ def import_auto_logbooks():
|
|||||||
for lbe in troggle.core.models.LogbookEntry.objects.all():
|
for lbe in troggle.core.models.LogbookEntry.objects.all():
|
||||||
lbe.delete()
|
lbe.delete()
|
||||||
for expedition in troggle.core.models.Expedition.objects.all():
|
for expedition in troggle.core.models.Expedition.objects.all():
|
||||||
directory = os.path.join(settings.EXPOWEB,
|
directory = os.path.join(settings.EXPOWEB,
|
||||||
"years",
|
"years",
|
||||||
expedition.year,
|
expedition.year,
|
||||||
"autologbook")
|
"autologbook")
|
||||||
for root, dirs, filenames in os.walk(directory):
|
for root, dirs, filenames in os.walk(directory):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
print(os.path.join(root, filename))
|
print(os.path.join(root, filename))
|
||||||
@@ -159,22 +168,17 @@ def pageredirects():
|
|||||||
f = troggle.flatpages.models.Redirect(originalURL = oldURL, newURL = newURL)
|
f = troggle.flatpages.models.Redirect(originalURL = oldURL, newURL = newURL)
|
||||||
f.save()
|
f.save()
|
||||||
|
|
||||||
def writeCaves():
|
|
||||||
for cave in Cave.objects.all():
|
|
||||||
cave.writeDataFile()
|
|
||||||
for entrance in Entrance.objects.all():
|
|
||||||
entrance.writeDataFile()
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print("""Usage is 'python databaseReset.py <command>'
|
print("""Usage is 'python databaseReset.py <command>'
|
||||||
where command is:
|
where command is:
|
||||||
reset - this is normal usage, clear database and reread everything
|
rebuild - this reloads database and set up directories & redirects only
|
||||||
desc
|
reset - this is normal usage, clear database and reread everything from files - time-consuming
|
||||||
caves - read in the caves
|
desc - NOT WORKING: function resetdesc() missing
|
||||||
logbooks - read in the logbooks
|
caves - read in the caves
|
||||||
autologbooks
|
logbooks - read in the logbooks, but read in people first
|
||||||
dumplogbooks
|
autologbooks - read in autologbooks
|
||||||
people
|
dumplogbooks - write out autologbooks (not working?)
|
||||||
|
people - read in the people from folk.csv
|
||||||
QMs - read in the QM files
|
QMs - read in the QM files
|
||||||
resetend
|
resetend
|
||||||
scans - read in the scanned surveynotes
|
scans - read in the scanned surveynotes
|
||||||
@@ -182,7 +186,6 @@ def usage():
|
|||||||
survexpos
|
survexpos
|
||||||
surveys
|
surveys
|
||||||
tunnel - read in the Tunnel files
|
tunnel - read in the Tunnel files
|
||||||
writeCaves
|
|
||||||
""")
|
""")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@@ -195,9 +198,6 @@ if __name__ == "__main__":
|
|||||||
elif "scans" in sys.argv:
|
elif "scans" in sys.argv:
|
||||||
import_surveyscans()
|
import_surveyscans()
|
||||||
elif "caves" in sys.argv:
|
elif "caves" in sys.argv:
|
||||||
reload_db()
|
|
||||||
make_dirs()
|
|
||||||
pageredirects()
|
|
||||||
import_caves()
|
import_caves()
|
||||||
elif "people" in sys.argv:
|
elif "people" in sys.argv:
|
||||||
import_people()
|
import_people()
|
||||||
@@ -218,14 +218,14 @@ if __name__ == "__main__":
|
|||||||
import_descriptions()
|
import_descriptions()
|
||||||
parse_descriptions()
|
parse_descriptions()
|
||||||
elif "survex" in sys.argv:
|
elif "survex" in sys.argv:
|
||||||
management.call_command('syncdb', interactive=False) # this sets the path so that import settings works in import_survex
|
# management.call_command('syncdb', interactive=False) # this sets the path so that import settings works in import_survex
|
||||||
import_survex()
|
import_survex()
|
||||||
elif "survexpos" in sys.argv:
|
elif "survexpos" in sys.argv:
|
||||||
management.call_command('syncdb', interactive=False) # this sets the path so that import settings works in import_survex
|
# management.call_command('syncdb', interactive=False) # this sets the path so that import settings works in import_survex
|
||||||
import parsers.survex
|
import parsers.survex
|
||||||
parsers.survex.LoadPos()
|
parsers.survex.LoadPos()
|
||||||
elif "logbooks" in sys.argv:
|
elif "logbooks" in sys.argv:
|
||||||
management.call_command('syncdb', interactive=False) # this sets the path so that import settings works in import_survex
|
# management.call_command('syncdb', interactive=False) # this sets the path so that import settings works in import_survex
|
||||||
import_logbooks()
|
import_logbooks()
|
||||||
elif "autologbooks" in sys.argv:
|
elif "autologbooks" in sys.argv:
|
||||||
import_auto_logbooks()
|
import_auto_logbooks()
|
||||||
@@ -237,10 +237,10 @@ if __name__ == "__main__":
|
|||||||
import_surveys()
|
import_surveys()
|
||||||
elif "help" in sys.argv:
|
elif "help" in sys.argv:
|
||||||
usage()
|
usage()
|
||||||
|
elif "reload_db" in sys.argv:
|
||||||
|
reload_db()
|
||||||
|
elif "rebuild" in sys.argv:
|
||||||
|
rebuild()
|
||||||
else:
|
else:
|
||||||
print("%s not recognised" % sys.argv)
|
print("%s not recognised" % sys.argv)
|
||||||
usage()
|
usage()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
import os
|
|
||||||
import time
|
|
||||||
import settings
|
|
||||||
os.environ['PYTHONPATH'] = settings.PYTHON_PATH
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
|
|
||||||
from django.core import management
|
|
||||||
from django.db import connection
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.core.urlresolvers import reverse
|
|
||||||
from troggle.core.models import Cave, Entrance
|
|
||||||
from troggle.core.models import PersonM, SurveyM, CaveM, ExpeditionM, Logbook_entryM, Cave_descriptionM
|
|
||||||
import troggle.flatpages.models
|
|
||||||
|
|
||||||
databasename=settings.DATABASES['default']['NAME']
|
|
||||||
expouser=settings.EXPOUSER
|
|
||||||
expouserpass=settings.EXPOUSERPASS
|
|
||||||
expouseremail=settings.EXPOUSER_EMAIL
|
|
||||||
|
|
||||||
def destroy():
|
|
||||||
if settings.DATABASES['default']['ENGINE'] == 'django.db.backends.sqlite3':
|
|
||||||
try:
|
|
||||||
os.remove(databasename)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
cursor = connection.cursor()
|
|
||||||
cursor.execute("DROP DATABASE %s" % databasename)
|
|
||||||
cursor.execute("CREATE DATABASE %s" % databasename)
|
|
||||||
cursor.execute("ALTER DATABASE %s CHARACTER SET=utf8" % databasename)
|
|
||||||
cursor.execute("USE %s" % databasename)
|
|
||||||
management.call_command('syncdb', interactive=False)
|
|
||||||
user = User.objects.create_user(expouser, expouseremail, expouserpass)
|
|
||||||
user.is_staff = True
|
|
||||||
user.is_superuser = True
|
|
||||||
user.save()
|
|
||||||
print('Nuked the database and rebuilt it. You savage monster')
|
|
||||||
|
|
||||||
def gracefull_flush():
|
|
||||||
CaveM.objects.all().delete()
|
|
||||||
PersonM.objects.all().delete()
|
|
||||||
SurveyM.objects.all().delete()
|
|
||||||
ExpeditionM.objects.all().delete()
|
|
||||||
Logbook_entryM.objects.all().delete()
|
|
||||||
Cave_descriptionM.objects.all().delete()
|
|
||||||
print('Deleted contents of the database, ready to load new stuff :)')
|
|
||||||
|
|
||||||
def load_redirects():
|
|
||||||
for oldURL, newURL in [("indxal.htm", reverse("caveindex"))]:
|
|
||||||
f = troggle.flatpages.models.Redirect(originalURL = oldURL, newURL = newURL)
|
|
||||||
f.save()
|
|
||||||
|
|
||||||
def load_caves():
|
|
||||||
import troggle.parsers.cavesM
|
|
||||||
troggle.parsers.cavesM.load()
|
|
||||||
|
|
||||||
def load_all():
|
|
||||||
load_caves()
|
|
||||||
load_surveys()
|
|
||||||
load_people()
|
|
||||||
load_redirects()
|
|
||||||
load_links()
|
|
||||||
print('Loaded everything. Your database is ready to go :)')
|
|
||||||
|
|
||||||
|
|
||||||
def help():
|
|
||||||
print("""Usage is 'python databaseResetM.py <command>'
|
|
||||||
where command is:
|
|
||||||
UNLOADERS:
|
|
||||||
gracefull_flush - flushes new (M-style) databases contents but keeps tables existing
|
|
||||||
destroy - destroys entire database and builds empty tables
|
|
||||||
|
|
||||||
LOADERS:
|
|
||||||
load_all - loads all tables and links
|
|
||||||
load_caves - loads all caves
|
|
||||||
load_surveys - loads all surveys (corresponds to .svx files)
|
|
||||||
load_people - loads all people
|
|
||||||
load_redirects - load page redirects
|
|
||||||
load_links - loads links between classes (run last! can't link non-existent things)
|
|
||||||
|
|
||||||
OTHER:
|
|
||||||
help - displays this page
|
|
||||||
----------------
|
|
||||||
This is a new version of database management written by RW 2019
|
|
||||||
----------------
|
|
||||||
""")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
import troggle.core.models
|
|
||||||
import sys
|
|
||||||
import django
|
|
||||||
django.setup()
|
|
||||||
if "destroy" in sys.argv:
|
|
||||||
destroy()
|
|
||||||
elif "gracefull_flush" in sys.argv:
|
|
||||||
gracefull_flush()
|
|
||||||
|
|
||||||
elif "load_all" in sys.argv:
|
|
||||||
load_all()
|
|
||||||
elif "load_caves" in sys.argv:
|
|
||||||
load_caves()
|
|
||||||
elif "load_surveys" in sys.argv:
|
|
||||||
load_surveys()
|
|
||||||
elif "load_people" in sys.argv:
|
|
||||||
load_people()
|
|
||||||
elif "load_redirects" in sys.argv:
|
|
||||||
load_redirects()
|
|
||||||
elif "load_links" in sys.argv:
|
|
||||||
load_links()
|
|
||||||
elif "help" in sys.argv:
|
|
||||||
help()
|
|
||||||
else:
|
|
||||||
print("%s not recognised" % sys.argv)
|
|
||||||
help()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
85
debian/serversetup
vendored
Normal file
85
debian/serversetup
vendored
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
Instructions for setting up new expo debian server/VM
|
||||||
|
For Debian Stretch, June 2019.
|
||||||
|
|
||||||
|
adduser expo
|
||||||
|
apt install openssh-server mosh tmux mc zile emacs-nox mc most ncdu
|
||||||
|
apt install python-django apache2 mysql-server survex make rsync
|
||||||
|
apt install libjs-openlayers make
|
||||||
|
apt install git mercurial mercurial-server?
|
||||||
|
|
||||||
|
for boe:
|
||||||
|
apt install libcgi-session-perl libcrypt-passwdmd5-perl libfile-slurp-perl libgit-wrapper-perl libhtml-template-perl libhtml-template-pro-perl libmime-lite-perl libtext-password-pronounceable-perl libtime-parsedate-perl libuuid-tiny-perl libcrypt-cracklib-perl
|
||||||
|
|
||||||
|
obsolete-packages:
|
||||||
|
bins (move to jigl?) (for photos)
|
||||||
|
python-django 1.7
|
||||||
|
backports: survex therion
|
||||||
|
not-packaged: caveview
|
||||||
|
|
||||||
|
make these dirs available at top documentroot:
|
||||||
|
cuccfiles
|
||||||
|
expofiles
|
||||||
|
loser (link to repo)
|
||||||
|
tunneldata (link to repo)
|
||||||
|
troggle (link to repo)
|
||||||
|
expoweb (link to repo)
|
||||||
|
boc/boe
|
||||||
|
|
||||||
|
|
||||||
|
config
|
||||||
|
containing:
|
||||||
|
|
||||||
|
setup apache configs for cucc and expo
|
||||||
|
#disable default website
|
||||||
|
a2dissite 000-default
|
||||||
|
a2ensite cucc
|
||||||
|
a2ensite expo
|
||||||
|
a2enmod cgid
|
||||||
|
|
||||||
|
|
||||||
|
Boe config:
|
||||||
|
Alias /boe /home/expo/boe/boc/boc.pl
|
||||||
|
<Directory /home/expo/boe/boc>
|
||||||
|
AddHandler cgi-script .pl
|
||||||
|
SetHandler cgi-script
|
||||||
|
Options +ExecCGI
|
||||||
|
Require all granted
|
||||||
|
</Directory>
|
||||||
|
And remember to set both program and data dir to be
|
||||||
|
www-data:www-data
|
||||||
|
(optionally make file group read/write by treasurer account)
|
||||||
|
create empty repo by clicking create in boe interface
|
||||||
|
then set names in 'settings'
|
||||||
|
|
||||||
|
Set up mysql (as root)
|
||||||
|
mysql -p
|
||||||
|
CREATE DATABASE troggle;
|
||||||
|
GRANT ALL PRIVILEGES ON troggle.* TO 'expo'@'localhost' IDENTIFIED BY 'somepassword';
|
||||||
|
|
||||||
|
install django:
|
||||||
|
sudo apt install python-django python-django-registration python-django-imagekit python-django-tinymce fonts-freefont-ttf libapache2-mod-wsgi
|
||||||
|
|
||||||
|
python-django-imagekit comes from https://salsa.debian.org/python-team/modules/python-django-imagekit
|
||||||
|
python-django-tinymce comes from https://salsa.debian.org/python-team/modules/python-django-tinymce
|
||||||
|
(both modified for stretch/python2). packages under /home/wookey/packages/
|
||||||
|
|
||||||
|
need fonts-freefont-ttf (to have truetype freesans available for troggle via PIL)
|
||||||
|
need libapache2-mod-wsgi for apache wsgi support.
|
||||||
|
|
||||||
|
On stretch the django 1.10 is no use so get rid of that:
|
||||||
|
apt remove python3-django python-django python-django-common python-django-doc
|
||||||
|
|
||||||
|
Then replace with django 1.7 (Needs to be built for stretch)
|
||||||
|
apt install python-django python-django-common python-django-doc
|
||||||
|
apt install python-django-registration python-django-imagekit python-django-tinymce
|
||||||
|
|
||||||
|
then hold them to stop them being upgraded by unattended upgrades:
|
||||||
|
echo "python-django hold" | sudo dpkg --set-selections
|
||||||
|
echo "python-django-common hold" | sudo dpkg --set-selections
|
||||||
|
echo "python-django-doc hold" | sudo dpkg --set-selections
|
||||||
|
|
||||||
|
#troggle has to have a writable logfile otherwise the website explodes
|
||||||
|
# 500 error on the server, and apache error log has non-rentrant errors
|
||||||
|
create /var/log/troggle/troggle.log
|
||||||
|
chown www-data:adm /var/log/troggle/troggle.log
|
||||||
|
chmod 660 /var/log/troggle/troggle.log
|
||||||
@@ -6,3 +6,4 @@ django-imagekit
|
|||||||
Image
|
Image
|
||||||
django-tinymce==2.7.0
|
django-tinymce==2.7.0
|
||||||
smartencoding
|
smartencoding
|
||||||
|
unidecode
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import troggle.settings as settings
|
import troggle.settings as settings
|
||||||
from troggle.helper import login_required_if_public
|
from troggle.helper import login_required_if_public
|
||||||
from utils import render_with_context
|
from django.shortcuts import render
|
||||||
|
|
||||||
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
from django.http import HttpResponse, HttpResponseRedirect, Http404
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
@@ -38,7 +38,7 @@ def flatpage(request, path):
|
|||||||
print("flat path noinfo", path)
|
print("flat path noinfo", path)
|
||||||
return HttpResponseRedirect(reverse("auth_login") + '?next=%s' % request.path)
|
return HttpResponseRedirect(reverse("auth_login") + '?next=%s' % request.path)
|
||||||
|
|
||||||
if path.endswith("/") or path == "":
|
if path.endswith("/") or path == "":
|
||||||
try:
|
try:
|
||||||
o = open(os.path.normpath(settings.EXPOWEB + path + "index.html"), "rb")
|
o = open(os.path.normpath(settings.EXPOWEB + path + "index.html"), "rb")
|
||||||
path = path + "index.html"
|
path = path + "index.html"
|
||||||
@@ -47,13 +47,13 @@ def flatpage(request, path):
|
|||||||
o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb")
|
o = open(os.path.normpath(settings.EXPOWEB + path + "index.htm"), "rb")
|
||||||
path = path + "index.htm"
|
path = path + "index.htm"
|
||||||
except IOError:
|
except IOError:
|
||||||
return render_with_context(request, 'pagenotfound.html', {'path': path})
|
return render(request, 'pagenotfound.html', {'path': path})
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
filetobeopened = os.path.normpath(settings.EXPOWEB + path)
|
filetobeopened = os.path.normpath(settings.EXPOWEB + path)
|
||||||
o = open(filetobeopened, "rb")
|
o = open(filetobeopened, "rb")
|
||||||
except IOError:
|
except IOError:
|
||||||
return render_with_context(request, 'pagenotfound.html', {'path': path})
|
return render(request, 'pagenotfound.html', {'path': path})
|
||||||
if path.endswith(".htm") or path.endswith(".html"):
|
if path.endswith(".htm") or path.endswith(".html"):
|
||||||
html = o.read()
|
html = o.read()
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ def flatpage(request, path):
|
|||||||
if re.search(r"iso-8859-1", html):
|
if re.search(r"iso-8859-1", html):
|
||||||
body = unicode(body, "iso-8859-1")
|
body = unicode(body, "iso-8859-1")
|
||||||
body.strip
|
body.strip
|
||||||
return render_with_context(request, 'flatpage.html', {'editable': True, 'path': path, 'title': title, 'body': body, 'homepage': (path == "index.htm"), 'has_menu': has_menu})
|
return render(request, 'flatpage.html', {'editable': True, 'path': path, 'title': title, 'body': body, 'homepage': (path == "index.htm"), 'has_menu': has_menu})
|
||||||
else:
|
else:
|
||||||
return HttpResponse(o.read(), content_type=getmimetype(path))
|
return HttpResponse(o.read(), content_type=getmimetype(path))
|
||||||
|
|
||||||
@@ -160,9 +160,9 @@ def editflatpage(request, path):
|
|||||||
flatpageForm = FlatPageForm({"html": body, "title": title})
|
flatpageForm = FlatPageForm({"html": body, "title": title})
|
||||||
else:
|
else:
|
||||||
flatpageForm = FlatPageForm()
|
flatpageForm = FlatPageForm()
|
||||||
return render_with_context(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, })
|
return render(request, 'editflatpage.html', {'path': path, 'form': flatpageForm, })
|
||||||
|
|
||||||
class FlatPageForm(forms.Form):
|
class FlatPageForm(forms.Form):
|
||||||
title = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
|
title = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
|
||||||
|
|
||||||
html = forms.CharField(widget=forms.Textarea())
|
html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 20}))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import sys
|
import sys
|
||||||
# link localsettings to this file for use on expo computer in austria
|
# This is the local settings for use with the docker compose dev setup. It is imported automatically
|
||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
'default': {
|
'default': {
|
||||||
@@ -47,13 +47,13 @@ MEDIA_URL = URL_ROOT + DIR_ROOT + 'site_media/'
|
|||||||
MEDIA_ROOT = REPOS_ROOT_PATH + '/troggle/media/'
|
MEDIA_ROOT = REPOS_ROOT_PATH + '/troggle/media/'
|
||||||
MEDIA_ADMIN_DIR = '/usr/lib/python2.7/site-packages/django/contrib/admin/media/'
|
MEDIA_ADMIN_DIR = '/usr/lib/python2.7/site-packages/django/contrib/admin/media/'
|
||||||
|
|
||||||
STATIC_URL = URL_ROOT
|
STATIC_URL = "/static/"
|
||||||
STATIC_ROOT = DIR_ROOT
|
STATIC_ROOT = "/expo/static"
|
||||||
|
|
||||||
JSLIB_URL = URL_ROOT + 'javascript/'
|
JSLIB_URL = URL_ROOT + 'javascript/'
|
||||||
|
|
||||||
TINY_MCE_MEDIA_ROOT = '/usr/share/tinymce/www/'
|
TINY_MCE_MEDIA_ROOT = STATIC_ROOT + '/tiny_mce/'
|
||||||
TINY_MCE_MEDIA_URL = URL_ROOT + DIR_ROOT + '/tinymce_media/'
|
TINY_MCE_MEDIA_URL = STATIC_ROOT + '/tiny_mce/'
|
||||||
|
|
||||||
TEMPLATE_DIRS = (
|
TEMPLATE_DIRS = (
|
||||||
PYTHON_PATH + "templates",
|
PYTHON_PATH + "templates",
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ MEDIA_ADMIN_DIR = '/usr/lib/python2.7/site-packages/django/contrib/admin/media/'
|
|||||||
|
|
||||||
JSLIB_URL = URL_ROOT + 'javascript/'
|
JSLIB_URL = URL_ROOT + 'javascript/'
|
||||||
|
|
||||||
TINY_MCE_MEDIA_ROOT = '/usr/share/tinymce/www/'
|
TINY_MCE_MEDIA_ROOT = STATIC_ROOT + '/tiny_mce/'
|
||||||
TINY_MCE_MEDIA_URL = URL_ROOT + DIR_ROOT + 'tinymce_media/'
|
TINY_MCE_MEDIA_URL = STATIC_ROOT + '/tiny_mce/'
|
||||||
|
|
||||||
TEMPLATE_DIRS = (
|
TEMPLATE_DIRS = (
|
||||||
PYTHON_PATH + "templates",
|
PYTHON_PATH + "templates",
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
body {
|
|
||||||
all: initial;
|
|
||||||
font-size: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#inputf {
|
|
||||||
display: inline-block;
|
|
||||||
width: 300px;
|
|
||||||
text-align: justify;
|
|
||||||
margin-top: 0px;
|
|
||||||
margin-bottom: 5px
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu, ul#links{
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
table {
|
|
||||||
border-spacing: 0;
|
|
||||||
width: 100%;
|
|
||||||
border: 1px solid #ddd;
|
|
||||||
font-family: monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
th {
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: #bbb
|
|
||||||
}
|
|
||||||
|
|
||||||
th, td {
|
|
||||||
padding: 16px;
|
|
||||||
max-height: 40px;
|
|
||||||
}
|
|
||||||
|
|
||||||
tr:nth-child(even) {
|
|
||||||
background-color: #f2f2f2
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
|
||||||
|
|
||||||
margin-right: 80px;
|
|
||||||
margin-left: 80px;
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
|
||||||
width: 300px
|
|
||||||
}
|
|
||||||
span#mono {
|
|
||||||
font-family: monospace;
|
|
||||||
background-color: #eee;
|
|
||||||
font-size: 120%;
|
|
||||||
}
|
|
||||||
@@ -1,159 +0,0 @@
|
|||||||
function filterTable(tablename)
|
|
||||||
{
|
|
||||||
table = document.getElementById(tablename);
|
|
||||||
|
|
||||||
mindepth = document.getElementById("CaveDepthMin").value;
|
|
||||||
maxdepth = document.getElementById("CaveDepthMax").value;
|
|
||||||
if(mindepth==0)mindepth=-999999;
|
|
||||||
if(maxdepth==0)maxdepth= 999999;
|
|
||||||
|
|
||||||
minlength = document.getElementById("CaveLengthMin").value;
|
|
||||||
maxlength = document.getElementById("CaveLengthMax").value;
|
|
||||||
if(minlength==0)minlength=-999999;
|
|
||||||
if(maxlength==0)maxlength= 999999;
|
|
||||||
|
|
||||||
visitdate = document.getElementById("VisitDate").value;
|
|
||||||
|
|
||||||
visitor = document.getElementById("Visitor").value;
|
|
||||||
|
|
||||||
cavename = document.getElementById("CaveName").value.toLowerCase();
|
|
||||||
|
|
||||||
incomplete = document.getElementById("Incomplete").checked;
|
|
||||||
|
|
||||||
var regexmode = false;
|
|
||||||
if(visitor[0]=='/' && visitor[visitor.length-1]=='/')
|
|
||||||
{
|
|
||||||
regexmode = true;
|
|
||||||
visitor = new RegExp(visitor.substr(1,visitor.length-2));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
visitor.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
rows = table.rows;
|
|
||||||
for(i=1; i< rows.length; i++)
|
|
||||||
{
|
|
||||||
name = (rows[i].getElementsByTagName("TD")[1]).innerHTML.toLowerCase();
|
|
||||||
|
|
||||||
depth = (rows[i].getElementsByTagName("TD")[2]).innerHTML.toLowerCase();
|
|
||||||
depth = Number(depth.replace(/[^0-9.]/g,''));
|
|
||||||
|
|
||||||
length = (rows[i].getElementsByTagName("TD")[3]).innerHTML.toLowerCase();
|
|
||||||
length = Number(length.replace(/[^0-9.]/g,''));
|
|
||||||
|
|
||||||
date = (rows[i].getElementsByTagName("TD")[4]).innerHTML.toLowerCase();
|
|
||||||
|
|
||||||
//recentvisitor = (rows[i].getElementsByTagName("TD")[4]).innerHTML.toLowerCase();
|
|
||||||
recentvisitor = ""
|
|
||||||
|
|
||||||
if(cavename != "" && !name.includes(cavename))
|
|
||||||
{
|
|
||||||
rows[i].style.visibility = "collapse";
|
|
||||||
}
|
|
||||||
if(depth<mindepth || depth>maxdepth)
|
|
||||||
{
|
|
||||||
rows[i].style.visibility = "collapse";
|
|
||||||
}
|
|
||||||
if(length<minlength || length>maxlength)
|
|
||||||
{
|
|
||||||
rows[i].style.visibility = "collapse";
|
|
||||||
}
|
|
||||||
if(date < visitdate)
|
|
||||||
{
|
|
||||||
rows[i].style.visibility = "collapse";
|
|
||||||
}
|
|
||||||
if(visitor != "" && regexmode && !visitor.test(recentvisitor))
|
|
||||||
{
|
|
||||||
rows[i].style.visibility = "collapse";
|
|
||||||
}
|
|
||||||
if(visitor != "" && !regexmode && !recentvisitor.includes(visitor))
|
|
||||||
{
|
|
||||||
rows[i].style.visibility = "collapse";
|
|
||||||
}
|
|
||||||
|
|
||||||
crow=rows[i].getElementsByTagName("TD");
|
|
||||||
for(var j=0; j<crow.length; j++)
|
|
||||||
{
|
|
||||||
if(crow[j].innerHTML == "" && incomplete)
|
|
||||||
{
|
|
||||||
rows[i].style.visibility = "collapse";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function filterTableReset(tablename)
|
|
||||||
{
|
|
||||||
table = document.getElementById(tablename);
|
|
||||||
rows = table.rows;
|
|
||||||
for(i=1; i< rows.length; i++)
|
|
||||||
{
|
|
||||||
rows[i].style.visibility = "visible";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function isOrdered(kvarray,numeric)
|
|
||||||
{
|
|
||||||
for(var i=0;i<kvarray.length-1;i++)
|
|
||||||
{
|
|
||||||
if(numeric==1 && Number(kvarray[i][0])>Number(kvarray[i+1][0]))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(numeric!=1 && kvarray[i][0]>kvarray[i+1][0])
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sortTable(n, tablename, numeric) {
|
|
||||||
table = document.getElementById(tablename);
|
|
||||||
rows = table.rows;
|
|
||||||
var ordering = [];
|
|
||||||
var i;
|
|
||||||
|
|
||||||
//construct key-value pairs for sorting
|
|
||||||
for(i = 1; i < rows.length; i++) //remember header rows
|
|
||||||
{
|
|
||||||
key = rows[i].getElementsByTagName("TD")[n];
|
|
||||||
key = key.innerHTML.toLowerCase();
|
|
||||||
if(numeric==1)
|
|
||||||
{
|
|
||||||
key=key.replace(/[^0-9.]/g,'')
|
|
||||||
}
|
|
||||||
ordering.push([key,i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var ascending = isOrdered(ordering,numeric);
|
|
||||||
|
|
||||||
//sort either numerically or alphabetically
|
|
||||||
if(numeric==1)
|
|
||||||
{
|
|
||||||
ordering.sort((x,y) => Number(x[0])-Number(y[0]));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ordering.sort(); //sorts alphabetically
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ascending) ordering.reverse();
|
|
||||||
|
|
||||||
for(i = 0; i < ordering.length; i++) //add sorted list at the end of the table
|
|
||||||
{
|
|
||||||
var keyval = ordering[i];
|
|
||||||
id = keyval[1]; //get rownumber of n^th sorted value
|
|
||||||
cln = rows[id].cloneNode(true); //deep clone of current node
|
|
||||||
table.insertBefore(cln,null); //add n^th row at the end
|
|
||||||
}
|
|
||||||
for(i = 1; i < ordering.length+1; i++) //remove unsorted nodes
|
|
||||||
{
|
|
||||||
table.deleteRow(1);// 0 -> header; 1 -> first row
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
0
modelviz.py
Executable file → Normal file
0
modelviz.py
Executable file → Normal file
@@ -17,19 +17,19 @@ def parseCaveQMs(cave,inputFile):
|
|||||||
try:
|
try:
|
||||||
steinBr=Cave.objects.get(official_name="Steinbrückenhöhle")
|
steinBr=Cave.objects.get(official_name="Steinbrückenhöhle")
|
||||||
except Cave.DoesNotExist:
|
except Cave.DoesNotExist:
|
||||||
print "Steinbruckenhoehle is not in the database. Please run parsers.cavetab first."
|
print("Steinbruckenhoehle is not in the database. Please run parsers.cavetab first.")
|
||||||
return
|
return
|
||||||
elif cave=='hauch':
|
elif cave=='hauch':
|
||||||
try:
|
try:
|
||||||
hauchHl=Cave.objects.get(official_name="Hauchhöhle")
|
hauchHl=Cave.objects.get(official_name="Hauchhöhle")
|
||||||
except Cave.DoesNotExist:
|
except Cave.DoesNotExist:
|
||||||
print "Hauchhoele is not in the database. Please run parsers.cavetab first."
|
print("Hauchhoele is not in the database. Please run parsers.cavetab first.")
|
||||||
return
|
return
|
||||||
elif cave =='kh':
|
elif cave =='kh':
|
||||||
try:
|
try:
|
||||||
kh=Cave.objects.get(official_name="Kaninchenhöhle")
|
kh=Cave.objects.get(official_name="Kaninchenhöhle")
|
||||||
except Cave.DoesNotExist:
|
except Cave.DoesNotExist:
|
||||||
print "KH is not in the database. Please run parsers.cavetab first."
|
print("KH is not in the database. Please run parsers.cavetab first.")
|
||||||
parse_KH_QMs(kh, inputFile=inputFile)
|
parse_KH_QMs(kh, inputFile=inputFile)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ def parseCaveQMs(cave,inputFile):
|
|||||||
elif cave=='hauch':
|
elif cave=='hauch':
|
||||||
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, title="placeholder for QMs in 234", text="QMs temporarily attached to this should be re-attached to their actual trips", defaults={"date": date(year, 1, 1),"cave":hauchHl})
|
placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, title="placeholder for QMs in 234", text="QMs temporarily attached to this should be re-attached to their actual trips", defaults={"date": date(year, 1, 1),"cave":hauchHl})
|
||||||
if hadToCreate:
|
if hadToCreate:
|
||||||
print cave+" placeholder logbook entry for " + str(year) + " added to database"
|
print(cave + " placeholder logbook entry for " + str(year) + " added to database")
|
||||||
QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb")
|
QMnum=re.match(r".*?-\d*?-X?(?P<numb>\d*)",line[0]).group("numb")
|
||||||
newQM = QM()
|
newQM = QM()
|
||||||
newQM.found_by=placeholder
|
newQM.found_by=placeholder
|
||||||
@@ -71,19 +71,18 @@ def parseCaveQMs(cave,inputFile):
|
|||||||
if preexistingQM.new_since_parsing==False: #if the pre-existing QM has not been modified, overwrite it
|
if preexistingQM.new_since_parsing==False: #if the pre-existing QM has not been modified, overwrite it
|
||||||
preexistingQM.delete()
|
preexistingQM.delete()
|
||||||
newQM.save()
|
newQM.save()
|
||||||
print "overwriting " + str(preexistingQM) +"\r",
|
print("overwriting " + str(preexistingQM) +"\r")
|
||||||
|
|
||||||
else: # otherwise, print that it was ignored
|
else: # otherwise, print that it was ignored
|
||||||
print "preserving "+ str(preexistingQM) + ", which was edited in admin \r",
|
print("preserving " + str(preexistingQM) + ", which was edited in admin \r")
|
||||||
|
|
||||||
except QM.DoesNotExist: #if there is no pre-existing QM, save the new one
|
except QM.DoesNotExist: #if there is no pre-existing QM, save the new one
|
||||||
newQM.save()
|
newQM.save()
|
||||||
print "QM "+str(newQM) + ' added to database\r',
|
print("QM "+str(newQM) + ' added to database\r')
|
||||||
|
|
||||||
except KeyError: #check on this one
|
except KeyError: #check on this one
|
||||||
continue
|
continue
|
||||||
except IndexError:
|
except IndexError:
|
||||||
print "Index error in " + str(line)
|
print("Index error in " + str(line))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
def parse_KH_QMs(kh, inputFile):
|
def parse_KH_QMs(kh, inputFile):
|
||||||
@@ -104,7 +103,7 @@ def parse_KH_QMs(kh, inputFile):
|
|||||||
}
|
}
|
||||||
nonLookupArgs={
|
nonLookupArgs={
|
||||||
'grade':res['grade'],
|
'grade':res['grade'],
|
||||||
'nearest_station':res['nearest_station'],
|
'nearest_station_name':res['nearest_station'],
|
||||||
'location_description':res['description']
|
'location_description':res['description']
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,3 +114,4 @@ parseCaveQMs(cave='stein',inputFile=r"1623/204/qm.csv")
|
|||||||
parseCaveQMs(cave='hauch',inputFile=r"1623/234/qm.csv")
|
parseCaveQMs(cave='hauch',inputFile=r"1623/234/qm.csv")
|
||||||
parseCaveQMs(cave='kh', inputFile="1623/161/qmtodo.htm")
|
parseCaveQMs(cave='kh', inputFile="1623/161/qmtodo.htm")
|
||||||
#parseCaveQMs(cave='balkonhoehle',inputFile=r"1623/264/qm.csv")
|
#parseCaveQMs(cave='balkonhoehle',inputFile=r"1623/264/qm.csv")
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,18 @@ import re
|
|||||||
|
|
||||||
|
|
||||||
def readcaves():
|
def readcaves():
|
||||||
newArea = models.Area(short_name = "1623", parent = None)
|
|
||||||
newArea.save()
|
# Clear the cave data issues as we are reloading
|
||||||
newArea = models.Area(short_name = "1626", parent = None)
|
models.DataIssue.objects.filter(parser='caves').delete()
|
||||||
newArea.save()
|
|
||||||
print("Reading Entrances")
|
area_1623 = models.Area.objects.update_or_create(short_name = "1623", parent = None)
|
||||||
|
area_1626 = models.Area.objects.update_or_create(short_name = "1626", parent = None)
|
||||||
|
print(" - Reading Entrances")
|
||||||
#print "list of <Slug> <Filename>"
|
#print "list of <Slug> <Filename>"
|
||||||
for filename in os.walk(settings.ENTRANCEDESCRIPTIONS).next()[2]: #Should be a better way of getting a list of files
|
for filename in os.walk(settings.ENTRANCEDESCRIPTIONS).next()[2]: #Should be a better way of getting a list of files
|
||||||
if filename.endswith('.html'):
|
if filename.endswith('.html'):
|
||||||
readentrance(filename)
|
readentrance(filename)
|
||||||
print ("Reading Caves")
|
print (" - Reading Caves")
|
||||||
for filename in os.walk(settings.CAVEDESCRIPTIONS).next()[2]: #Should be a better way of getting a list of files
|
for filename in os.walk(settings.CAVEDESCRIPTIONS).next()[2]: #Should be a better way of getting a list of files
|
||||||
if filename.endswith('.html'):
|
if filename.endswith('.html'):
|
||||||
readcave(filename)
|
readcave(filename)
|
||||||
@@ -51,7 +53,7 @@ def readentrance(filename):
|
|||||||
bearings = getXML(entrancecontents, "bearings", maxItems = 1, context = context)
|
bearings = getXML(entrancecontents, "bearings", maxItems = 1, context = context)
|
||||||
url = getXML(entrancecontents, "url", maxItems = 1, context = context)
|
url = getXML(entrancecontents, "url", maxItems = 1, context = context)
|
||||||
if len(non_public) == 1 and len(slugs) >= 1 and len(name) >= 1 and len(entrance_description) == 1 and len(explorers) == 1 and len(map_description) == 1 and len(location_description) == 1 and len(approach) == 1 and len(underground_description) == 1 and len(marking) == 1 and len(marking_comment) == 1 and len(findability) == 1 and len(findability_description) == 1 and len(alt) == 1 and len(northing) == 1 and len(easting) == 1 and len(tag_station) == 1 and len(exact_station) == 1 and len(other_station) == 1 and len(other_description) == 1 and len(bearings) == 1 and len(url) == 1:
|
if len(non_public) == 1 and len(slugs) >= 1 and len(name) >= 1 and len(entrance_description) == 1 and len(explorers) == 1 and len(map_description) == 1 and len(location_description) == 1 and len(approach) == 1 and len(underground_description) == 1 and len(marking) == 1 and len(marking_comment) == 1 and len(findability) == 1 and len(findability_description) == 1 and len(alt) == 1 and len(northing) == 1 and len(easting) == 1 and len(tag_station) == 1 and len(exact_station) == 1 and len(other_station) == 1 and len(other_description) == 1 and len(bearings) == 1 and len(url) == 1:
|
||||||
e = models.Entrance(name = name[0],
|
e, state = models.Entrance.objects.update_or_create(name = name[0],
|
||||||
non_public = {"True": True, "False": False, "true": True, "false": False,}[non_public[0]],
|
non_public = {"True": True, "False": False, "true": True, "false": False,}[non_public[0]],
|
||||||
entrance_description = entrance_description[0],
|
entrance_description = entrance_description[0],
|
||||||
explorers = explorers[0],
|
explorers = explorers[0],
|
||||||
@@ -75,14 +77,12 @@ def readentrance(filename):
|
|||||||
url = url[0],
|
url = url[0],
|
||||||
filename = filename,
|
filename = filename,
|
||||||
cached_primary_slug = slugs[0])
|
cached_primary_slug = slugs[0])
|
||||||
e.save()
|
|
||||||
primary = True
|
primary = True
|
||||||
for slug in slugs:
|
for slug in slugs:
|
||||||
#print slug, filename
|
#print slug, filename
|
||||||
cs = models.EntranceSlug(entrance = e,
|
cs = models.EntranceSlug.objects.update_or_create(entrance = e,
|
||||||
slug = slug,
|
slug = slug,
|
||||||
primary = primary)
|
primary = primary)
|
||||||
cs.save()
|
|
||||||
primary = False
|
primary = False
|
||||||
|
|
||||||
def readcave(filename):
|
def readcave(filename):
|
||||||
@@ -117,7 +117,7 @@ def readcave(filename):
|
|||||||
url = getXML(cavecontents, "url", maxItems = 1, context = context)
|
url = getXML(cavecontents, "url", maxItems = 1, context = context)
|
||||||
entrances = getXML(cavecontents, "entrance", context = context)
|
entrances = getXML(cavecontents, "entrance", context = context)
|
||||||
if len(non_public) == 1 and len(slugs) >= 1 and len(official_name) == 1 and len(areas) >= 1 and len(kataster_code) == 1 and len(kataster_number) == 1 and len(unofficial_number) == 1 and len(explorers) == 1 and len(underground_description) == 1 and len(equipment) == 1 and len(references) == 1 and len(survey) == 1 and len(kataster_status) == 1 and len(underground_centre_line) == 1 and len(notes) == 1 and len(length) == 1 and len(depth) == 1 and len(extent) == 1 and len(survex_file) == 1 and len(description_file ) == 1 and len(url) == 1 and len(entrances) >= 1:
|
if len(non_public) == 1 and len(slugs) >= 1 and len(official_name) == 1 and len(areas) >= 1 and len(kataster_code) == 1 and len(kataster_number) == 1 and len(unofficial_number) == 1 and len(explorers) == 1 and len(underground_description) == 1 and len(equipment) == 1 and len(references) == 1 and len(survey) == 1 and len(kataster_status) == 1 and len(underground_centre_line) == 1 and len(notes) == 1 and len(length) == 1 and len(depth) == 1 and len(extent) == 1 and len(survex_file) == 1 and len(description_file ) == 1 and len(url) == 1 and len(entrances) >= 1:
|
||||||
c = models.Cave(non_public = {"True": True, "False": False, "true": True, "false": False,}[non_public[0]],
|
c, state = models.Cave.objects.update_or_create(non_public = {"True": True, "False": False, "true": True, "false": False,}[non_public[0]],
|
||||||
official_name = official_name[0],
|
official_name = official_name[0],
|
||||||
kataster_code = kataster_code[0],
|
kataster_code = kataster_code[0],
|
||||||
kataster_number = kataster_number[0],
|
kataster_number = kataster_number[0],
|
||||||
@@ -137,7 +137,6 @@ def readcave(filename):
|
|||||||
description_file = description_file[0],
|
description_file = description_file[0],
|
||||||
url = url[0],
|
url = url[0],
|
||||||
filename = filename)
|
filename = filename)
|
||||||
c.save()
|
|
||||||
for area_slug in areas:
|
for area_slug in areas:
|
||||||
area = models.Area.objects.filter(short_name = area_slug)
|
area = models.Area.objects.filter(short_name = area_slug)
|
||||||
if area:
|
if area:
|
||||||
@@ -149,12 +148,13 @@ def readcave(filename):
|
|||||||
primary = True
|
primary = True
|
||||||
for slug in slugs:
|
for slug in slugs:
|
||||||
try:
|
try:
|
||||||
cs = models.CaveSlug(cave = c,
|
cs = models.CaveSlug.objects.update_or_create(cave = c,
|
||||||
slug = slug,
|
slug = slug,
|
||||||
primary = primary)
|
primary = primary)
|
||||||
cs.save()
|
|
||||||
except:
|
except:
|
||||||
print("Can't find text (slug): %s, skipping %s" % (slug, context))
|
message = "Can't find text (slug): %s, skipping %s" % (slug, context)
|
||||||
|
models.DataIssue.objects.create(parser='caves', message=message)
|
||||||
|
print(message)
|
||||||
|
|
||||||
primary = False
|
primary = False
|
||||||
for entrance in entrances:
|
for entrance in entrances:
|
||||||
@@ -162,20 +162,26 @@ def readcave(filename):
|
|||||||
letter = getXML(entrance, "letter", maxItems = 1, context = context)[0]
|
letter = getXML(entrance, "letter", maxItems = 1, context = context)[0]
|
||||||
try:
|
try:
|
||||||
entrance = models.Entrance.objects.get(entranceslug__slug = slug)
|
entrance = models.Entrance.objects.get(entranceslug__slug = slug)
|
||||||
ce = models.CaveAndEntrance(cave = c, entrance_letter = letter, entrance = entrance)
|
ce = models.CaveAndEntrance.objects.update_or_create(cave = c, entrance_letter = letter, entrance = entrance)
|
||||||
ce.save()
|
|
||||||
except:
|
except:
|
||||||
print ("Entrance text (slug) %s missing %s" % (slug, context))
|
message = "Entrance text (slug) %s missing %s" % (slug, context)
|
||||||
|
models.DataIssue.objects.create(parser='caves', message=message)
|
||||||
|
print(message)
|
||||||
|
|
||||||
|
|
||||||
def getXML(text, itemname, minItems = 1, maxItems = None, printwarnings = True, context = ""):
|
def getXML(text, itemname, minItems = 1, maxItems = None, printwarnings = True, context = ""):
|
||||||
items = re.findall("<%(itemname)s>(.*?)</%(itemname)s>" % {"itemname": itemname}, text, re.S)
|
items = re.findall("<%(itemname)s>(.*?)</%(itemname)s>" % {"itemname": itemname}, text, re.S)
|
||||||
if len(items) < minItems and printwarnings:
|
if len(items) < minItems and printwarnings:
|
||||||
print("%(count)i %(itemname)s found, at least %(min)i expected" % {"count": len(items),
|
message = "%(count)i %(itemname)s found, at least %(min)i expected" % {"count": len(items),
|
||||||
"itemname": itemname,
|
"itemname": itemname,
|
||||||
"min": minItems} + context)
|
"min": minItems} + context
|
||||||
|
models.DataIssue.objects.create(parser='caves', message=message)
|
||||||
|
print(message)
|
||||||
|
|
||||||
if maxItems is not None and len(items) > maxItems and printwarnings:
|
if maxItems is not None and len(items) > maxItems and printwarnings:
|
||||||
print("%(count)i %(itemname)s found, no more than %(max)i expected" % {"count": len(items),
|
message = "%(count)i %(itemname)s found, no more than %(max)i expected" % {"count": len(items),
|
||||||
"itemname": itemname,
|
"itemname": itemname,
|
||||||
"max": maxItems} + context)
|
"max": maxItems} + context
|
||||||
|
models.DataIssue.objects.create(parser='caves', message=message)
|
||||||
|
print(message)
|
||||||
return items
|
return items
|
||||||
|
|||||||
@@ -1,210 +0,0 @@
|
|||||||
|
|
||||||
import troggle.core.models as models #import models for various objects
|
|
||||||
from django.conf import settings
|
|
||||||
import xml.etree.ElementTree as ET #this is used to parse XML's
|
|
||||||
import subprocess
|
|
||||||
import re
|
|
||||||
|
|
||||||
#
|
|
||||||
# This parser has to find several things:
|
|
||||||
# There are files of .html format in expoweb area - they contain some of the important information
|
|
||||||
# There is a similar number of .svx files in loser are - they contain all the measurements
|
|
||||||
#
|
|
||||||
# Previous version was incredibly slow due to various shitty ideas about finding things
|
|
||||||
# and overelayance on python when handling regular expressions, new version delegates heavy lifting to shell
|
|
||||||
# and handles more sophisticated bits only
|
|
||||||
#
|
|
||||||
|
|
||||||
def load():
|
|
||||||
print('Hi! I\'m caves parser. Ready to work')
|
|
||||||
|
|
||||||
print('Loading caves of 1623 area')
|
|
||||||
loadarea('1623')
|
|
||||||
|
|
||||||
|
|
||||||
def loadarea(areacode):
|
|
||||||
|
|
||||||
if not file_exists(settings.SURVEX_DATA+'1623-and-1626.3d'):
|
|
||||||
print('Computing master .3d file')
|
|
||||||
bash('cavern -o'+settings.SURVEX_DATA+' '+settings.SURVEX_DATA+'1623-and-1626.svx')
|
|
||||||
else:
|
|
||||||
print('Loading from existing master .3d file')
|
|
||||||
|
|
||||||
master3d = bash('dump3d -d '+settings.SURVEX_DATA+'1623-and-1626.3d').splitlines()
|
|
||||||
master3dN = [x for x in master3d if ('NODE' in x)] #list of nodes of master survex file
|
|
||||||
master3dL = [x for x in master3d if ('LINE' in x)] #list of nodes of master survex file
|
|
||||||
|
|
||||||
print('Searching all cave dirs files')
|
|
||||||
basedir = settings.SURVEX_DATA+'caves-'+areacode+'/'
|
|
||||||
|
|
||||||
cavedirs = bash("find "+basedir+" -maxdepth 1 -type d").splitlines() #this command finds all directories
|
|
||||||
print('Obtained list of directories! (#dirs='+str(len(cavedirs))+')')
|
|
||||||
ndirs = len(cavedirs) #remember number of dirs for nice debug output
|
|
||||||
|
|
||||||
for cavedir in cavedirs:
|
|
||||||
if cavedir==basedir:
|
|
||||||
continue #skip the basedir - a non-proper subdirectory
|
|
||||||
cavename = bash('echo '+cavedir+' | rev | cut -f1 -d \'/\' | rev').splitlines()[0] #get final bit of the directory
|
|
||||||
|
|
||||||
test = bash('if [ ! -f '+cavedir+'/'+cavename+'.svx ] ; then echo MISSING; fi')#test for file exisence
|
|
||||||
if not file_exists(cavedir+'/'+cavename+'.svx'):
|
|
||||||
msg = models.Parser_messageM(parsername='caves',content=cavedir+'/'+cavename+' MISSING!',message_type='warn')
|
|
||||||
print('Cave missing'+cavename+' :(')
|
|
||||||
msg.save()
|
|
||||||
continue
|
|
||||||
fullname=cavedir+'/'+cavename+'.svx'
|
|
||||||
print('Found cave:'+cavename)
|
|
||||||
cavernout = bash('cavern -o '+cavedir+' '+fullname) #make cavern process the thing
|
|
||||||
if 'cavern: error:' in cavernout:
|
|
||||||
msg = models.Parser_messageM(parsername='caves',content=cavedir+'/'+cavename+' Survex file messed up!',message_type='warn')
|
|
||||||
print('Fucked svx'+cavename+' :(')
|
|
||||||
msg.save()
|
|
||||||
continue
|
|
||||||
|
|
||||||
cavernout = cavernout.splitlines()
|
|
||||||
depth = float(([x for x in cavernout if ('Total vertical length' in x)][0].split()[-1])[:-2])
|
|
||||||
length = float(([x for x in cavernout if ('Total length' in x)][0].split()[6])[:-1])
|
|
||||||
cavefile = open(fullname,'r')
|
|
||||||
cavefilecontents = cavefile.read().splitlines()
|
|
||||||
surveyname = [x for x in cavefilecontents if ('*begin ') in x][0].split()[1].lower()
|
|
||||||
try:
|
|
||||||
title = [x for x in cavefilecontents if ('*title ') in x][0].split()[1]
|
|
||||||
except:
|
|
||||||
syrveyname = "Untitled"
|
|
||||||
|
|
||||||
relevant_nodes = [x for x in master3dN if (('['+areacode+'.'+surveyname+'.' in x) or ('['+areacode+'.'+surveyname+']' in x))]
|
|
||||||
entrance_nodes = [x for x in relevant_nodes if 'ENTRANCE' in x]
|
|
||||||
surface_nodes = [x for x in relevant_nodes if 'SURFACE' in x]
|
|
||||||
location_nodes = []
|
|
||||||
print('rel_nodes'+str(len(relevant_nodes)))
|
|
||||||
if len(entrance_nodes) > 0:
|
|
||||||
location_nodes = entrance_nodes
|
|
||||||
elif len(surface_nodes) > 0:
|
|
||||||
location_nodes = surface_nodes
|
|
||||||
elif len(relevant_nodes) > 0:
|
|
||||||
location_nodes = relevant_nodes
|
|
||||||
|
|
||||||
try:
|
|
||||||
location = sorted(location_nodes, key = lambda y : float(y.split()[3])).pop()
|
|
||||||
except:
|
|
||||||
print(location_nodes)
|
|
||||||
location = 'Not found'
|
|
||||||
|
|
||||||
relevant_lines = [x for x in master3dL if (('['+areacode+'.'+surveyname+'.' in x) or ('['+areacode+'.'+surveyname+']' in x))]
|
|
||||||
try:
|
|
||||||
lastleg = sorted(relevant_lines, key = lambda y : y.split().pop()).pop()
|
|
||||||
except:
|
|
||||||
lastleg = ['LINE 1900.01.01']
|
|
||||||
try:
|
|
||||||
lastdate = lastleg.split().pop()
|
|
||||||
if 'STYLE' in lastdate:
|
|
||||||
lastdate = lastleg.split().pop().pop()
|
|
||||||
except:
|
|
||||||
lastdate = '1900.01.01'
|
|
||||||
|
|
||||||
entrance = ' '.join(location.split()[1:3])
|
|
||||||
print((('depth','length','surv name','entr','date'),(depth,length,surveyname,entrance,lastdate))) #sanity check print
|
|
||||||
|
|
||||||
|
|
||||||
newcave = models.CaveM(
|
|
||||||
survex_file = fullname,
|
|
||||||
total_length = length,
|
|
||||||
name=areacode+'.'+surveyname,
|
|
||||||
total_depth = depth,
|
|
||||||
date = lastdate,
|
|
||||||
entrance = entrance)
|
|
||||||
newcave.save()
|
|
||||||
#end of reading survex masterfiles
|
|
||||||
|
|
||||||
print ("Reading cave descriptions")
|
|
||||||
cavefiles = bash('find '+settings.CAVEDESCRIPTIONS+' -name \'*.html\'').splitlines()
|
|
||||||
for fn in cavefiles:
|
|
||||||
f = open(fn, "r")
|
|
||||||
print(fn)
|
|
||||||
contents = f.read()
|
|
||||||
|
|
||||||
slug = re.sub(r"\s+", "", extractXML(contents,'caveslug'))
|
|
||||||
desc = extractXML(contents,'underground_description')
|
|
||||||
name = slug[5:] #get survex compatible name
|
|
||||||
area = slug[0:4]
|
|
||||||
|
|
||||||
print([area,name])
|
|
||||||
|
|
||||||
if desc==None or name==None:
|
|
||||||
msg = models.Parser_messageM(parsername='caves',content=fn+' Description meesed up!',message_type='warn')
|
|
||||||
print('Fucked description '+fn+' :(')
|
|
||||||
msg.save()
|
|
||||||
continue
|
|
||||||
|
|
||||||
print(area+'/'+name+'/'+name+'.svx')
|
|
||||||
|
|
||||||
updatecave = models.CaveM.objects.filter(survex_file__icontains=area+'/'+name+'/'+name+'.svx')
|
|
||||||
if len(updatecave)>1:
|
|
||||||
print('Non unique solution - skipping. Name:'+name)
|
|
||||||
elif len(updatecave)==0:
|
|
||||||
print('Cave with no survex data:'+name)
|
|
||||||
continue
|
|
||||||
else: #exaclty one match
|
|
||||||
print('Adding desc:'+name)
|
|
||||||
updatecave = updatecave[0]
|
|
||||||
updatecave.description = '/cave/descriptionM/'+slug #area-name
|
|
||||||
updatecave.title=name
|
|
||||||
updatecave.save()
|
|
||||||
|
|
||||||
slugS = slug
|
|
||||||
explorersS = extractXML(contents,'explorers')
|
|
||||||
underground_descriptionS = extractXML(contents,'underground_description')
|
|
||||||
equipmentS = extractXML(contents,'equipment')
|
|
||||||
referencesS = extractXML(contents,'references')
|
|
||||||
surveyS = extractXML(contents,'survey')
|
|
||||||
kataster_statusS = extractXML(contents,'kataster_status')
|
|
||||||
underground_centre_lineS = extractXML(contents,'underground_centre_line')
|
|
||||||
survex_fileS = extractXML(contents,'survex_file')
|
|
||||||
notesS = extractXML(contents,'notes')
|
|
||||||
|
|
||||||
|
|
||||||
newcavedesc = models.Cave_descriptionM(
|
|
||||||
slug = slugS,
|
|
||||||
explorers = explorersS,
|
|
||||||
underground_description = underground_descriptionS,
|
|
||||||
equipment = equipmentS,
|
|
||||||
references = referencesS,
|
|
||||||
survey = surveyS,
|
|
||||||
kataster_status = kataster_statusS,
|
|
||||||
underground_centre_line = underground_centre_lineS,
|
|
||||||
survex_file = survex_fileS,
|
|
||||||
notes = notesS)
|
|
||||||
newcavedesc.save()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#end of reading cave descriptions
|
|
||||||
|
|
||||||
def file_exists(filename):
|
|
||||||
test = bash('if [ ! -f '+filename+' ] ; then echo MISSING; fi')#test for file exisence
|
|
||||||
if 'MISSING' in test: #send error message to the database
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def extractXML(contents,tag):
|
|
||||||
#find correct lines
|
|
||||||
lines = contents.splitlines()
|
|
||||||
beg = [x for x in lines if ('<'+tag+'>' in x)]
|
|
||||||
end = [x for x in lines if ('</'+tag+'>' in x)]
|
|
||||||
if (not beg) or (not end):
|
|
||||||
return None
|
|
||||||
begi = lines.index(beg[0])
|
|
||||||
endi = lines.index(end[0])
|
|
||||||
if endi!=begi:
|
|
||||||
segment = '\n'.join(lines[begi:endi+1])
|
|
||||||
else:
|
|
||||||
segment = lines[begi:endi+1][0]
|
|
||||||
|
|
||||||
hit = re.findall('<'+tag+'>(.*)</'+tag+'>', segment, re.S)[0]
|
|
||||||
return hit
|
|
||||||
|
|
||||||
def bash(cmd): #calls command in bash shell, returns output
|
|
||||||
process = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
|
|
||||||
output, error = process.communicate()
|
|
||||||
return output
|
|
||||||
@@ -7,6 +7,8 @@ from parsers.people import GetPersonExpeditionNameLookup
|
|||||||
from parsers.cavetab import GetCaveLookup
|
from parsers.cavetab import GetCaveLookup
|
||||||
|
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
|
from django.utils.timezone import get_current_timezone
|
||||||
|
from django.utils.timezone import make_aware
|
||||||
|
|
||||||
import csv
|
import csv
|
||||||
import re
|
import re
|
||||||
@@ -23,19 +25,23 @@ from utils import save_carefully
|
|||||||
#
|
#
|
||||||
# the logbook loading section
|
# the logbook loading section
|
||||||
#
|
#
|
||||||
def GetTripPersons(trippeople, expedition, logtime_underground):
|
def GetTripPersons(trippeople, expedition, logtime_underground):
|
||||||
res = [ ]
|
res = [ ]
|
||||||
author = None
|
author = None
|
||||||
for tripperson in re.split(",|\+|&|&(?!\w+;)| and ", trippeople):
|
round_bracket_regex = re.compile(r"[\(\[].*?[\)\]]")
|
||||||
|
for tripperson in re.split(r",|\+|&|&(?!\w+;)| and ", trippeople):
|
||||||
tripperson = tripperson.strip()
|
tripperson = tripperson.strip()
|
||||||
mul = re.match("<u>(.*?)</u>$(?i)", tripperson)
|
mul = re.match(r"<u>(.*?)</u>$(?i)", tripperson)
|
||||||
if mul:
|
if mul:
|
||||||
tripperson = mul.group(1).strip()
|
tripperson = mul.group(1).strip()
|
||||||
if tripperson and tripperson[0] != '*':
|
if tripperson and tripperson[0] != '*':
|
||||||
#assert tripperson in personyearmap, "'%s' << %s\n\n %s" % (tripperson, trippeople, personyearmap)
|
#assert tripperson in personyearmap, "'%s' << %s\n\n %s" % (tripperson, trippeople, personyearmap)
|
||||||
|
tripperson = re.sub(round_bracket_regex, "", tripperson).strip()
|
||||||
personyear = GetPersonExpeditionNameLookup(expedition).get(tripperson.lower())
|
personyear = GetPersonExpeditionNameLookup(expedition).get(tripperson.lower())
|
||||||
if not personyear:
|
if not personyear:
|
||||||
print "NoMatchFor: '%s'" % tripperson
|
print(" - No name match for: '%s'" % tripperson)
|
||||||
|
message = "No name match for: '%s' in year '%s'" % (tripperson, expedition.year)
|
||||||
|
models.DataIssue.objects.create(parser='logbooks', message=message)
|
||||||
res.append((personyear, logtime_underground))
|
res.append((personyear, logtime_underground))
|
||||||
if mul:
|
if mul:
|
||||||
author = personyear
|
author = personyear
|
||||||
@@ -45,7 +51,7 @@ def GetTripPersons(trippeople, expedition, logtime_underground):
|
|||||||
author = res[-1][0]
|
author = res[-1][0]
|
||||||
return res, author
|
return res, author
|
||||||
|
|
||||||
def GetTripCave(place): #need to be fuzzier about matching here. Already a very slow function...
|
def GetTripCave(place): #need to be fuzzier about matching here. Already a very slow function...
|
||||||
# print "Getting cave for " , place
|
# print "Getting cave for " , place
|
||||||
try:
|
try:
|
||||||
katastNumRes=[]
|
katastNumRes=[]
|
||||||
@@ -65,32 +71,34 @@ def GetTripCave(place): #need to be fuzzier about matching h
|
|||||||
return tripCaveRes
|
return tripCaveRes
|
||||||
|
|
||||||
elif len(tripCaveRes)>1:
|
elif len(tripCaveRes)>1:
|
||||||
print "Ambiguous place " + str(place) + " entered. Choose from " + str(tripCaveRes)
|
print("Ambiguous place " + str(place) + " entered. Choose from " + str(tripCaveRes))
|
||||||
correctIndex=input("type list index of correct cave")
|
correctIndex=input("type list index of correct cave")
|
||||||
return tripCaveRes[correctIndex]
|
return tripCaveRes[correctIndex]
|
||||||
else:
|
else:
|
||||||
print "No cave found for place " , place
|
print("No cave found for place " , place)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
noncaveplaces = [ "Journey", "Loser Plateau" ]
|
noncaveplaces = [ "Journey", "Loser Plateau" ]
|
||||||
def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground):
|
def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground, entry_type="wiki"):
|
||||||
""" saves a logbook entry and related persontrips """
|
""" saves a logbook entry and related persontrips """
|
||||||
trippersons, author = GetTripPersons(trippeople, expedition, logtime_underground)
|
trippersons, author = GetTripPersons(trippeople, expedition, logtime_underground)
|
||||||
if not author:
|
if not author:
|
||||||
print "skipping logentry", title
|
print(" - Skipping logentry: " + title + " - no author for entry")
|
||||||
|
message = "Skipping logentry: %s - no author for entry in year '%s'" % (title, expedition.year)
|
||||||
|
models.DataIssue.objects.create(parser='logbooks', message=message)
|
||||||
return
|
return
|
||||||
|
|
||||||
# tripCave = GetTripCave(place)
|
#tripCave = GetTripCave(place)
|
||||||
#
|
|
||||||
lplace = place.lower()
|
lplace = place.lower()
|
||||||
if lplace not in noncaveplaces:
|
if lplace not in noncaveplaces:
|
||||||
cave=GetCaveLookup().get(lplace)
|
cave=GetCaveLookup().get(lplace)
|
||||||
|
|
||||||
#Check for an existing copy of the current entry, and save
|
#Check for an existing copy of the current entry, and save
|
||||||
expeditionday = expedition.get_expedition_day(date)
|
expeditionday = expedition.get_expedition_day(date)
|
||||||
lookupAttribs={'date':date, 'title':title}
|
lookupAttribs={'date':date, 'title':title}
|
||||||
nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave':cave, 'slug':slugify(title)[:50]}
|
nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave':cave, 'slug':slugify(title)[:50], 'entry_type':entry_type}
|
||||||
lbo, created=save_carefully(models.LogbookEntry, lookupAttribs, nonLookupAttribs)
|
lbo, created=save_carefully(models.LogbookEntry, lookupAttribs, nonLookupAttribs)
|
||||||
|
|
||||||
for tripperson, time_underground in trippersons:
|
for tripperson, time_underground in trippersons:
|
||||||
@@ -102,8 +110,8 @@ def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_
|
|||||||
|
|
||||||
def ParseDate(tripdate, year):
|
def ParseDate(tripdate, year):
|
||||||
""" Interprets dates in the expo logbooks and returns a correct datetime.date object """
|
""" Interprets dates in the expo logbooks and returns a correct datetime.date object """
|
||||||
mdatestandard = re.match("(\d\d\d\d)-(\d\d)-(\d\d)", tripdate)
|
mdatestandard = re.match(r"(\d\d\d\d)-(\d\d)-(\d\d)", tripdate)
|
||||||
mdategoof = re.match("(\d\d?)/0?(\d)/(20|19)?(\d\d)", tripdate)
|
mdategoof = re.match(r"(\d\d?)/0?(\d)/(20|19)?(\d\d)", tripdate)
|
||||||
if mdatestandard:
|
if mdatestandard:
|
||||||
assert mdatestandard.group(1) == year, (tripdate, year)
|
assert mdatestandard.group(1) == year, (tripdate, year)
|
||||||
year, month, day = int(mdatestandard.group(1)), int(mdatestandard.group(2)), int(mdatestandard.group(3))
|
year, month, day = int(mdatestandard.group(1)), int(mdatestandard.group(2)), int(mdatestandard.group(3))
|
||||||
@@ -115,9 +123,9 @@ def ParseDate(tripdate, year):
|
|||||||
assert False, tripdate
|
assert False, tripdate
|
||||||
return datetime.date(year, month, day)
|
return datetime.date(year, month, day)
|
||||||
|
|
||||||
# 2007, 2008, 2006
|
# 2006, 2008 - 2010
|
||||||
def Parselogwikitxt(year, expedition, txt):
|
def Parselogwikitxt(year, expedition, txt):
|
||||||
trippara = re.findall("===(.*?)===([\s\S]*?)(?====)", txt)
|
trippara = re.findall(r"===(.*?)===([\s\S]*?)(?====)", txt)
|
||||||
for triphead, triptext in trippara:
|
for triphead, triptext in trippara:
|
||||||
tripheadp = triphead.split("|")
|
tripheadp = triphead.split("|")
|
||||||
#print "ttt", tripheadp
|
#print "ttt", tripheadp
|
||||||
@@ -126,7 +134,7 @@ def Parselogwikitxt(year, expedition, txt):
|
|||||||
tripsplace = tripplace.split(" - ")
|
tripsplace = tripplace.split(" - ")
|
||||||
tripcave = tripsplace[0].strip()
|
tripcave = tripsplace[0].strip()
|
||||||
|
|
||||||
tul = re.findall("T/?U:?\s*(\d+(?:\.\d*)?|unknown)\s*(hrs|hours)?", triptext)
|
tul = re.findall(r"T/?U:?\s*(\d+(?:\.\d*)?|unknown)\s*(hrs|hours)?", triptext)
|
||||||
if tul:
|
if tul:
|
||||||
#assert len(tul) <= 1, (triphead, triptext)
|
#assert len(tul) <= 1, (triphead, triptext)
|
||||||
#assert tul[0][1] in ["hrs", "hours"], (triphead, triptext)
|
#assert tul[0][1] in ["hrs", "hours"], (triphead, triptext)
|
||||||
@@ -140,12 +148,16 @@ def Parselogwikitxt(year, expedition, txt):
|
|||||||
#print "\n", tripcave, "--- ppp", trippeople, len(triptext)
|
#print "\n", tripcave, "--- ppp", trippeople, len(triptext)
|
||||||
EnterLogIntoDbase(date = ldate, place = tripcave, title = tripplace, text = triptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
|
EnterLogIntoDbase(date = ldate, place = tripcave, title = tripplace, text = triptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
|
||||||
|
|
||||||
# 2002, 2004, 2005
|
# 2002, 2004, 2005, 2007, 2011 - 2018
|
||||||
def Parseloghtmltxt(year, expedition, txt):
|
def Parseloghtmltxt(year, expedition, txt):
|
||||||
tripparas = re.findall("<hr\s*/>([\s\S]*?)(?=<hr)", txt)
|
#print(" - Starting log html parser")
|
||||||
|
tripparas = re.findall(r"<hr\s*/>([\s\S]*?)(?=<hr)", txt)
|
||||||
|
logbook_entry_count = 0
|
||||||
for trippara in tripparas:
|
for trippara in tripparas:
|
||||||
|
#print(" - HR detected - maybe a trip?")
|
||||||
|
logbook_entry_count += 1
|
||||||
|
|
||||||
s = re.match('''(?x)(?:\s*<div\sclass="tripdate"\sid=".*?">.*?</div>\s*<p>)? # second date
|
s = re.match(r'''(?x)(?:\s*<div\sclass="tripdate"\sid=".*?">.*?</div>\s*<p>)? # second date
|
||||||
\s*(?:<a\s+id="(.*?)"\s*/>\s*</a>)?
|
\s*(?:<a\s+id="(.*?)"\s*/>\s*</a>)?
|
||||||
\s*<div\s+class="tripdate"\s*(?:id="(.*?)")?>(.*?)</div>(?:<p>)?
|
\s*<div\s+class="tripdate"\s*(?:id="(.*?)")?>(.*?)</div>(?:<p>)?
|
||||||
\s*<div\s+class="trippeople">\s*(.*?)</div>
|
\s*<div\s+class="trippeople">\s*(.*?)</div>
|
||||||
@@ -155,38 +167,41 @@ def Parseloghtmltxt(year, expedition, txt):
|
|||||||
\s*$
|
\s*$
|
||||||
''', trippara)
|
''', trippara)
|
||||||
if not s:
|
if not s:
|
||||||
if not re.search("Rigging Guide", trippara):
|
if not re.search(r"Rigging Guide", trippara):
|
||||||
print "can't parse: ", trippara # this is 2007 which needs editing
|
print("can't parse: ", trippara) # this is 2007 which needs editing
|
||||||
#assert s, trippara
|
#assert s, trippara
|
||||||
continue
|
continue
|
||||||
|
|
||||||
tripid, tripid1, tripdate, trippeople, triptitle, triptext, tu = s.groups()
|
tripid, tripid1, tripdate, trippeople, triptitle, triptext, tu = s.groups()
|
||||||
ldate = ParseDate(tripdate.strip(), year)
|
ldate = ParseDate(tripdate.strip(), year)
|
||||||
#assert tripid[:-1] == "t" + tripdate, (tripid, tripdate)
|
#assert tripid[:-1] == "t" + tripdate, (tripid, tripdate)
|
||||||
trippeople = re.sub("Ol(?!l)", "Olly", trippeople)
|
#trippeople = re.sub(r"Ol(?!l)", "Olly", trippeople)
|
||||||
trippeople = re.sub("Wook(?!e)", "Wookey", trippeople)
|
#trippeople = re.sub(r"Wook(?!e)", "Wookey", trippeople)
|
||||||
triptitles = triptitle.split(" - ")
|
triptitles = triptitle.split(" - ")
|
||||||
if len(triptitles) >= 2:
|
if len(triptitles) >= 2:
|
||||||
tripcave = triptitles[0]
|
tripcave = triptitles[0]
|
||||||
else:
|
else:
|
||||||
tripcave = "UNKNOWN"
|
tripcave = "UNKNOWN"
|
||||||
#print "\n", tripcave, "--- ppp", trippeople, len(triptext)
|
#print("\n", tripcave, "--- ppp", trippeople, len(triptext))
|
||||||
ltriptext = re.sub("</p>", "", triptext)
|
ltriptext = re.sub(r"</p>", "", triptext)
|
||||||
ltriptext = re.sub("\s*?\n\s*", " ", ltriptext)
|
ltriptext = re.sub(r"\s*?\n\s*", " ", ltriptext)
|
||||||
ltriptext = re.sub("<p>", "\n\n", ltriptext).strip()
|
ltriptext = re.sub(r"<p>", "</br></br>", ltriptext).strip()
|
||||||
EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
|
EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext,
|
||||||
|
trippeople=trippeople, expedition=expedition, logtime_underground=0,
|
||||||
|
entry_type="html")
|
||||||
|
if logbook_entry_count == 0:
|
||||||
|
print(" - No trip entrys found in logbook, check the syntax matches htmltxt format")
|
||||||
|
|
||||||
|
|
||||||
# main parser for pre-2001. simpler because the data has been hacked so much to fit it
|
# main parser for 1991 - 2001. simpler because the data has been hacked so much to fit it
|
||||||
def Parseloghtml01(year, expedition, txt):
|
def Parseloghtml01(year, expedition, txt):
|
||||||
tripparas = re.findall("<hr[\s/]*>([\s\S]*?)(?=<hr)", txt)
|
tripparas = re.findall(r"<hr[\s/]*>([\s\S]*?)(?=<hr)", txt)
|
||||||
for trippara in tripparas:
|
for trippara in tripparas:
|
||||||
s = re.match(u"(?s)\s*(?:<p>)?(.*?)</?p>(.*)$(?i)", trippara)
|
s = re.match(u"(?s)\s*(?:<p>)?(.*?)</?p>(.*)$(?i)", trippara)
|
||||||
assert s, trippara[:300]
|
assert s, trippara[:300]
|
||||||
tripheader, triptext = s.group(1), s.group(2)
|
tripheader, triptext = s.group(1), s.group(2)
|
||||||
mtripid = re.search('<a id="(.*?)"', tripheader)
|
mtripid = re.search(r'<a id="(.*?)"', tripheader)
|
||||||
tripid = mtripid and mtripid.group(1) or ""
|
tripid = mtripid and mtripid.group(1) or ""
|
||||||
tripheader = re.sub("</?(?:[ab]|span)[^>]*>", "", tripheader)
|
tripheader = re.sub(r"</?(?:[ab]|span)[^>]*>", "", tripheader)
|
||||||
|
|
||||||
#print " ", [tripheader]
|
#print " ", [tripheader]
|
||||||
#continue
|
#continue
|
||||||
@@ -194,7 +209,7 @@ def Parseloghtml01(year, expedition, txt):
|
|||||||
tripdate, triptitle, trippeople = tripheader.split("|")
|
tripdate, triptitle, trippeople = tripheader.split("|")
|
||||||
ldate = ParseDate(tripdate.strip(), year)
|
ldate = ParseDate(tripdate.strip(), year)
|
||||||
|
|
||||||
mtu = re.search('<p[^>]*>(T/?U.*)', triptext)
|
mtu = re.search(r'<p[^>]*>(T/?U.*)', triptext)
|
||||||
if mtu:
|
if mtu:
|
||||||
tu = mtu.group(1)
|
tu = mtu.group(1)
|
||||||
triptext = triptext[:mtu.start(0)] + triptext[mtu.end():]
|
triptext = triptext[:mtu.start(0)] + triptext[mtu.end():]
|
||||||
@@ -206,38 +221,40 @@ def Parseloghtml01(year, expedition, txt):
|
|||||||
|
|
||||||
ltriptext = triptext
|
ltriptext = triptext
|
||||||
|
|
||||||
mtail = re.search('(?:<a href="[^"]*">[^<]*</a>|\s|/|-|&|</?p>|\((?:same day|\d+)\))*$', ltriptext)
|
mtail = re.search(r'(?:<a href="[^"]*">[^<]*</a>|\s|/|-|&|</?p>|\((?:same day|\d+)\))*$', ltriptext)
|
||||||
if mtail:
|
if mtail:
|
||||||
#print mtail.group(0)
|
#print mtail.group(0)
|
||||||
ltriptext = ltriptext[:mtail.start(0)]
|
ltriptext = ltriptext[:mtail.start(0)]
|
||||||
ltriptext = re.sub("</p>", "", ltriptext)
|
ltriptext = re.sub(r"</p>", "", ltriptext)
|
||||||
ltriptext = re.sub("\s*?\n\s*", " ", ltriptext)
|
ltriptext = re.sub(r"\s*?\n\s*", " ", ltriptext)
|
||||||
ltriptext = re.sub("<p>|<br>", "\n\n", ltriptext).strip()
|
ltriptext = re.sub(r"<p>|<br>", "\n\n", ltriptext).strip()
|
||||||
#ltriptext = re.sub("[^\s0-9a-zA-Z\-.,:;'!]", "NONASCII", ltriptext)
|
#ltriptext = re.sub("[^\s0-9a-zA-Z\-.,:;'!]", "NONASCII", ltriptext)
|
||||||
ltriptext = re.sub("</?u>", "_", ltriptext)
|
ltriptext = re.sub(r"</?u>", "_", ltriptext)
|
||||||
ltriptext = re.sub("</?i>", "''", ltriptext)
|
ltriptext = re.sub(r"</?i>", "''", ltriptext)
|
||||||
ltriptext = re.sub("</?b>", "'''", ltriptext)
|
ltriptext = re.sub(r"</?b>", "'''", ltriptext)
|
||||||
|
|
||||||
|
|
||||||
#print ldate, trippeople.strip()
|
#print ldate, trippeople.strip()
|
||||||
# could includ the tripid (url link for cross referencing)
|
# could includ the tripid (url link for cross referencing)
|
||||||
EnterLogIntoDbase(date=ldate, place=tripcave, title=triptitle, text=ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
|
EnterLogIntoDbase(date=ldate, place=tripcave, title=triptitle, text=ltriptext,
|
||||||
|
trippeople=trippeople, expedition=expedition, logtime_underground=0,
|
||||||
|
entry_type="html")
|
||||||
|
|
||||||
|
# parser for 2003
|
||||||
def Parseloghtml03(year, expedition, txt):
|
def Parseloghtml03(year, expedition, txt):
|
||||||
tripparas = re.findall("<hr\s*/>([\s\S]*?)(?=<hr)", txt)
|
tripparas = re.findall(r"<hr\s*/>([\s\S]*?)(?=<hr)", txt)
|
||||||
for trippara in tripparas:
|
for trippara in tripparas:
|
||||||
s = re.match(u"(?s)\s*<p>(.*?)</p>(.*)$", trippara)
|
s = re.match(u"(?s)\s*<p>(.*?)</p>(.*)$", trippara)
|
||||||
assert s, trippara
|
assert s, trippara
|
||||||
tripheader, triptext = s.group(1), s.group(2)
|
tripheader, triptext = s.group(1), s.group(2)
|
||||||
tripheader = re.sub(" ", " ", tripheader)
|
tripheader = re.sub(r" ", " ", tripheader)
|
||||||
tripheader = re.sub("\s+", " ", tripheader).strip()
|
tripheader = re.sub(r"\s+", " ", tripheader).strip()
|
||||||
sheader = tripheader.split(" -- ")
|
sheader = tripheader.split(" -- ")
|
||||||
tu = ""
|
tu = ""
|
||||||
if re.match("T/U|Time underwater", sheader[-1]):
|
if re.match("T/U|Time underwater", sheader[-1]):
|
||||||
tu = sheader.pop()
|
tu = sheader.pop()
|
||||||
if len(sheader) != 3:
|
if len(sheader) != 3:
|
||||||
print "header not three pieces", sheader
|
print("header not three pieces", sheader)
|
||||||
tripdate, triptitle, trippeople = sheader
|
tripdate, triptitle, trippeople = sheader
|
||||||
ldate = ParseDate(tripdate.strip(), year)
|
ldate = ParseDate(tripdate.strip(), year)
|
||||||
triptitles = triptitle.split(" , ")
|
triptitles = triptitle.split(" , ")
|
||||||
@@ -246,37 +263,14 @@ def Parseloghtml03(year, expedition, txt):
|
|||||||
else:
|
else:
|
||||||
tripcave = "UNKNOWN"
|
tripcave = "UNKNOWN"
|
||||||
#print tripcave, "--- ppp", triptitle, trippeople, len(triptext)
|
#print tripcave, "--- ppp", triptitle, trippeople, len(triptext)
|
||||||
ltriptext = re.sub("</p>", "", triptext)
|
ltriptext = re.sub(r"</p>", "", triptext)
|
||||||
ltriptext = re.sub("\s*?\n\s*", " ", ltriptext)
|
ltriptext = re.sub(r"\s*?\n\s*", " ", ltriptext)
|
||||||
ltriptext = re.sub("<p>", "\n\n", ltriptext).strip()
|
ltriptext = re.sub(r"<p>", "\n\n", ltriptext).strip()
|
||||||
ltriptext = re.sub("[^\s0-9a-zA-Z\-.,:;'!&()\[\]<>?=+*%]", "_NONASCII_", ltriptext)
|
ltriptext = re.sub(r"[^\s0-9a-zA-Z\-.,:;'!&()\[\]<>?=+*%]", "_NONASCII_", ltriptext)
|
||||||
EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
|
EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle,
|
||||||
|
text = ltriptext, trippeople=trippeople, expedition=expedition,
|
||||||
|
logtime_underground=0, entry_type="html")
|
||||||
|
|
||||||
yearlinks = [
|
|
||||||
# ("2013", "2013/logbook.html", Parseloghtmltxt),
|
|
||||||
("2012", "2012/logbook.html", Parseloghtmltxt),
|
|
||||||
("2011", "2011/logbook.html", Parseloghtmltxt),
|
|
||||||
("2010", "2010/logbook.html", Parselogwikitxt),
|
|
||||||
("2009", "2009/2009logbook.txt", Parselogwikitxt),
|
|
||||||
("2008", "2008/2008logbook.txt", Parselogwikitxt),
|
|
||||||
("2007", "2007/logbook.html", Parseloghtmltxt),
|
|
||||||
("2006", "2006/logbook/logbook_06.txt", Parselogwikitxt),
|
|
||||||
("2005", "2005/logbook.html", Parseloghtmltxt),
|
|
||||||
("2004", "2004/logbook.html", Parseloghtmltxt),
|
|
||||||
("2003", "2003/logbook.html", Parseloghtml03),
|
|
||||||
("2002", "2002/logbook.html", Parseloghtmltxt),
|
|
||||||
("2001", "2001/log.htm", Parseloghtml01),
|
|
||||||
("2000", "2000/log.htm", Parseloghtml01),
|
|
||||||
("1999", "1999/log.htm", Parseloghtml01),
|
|
||||||
("1998", "1998/log.htm", Parseloghtml01),
|
|
||||||
("1997", "1997/log.htm", Parseloghtml01),
|
|
||||||
("1996", "1996/log.htm", Parseloghtml01),
|
|
||||||
("1995", "1995/log.htm", Parseloghtml01),
|
|
||||||
("1994", "1994/log.htm", Parseloghtml01),
|
|
||||||
("1993", "1993/log.htm", Parseloghtml01),
|
|
||||||
("1992", "1992/log.htm", Parseloghtml01),
|
|
||||||
("1991", "1991/log.htm", Parseloghtml01),
|
|
||||||
]
|
|
||||||
|
|
||||||
def SetDatesFromLogbookEntries(expedition):
|
def SetDatesFromLogbookEntries(expedition):
|
||||||
"""
|
"""
|
||||||
@@ -295,54 +289,67 @@ def SetDatesFromLogbookEntries(expedition):
|
|||||||
persontrip.persontrip_next = None
|
persontrip.persontrip_next = None
|
||||||
lprevpersontrip = persontrip
|
lprevpersontrip = persontrip
|
||||||
persontrip.save()
|
persontrip.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def LoadLogbookForExpedition(expedition):
|
def LoadLogbookForExpedition(expedition):
|
||||||
""" Parses all logbook entries for one expedition """
|
""" Parses all logbook entries for one expedition """
|
||||||
|
|
||||||
expowebbase = os.path.join(settings.EXPOWEB, "years")
|
expowebbase = os.path.join(settings.EXPOWEB, "years")
|
||||||
year = str(expedition.year)
|
yearlinks = settings.LOGBOOK_PARSER_SETTINGS
|
||||||
for lyear, lloc, parsefunc in yearlinks:
|
|
||||||
if lyear == year:
|
logbook_parseable = False
|
||||||
break
|
|
||||||
fin = open(os.path.join(expowebbase, lloc))
|
if expedition.year in yearlinks:
|
||||||
print "opennning", lloc
|
year_settings = yearlinks[expedition.year]
|
||||||
txt = fin.read().decode("latin1")
|
file_in = open(os.path.join(expowebbase, year_settings[0]))
|
||||||
fin.close()
|
txt = file_in.read().decode("latin1")
|
||||||
parsefunc(year, expedition, txt)
|
file_in.close()
|
||||||
SetDatesFromLogbookEntries(expedition)
|
parsefunc = year_settings[1]
|
||||||
return "TOLOAD: " + year + " " + str(expedition.personexpedition_set.all()[1].logbookentry_set.count()) + " " + str(models.PersonTrip.objects.filter(personexpedition__expedition=expedition).count())
|
logbook_parseable = True
|
||||||
|
print(" - Parsing logbook: " + year_settings[0] + "\n - Using parser: " + year_settings[1])
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
file_in = open(os.path.join(expowebbase, expedition.year, settings.DEFAULT_LOGBOOK_FILE))
|
||||||
|
txt = file_in.read().decode("latin1")
|
||||||
|
file_in.close()
|
||||||
|
logbook_parseable = True
|
||||||
|
print("No set parser found using default")
|
||||||
|
parsefunc = settings.DEFAULT_LOGBOOK_PARSER
|
||||||
|
except (IOError):
|
||||||
|
logbook_parseable = False
|
||||||
|
print("Couldn't open default logbook file and nothing in settings for expo " + expedition.year)
|
||||||
|
|
||||||
|
if logbook_parseable:
|
||||||
|
parser = globals()[parsefunc]
|
||||||
|
parser(expedition.year, expedition, txt)
|
||||||
|
SetDatesFromLogbookEntries(expedition)
|
||||||
|
|
||||||
|
#return "TOLOAD: " + year + " " + str(expedition.personexpedition_set.all()[1].logbookentry_set.count()) + " " + str(models.PersonTrip.objects.filter(personexpedition__expedition=expedition).count())
|
||||||
|
|
||||||
|
|
||||||
def LoadLogbooks():
|
def LoadLogbooks():
|
||||||
""" This is the master function for parsing all logbooks into the Troggle database. Requires yearlinks, which is a list of tuples for each expedition with expedition year, logbook path, and parsing function. """
|
""" This is the master function for parsing all logbooks into the Troggle database. """
|
||||||
|
|
||||||
#Deletion has been moved to a seperate function to enable the non-destructive importing
|
|
||||||
#models.LogbookEntry.objects.all().delete()
|
|
||||||
expowebbase = os.path.join(settings.EXPOWEB, "years")
|
|
||||||
#yearlinks = [ ("2001", "2001/log.htm", Parseloghtml01), ] #overwrite
|
|
||||||
#yearlinks = [ ("1996", "1996/log.htm", Parseloghtml01),] # overwrite
|
|
||||||
|
|
||||||
for year, lloc, parsefunc in yearlinks:
|
# Clear the logbook data issues as we are reloading
|
||||||
# This will not work until the corresponding year exists in the database.
|
models.DataIssue.objects.filter(parser='logbooks').delete()
|
||||||
# In 2012 this needed noscript/folk.csv to be updated first.
|
# Fetch all expos
|
||||||
expedition = models.Expedition.objects.filter(year = year)[0]
|
expos = models.Expedition.objects.all()
|
||||||
fin = open(os.path.join(expowebbase, lloc))
|
for expo in expos:
|
||||||
txt = fin.read().decode("latin1")
|
print("\nLoading Logbook for: " + expo.year)
|
||||||
fin.close()
|
|
||||||
parsefunc(year, expedition, txt)
|
# Load logbook for expo
|
||||||
SetDatesFromLogbookEntries(expedition)
|
LoadLogbookForExpedition(expo)
|
||||||
|
|
||||||
dateRegex = re.compile('<span\s+class="date">(\d\d\d\d)-(\d\d)-(\d\d)</span>', re.S)
|
|
||||||
expeditionYearRegex = re.compile('<span\s+class="expeditionyear">(.*?)</span>', re.S)
|
dateRegex = re.compile(r'<span\s+class="date">(\d\d\d\d)-(\d\d)-(\d\d)</span>', re.S)
|
||||||
titleRegex = re.compile('<H1>(.*?)</H1>', re.S)
|
expeditionYearRegex = re.compile(r'<span\s+class="expeditionyear">(.*?)</span>', re.S)
|
||||||
reportRegex = re.compile('<div\s+class="report">(.*)</div>\s*</body>', re.S)
|
titleRegex = re.compile(r'<H1>(.*?)</H1>', re.S)
|
||||||
personRegex = re.compile('<div\s+class="person">(.*?)</div>', re.S)
|
reportRegex = re.compile(r'<div\s+class="report">(.*)</div>\s*</body>', re.S)
|
||||||
nameAuthorRegex = re.compile('<span\s+class="name(,author|)">(.*?)</span>', re.S)
|
personRegex = re.compile(r'<div\s+class="person">(.*?)</div>', re.S)
|
||||||
TURegex = re.compile('<span\s+class="TU">([0-9]*\.?[0-9]+)</span>', re.S)
|
nameAuthorRegex = re.compile(r'<span\s+class="name(,author|)">(.*?)</span>', re.S)
|
||||||
locationRegex = re.compile('<span\s+class="location">(.*?)</span>', re.S)
|
TURegex = re.compile(r'<span\s+class="TU">([0-9]*\.?[0-9]+)</span>', re.S)
|
||||||
caveRegex = re.compile('<span\s+class="cave">(.*?)</span>', re.S)
|
locationRegex = re.compile(r'<span\s+class="location">(.*?)</span>', re.S)
|
||||||
|
caveRegex = re.compile(r'<span\s+class="cave">(.*?)</span>', re.S)
|
||||||
|
|
||||||
def parseAutoLogBookEntry(filename):
|
def parseAutoLogBookEntry(filename):
|
||||||
errors = []
|
errors = []
|
||||||
@@ -435,4 +442,4 @@ def parseAutoLogBookEntry(filename):
|
|||||||
time_underground = TU,
|
time_underground = TU,
|
||||||
logbook_entry = logbookEntry,
|
logbook_entry = logbookEntry,
|
||||||
is_logbook_entry_author = author).save()
|
is_logbook_entry_author = author).save()
|
||||||
print logbookEntry
|
print(logbookEntry)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ from django.conf import settings
|
|||||||
import troggle.core.models as models
|
import troggle.core.models as models
|
||||||
import csv, re, datetime, os, shutil
|
import csv, re, datetime, os, shutil
|
||||||
from utils import save_carefully
|
from utils import save_carefully
|
||||||
|
from HTMLParser import HTMLParser
|
||||||
|
from unidecode import unidecode
|
||||||
|
|
||||||
def saveMugShot(mugShotPath, mugShotFilename, person):
|
def saveMugShot(mugShotPath, mugShotFilename, person):
|
||||||
if mugShotFilename.startswith(r'i/'): #if filename in cell has the directory attached (I think they all do), remove it
|
if mugShotFilename.startswith(r'i/'): #if filename in cell has the directory attached (I think they all do), remove it
|
||||||
@@ -44,13 +46,13 @@ def parseMugShotAndBlurb(personline, header, person):
|
|||||||
|
|
||||||
def LoadPersonsExpos():
|
def LoadPersonsExpos():
|
||||||
|
|
||||||
persontab = open(os.path.join(settings.EXPOWEB, "noinfo", "folk.csv"))
|
persontab = open(os.path.join(settings.EXPOWEB, "folk", "folk.csv"))
|
||||||
personreader = csv.reader(persontab)
|
personreader = csv.reader(persontab)
|
||||||
headers = personreader.next()
|
headers = personreader.next()
|
||||||
header = dict(zip(headers, range(len(headers))))
|
header = dict(zip(headers, range(len(headers))))
|
||||||
|
|
||||||
# make expeditions
|
# make expeditions
|
||||||
print "Loading expeditions"
|
print("Loading expeditions")
|
||||||
years = headers[5:]
|
years = headers[5:]
|
||||||
|
|
||||||
for year in years:
|
for year in years:
|
||||||
@@ -59,20 +61,35 @@ def LoadPersonsExpos():
|
|||||||
|
|
||||||
save_carefully(models.Expedition, lookupAttribs, nonLookupAttribs)
|
save_carefully(models.Expedition, lookupAttribs, nonLookupAttribs)
|
||||||
|
|
||||||
|
|
||||||
# make persons
|
# make persons
|
||||||
print "Loading personexpeditions"
|
print("Loading personexpeditions")
|
||||||
|
|
||||||
for personline in personreader:
|
for personline in personreader:
|
||||||
name = personline[header["Name"]]
|
name = personline[header["Name"]]
|
||||||
name = re.sub("<.*?>", "", name)
|
name = re.sub(r"<.*?>", "", name)
|
||||||
mname = re.match("(\w+)(?:\s((?:van |ten )?\w+))?(?:\s\(([^)]*)\))?", name)
|
|
||||||
nickname = mname.group(3) or ""
|
firstname = ""
|
||||||
|
nickname = ""
|
||||||
lookupAttribs={'first_name':mname.group(1), 'last_name':(mname.group(2) or "")}
|
|
||||||
nonLookupAttribs={'is_vfho':personline[header["VfHO member"]],}
|
rawlastname = personline[header["Lastname"]].strip()
|
||||||
|
matchlastname = re.match(r"^([\w&;\s]+)(?:\(([^)]*)\))?", rawlastname)
|
||||||
|
lastname = matchlastname.group(1).strip()
|
||||||
|
|
||||||
|
splitnick = re.match(r"^([\w&;\s]+)(?:\(([^)]*)\))?", name)
|
||||||
|
fullname = splitnick.group(1)
|
||||||
|
|
||||||
|
nickname = splitnick.group(2) or ""
|
||||||
|
|
||||||
|
fullname = fullname.strip()
|
||||||
|
names = fullname.split(' ')
|
||||||
|
firstname = names[0]
|
||||||
|
if len(names) == 1:
|
||||||
|
lastname = ""
|
||||||
|
|
||||||
|
lookupAttribs={'first_name':firstname, 'last_name':(lastname or "")}
|
||||||
|
nonLookupAttribs={'is_vfho':personline[header["VfHO member"]], 'fullname':fullname}
|
||||||
person, created = save_carefully(models.Person, lookupAttribs, nonLookupAttribs)
|
person, created = save_carefully(models.Person, lookupAttribs, nonLookupAttribs)
|
||||||
|
|
||||||
parseMugShotAndBlurb(personline=personline, header=header, person=person)
|
parseMugShotAndBlurb(personline=personline, header=header, person=person)
|
||||||
|
|
||||||
# make person expedition from table
|
# make person expedition from table
|
||||||
@@ -83,7 +100,26 @@ def LoadPersonsExpos():
|
|||||||
nonLookupAttribs = {'nickname':nickname, 'is_guest':(personline[header["Guest"]] == "1")}
|
nonLookupAttribs = {'nickname':nickname, 'is_guest':(personline[header["Guest"]] == "1")}
|
||||||
save_carefully(models.PersonExpedition, lookupAttribs, nonLookupAttribs)
|
save_carefully(models.PersonExpedition, lookupAttribs, nonLookupAttribs)
|
||||||
|
|
||||||
|
|
||||||
|
# this fills in those people for whom 2008 was their first expo
|
||||||
|
#print "Loading personexpeditions 2008"
|
||||||
|
#expoers2008 = """Edvin Deadman,Kathryn Hopkins,Djuke Veldhuis,Becka Lawson,Julian Todd,Natalie Uomini,Aaron Curtis,Tony Rooke,Ollie Stevens,Frank Tully,Martin Jahnke,Mark Shinwell,Jess Stirrups,Nial Peters,Serena Povia,Olly Madge,Steve Jones,Pete Harley,Eeva Makiranta,Keith Curtis""".split(",")
|
||||||
|
#expomissing = set(expoers2008)
|
||||||
|
#for name in expomissing:
|
||||||
|
# firstname, lastname = name.split()
|
||||||
|
# is_guest = name in ["Eeva Makiranta", "Keith Curtis"]
|
||||||
|
# print "2008:", name
|
||||||
|
# persons = list(models.Person.objects.filter(first_name=firstname, last_name=lastname))
|
||||||
|
# if not persons:
|
||||||
|
# person = models.Person(first_name=firstname, last_name = lastname, is_vfho = False, mug_shot = "")
|
||||||
|
# #person.Sethref()
|
||||||
|
# person.save()
|
||||||
|
# else:
|
||||||
|
# person = persons[0]
|
||||||
|
# expedition = models.Expedition.objects.get(year="2008")
|
||||||
|
# personexpedition = models.PersonExpedition(person=person, expedition=expedition, nickname="", is_guest=is_guest)
|
||||||
|
# personexpedition.save()
|
||||||
|
|
||||||
# used in other referencing parser functions
|
# used in other referencing parser functions
|
||||||
# expedition name lookup cached for speed (it's a very big list)
|
# expedition name lookup cached for speed (it's a very big list)
|
||||||
Gpersonexpeditionnamelookup = { }
|
Gpersonexpeditionnamelookup = { }
|
||||||
@@ -96,20 +132,33 @@ def GetPersonExpeditionNameLookup(expedition):
|
|||||||
res = { }
|
res = { }
|
||||||
duplicates = set()
|
duplicates = set()
|
||||||
|
|
||||||
print "Calculating GetPersonExpeditionNameLookup for", expedition.year
|
print("Calculating GetPersonExpeditionNameLookup for " + expedition.year)
|
||||||
personexpeditions = models.PersonExpedition.objects.filter(expedition=expedition)
|
personexpeditions = models.PersonExpedition.objects.filter(expedition=expedition)
|
||||||
|
htmlparser = HTMLParser()
|
||||||
for personexpedition in personexpeditions:
|
for personexpedition in personexpeditions:
|
||||||
possnames = [ ]
|
possnames = [ ]
|
||||||
f = personexpedition.person.first_name.lower()
|
f = unidecode(htmlparser.unescape(personexpedition.person.first_name.lower()))
|
||||||
l = personexpedition.person.last_name.lower()
|
l = unidecode(htmlparser.unescape(personexpedition.person.last_name.lower()))
|
||||||
|
full = unidecode(htmlparser.unescape(personexpedition.person.fullname.lower()))
|
||||||
if l:
|
if l:
|
||||||
possnames.append(f + " " + l)
|
possnames.append(f + " " + l)
|
||||||
possnames.append(f + " " + l[0])
|
possnames.append(f + " " + l[0])
|
||||||
possnames.append(f + l[0])
|
possnames.append(f + l[0])
|
||||||
possnames.append(f[0] + " " + l)
|
possnames.append(f[0] + " " + l)
|
||||||
possnames.append(f)
|
possnames.append(f)
|
||||||
if personexpedition.nickname:
|
if full not in possnames:
|
||||||
|
possnames.append(full)
|
||||||
|
if personexpedition.nickname not in possnames:
|
||||||
possnames.append(personexpedition.nickname.lower())
|
possnames.append(personexpedition.nickname.lower())
|
||||||
|
if l:
|
||||||
|
# This allows for nickname to be used for short name eg Phil
|
||||||
|
# adding Phil Sargent to the list
|
||||||
|
if str(personexpedition.nickname.lower() + " " + l) not in possnames:
|
||||||
|
possnames.append(personexpedition.nickname.lower() + " " + l)
|
||||||
|
if str(personexpedition.nickname.lower() + " " + l[0]) not in possnames:
|
||||||
|
possnames.append(personexpedition.nickname.lower() + " " + l[0])
|
||||||
|
if str(personexpedition.nickname.lower() + l[0]) not in possnames:
|
||||||
|
possnames.append(personexpedition.nickname.lower() + l[0])
|
||||||
|
|
||||||
for possname in possnames:
|
for possname in possnames:
|
||||||
if possname in res:
|
if possname in res:
|
||||||
|
|||||||
@@ -5,20 +5,26 @@ import troggle.settings as settings
|
|||||||
from subprocess import call, Popen, PIPE
|
from subprocess import call, Popen, PIPE
|
||||||
|
|
||||||
from troggle.parsers.people import GetPersonExpeditionNameLookup
|
from troggle.parsers.people import GetPersonExpeditionNameLookup
|
||||||
|
from django.utils.timezone import get_current_timezone
|
||||||
|
from django.utils.timezone import make_aware
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
line_leg_regex = re.compile(r"[\d\-+.]+$")
|
||||||
|
|
||||||
def LoadSurvexLineLeg(survexblock, stardata, sline, comment):
|
def LoadSurvexLineLeg(survexblock, stardata, sline, comment, cave):
|
||||||
|
# The try catches here need replacing as they are relativly expensive
|
||||||
ls = sline.lower().split()
|
ls = sline.lower().split()
|
||||||
ssfrom = survexblock.MakeSurvexStation(ls[stardata["from"]])
|
ssfrom = survexblock.MakeSurvexStation(ls[stardata["from"]])
|
||||||
ssto = survexblock.MakeSurvexStation(ls[stardata["to"]])
|
ssto = survexblock.MakeSurvexStation(ls[stardata["to"]])
|
||||||
|
|
||||||
survexleg = models.SurvexLeg(block=survexblock, stationfrom=ssfrom, stationto=ssto)
|
survexleg = models.SurvexLeg(block=survexblock, stationfrom=ssfrom, stationto=ssto)
|
||||||
if stardata["type"] == "normal":
|
if stardata["type"] == "normal":
|
||||||
try:
|
try:
|
||||||
survexleg.tape = float(ls[stardata["tape"]])
|
survexleg.tape = float(ls[stardata["tape"]])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print("Tape misread in", survexblock.survexfile.path)
|
print("Tape misread in", survexblock.survexfile.path)
|
||||||
print("Stardata:", stardata)
|
print("Stardata:", stardata)
|
||||||
print("Line:", ls)
|
print("Line:", ls)
|
||||||
@@ -53,14 +59,17 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment):
|
|||||||
survexleg.compass = 1000
|
survexleg.compass = 1000
|
||||||
survexleg.clino = -90.0
|
survexleg.clino = -90.0
|
||||||
else:
|
else:
|
||||||
assert re.match(r"[\d\-+.]+$", lcompass), ls
|
assert line_leg_regex.match(lcompass), ls
|
||||||
assert re.match(r"[\d\-+.]+$", lclino) and lclino != "-", ls
|
assert line_leg_regex.match(lclino) and lclino != "-", ls
|
||||||
survexleg.compass = float(lcompass)
|
survexleg.compass = float(lcompass)
|
||||||
survexleg.clino = float(lclino)
|
survexleg.clino = float(lclino)
|
||||||
|
|
||||||
|
if cave:
|
||||||
|
survexleg.cave = cave
|
||||||
|
|
||||||
# only save proper legs
|
# only save proper legs
|
||||||
survexleg.save()
|
survexleg.save()
|
||||||
|
|
||||||
itape = stardata.get("tape")
|
itape = stardata.get("tape")
|
||||||
if itape:
|
if itape:
|
||||||
try:
|
try:
|
||||||
@@ -80,96 +89,212 @@ def LoadSurvexEquate(survexblock, sline):
|
|||||||
|
|
||||||
def LoadSurvexLinePassage(survexblock, stardata, sline, comment):
|
def LoadSurvexLinePassage(survexblock, stardata, sline, comment):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
stardatadefault = {"type":"normal", "t":"leg", "from":0, "to":1, "tape":2, "compass":3, "clino":4}
|
stardatadefault = {"type":"normal", "t":"leg", "from":0, "to":1, "tape":2, "compass":3, "clino":4}
|
||||||
stardataparamconvert = {"length":"tape", "bearing":"compass", "gradient":"clino"}
|
stardataparamconvert = {"length":"tape", "bearing":"compass", "gradient":"clino"}
|
||||||
|
|
||||||
|
regex_comment = re.compile(r"([^;]*?)\s*(?:;\s*(.*))?\n?$")
|
||||||
|
regex_ref = re.compile(r'.*?ref.*?(\d+)\s*#\s*(\d+)')
|
||||||
|
regex_star = re.compile(r'\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$')
|
||||||
|
regex_team = re.compile(r"(Insts|Notes|Tape|Dog|Useless|Pics|Helper|Disto|Consultant)\s+(.*)$(?i)")
|
||||||
|
regex_team_member = re.compile(r" and | / |, | & | \+ |^both$|^none$(?i)")
|
||||||
|
regex_qm = re.compile(r'^\s*QM(\d)\s+?([a-dA-DxX])\s+([\w\-]+)\.(\d+)\s+(([\w\-]+)\.(\d+)|\-)\s+(.+)$')
|
||||||
|
|
||||||
def RecursiveLoad(survexblock, survexfile, fin, textlines):
|
def RecursiveLoad(survexblock, survexfile, fin, textlines):
|
||||||
iblankbegins = 0
|
iblankbegins = 0
|
||||||
text = [ ]
|
text = [ ]
|
||||||
stardata = stardatadefault
|
stardata = stardatadefault
|
||||||
teammembers = [ ]
|
teammembers = [ ]
|
||||||
|
|
||||||
# uncomment to print out all files during parsing
|
# uncomment to print out all files during parsing
|
||||||
print("Reading file:", survexblock.survexfile.path)
|
print(" - Reading file: " + survexblock.survexfile.path)
|
||||||
while True:
|
stamp = datetime.now()
|
||||||
svxline = fin.readline().decode("latin1")
|
lineno = 0
|
||||||
if not svxline:
|
|
||||||
return
|
# Try to find the cave in the DB if not use the string as before
|
||||||
textlines.append(svxline)
|
path_match = re.search(r"caves-(\d\d\d\d)/(\d+|\d\d\d\d-?\w+-\d+)/", survexblock.survexfile.path)
|
||||||
|
if path_match:
|
||||||
|
pos_cave = '%s-%s' % (path_match.group(1), path_match.group(2))
|
||||||
|
# print('Match')
|
||||||
|
# print(pos_cave)
|
||||||
|
cave = models.getCaveByReference(pos_cave)
|
||||||
|
if cave:
|
||||||
|
survexfile.cave = cave
|
||||||
|
svxlines = ''
|
||||||
|
svxlines = fin.read().splitlines()
|
||||||
|
# print('Cave - preloop ' + str(survexfile.cave))
|
||||||
|
# print(survexblock)
|
||||||
|
for svxline in svxlines:
|
||||||
|
|
||||||
|
# print(survexblock)
|
||||||
|
|
||||||
|
# print(svxline)
|
||||||
|
# if not svxline:
|
||||||
|
# print(' - Not survex')
|
||||||
|
# return
|
||||||
|
# textlines.append(svxline)
|
||||||
|
|
||||||
|
lineno += 1
|
||||||
|
|
||||||
|
# print(' - Line: %d' % lineno)
|
||||||
|
|
||||||
# break the line at the comment
|
# break the line at the comment
|
||||||
sline, comment = re.match(r"([^;]*?)\s*(?:;\s*(.*))?\n?$", svxline.strip()).groups()
|
sline, comment = regex_comment.match(svxline.strip()).groups()
|
||||||
|
|
||||||
# detect ref line pointing to the scans directory
|
# detect ref line pointing to the scans directory
|
||||||
mref = comment and re.match(r'.*?ref.*?(\d+)\s*#\s*(\d+)', comment)
|
mref = comment and regex_ref.match(comment)
|
||||||
if mref:
|
if mref:
|
||||||
refscan = "%s#%s" % (mref.group(1), mref.group(2))
|
refscan = "%s#%s" % (mref.group(1), mref.group(2))
|
||||||
survexscansfolders = models.SurvexScansFolder.objects.filter(walletname=refscan)
|
survexscansfolders = models.SurvexScansFolder.objects.filter(walletname=refscan)
|
||||||
if survexscansfolders:
|
if survexscansfolders:
|
||||||
survexblock.survexscansfolder = survexscansfolders[0]
|
survexblock.survexscansfolder = survexscansfolders[0]
|
||||||
#survexblock.refscandir = "%s/%s%%23%s" % (mref.group(1), mref.group(1), mref.group(2))
|
#survexblock.refscandir = "%s/%s%%23%s" % (mref.group(1), mref.group(1), mref.group(2))
|
||||||
survexblock.save()
|
survexblock.save()
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# This whole section should be moved if we can have *QM become a proper survex command
|
||||||
|
# Spec of QM in SVX files, currently commented out need to add to survex
|
||||||
|
# needs to match regex_qm
|
||||||
|
# ;Serial number grade(A/B/C/D/X) nearest-station resolution-station description
|
||||||
|
# ;QM1 a hobnob_hallway_2.42 hobnob-hallway_3.42 junction of keyhole passage
|
||||||
|
# ;QM1 a hobnob_hallway_2.42 - junction of keyhole passage
|
||||||
|
qmline = comment and regex_qm.match(comment)
|
||||||
|
if qmline:
|
||||||
|
print(qmline.groups())
|
||||||
|
#(u'1', u'B', u'miraclemaze', u'1.17', u'-', None, u'\tcontinuation of rift')
|
||||||
|
qm_no = qmline.group(1)
|
||||||
|
qm_grade = qmline.group(2)
|
||||||
|
qm_from_section = qmline.group(3)
|
||||||
|
qm_from_station = qmline.group(4)
|
||||||
|
qm_resolve_section = qmline.group(6)
|
||||||
|
qm_resolve_station = qmline.group(7)
|
||||||
|
qm_notes = qmline.group(8)
|
||||||
|
|
||||||
|
print('Cave - %s' % survexfile.cave)
|
||||||
|
print('QM no %d' % int(qm_no))
|
||||||
|
print('QM grade %s' % qm_grade)
|
||||||
|
print('QM section %s' % qm_from_section)
|
||||||
|
print('QM station %s' % qm_from_station)
|
||||||
|
print('QM res section %s' % qm_resolve_section)
|
||||||
|
print('QM res station %s' % qm_resolve_station)
|
||||||
|
print('QM notes %s' % qm_notes)
|
||||||
|
|
||||||
|
# If the QM isn't resolved (has a resolving station) thn load it
|
||||||
|
if not qm_resolve_section or qm_resolve_section is not '-' or qm_resolve_section is not 'None':
|
||||||
|
from_section = models.SurvexBlock.objects.filter(name=qm_from_section)
|
||||||
|
# If we can find a section (survex note chunck, named)
|
||||||
|
if len(from_section) > 0:
|
||||||
|
print(from_section[0])
|
||||||
|
from_station = models.SurvexStation.objects.filter(block=from_section[0], name=qm_from_station)
|
||||||
|
# If we can find a from station then we have the nearest station and can import it
|
||||||
|
if len(from_station) > 0:
|
||||||
|
print(from_station[0])
|
||||||
|
qm = models.QM.objects.create(number=qm_no,
|
||||||
|
nearest_station=from_station[0],
|
||||||
|
grade=qm_grade.upper(),
|
||||||
|
location_description=qm_notes)
|
||||||
|
else:
|
||||||
|
print('QM found but resolved')
|
||||||
|
|
||||||
|
#print('Cave -sline ' + str(cave))
|
||||||
if not sline:
|
if not sline:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# detect the star command
|
# detect the star command
|
||||||
mstar = re.match(r'\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$', sline)
|
mstar = regex_star.match(sline)
|
||||||
if not mstar:
|
if not mstar:
|
||||||
if "from" in stardata:
|
if "from" in stardata:
|
||||||
LoadSurvexLineLeg(survexblock, stardata, sline, comment)
|
# print('Cave ' + str(survexfile.cave))
|
||||||
|
# print(survexblock)
|
||||||
|
LoadSurvexLineLeg(survexblock, stardata, sline, comment, survexfile.cave)
|
||||||
|
# print(' - From: ')
|
||||||
|
#print(stardata)
|
||||||
|
pass
|
||||||
elif stardata["type"] == "passage":
|
elif stardata["type"] == "passage":
|
||||||
LoadSurvexLinePassage(survexblock, stardata, sline, comment)
|
LoadSurvexLinePassage(survexblock, stardata, sline, comment)
|
||||||
|
# print(' - Passage: ')
|
||||||
#Missing "station" in stardata.
|
#Missing "station" in stardata.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# detect the star command
|
# detect the star command
|
||||||
cmd, line = mstar.groups()
|
cmd, line = mstar.groups()
|
||||||
cmd = cmd.lower()
|
cmd = cmd.lower()
|
||||||
if re.match("include$(?i)", cmd):
|
if re.match("include$(?i)", cmd):
|
||||||
includepath = os.path.join(os.path.split(survexfile.path)[0], re.sub(r"\.svx$", "", line))
|
includepath = os.path.join(os.path.split(survexfile.path)[0], re.sub(r"\.svx$", "", line))
|
||||||
includesurvexfile = models.SurvexFile(path=includepath, cave=survexfile.cave)
|
print(' - Include file found including - ' + includepath)
|
||||||
|
# Try to find the cave in the DB if not use the string as before
|
||||||
|
path_match = re.search(r"caves-(\d\d\d\d)/(\d+|\d\d\d\d-?\w+-\d+)/", includepath)
|
||||||
|
if path_match:
|
||||||
|
pos_cave = '%s-%s' % (path_match.group(1), path_match.group(2))
|
||||||
|
# print(pos_cave)
|
||||||
|
cave = models.getCaveByReference(pos_cave)
|
||||||
|
if cave:
|
||||||
|
survexfile.cave = cave
|
||||||
|
else:
|
||||||
|
print('No match for %s' % includepath)
|
||||||
|
includesurvexfile = models.SurvexFile(path=includepath)
|
||||||
includesurvexfile.save()
|
includesurvexfile.save()
|
||||||
includesurvexfile.SetDirectory()
|
includesurvexfile.SetDirectory()
|
||||||
if includesurvexfile.exists():
|
if includesurvexfile.exists():
|
||||||
|
survexblock.save()
|
||||||
fininclude = includesurvexfile.OpenFile()
|
fininclude = includesurvexfile.OpenFile()
|
||||||
RecursiveLoad(survexblock, includesurvexfile, fininclude, textlines)
|
RecursiveLoad(survexblock, includesurvexfile, fininclude, textlines)
|
||||||
|
|
||||||
elif re.match("begin$(?i)", cmd):
|
elif re.match("begin$(?i)", cmd):
|
||||||
if line:
|
if line:
|
||||||
|
newsvxpath = os.path.join(os.path.split(survexfile.path)[0], re.sub(r"\.svx$", "", line))
|
||||||
|
# Try to find the cave in the DB if not use the string as before
|
||||||
|
path_match = re.search(r"caves-(\d\d\d\d)/(\d+|\d\d\d\d-?\w+-\d+)/", newsvxpath)
|
||||||
|
if path_match:
|
||||||
|
pos_cave = '%s-%s' % (path_match.group(1), path_match.group(2))
|
||||||
|
print(pos_cave)
|
||||||
|
cave = models.getCaveByReference(pos_cave)
|
||||||
|
if cave:
|
||||||
|
survexfile.cave = cave
|
||||||
|
else:
|
||||||
|
print('No match for %s' % newsvxpath)
|
||||||
|
|
||||||
name = line.lower()
|
name = line.lower()
|
||||||
survexblockdown = models.SurvexBlock(name=name, begin_char=fin.tell(), parent=survexblock, survexpath=survexblock.survexpath+"."+name, cave=survexblock.cave, survexfile=survexfile, totalleglength=0.0)
|
print(' - Begin found for: ' + name)
|
||||||
|
# print('Block cave: ' + str(survexfile.cave))
|
||||||
|
survexblockdown = models.SurvexBlock(name=name, begin_char=fin.tell(), parent=survexblock, survexpath=survexblock.survexpath+"."+name, cave=survexfile.cave, survexfile=survexfile, totalleglength=0.0)
|
||||||
survexblockdown.save()
|
survexblockdown.save()
|
||||||
|
survexblock.save()
|
||||||
|
survexblock = survexblockdown
|
||||||
|
# print(survexblockdown)
|
||||||
textlinesdown = [ ]
|
textlinesdown = [ ]
|
||||||
RecursiveLoad(survexblockdown, survexfile, fin, textlinesdown)
|
RecursiveLoad(survexblockdown, survexfile, fin, textlinesdown)
|
||||||
else:
|
else:
|
||||||
iblankbegins += 1
|
iblankbegins += 1
|
||||||
|
|
||||||
elif re.match("end$(?i)", cmd):
|
elif re.match("end$(?i)", cmd):
|
||||||
if iblankbegins:
|
if iblankbegins:
|
||||||
iblankbegins -= 1
|
iblankbegins -= 1
|
||||||
else:
|
else:
|
||||||
survexblock.text = "".join(textlines)
|
survexblock.text = "".join(textlines)
|
||||||
survexblock.save()
|
survexblock.save()
|
||||||
|
# print(' - End found: ')
|
||||||
|
endstamp = datetime.now()
|
||||||
|
timetaken = endstamp - stamp
|
||||||
|
# print(' - Time to process: ' + str(timetaken))
|
||||||
return
|
return
|
||||||
|
|
||||||
elif re.match("date$(?i)", cmd):
|
elif re.match("date$(?i)", cmd):
|
||||||
if len(line) == 10:
|
if len(line) == 10:
|
||||||
survexblock.date = re.sub(r"\.", "-", line)
|
#print(' - Date found: ' + line)
|
||||||
|
survexblock.date = make_aware(datetime.strptime(re.sub(r"\.", "-", line), '%Y-%m-%d'), get_current_timezone())
|
||||||
expeditions = models.Expedition.objects.filter(year=line[:4])
|
expeditions = models.Expedition.objects.filter(year=line[:4])
|
||||||
if expeditions:
|
if expeditions:
|
||||||
assert len(expeditions) == 1
|
assert len(expeditions) == 1
|
||||||
survexblock.expedition = expeditions[0]
|
survexblock.expedition = expeditions[0]
|
||||||
survexblock.expeditionday = survexblock.expedition.get_expedition_day(survexblock.date)
|
survexblock.expeditionday = survexblock.expedition.get_expedition_day(survexblock.date)
|
||||||
survexblock.save()
|
survexblock.save()
|
||||||
|
|
||||||
elif re.match("team$(?i)", cmd):
|
elif re.match("team$(?i)", cmd):
|
||||||
mteammember = re.match(r"(Insts|Notes|Tape|Dog|Useless|Pics|Helper|Disto|Consultant)\s+(.*)$(?i)", line)
|
pass
|
||||||
|
# print(' - Team found: ')
|
||||||
|
mteammember = regex_team.match(line)
|
||||||
if mteammember:
|
if mteammember:
|
||||||
for tm in re.split(r" and | / |, | & | \+ |^both$|^none$(?i)", mteammember.group(2)):
|
for tm in regex_team_member.split(mteammember.group(2)):
|
||||||
if tm:
|
if tm:
|
||||||
personexpedition = survexblock.expedition and GetPersonExpeditionNameLookup(survexblock.expedition).get(tm.lower())
|
personexpedition = survexblock.expedition and GetPersonExpeditionNameLookup(survexblock.expedition).get(tm.lower())
|
||||||
if (personexpedition, tm) not in teammembers:
|
if (personexpedition, tm) not in teammembers:
|
||||||
@@ -179,18 +304,23 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
|
|||||||
if personexpedition:
|
if personexpedition:
|
||||||
personrole.person=personexpedition.person
|
personrole.person=personexpedition.person
|
||||||
personrole.save()
|
personrole.save()
|
||||||
|
|
||||||
elif cmd == "title":
|
elif cmd == "title":
|
||||||
survextitle = models.SurvexTitle(survexblock=survexblock, title=line.strip('"'), cave=survexblock.cave)
|
#print(' - Title found: ')
|
||||||
|
survextitle = models.SurvexTitle(survexblock=survexblock, title=line.strip('"'), cave=survexfile.cave)
|
||||||
survextitle.save()
|
survextitle.save()
|
||||||
|
pass
|
||||||
|
|
||||||
elif cmd == "require":
|
elif cmd == "require":
|
||||||
# should we check survex version available for processing?
|
# should we check survex version available for processing?
|
||||||
pass
|
pass
|
||||||
|
|
||||||
elif cmd == "data":
|
elif cmd == "data":
|
||||||
|
#print(' - Data found: ')
|
||||||
ls = line.lower().split()
|
ls = line.lower().split()
|
||||||
stardata = { "type":ls[0] }
|
stardata = { "type":ls[0] }
|
||||||
|
#print(' - Star data: ', stardata)
|
||||||
|
#print(ls)
|
||||||
for i in range(0, len(ls)):
|
for i in range(0, len(ls)):
|
||||||
stardata[stardataparamconvert.get(ls[i], ls[i])] = i - 1
|
stardata[stardataparamconvert.get(ls[i], ls[i])] = i - 1
|
||||||
if ls[0] in ["normal", "cartesian", "nosurvey"]:
|
if ls[0] in ["normal", "cartesian", "nosurvey"]:
|
||||||
@@ -199,40 +329,23 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
|
|||||||
stardata = stardatadefault
|
stardata = stardatadefault
|
||||||
else:
|
else:
|
||||||
assert ls[0] == "passage", line
|
assert ls[0] == "passage", line
|
||||||
|
|
||||||
elif cmd == "equate":
|
elif cmd == "equate":
|
||||||
|
#print(' - Equate found: ')
|
||||||
LoadSurvexEquate(survexblock, line)
|
LoadSurvexEquate(survexblock, line)
|
||||||
|
|
||||||
elif cmd == "fix":
|
elif cmd == "fix":
|
||||||
|
#print(' - Fix found: ')
|
||||||
survexblock.MakeSurvexStation(line.split()[0])
|
survexblock.MakeSurvexStation(line.split()[0])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
#print(' - Stuff')
|
||||||
if cmd not in ["sd", "include", "units", "entrance", "data", "flags", "title", "export", "instrument",
|
if cmd not in ["sd", "include", "units", "entrance", "data", "flags", "title", "export", "instrument",
|
||||||
"calibrate", "set", "infer", "alias", "ref", "cs", "declination", "case"]:
|
"calibrate", "set", "infer", "alias", "ref", "cs", "declination", "case"]:
|
||||||
print("Unrecognised command in line:", cmd, line, survexblock, survexblock.survexfile.path)
|
print("Unrecognised command in line:", cmd, line, survexblock, survexblock.survexfile.path)
|
||||||
|
endstamp = datetime.now()
|
||||||
|
timetaken = endstamp - stamp
|
||||||
def ReloadSurvexCave(survex_cave, area):
|
# print(' - Time to process: ' + str(timetaken))
|
||||||
print(survex_cave, area)
|
|
||||||
cave = models.Cave.objects.get(kataster_number=survex_cave, area__short_name=area)
|
|
||||||
print(cave)
|
|
||||||
#cave = models.Cave.objects.get(kataster_number=survex_cave)
|
|
||||||
cave.survexblock_set.all().delete()
|
|
||||||
cave.survexfile_set.all().delete()
|
|
||||||
cave.survexdirectory_set.all().delete()
|
|
||||||
|
|
||||||
survexfile = models.SurvexFile(path="caves-" + cave.kat_area() + "/" + survex_cave + "/" + survex_cave, cave=cave)
|
|
||||||
survexfile.save()
|
|
||||||
survexfile.SetDirectory()
|
|
||||||
|
|
||||||
survexblockroot = models.SurvexBlock(name="root", survexpath="caves-" + cave.kat_area(), begin_char=0, cave=cave, survexfile=survexfile, totalleglength=0.0)
|
|
||||||
survexblockroot.save()
|
|
||||||
fin = survexfile.OpenFile()
|
|
||||||
textlines = [ ]
|
|
||||||
RecursiveLoad(survexblockroot, survexfile, fin, textlines)
|
|
||||||
survexblockroot.text = "".join(textlines)
|
|
||||||
survexblockroot.save()
|
|
||||||
|
|
||||||
|
|
||||||
def LoadAllSurvexBlocks():
|
def LoadAllSurvexBlocks():
|
||||||
|
|
||||||
@@ -249,7 +362,7 @@ def LoadAllSurvexBlocks():
|
|||||||
|
|
||||||
print(" - Data flushed")
|
print(" - Data flushed")
|
||||||
|
|
||||||
survexfile = models.SurvexFile(path="all", cave=None)
|
survexfile = models.SurvexFile(path=settings.SURVEX_TOPNAME, cave=None)
|
||||||
survexfile.save()
|
survexfile.save()
|
||||||
survexfile.SetDirectory()
|
survexfile.SetDirectory()
|
||||||
|
|
||||||
@@ -258,22 +371,13 @@ def LoadAllSurvexBlocks():
|
|||||||
survexblockroot.save()
|
survexblockroot.save()
|
||||||
fin = survexfile.OpenFile()
|
fin = survexfile.OpenFile()
|
||||||
textlines = [ ]
|
textlines = [ ]
|
||||||
|
# The real work starts here
|
||||||
RecursiveLoad(survexblockroot, survexfile, fin, textlines)
|
RecursiveLoad(survexblockroot, survexfile, fin, textlines)
|
||||||
|
fin.close()
|
||||||
survexblockroot.text = "".join(textlines)
|
survexblockroot.text = "".join(textlines)
|
||||||
survexblockroot.save()
|
survexblockroot.save()
|
||||||
|
|
||||||
|
|
||||||
#Load each cave,
|
|
||||||
#FIXME this should be dealt with load all above
|
|
||||||
print(" - Reloading all caves")
|
|
||||||
caves = models.Cave.objects.all()
|
|
||||||
for cave in caves:
|
|
||||||
if cave.kataster_number and os.path.isdir(os.path.join(settings.SURVEX_DATA, "caves-" + cave.kat_area(), cave.kataster_number)):
|
|
||||||
if cave.kataster_number not in ['40']:
|
|
||||||
print("loading", cave, cave.kat_area())
|
|
||||||
ReloadSurvexCave(cave.kataster_number, cave.kat_area())
|
|
||||||
|
|
||||||
|
|
||||||
poslineregex = re.compile(r"^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$")
|
poslineregex = re.compile(r"^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$")
|
||||||
|
|
||||||
|
|
||||||
@@ -281,12 +385,12 @@ def LoadPos():
|
|||||||
|
|
||||||
print('Loading Pos....')
|
print('Loading Pos....')
|
||||||
|
|
||||||
call([settings.CAVERN, "--output=%s/all.3d" % settings.SURVEX_DATA, "%s/all.svx" % settings.SURVEX_DATA])
|
call([settings.CAVERN, "--output=%s%s.3d" % (settings.SURVEX_DATA, settings.SURVEX_TOPNAME), "%s%s.svx" % (settings.SURVEX_DATA, settings.SURVEX_TOPNAME)])
|
||||||
call([settings.THREEDTOPOS, '%sall.3d' % settings.SURVEX_DATA], cwd = settings.SURVEX_DATA)
|
call([settings.THREEDTOPOS, '%s%s.3d' % (settings.SURVEX_DATA, settings.SURVEX_TOPNAME)], cwd = settings.SURVEX_DATA)
|
||||||
posfile = open("%sall.pos" % settings.SURVEX_DATA)
|
posfile = open("%s%s.pos" % (settings.SURVEX_DATA, settings.SURVEX_TOPNAME))
|
||||||
posfile.readline() #Drop header
|
posfile.readline() #Drop header
|
||||||
for line in posfile.readlines():
|
for line in posfile.readlines():
|
||||||
r = poslineregex.match(line)
|
r = poslineregex.match(line)
|
||||||
if r:
|
if r:
|
||||||
x, y, z, name = r.groups()
|
x, y, z, name = r.groups()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ def parseSurveyScans(expedition, logfile=None):
|
|||||||
#scanList = listdir(expedition.year, surveyFolder)
|
#scanList = listdir(expedition.year, surveyFolder)
|
||||||
scanList=os.listdir(os.path.join(yearPath,surveyFolder))
|
scanList=os.listdir(os.path.join(yearPath,surveyFolder))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print(surveyFolder + " ignored\r",)
|
print("Folder: " + surveyFolder + " ignored\r")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for scan in scanList:
|
for scan in scanList:
|
||||||
@@ -107,7 +107,7 @@ def parseSurveyScans(expedition, logfile=None):
|
|||||||
scanChopped=re.match(r'(?i).*(notes|elev|plan|elevation|extend)(\d*)\.(png|jpg|jpeg)',scan).groups()
|
scanChopped=re.match(r'(?i).*(notes|elev|plan|elevation|extend)(\d*)\.(png|jpg|jpeg)',scan).groups()
|
||||||
scanType,scanNumber,scanFormat=scanChopped
|
scanType,scanNumber,scanFormat=scanChopped
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
print(scan + " ignored\r",)
|
print("File: " + scan + " ignored\r")
|
||||||
continue
|
continue
|
||||||
if scanType == 'elev' or scanType == 'extend':
|
if scanType == 'elev' or scanType == 'extend':
|
||||||
scanType = 'elevation'
|
scanType = 'elevation'
|
||||||
@@ -174,9 +174,6 @@ def GetListDir(sdir):
|
|||||||
ff = os.path.join(sdir, f)
|
ff = os.path.join(sdir, f)
|
||||||
res.append((f, ff, os.path.isdir(ff)))
|
res.append((f, ff, os.path.isdir(ff)))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def LoadListScansFile(survexscansfolder):
|
def LoadListScansFile(survexscansfolder):
|
||||||
|
|||||||
47
settings.py
47
settings.py
@@ -10,7 +10,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|||||||
DEBUG = True
|
DEBUG = True
|
||||||
TEMPLATE_DEBUG = DEBUG
|
TEMPLATE_DEBUG = DEBUG
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS = [u'expo.survex.com']
|
||||||
|
|
||||||
ADMINS = (
|
ADMINS = (
|
||||||
# ('Your Name', 'your_email@domain.com'),
|
# ('Your Name', 'your_email@domain.com'),
|
||||||
@@ -45,14 +45,52 @@ NOTABLECAVESHREFS = [ "161", "204", "258", "76", "107", "264" ]
|
|||||||
# Examples: "http://foo.com/media/", "/media/".
|
# Examples: "http://foo.com/media/", "/media/".
|
||||||
ADMIN_MEDIA_PREFIX = '/troggle/media-admin/'
|
ADMIN_MEDIA_PREFIX = '/troggle/media-admin/'
|
||||||
PHOTOS_ROOT = os.path.join(EXPOWEB, 'photos')
|
PHOTOS_ROOT = os.path.join(EXPOWEB, 'photos')
|
||||||
CAVEDESCRIPTIONS = os.path.join(EXPOWEB, "noinfo", "cave_data")
|
CAVEDESCRIPTIONS = os.path.join(EXPOWEB, "cave_data")
|
||||||
ENTRANCEDESCRIPTIONS = os.path.join(EXPOWEB, "noinfo", "entrance_data")
|
ENTRANCEDESCRIPTIONS = os.path.join(EXPOWEB, "entrance_data")
|
||||||
|
|
||||||
MEDIA_URL = urlparse.urljoin(URL_ROOT , '/site_media/')
|
MEDIA_URL = urlparse.urljoin(URL_ROOT , '/site_media/')
|
||||||
SURVEYS_URL = urlparse.urljoin(URL_ROOT , '/survey_scans/')
|
SURVEYS_URL = urlparse.urljoin(URL_ROOT , '/survey_scans/')
|
||||||
PHOTOS_URL = urlparse.urljoin(URL_ROOT , '/photos/')
|
PHOTOS_URL = urlparse.urljoin(URL_ROOT , '/photos/')
|
||||||
SVX_URL = urlparse.urljoin(URL_ROOT , '/survex/')
|
SVX_URL = urlparse.urljoin(URL_ROOT , '/survex/')
|
||||||
|
|
||||||
|
# top-level survex file basename (without .svx)
|
||||||
|
SURVEX_TOPNAME = "1623"
|
||||||
|
|
||||||
|
DEFAULT_LOGBOOK_PARSER = "Parseloghtmltxt"
|
||||||
|
DEFAULT_LOGBOOK_FILE = "logbook.html"
|
||||||
|
|
||||||
|
LOGBOOK_PARSER_SETTINGS = {
|
||||||
|
"2019": ("2019/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2018": ("2018/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2017": ("2017/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2016": ("2016/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2015": ("2015/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2014": ("2014/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2013": ("2013/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2012": ("2012/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2011": ("2011/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2010": ("2010/logbook.html", "Parselogwikitxt"),
|
||||||
|
"2009": ("2009/2009logbook.txt", "Parselogwikitxt"),
|
||||||
|
"2008": ("2008/2008logbook.txt", "Parselogwikitxt"),
|
||||||
|
"2007": ("2007/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2006": ("2006/logbook/logbook_06.txt", "Parselogwikitxt"),
|
||||||
|
"2005": ("2005/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2004": ("2004/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2003": ("2003/logbook.html", "Parseloghtml03"),
|
||||||
|
"2002": ("2002/logbook.html", "Parseloghtmltxt"),
|
||||||
|
"2001": ("2001/log.htm", "Parseloghtml01"),
|
||||||
|
"2000": ("2000/log.htm", "Parseloghtml01"),
|
||||||
|
"1999": ("1999/log.htm", "Parseloghtml01"),
|
||||||
|
"1998": ("1998/log.htm", "Parseloghtml01"),
|
||||||
|
"1997": ("1997/log.htm", "Parseloghtml01"),
|
||||||
|
"1996": ("1996/log.htm", "Parseloghtml01"),
|
||||||
|
"1995": ("1995/log.htm", "Parseloghtml01"),
|
||||||
|
"1994": ("1994/log.htm", "Parseloghtml01"),
|
||||||
|
"1993": ("1993/log.htm", "Parseloghtml01"),
|
||||||
|
"1992": ("1992/log.htm", "Parseloghtml01"),
|
||||||
|
"1991": ("1991/log.htm", "Parseloghtml01"),
|
||||||
|
}
|
||||||
|
|
||||||
APPEND_SLASH = False
|
APPEND_SLASH = False
|
||||||
SMART_APPEND_SLASH = True
|
SMART_APPEND_SLASH = True
|
||||||
|
|
||||||
@@ -71,9 +109,6 @@ if django.VERSION[0] == 1 and django.VERSION[1] < 4:
|
|||||||
else:
|
else:
|
||||||
authmodule = 'django.contrib.auth.context_processors.auth'
|
authmodule = 'django.contrib.auth.context_processors.auth'
|
||||||
|
|
||||||
TOPCAMPX=411571.00
|
|
||||||
TOPCAMPY=5282639.00
|
|
||||||
|
|
||||||
TEMPLATE_CONTEXT_PROCESSORS = ( authmodule, "core.context.troggle_context", )
|
TEMPLATE_CONTEXT_PROCESSORS = ( authmodule, "core.context.troggle_context", )
|
||||||
|
|
||||||
LOGIN_REDIRECT_URL = '/'
|
LOGIN_REDIRECT_URL = '/'
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
<link rel="stylesheet" type="text/css" href="{{ settings.MEDIA_URL }}css/main3.css" title="eyeCandy"/>
|
<link rel="stylesheet" type="text/css" href="{{ settings.MEDIA_URL }}css/main3.css" title="eyeCandy"/>
|
||||||
<link rel="alternate stylesheet" type="text/css" href="{{ settings.MEDIA_URL }}css/mainplain.css" title="plain"/>
|
<link rel="alternate stylesheet" type="text/css" href="{{ settings.MEDIA_URL }}css/mainplain.css" title="plain"/>
|
||||||
<link rel="stylesheet" type="text/css" href="{{ settings.MEDIA_URL }}css/dropdownNavStyle.css" />
|
<link rel="stylesheet" type="text/css" href="{{ settings.MEDIA_URL }}css/dropdownNavStyle.css" />
|
||||||
<title>{% block title %}Troggle{% endblock %}</title>
|
<title>{% block title %}Troggle{% endblock %}</title>
|
||||||
<script src="{{ settings.JSLIB_URL }}jquery/jquery.min.js" type="text/javascript"></script>
|
<!-- <script src="{{ settings.JSLIB_URL }}jquery/jquery.min.js" type="text/javascript"></script> -->
|
||||||
<script src="{{ settings.MEDIA_URL }}js/jquery.quicksearch.js" type="text/javascript"></script>
|
<script src="{{ settings.MEDIA_URL }}js/jquery.quicksearch.js" type="text/javascript"></script>
|
||||||
<script src="{{ settings.MEDIA_URL }}js/base.js" type="text/javascript"></script>
|
<script src="{{ settings.MEDIA_URL }}js/base.js" type="text/javascript"></script>
|
||||||
<script src="{{ settings.MEDIA_URL }}js/jquery.dropdownPlain.js" type="text/javascript"></script>
|
<script src="{{ settings.MEDIA_URL }}js/jquery.dropdownPlain.js" type="text/javascript"></script>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<body onLoad="contentHeight();">
|
<body onLoad="contentHeight();">
|
||||||
|
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<h1>CUCC Expeditions to Austria: 1976 - 2018</h1>
|
<h1>CUCC Expeditions to Austria: 1976 - 2020</h1>
|
||||||
<div id="editLinks"> {% block loginInfo %}
|
<div id="editLinks"> {% block loginInfo %}
|
||||||
<a href="{{settings.EXPOWEB_URL}}">Website home</a> |
|
<a href="{{settings.EXPOWEB_URL}}">Website home</a> |
|
||||||
{% if user.username %}
|
{% if user.username %}
|
||||||
@@ -43,6 +43,8 @@
|
|||||||
<a href="{% url "expedition" 2016 %}">Expo2016</a> |
|
<a href="{% url "expedition" 2016 %}">Expo2016</a> |
|
||||||
<a href="{% url "expedition" 2017 %}">Expo2017</a> |
|
<a href="{% url "expedition" 2017 %}">Expo2017</a> |
|
||||||
<a href="{% url "expedition" 2018 %}">Expo2018</a> |
|
<a href="{% url "expedition" 2018 %}">Expo2018</a> |
|
||||||
|
<a href="{% url "expedition" 2019 %}">Expo2019</a> |
|
||||||
|
<a href="{% url "expedition" 2020 %}">Expo2020</a> |
|
||||||
|
|
||||||
<a href="/admin/">Django admin</a>
|
<a href="/admin/">Django admin</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -81,7 +83,7 @@
|
|||||||
|
|
||||||
<li><a href="#">External links</a>
|
<li><a href="#">External links</a>
|
||||||
<ul class="sub_menu">
|
<ul class="sub_menu">
|
||||||
<li><a id="cuccLink" href="http://www.srcf.ucam.org/caving/wiki/Main_Page">CUCC website</a></li>
|
<li><a id="cuccLink" href="https://camcaving.uk">CUCC website</a></li>
|
||||||
<li><a id="expoWebsiteLink" href="http://expo.survex.com">Expedition website</a></li>
|
<li><a id="expoWebsiteLink" href="http://expo.survex.com">Expedition website</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -408,8 +408,8 @@ div#scene {
|
|||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script type="text/javascript" src="/CaveView/js/CaveView.js" ></script>
|
<script type="text/javascript" src="/javascript/CaveView/js/CaveView.js" ></script>
|
||||||
<script type="text/javascript" src="/CaveView/lib/proj4.js" ></script>
|
<script type="text/javascript" src="/javascript/CaveView/lib/proj4.js" ></script>
|
||||||
|
|
||||||
|
|
||||||
<script type="text/javascript" >
|
<script type="text/javascript" >
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<h3>Notable caves</h3>
|
<h3>Notable caves</h3>
|
||||||
<ul>
|
<ul>
|
||||||
{% for cave in notablecaves %}
|
{% for cave in notablecaves %}
|
||||||
<li> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li>
|
<li> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{% endif %} {{cave.official_name|safe}}</a> </li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<table class="searchable">
|
<table class="searchable">
|
||||||
{% for cave in caves1623 %}
|
{% for cave in caves1623 %}
|
||||||
|
|
||||||
<tr><td> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> {{ cave.slug }}</td></tr>
|
<tr><td> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }} {{cave.official_name|safe}}</a> {% if cave.unofficial_number %}({{cave.unofficial_number }}){% endif %}{% else %}{{cave.unofficial_number }} {{cave.official_name|safe}}</a> {% endif %}</td></tr>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
@@ -30,7 +30,8 @@
|
|||||||
<ul class="searchable">
|
<ul class="searchable">
|
||||||
{% for cave in caves1626 %}
|
{% for cave in caves1626 %}
|
||||||
|
|
||||||
<li> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }}{% else %}{{cave.unofficial_number }}{%endif %} {{cave.official_name|safe}}</a> </li>
|
<li> <a href="{{ cave.url }}">{% if cave.kataster_number %}{{ cave.kataster_number }} {{cave.official_name|safe}}</a> {% if cave.unofficial_number %}({{cave.unofficial_number }}){% endif %}{% else %}{{cave.unofficial_number }} {{cave.official_name|safe}}</a> {% endif %}
|
||||||
|
</li>
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -23,25 +23,45 @@
|
|||||||
|
|
||||||
|
|
||||||
<form name="reset" method="post" action="">
|
<form name="reset" method="post" action="">
|
||||||
<h3>Wipe:</h3>
|
<h3>Wipe:</h3>
|
||||||
|
<table>
|
||||||
<table>
|
<tr>
|
||||||
<tr><td>Wipe entire database and recreate tables: </td><td><input type="checkbox" name="reload_db" /></td><td> <input type="submit" id="Import" value="I really want to delete all information in troggle, and accept all responsibility."></td></tr>
|
<td>Wipe entire database and recreate tables: </td>
|
||||||
</table>
|
<td><input type="checkbox" name="reload_db" /></td>
|
||||||
|
<td>
|
||||||
|
<input type="submit" id="Import" value="I really want to delete all information in troggle, and accept all responsibility.">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
</form>
|
</form>
|
||||||
<h3>Import (non-destructive):</h3>
|
<h3>Import (non-destructive):</h3>
|
||||||
<form name="import" method="post" action="">
|
<form name="import" method="post" action="">
|
||||||
<table>
|
<table>
|
||||||
<tr><td>people from folk.csv using parsers\people.py</td><td><input type="checkbox" name="import_people"/></td></tr>
|
<tr>
|
||||||
<tr><td>caves from cavetab2.csv using parsers\cavetab.py</td><td> <input type="checkbox" class="parser" name="import_cavetab"/></td></tr>
|
<td>people from folk.csv using parsers\people.py</td>
|
||||||
<tr><td>logbook entries using parsers\logbooks.py</td><td><input type="checkbox" name="import_logbooks"/></td></tr>
|
<td><input type="checkbox" name="import_people"/></td>
|
||||||
<tr><td>QMs using parsers\QMs.py</td><td><input type="checkbox" name="import_QMs" /></td></tr>
|
</tr>
|
||||||
<tr><td>survey scans using parsers\surveys.py</td><td><input type="checkbox" name="import_surveys" /></td></tr>
|
<tr>
|
||||||
<tr><td>survex data using parsers\survex.py</td><td><input type="checkbox" name="import_survex" /></td></tr>
|
<td>caves from cavetab2.csv using parsers\cavetab.py</td>
|
||||||
|
<td> <input type="checkbox" class="parser" name="import_cavetab"/></td>
|
||||||
</table>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>logbook entries using parsers\logbooks.py</td>
|
||||||
|
<td><input type="checkbox" name="import_logbooks"/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>QMs using parsers\QMs.py</td>
|
||||||
|
<td><input type="checkbox" name="import_QMs" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>survey scans using parsers\surveys.py</td>
|
||||||
|
<td><input type="checkbox" name="import_surveys" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>survex data using parsers\survex.py</td>
|
||||||
|
<td><input type="checkbox" name="import_survex" /></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
<p>
|
<p>
|
||||||
<input type="submit" id="Import" value="Import">
|
<input type="submit" id="Import" value="Import">
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
<!DOCTYPE html>
|
||||||
<!-- Only put one cave in this file -->
|
<!-- Only put one cave in this file -->
|
||||||
<!-- If you edit this file, make sure you update the websites database -->
|
<!-- If you edit this file, make sure you update the websites database -->
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
<!DOCTYPE html>
|
||||||
<!-- Only put one entrance in this file -->
|
<!-- Only put one entrance in this file -->
|
||||||
<!-- If you edit this file, make sure you update the websites database -->
|
<!-- If you edit this file, make sure you update the websites database -->
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{% autoescape off %}
|
{% autoescape off %}
|
||||||
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<style type="text/css">.author {text-decoration:underline}</style>
|
<style type="text/css">.author {text-decoration:underline}</style>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
<script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script>
|
<script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<h1>Edit Cave</h1>
|
||||||
<form action="" method="post">{% csrf_token %}
|
<form action="" method="post">{% csrf_token %}
|
||||||
<table>{{ form }}{{caveAndEntranceFormSet}}</table>
|
<table>{{ form }}{{caveAndEntranceFormSet}}</table>
|
||||||
{{ versionControlForm }}
|
{{ versionControlForm }}
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
{% block extrahead %}
|
{% block extrahead %}
|
||||||
{% load csrffaker %}
|
{% load csrffaker %}
|
||||||
<script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script>
|
<script src="{{ settings.TINY_MCE_MEDIA_URL }}tiny_mce.js" type="text/javascript"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
tinyMCE.init({
|
||||||
|
mode : "textareas"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Edit {{ path }}</h1>
|
<h1>Edit {{ path }}</h1>
|
||||||
|
|||||||
@@ -10,10 +10,6 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{% if message %}
|
|
||||||
<p>debug message: {{message}}</p>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<h2>{{expedition.name}}</h2>
|
<h2>{{expedition.name}}</h2>
|
||||||
|
|
||||||
<p><b>Other years:</b>
|
<p><b>Other years:</b>
|
||||||
@@ -41,13 +37,13 @@ an "S" for a survey trip. The colours are the same for people on the same trip.
|
|||||||
</tr>
|
</tr>
|
||||||
{% for personexpeditionday in personexpeditiondays %}
|
{% for personexpeditionday in personexpeditiondays %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ personexpeditionday.personexpedition.get_absolute_url }}">{{personexpeditionday.personexpedition.person}}</a></td>
|
<td><a href="{{ personexpeditionday.personexpedition.get_absolute_url }}">{{personexpeditionday.personexpedition.person|safe}}</a></td>
|
||||||
{% for persondayactivities in personexpeditionday.personrow %}
|
{% for persondayactivities in personexpeditionday.personrow %}
|
||||||
|
|
||||||
{% if persondayactivities.persontrips or persondayactivities.survexblocks %}
|
{% if persondayactivities.persontrips or persondayactivities.survexblocks %}
|
||||||
<td class="persondayactivity">
|
<td class="persondayactivity">
|
||||||
{% for persontrip in persondayactivities.persontrips %}
|
{% for persontrip in persondayactivities.persontrips %}
|
||||||
<a href="{{persontrip.logbook_entry.get_absolute_url}}" class="dayindexlog-{{persontrip.logbook_entry.DayIndex}}">T</a>
|
<a href="{{persontrip.logbook_entry.get_absolute_url}}" class="dayindexlog-1">T</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<br/>
|
<br/>
|
||||||
{% for survexblock in persondayactivities.survexblocks %}
|
{% for survexblock in persondayactivities.survexblocks %}
|
||||||
@@ -73,7 +69,7 @@ an "S" for a survey trip. The colours are the same for people on the same trip.
|
|||||||
{% regroup dateditems|dictsort:"date" by date as dates %}
|
{% regroup dateditems|dictsort:"date" by date as dates %}
|
||||||
{% for date in dates %}
|
{% for date in dates %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{date.grouper}}</td>
|
<td>{{date.grouper|date:"D d M Y"}}</td>
|
||||||
<td>{% for item in date.list %}
|
<td>{% for item in date.list %}
|
||||||
{% if item.isLogbookEntry %}<a href="{{ item.get_absolute_url }}">{{item.title|safe}}</a><br/>{% endif %}
|
{% if item.isLogbookEntry %}<a href="{{ item.get_absolute_url }}">{{item.title|safe}}</a><br/>{% endif %}
|
||||||
{% endfor %}</td>
|
{% endfor %}</td>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
{% if entry.is_deletion %}
|
{% if entry.is_deletion %}
|
||||||
{{ entry.object_repr }}
|
{{ entry.object_repr }}
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="admin/{{ entry.get_admin_url }}">{{ entry.object_repr }}</a>
|
<a href="admin/{{ entry.get_admin_url }}/">{{ entry.object_repr }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br/>
|
<br/>
|
||||||
{% if entry.content_type %}
|
{% if entry.content_type %}
|
||||||
@@ -49,17 +49,6 @@ Here you will find information about the {{expedition.objects.count}} expedition
|
|||||||
If you are an expedition member, please sign up using the link to the top right and begin editing.
|
If you are an expedition member, please sign up using the link to the top right and begin editing.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3>News</h3>
|
|
||||||
|
|
||||||
<p class="indent">
|
|
||||||
Everyone is gearing up for the 2009 expedition; please see the link below for the main expedition website.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<h3>Troggle development</h3>
|
|
||||||
<p class="indent">
|
|
||||||
Troggle is still under development. Check out the <a href="http://troggle.googlecode.com">development page</a> on google code, where you can file bug reports, make suggestions, and help develop the code. There is also an old todo list at <a href="{%url "todo"%}">here</a>.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
{% block margins %}
|
{% block margins %}
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
{% load wiki_markup %}
|
{% load wiki_markup %}
|
||||||
|
|
||||||
{% block title %}Logbook {{logbookentry.id}}{% endblock %}
|
{% block title %}Logbook {{logbookentry.id}}{% endblock %}
|
||||||
{% block editLink %}<a href={{logbookentry.get_admin_url}}>Edit logbook entry {{logbookentry|wiki_to_html_short}}</a>{% endblock %}
|
{% block editLink %}<a href={{logbookentry.get_admin_url}}/>Edit logbook entry {{logbookentry|wiki_to_html_short}}</a>{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{% block related %}{% endblock %}
|
{% block related %}{% endblock %}
|
||||||
{% block nav %}{% endblock %}
|
{% block nav %}{% endblock %}
|
||||||
<h2>{{logbookentry.title}}</h2>
|
<h2>{{logbookentry.title|safe}}</h2>
|
||||||
|
|
||||||
<div id="related">
|
<div id="related">
|
||||||
<p><a href="{{ logbookentry.expedition.get_absolute_url }}">{{logbookentry.expedition.name}}</a></p>
|
<p><a href="{{ logbookentry.expedition.get_absolute_url }}">{{logbookentry.expedition.name}}</a></p>
|
||||||
@@ -20,10 +20,10 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% if logbookentry.get_previous_by_date %}
|
{% if logbookentry.get_previous_by_date %}
|
||||||
<a href="{{ logbookentry.get_previous_by_date.get_absolute_url }}">{{logbookentry.get_previous_by_date.date}}</a>
|
<a href="{{ logbookentry.get_previous_by_date.get_absolute_url }}">{{logbookentry.get_previous_by_date.date|date:"D d M Y"}}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if logbookentry.get_next_by_date %}
|
{% if logbookentry.get_next_by_date %}
|
||||||
<a href="{{ logbookentry.get_next_by_date.get_absolute_url }}">{{logbookentry.get_next_by_date.date}}</a>
|
<a href="{{ logbookentry.get_next_by_date.get_absolute_url }}">{{logbookentry.get_next_by_date.date|date:"D d M Y"}}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -47,12 +47,12 @@
|
|||||||
|
|
||||||
<td>
|
<td>
|
||||||
{% if persontrip.persontrip_prev %}
|
{% if persontrip.persontrip_prev %}
|
||||||
<a href="{{ persontrip.persontrip_prev.logbook_entry.get_absolute_url }}">{{persontrip.persontrip_prev.logbook_entry.date}}</a>
|
<a href="{{ persontrip.persontrip_prev.logbook_entry.get_absolute_url }}">{{persontrip.persontrip_prev.logbook_entry.date|date:"D d M Y"}}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% if persontrip.persontrip_next %}
|
{% if persontrip.persontrip_next %}
|
||||||
<a href="{{ persontrip.persontrip_next.logbook_entry.get_absolute_url }}">{{persontrip.persontrip_next.logbook_entry.date}}</a>
|
<a href="{{ persontrip.persontrip_next.logbook_entry.get_absolute_url }}">{{persontrip.persontrip_next.logbook_entry.date|date:"D d M Y"}}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
@@ -65,9 +65,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="col1">
|
<div id="col1">
|
||||||
<div class="logbookentry">
|
<div class="logbookentry">
|
||||||
<b>{{logbookentry.date}}</b>
|
<b>{{logbookentry.date|date:"D d M Y"}}</b>
|
||||||
{{logbookentry.text|wiki_to_html}}</div>
|
{% if logbookentry.entry_type == "html" %}
|
||||||
|
<p>{{logbookentry.text|safe}}</p>
|
||||||
|
{% else %}
|
||||||
|
{{logbookentry.text|wiki_to_html}}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,69 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="stylesheet" type="text/css" href="{{ settings.MEDIA_URL }}/css/cavetables.css">
|
|
||||||
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<h2>Caves of loserplateau (locations acording to all.3d)</h2>
|
|
||||||
<span style="font-size:70%">
|
|
||||||
Name contains:<br>
|
|
||||||
<div id="inputf"><input type="text" name="CaveName" id="CaveName" style="width:100%"></div><br>
|
|
||||||
Depth between (min, max) in meters (0 disables filter):<br>
|
|
||||||
<div id="inputf"><input type="number" name="CaveDepthMin" id="CaveDepthMin" style="width:45%"> - <input type="number" name="CaveDepthMax" id="CaveDepthMax" style="width:45%"></div><br>
|
|
||||||
Length between (min, max) in meters (0 disables filter):<br>
|
|
||||||
<div id="inputf"><input type="number" name="CaveLengthMin" id="CaveLengthMin" style="width:45%"> - <input type="number" name="CaveLengthMax" id="CaveLengthMax" style="width:45%"></div><br>
|
|
||||||
Last visit after (date in YYYY.MM.DD format works best):<br>
|
|
||||||
<div id="inputf"><input type="text" name="VisitDate" id="VisitDate" style="width:100%"></div><br>
|
|
||||||
Last visited by (single word or regular expression, search is not case sensitive):<br>
|
|
||||||
(e.g. <span id="mono">/da.e/</span> matches both Dave and Dane, <span id="mono">/w..k|ol{2}y/</span> matches either Wook and Olly)<br>
|
|
||||||
<div id="inputf"><input type="text" name="Visitor" id="Visitor" style="width:100%"></div><br>
|
|
||||||
Hide incomplete entries:<br>
|
|
||||||
<div id="inputf"><input type="checkbox" name="Incomplete" id="Incomplete" style="width:100%"></div><br><br>
|
|
||||||
|
|
||||||
<button onclick="filterTable('caves_table')">Filter</button><br>
|
|
||||||
<button onclick="filterTableReset('caves_table')">Reset filters</button><br>
|
|
||||||
|
|
||||||
Click on column headers to sort/reverse sort<br><br><br>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<table id="caves_table">
|
|
||||||
<tr>
|
|
||||||
<th onclick="sortTable(0,'caves_table',0)">Cave survex id</th>
|
|
||||||
<th onclick="sortTable(1,'caves_table',0)">Cave name</th>
|
|
||||||
<th onclick="sortTable(2,'caves_table',1)">Cave depth</th>
|
|
||||||
<th onclick="sortTable(3,'caves_table',1)">Cave length</th>
|
|
||||||
<th onclick="sortTable(4,'caves_table',0)">Last leg date</th>
|
|
||||||
<th onclick="sortTable(5,'caves_table',0)">Cave location (UTM)</th>
|
|
||||||
<th onclick="sortTable(6,'caves_table',0)">Cave location (lat/lon)</th>
|
|
||||||
<th onclick="sortTable(7,'caves_table',1)">Top camp distance [m]</th>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
{% for cave in caves %}
|
|
||||||
<tr>
|
|
||||||
<td><a href={{cave.description}}>{{ cave.name }}</a></td>
|
|
||||||
<td>{{ cave.title }}</td>
|
|
||||||
<td>{{ cave.total_depth }}</td>
|
|
||||||
<td>{{ cave.total_length }}</td>
|
|
||||||
<td>{{ cave.date }}</td>
|
|
||||||
<td>33U {{ cave.entrance }}</td>
|
|
||||||
<td>{{ cave.lat_lon_entrance }}</td>
|
|
||||||
<td>{{ cave.top_camp_distance}}</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<script type="text/javascript" src="{{ settings.MEDIA_URL }}/scripts/TableSort.js"></script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
|
|
||||||
|
|
||||||
</html>
|
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>
|
<h1>
|
||||||
<a href="{{personexpedition.person.get_absolute_url}}">{{personexpedition.person}}</a> :
|
<a href="{{personexpedition.person.get_absolute_url}}">{{personexpedition.person|safe}}</a> :
|
||||||
<a href="{{personexpedition.expedition.get_absolute_url}}">{{personexpedition.expedition}}</a>
|
<a href="{{personexpedition.expedition.get_absolute_url}}">{{personexpedition.expedition}}</a>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,12 @@
|
|||||||
<h2>Notable expoers</h2>
|
<h2>Notable expoers</h2>
|
||||||
<table class="searchable">
|
<table class="searchable">
|
||||||
<tr><th>Person</th><th>First</th><th>Last</th><th>Notability</th></tr>
|
<tr><th>Person</th><th>First</th><th>Last</th><th>Notability</th></tr>
|
||||||
{% for person in notablepersons %}
|
{% for person in notablepersons|dictsortreversed:"notability" %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ person.get_absolute_url }}">{{person|wiki_to_html_short}}</a></td>
|
<td><a href="{{ person.get_absolute_url }}">{{person|wiki_to_html_short}}</a></td>
|
||||||
<td><a href="{{ person.first.get_absolute_url }}">{{ person.first.expedition.year }}</a></td>
|
<td><a href="{{ person.first.get_absolute_url }}">{{ person.first.expedition.year }}</a></td>
|
||||||
<td><a href="{{ person.last.get_absolute_url }}">{{ person.last.expedition.year }}</a></td>
|
<td><a href="{{ person.last.get_absolute_url }}">{{ person.last.expedition.year }}</a></td>
|
||||||
<td>{{person.notability}}</td>
|
<td>{{person.notability|floatformat:2}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
@@ -31,8 +31,8 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ person.get_absolute_url }}">{{person|wiki_to_html_short}}</a></td>
|
<td><a href="{{ person.get_absolute_url }}">{{person|wiki_to_html_short}}</a></td>
|
||||||
<td><a href="{{ person.first.get_absolute_url }}">{{person.first.expedition.year}}</a></td>
|
<td><a href="{{ person.first.get_absolute_url }}">{{person.first.expedition.year}}</a></td>
|
||||||
<td><a href="{{ person.last.get_absolute_url }}">{{person.last.expedition.year}}</a></td>
|
<td><a href="{{ person.last.get_absolute_url }}">{{person.last.expedition.year}}</a></td>
|
||||||
<td>{{ person.surveyedleglength }}</td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<td>{{survexblock.name}}</td>
|
<td>{{survexblock.name}}</td>
|
||||||
<td>
|
<td>
|
||||||
{% if survexblock.expedition %}
|
{% if survexblock.expedition %}
|
||||||
<a href="{{survexblock.expedition.get_absolute_url}}">{{survexblock.date}}</a>
|
<a href="{{survexblock.expedition.get_absolute_url}}">{{survexblock.date|date:"D d M Y"}}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
{{survexblock.date}}
|
{{survexblock.date}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ $(document).ready(function()
|
|||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<form id="codewikiform" action="" method="POST">
|
<form id="codewikiform" action="" method="POST">{% csrf_token %}
|
||||||
<div class="codeframebit">{{form.code}}</div>
|
<div class="codeframebit">{{form.code}}</div>
|
||||||
<div style="display:none">{{form.filename}} {{form.dirname}} {{form.datetime}} {{form.outputtype}}</div>
|
<div style="display:none">{{form.filename}} {{form.dirname}} {{form.datetime}} {{form.outputtype}}</div>
|
||||||
<input type="submit" name="diff" value="Diffy" />
|
<input type="submit" name="diff" value="Diffy" />
|
||||||
|
|||||||
13
urls.py
13
urls.py
@@ -22,10 +22,9 @@ admin.autodiscover()
|
|||||||
|
|
||||||
actualurlpatterns = patterns('',
|
actualurlpatterns = patterns('',
|
||||||
|
|
||||||
|
url(r'^testingurl/?$' , views_caves.millenialcaves, name="testing"),
|
||||||
|
|
||||||
url(r'^millenialcaves/?$', views_caves.millenialcaves, name="millenialcaves"),
|
url(r'^millenialcaves/?$', views_caves.millenialcaves, name="millenialcaves"),
|
||||||
url(r'^cave/descriptionM/([^/]+)/?$', views_caves.millenialdescription),
|
|
||||||
#url(r'^cave/description/([^/]+)/?$', views_caves.caveDescription),
|
|
||||||
|
|
||||||
url(r'^troggle$', views_other.frontpage, name="frontpage"),
|
url(r'^troggle$', views_other.frontpage, name="frontpage"),
|
||||||
url(r'^todo/$', views_other.todo, name="todo"),
|
url(r'^todo/$', views_other.todo, name="todo"),
|
||||||
@@ -36,12 +35,12 @@ actualurlpatterns = patterns('',
|
|||||||
url(r'^newqmnumber/?$', views_other.ajax_QM_number, ),
|
url(r'^newqmnumber/?$', views_other.ajax_QM_number, ),
|
||||||
url(r'^lbo_suggestions/?$', logbook_entry_suggestions),
|
url(r'^lbo_suggestions/?$', logbook_entry_suggestions),
|
||||||
#(r'^person/(?P<person_id>\d*)/?$', views_logbooks.person),
|
#(r'^person/(?P<person_id>\d*)/?$', views_logbooks.person),
|
||||||
url(r'^person/(?P<first_name>[A-Z]*[a-z\-\']*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[A-Z]*[a-z\-]*)/?', views_logbooks.person, name="person"),
|
url(r'^person/(?P<first_name>[A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[A-Z]*[a-z\-&;]*)/?', views_logbooks.person, name="person"),
|
||||||
#url(r'^person/(\w+_\w+)$', views_logbooks.person, name="person"),
|
#url(r'^person/(\w+_\w+)$', views_logbooks.person, name="person"),
|
||||||
|
|
||||||
url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"),
|
url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"),
|
||||||
url(r'^expeditions/?$', views_logbooks.ExpeditionListView.as_view(), name="expeditions"),
|
url(r'^expeditions/?$', views_logbooks.ExpeditionListView.as_view(), name="expeditions"),
|
||||||
url(r'^personexpedition/(?P<first_name>[A-Z]*[a-z]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-z]*)/(?P<year>\d+)/?$', views_logbooks.personexpedition, name="personexpedition"),
|
url(r'^personexpedition/(?P<first_name>[A-Z]*[a-z&;]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-zA-Z&;]*)/(?P<year>\d+)/?$', views_logbooks.personexpedition, name="personexpedition"),
|
||||||
url(r'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', views_logbooks.logbookentry,name="logbookentry"),
|
url(r'^logbookentry/(?P<date>.*)/(?P<slug>.*)/?$', views_logbooks.logbookentry,name="logbookentry"),
|
||||||
url(r'^newlogbookentry/(?P<expeditionyear>.*)$', views_logbooks.newLogbookEntry, name="newLogBookEntry"),
|
url(r'^newlogbookentry/(?P<expeditionyear>.*)$', views_logbooks.newLogbookEntry, name="newLogBookEntry"),
|
||||||
url(r'^editlogbookentry/(?P<expeditionyear>[^/]*)/(?P<pdate>[^/]*)/(?P<pslug>[^/]*)/$', views_logbooks.newLogbookEntry, name="editLogBookEntry"),
|
url(r'^editlogbookentry/(?P<expeditionyear>[^/]*)/(?P<pdate>[^/]*)/(?P<pslug>[^/]*)/$', views_logbooks.newLogbookEntry, name="editLogBookEntry"),
|
||||||
@@ -54,7 +53,7 @@ actualurlpatterns = patterns('',
|
|||||||
url(r'^getLogBookEntries/(?P<expeditionslug>.*)', views_logbooks.get_logbook_entries, name = "get_logbook_entries"),
|
url(r'^getLogBookEntries/(?P<expeditionslug>.*)', views_logbooks.get_logbook_entries, name = "get_logbook_entries"),
|
||||||
|
|
||||||
|
|
||||||
url(r'^cave/new/$', edit_cave, name="newcave"),
|
url(r'^cave/new/$', views_caves.edit_cave, name="newcave"),
|
||||||
url(r'^cave/(?P<cave_id>[^/]+)/?$', views_caves.cave, name="cave"),
|
url(r'^cave/(?P<cave_id>[^/]+)/?$', views_caves.cave, name="cave"),
|
||||||
url(r'^caveslug/([^/]+)/?$', views_caves.caveSlug, name="caveSlug"),
|
url(r'^caveslug/([^/]+)/?$', views_caves.caveSlug, name="caveSlug"),
|
||||||
url(r'^cave/entrance/([^/]+)/?$', views_caves.caveEntrance),
|
url(r'^cave/entrance/([^/]+)/?$', views_caves.caveEntrance),
|
||||||
@@ -72,7 +71,7 @@ actualurlpatterns = patterns('',
|
|||||||
# url(r'^jgtuploadfile$', view_surveys.jgtuploadfile, name="jgtuploadfile"),
|
# url(r'^jgtuploadfile$', view_surveys.jgtuploadfile, name="jgtuploadfile"),
|
||||||
|
|
||||||
url(r'^cave/(?P<cave_id>[^/]+)/?(?P<ent_letter>[^/])$', ent),
|
url(r'^cave/(?P<cave_id>[^/]+)/?(?P<ent_letter>[^/])$', ent),
|
||||||
url(r'^cave/(?P<slug>[^/]+)/edit/$', edit_cave, name="edit_cave"),
|
url(r'^cave/(?P<slug>[^/]+)/edit/$', views_caves.edit_cave, name="edit_cave"),
|
||||||
#(r'^cavesearch', caveSearch),
|
#(r'^cavesearch', caveSearch),
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
16
utils.py
16
utils.py
@@ -1,4 +1,5 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.shortcuts import render
|
||||||
import random, re, logging
|
import random, re, logging
|
||||||
from troggle.core.models import CaveDescription
|
from troggle.core.models import CaveDescription
|
||||||
|
|
||||||
@@ -58,21 +59,6 @@ def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}):
|
|||||||
if not created and not instance.new_since_parsing:
|
if not created and not instance.new_since_parsing:
|
||||||
logging.info(str(instance) + " existed in the database unchanged since last parse. It was overwritten by the current script. \n")
|
logging.info(str(instance) + " existed in the database unchanged since last parse. It was overwritten by the current script. \n")
|
||||||
return (instance, created)
|
return (instance, created)
|
||||||
|
|
||||||
def render_with_context(req, *args, **kwargs):
|
|
||||||
"""this is the snippet from http://www.djangosnippets.org/snippets/3/
|
|
||||||
|
|
||||||
Django uses Context, not RequestContext when you call render_to_response.
|
|
||||||
We always want to use RequestContext, so that django adds the context from
|
|
||||||
settings.TEMPLATE_CONTEXT_PROCESSORS. This way we automatically get
|
|
||||||
necessary settings variables passed to each template. So we use a custom
|
|
||||||
method, render_response instead of render_to_response. Hopefully future
|
|
||||||
Django releases will make this unnecessary."""
|
|
||||||
|
|
||||||
from django.shortcuts import render_to_response
|
|
||||||
from django.template import RequestContext
|
|
||||||
kwargs['context_instance'] = RequestContext(req)
|
|
||||||
return render_to_response(*args, **kwargs)
|
|
||||||
|
|
||||||
re_body = re.compile(r"\<body[^>]*\>(.*)\</body\>", re.DOTALL)
|
re_body = re.compile(r"\<body[^>]*\>(.*)\</body\>", re.DOTALL)
|
||||||
re_title = re.compile(r"\<title[^>]*\>(.*)\</title\>", re.DOTALL)
|
re_title = re.compile(r"\<title[^>]*\>(.*)\</title\>", re.DOTALL)
|
||||||
|
|||||||
Reference in New Issue
Block a user