Skip to content

Commit f0c5fbf

Browse files
authored
feat: Ordered filetree (#222)
* chore: fix merge conflicts with master
1 parent 8b1914e commit f0c5fbf

File tree

4 files changed

+46
-16
lines changed

4 files changed

+46
-16
lines changed

lms/models/solutions.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from io import BytesIO
22
from lms.extractors.base import File
3-
from operator import itemgetter
43
import os
5-
from typing import Any, Dict, Iterable, List, Optional, Union
4+
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
65
from zipfile import ZipFile
76

87
from flask_babel import gettext as _
@@ -63,19 +62,26 @@ def create_zip_from_solution(
6362
return memory_file.read()
6463

6564

65+
def order_files(file: Dict[str, Any]) -> Tuple[str, bool]:
66+
return (
67+
os.path.split(file['fullpath'])[0],
68+
not file['is_folder'], # folders should be before the files
69+
)
70+
71+
6672
def get_files_tree(files: Iterable[SolutionFile]) -> List[Dict[str, Any]]:
6773
file_details = [
6874
{
69-
'id': file.id,
75+
'id': file.id, # type: ignore
7076
'fullpath': file.path,
71-
'path': file.path.strip('/').rpartition('/')[2],
72-
'indent': file.path.strip('/').count('/'),
77+
'path': os.path.split(file.path.strip('/'))[1], # type: ignore
78+
'indent': file.path.strip('/').count('/'), # type: ignore
7379
'is_folder': file.path.endswith('/'),
7480
'code': file.code,
7581
}
7682
for file in files
7783
]
78-
file_details.sort(key=itemgetter('fullpath'))
84+
file_details.sort(key=order_files)
7985
for file in file_details:
8086
del file['fullpath']
8187
return file_details

lms/models/upload.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def _upload_to_db(
2828
elif not exercise.open_for_new_solutions():
2929
raise UploadError(
3030
f'Exercise {exercise_id} is closed for new solutions.')
31-
if _is_uploaded_before(user, solution_hash):
31+
32+
if solution_hash and _is_uploaded_before(user, solution_hash):
3233
raise AlreadyExists('You try to reupload an old solution.')
3334
elif not files:
3435
raise UploadError(f'There are no files to upload for {exercise_id}.')

lms/static/my.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ button#share-action:hover {
283283
flex-direction: column;
284284
}
285285

286+
.file-comments-count {
287+
height: 1.5em;
288+
display: inline-flex;
289+
align-self: center;
290+
margin: 0 0.25em;
291+
width: 1em;
292+
}
293+
286294
#files .file {
287295
display: flex;
288296
flex-direction: row;

lms/templates/filetree.html

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,38 @@
22
<ol id="files">
33
{%- for file in files %}
44
<li class="file" data-id="{{ file.id }}">
5-
<span class="indent" style="padding-left: {{ file.indent }}em"></span>
6-
{%- if not shared_url %}
7-
<div class="file-comments-count">
8-
<span style="margin-left: {{ file.indent }}em"
9-
class="badge bg-{%- if comments[file.id] -%}danger{%- else -%}success{%- endif -%}">
10-
{{ comments[file.id] }}
11-
</span>
12-
</div>
5+
<div class="file-comments-count">
6+
{%- if not shared_url and not file.is_folder %}
7+
<span class="badge bg-{%- if comments[file.id] -%}danger{%- else -%}success{%- endif -%}">
8+
{{ comments[file.id] }}
9+
</span>
1310
{% endif -%}
11+
</div>
12+
<span class="indent" style="margin-left: {{ file.indent * 1.5 }}em"></span>
1413
<span class="
1514
{%- if file.is_folder -%}
1615
icon hawcons-icon-folder">
1716
{%- else -%}
1817
icon hawcons-icon-document-text hawcons-icon-file-{{ file.path.rsplit('.')[-1] | e }} file-icon">
1918
{%- endif -%}
2019
</span>
21-
<a {% if not file.is_folder %}href="/{%- if not shared_url %}view/{{ solution.id }}{%- else %}shared/{{ shared_url }}{% endif -%}/{{ file.id }}"{% endif %} class="filename link" title="{{ file.path | e }}">{{ file.path | truncate(25, killwords=True) | e }}</a>
20+
{% if not file.is_folder -%}
21+
<a href="/
22+
{%- if not shared_url -%}
23+
view/{{ solution.id }}
24+
{%- else -%}
25+
shared/{{ shared_url }}
26+
{%- endif -%}
27+
/{{ file.id }}"
28+
{% else -%}
29+
<span
30+
{% endif -%}
31+
class="filename link" title="{{ file.path | e }}">{{ file.path | truncate(25, killwords=True) | e }}
32+
{%- if not file.is_folder -%}
33+
</a>
34+
{%- else -%}
35+
</span>
36+
{%- endif -%}
2237
</li>
2338
{% endfor -%}
2439
</ol>

0 commit comments

Comments
 (0)