Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generate_template function and add UI for incomplete file #636

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
906cb47
Added Draft mode
ulyssear Oct 23, 2022
e89b20b
Merge branch 'main' into features/draft
ulyssear Oct 23, 2022
0f0ae0b
Command generate_missing_templates to generate missing thesaurus with…
ulyssear Oct 23, 2022
4457aff
Merge branch 'features/draft' of github.com:ulyssear/codethesaur.us i…
ulyssear Oct 23, 2022
bd6d389
Removed useless comment
ulyssear Oct 23, 2022
d407c76
Removed unused import
ulyssear Oct 23, 2022
222518e
Removed useless parameters
ulyssear Oct 23, 2022
363d069
Updated description of command generate_missing_template
ulyssear Oct 23, 2022
a8926eb
Fixed indentation
ulyssear Oct 23, 2022
dc8a402
Re-added parameters not-so-useless
ulyssear Oct 23, 2022
fe20260
Minor changes on the command generate_missing_templates
ulyssear Oct 24, 2022
8eb81e7
Merge branch 'main' into features/draft
ulyssear Oct 26, 2022
d506f8b
Merge branch 'main' into features/draft
geekygirlsarah Oct 29, 2022
b4a0c61
Merge branch 'main' into features/draft
ulyssear Oct 29, 2022
73398b8
Merge branch 'main' into features/draft
ulyssear Oct 30, 2022
c8440b0
Removed Draft mode
ulyssear Oct 30, 2022
95d3a99
Merge branch 'features/draft' of github.com:ulyssear/codethesaur.us i…
ulyssear Oct 30, 2022
bf041f0
Merge branch 'main' into features/draft
geekygirlsarah Nov 10, 2022
3ce9a93
Merge branch 'main' into features/draft
geekygirlsarah Nov 14, 2022
e5334fb
Removed draft
ulyssear Nov 14, 2022
3662ad1
Merge branch 'features/draft' of github.com:ulyssear/codethesaur.us i…
ulyssear Nov 14, 2022
542325d
Merge branch 'main' into features/draft
ulyssear Nov 14, 2022
c7d2e5e
is_incomplete checks now complete template
ulyssear Nov 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions web/management/commands/generate_missing_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.core.management.base import BaseCommand

from web.models import Language, MetaInfo

import os


class Command(BaseCommand):
help = 'Generate missing language thesaurus files to be filled out'

def handle(self, *args, **options):
meta_info = MetaInfo()
languages = meta_info.languages
structures = meta_info.structures

for language in languages:
versions = Language(language, languages[language]).versions()
for version in versions:
for structure in structures:
file_path = os.path.join(
'web',
'thesauruses',
language,
version,
structure + '.json'
)
if not os.path.exists(file_path):
os.system(f'python manage.py generate_template "{language}" "{structure}" --language-version="{version}"')
8 changes: 5 additions & 3 deletions web/management/commands/generate_template.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import unicodedata
from django.core.management.base import BaseCommand

from web.thesaurus_template_generators import generate_language_template
Expand Down Expand Up @@ -31,15 +32,16 @@ def generate_file(self, language, structure, language_version):
template = generate_language_template(
language,
structure,
language_version
language_version,
)
except ValueError:
self.stdout.write(
f'The structure "{structure}" is not implemented yet. You can visit https://docs.codethesaur.us/thesaurus/ to learn how to add one.'
)

version = parse_version(language_version)
major_version = version.major
major_version = getattr(version, 'major', version.base_version)

language_dir_path = os.path.join(
'web',
'thesauruses',
Expand Down Expand Up @@ -80,4 +82,4 @@ def generate_file(self, language, structure, language_version):
'Created template file '\
f'"{self.style.SUCCESS(template_file_path)}" which you can '\
'now edit.'
)
)
23 changes: 23 additions & 0 deletions web/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,29 @@ def concept_comment(self, concept_key):
"""
return self.concept(concept_key).get("comment", "")

def is_incomplete(self, version, structure_key):
"""
Returns a Boolean if the version is incomplete

:param version: the version of the language
:param structure_key: the ID for the structure to load
:return: Boolean if the version is incomplete
"""
file_name = f"{structure_key}.json"
file_path = os.path.join(self.language_dir, version, file_name)

with open(file_path, 'r', encoding='UTF-8') as file:
file_json = json.load(file)
for concept in file_json["concepts"].values():
code = concept.get("code")
if isinstance(code, list):
code = "".join(code)
if isinstance(code, str) and code.strip() == "":
return True

return False



class MetaInfo:
"""Holds info about structures and languages"""
Expand Down
12 changes: 12 additions & 0 deletions web/templates/compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@ <h3 class="text-center">Concept</h3>
<div class="card">
<div class="card-body">
<h3 class="text-center">{{ lang1_friendlyname|linebreaksbr }}'s Implementation</h3>
{% if is_lang1_incomplete %}
<div class="alert alert-warning" role="alert">
<strong>Warning!</strong> This thesaurus is incomplete.
<a href="https://github.com/codethesaurus/codethesaur.us/edit/main/web/thesauruses/{{ lang1 }}/{{ version1 }}/{{ concept }}.json" class="alert-link">Help us improve!</a>
</div>
{% endif %}
</div>
</div>
<div class="card">
<div class="card-body">
<h3 class="text-center">{{ lang2_friendlyname|linebreaksbr }}'s Implementation</h3>
{% if is_lang2_incomplete %}
<div class="alert alert-warning" role="alert">
<strong>Warning!</strong> This thesaurus is incomplete.
<a href="https://github.com/codethesaurus/codethesaur.us/edit/main/web/thesauruses/{{ lang2 }}/{{ version2 }}/{{ concept }}.json" class="alert-link">Help us improve!</a>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions web/templates/reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ <h3 class="text-center">Concept</h3>
<div class="card">
<div class="card-body">
<h3 class="text-center">{{ lang_friendlyname|linebreaksbr }}'s Implementation</h3>
{% if is_incomplete %}
<div class="alert alert-warning" role="alert">
<strong>Warning!</strong> This thesaurus is incomplete.
<a href="https://github.com/codethesaurus/codethesaur.us/edit/main/web/thesauruses/{{ lang }}/{{ version }}/{{ concept }}.json" class="alert-link">Help us improve!</a>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion web/thesaurus_template_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from web.models import MetaInfo


def generate_language_template(language_id, structure_id, version=None):
def generate_language_template(language_id, structure_id, version=None, draft=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this get removed as I think we decided against "draft mode"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to remove it, sorry for that.

"""Generate a template for the given language and structure"""
meta_info = MetaInfo()
if structure_id not in meta_info.structures:
Expand All @@ -20,6 +20,9 @@ def generate_language_template(language_id, structure_id, version=None):

if version:
meta['language_version'] = version

if draft:
meta['draft'] = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for removing this


concepts = {
id: {
Expand Down
8 changes: 8 additions & 0 deletions web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ def compare(request):
"concepts": concepts
})

is_lang1_incomplete = lang1.is_incomplete(version1, meta_structure.key)
is_lang2_incomplete = lang2.is_incomplete(version2, meta_structure.key)

response = {
"title": f"Comparing {lang1.friendly_name} and {lang2.friendly_name}",
"concept": meta_structure.key,
Expand All @@ -240,6 +243,8 @@ def compare(request):
"version2": version2,
"lang1_friendlyname": lang1.friendly_name,
"lang2_friendlyname": lang2.friendly_name,
"is_lang1_incomplete": is_lang1_incomplete,
"is_lang2_incomplete": is_lang2_incomplete,
"categories": both_categories,
"description": f"Code Thesaurus: Comparing {lang1.friendly_name} \
and {lang2.friendly_name}",
Expand Down Expand Up @@ -325,6 +330,8 @@ def reference(request):
"concepts": concepts
})

is_incomplete = lang.is_incomplete(version, meta_structure.key)

response = {
"title": f"Reference for {lang.key}",
"concept": meta_structure.key,
Expand All @@ -333,6 +340,7 @@ def reference(request):
"version": version,
"lang_friendlyname": lang.friendly_name,
"categories": categories,
"is_incomplete": is_incomplete,
"description": f"Code Thesaurus: Reference for {lang.key}"
}

Expand Down