Skip to content

Commit

Permalink
Merge pull request #881 from DDMAL/staging
Browse files Browse the repository at this point in the history
Merge Staging into Production, 2023-07-24 edition
  • Loading branch information
jacobdgm authored Jul 25, 2023
2 parents f4e653d + bdfb4ba commit af465e5
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 25 deletions.
2 changes: 2 additions & 0 deletions django/cantusdb_project/cantusdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
"127.0.0.1",
]

CSRF_TRUSTED_ORIGINS = ["https://cantusdatabase.org", "https://www.cantusdatabase.org"]

if DEBUG:
INSTALLED_APPS.append("debug_toolbar")
# debug toolbar must be inserted as early in the middleware as possible
Expand Down
19 changes: 16 additions & 3 deletions django/cantusdb_project/main_app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CenturyAdmin(BaseModelAdmin):


class ChantAdmin(BaseModelAdmin):
list_display = ("incipit", "siglum", "genre")
list_display = ("incipit", "get_source_siglum", "genre")
search_fields = ("title", "incipit", "cantus_id")
list_filter = ("genre",)
exclude = EXCLUDE + (
Expand All @@ -35,9 +35,12 @@ class ChantAdmin(BaseModelAdmin):
"is_last_chant_in_feast",
)

def get_source_siglum(self, obj):
return obj.source.siglum


class FeastAdmin(BaseModelAdmin):
pass
search_fields = ("name", "feast_code")


class GenreAdmin(BaseModelAdmin):
Expand All @@ -53,7 +56,7 @@ class OfficeAdmin(BaseModelAdmin):


class ProvenanceAdmin(BaseModelAdmin):
pass
search_fields = ("name",)


class RismSiglumAdmin(BaseModelAdmin):
Expand All @@ -65,7 +68,17 @@ class SegmentAdmin(BaseModelAdmin):


class SequenceAdmin(BaseModelAdmin):
search_fields = (
"title",
"incipit",
"cantus_id",
)
exclude = EXCLUDE + ("c_sequence", "next_chant", "is_last_chant_in_feast")
list_display = ("incipit", "get_source_siglum", "genre")
list_filter = ("genre",)

def get_source_siglum(self, obj):
return obj.source.siglum


class SourceAdmin(BaseModelAdmin):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_new_chant(chant_id):

try:
differentia_new = json_response["field_differentia_new"]["und"][0]["value"]
except (KeyError, TypeError):
except (KeyError, TypeError, IndexError):
differentia_new = None

try:
Expand Down Expand Up @@ -261,14 +261,14 @@ def get_new_chant(chant_id):
genre_id = json_response["field_mc_genre"]["und"][0]["tid"]
# run this after running sync_genres
genre = Genre.objects.get(id=genre_id)
except (KeyError, TypeError):
except (KeyError, TypeError, ObjectDoesNotExist):
genre = None

try:
feast_id = json_response["field_mc_feast"]["und"][0]["tid"]
# run sync_feasts before running this, so we should already have all feasts
feast = Feast.objects.get(id=feast_id)
except (KeyError, TypeError):
except (KeyError, TypeError, ObjectDoesNotExist):
feast = None

chant_obj, created = Chant.objects.update_or_create(
Expand Down Expand Up @@ -344,11 +344,12 @@ def make_dummy_chant() -> None:
"Aborting attempt to create a new dummy chant."
)
return
except Source.DoesNotExist:
except Chant.DoesNotExist:
pass

dummy_source = Source.objects.get(id=1_000_000, published=False)
dummy_chant = Chant.objects.create(
Chant.objects.create(
title="DUMMY",
source=dummy_source,
manuscript_full_text_std_spelling=(
"This unpublished dummy chant exists in order that all newly created "
Expand All @@ -358,6 +359,7 @@ def make_dummy_chant() -> None:
"1,000,000 has been created, this dummy chant may be safely deleted."
),
)
dummy_chant = Chant.objects.filter(title="DUMMY")
dummy_chant.update(id=1_000_000)
return dummy_chant

Expand All @@ -380,9 +382,15 @@ def handle(self, *args, **options):
id = options["id"]
if id == "all":
all_chants = get_chant_list(CHANT_ID_FILE)
total = len(all_chants)
counter = 0
for chant_id in all_chants:
get_new_chant(chant_id)
make_dummy_chant()
if counter % 500 == 0:
print(
f"---------------- {counter} of {total} chants synced --------------"
)
counter += 1
else:
get_new_chant(id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ def make_dummy_sequence() -> None:
pass

dummy_source = Source.objects.get(id=1_000_000, published=False)
dummy_sequence = Sequence.objects.create(
Sequence.objects.create(
title="DUMMY",
source=dummy_source,
manuscript_full_text_std_spelling=(
"This unpublished dummy sequence exists in order that all newly created "
Expand All @@ -236,6 +237,7 @@ def make_dummy_sequence() -> None:
"1,000,000 has been created, this dummy sequence may be safely deleted."
),
)
dummy_sequence = Sequence.objects.filter(title="DUMMY")
dummy_sequence.update(id=1_000_000)
return dummy_sequence

Expand All @@ -258,10 +260,16 @@ def handle(self, *args, **options):
id = options["id"]
if id == "all":
all_seqs = get_seq_list(SEQUENCE_ID_FILE)
total = len(all_seqs)
counter = 0
for i, seq_id in enumerate(all_seqs):
# print(seq_id)
get_new_sequence(seq_id)
make_dummy_sequence()
if counter % 500 == 0:
print(
f"---------------- {counter} of {total} chants synced --------------"
)
counter += 1
else:
get_new_sequence(id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ def remove_extra_sources():
print(len(our_sources))
print(len(waterloo_sources))
extra_sources = [id for id in our_sources if id not in waterloo_sources]
if 1_000_000 in extra_sources:
extra_sources.remove(1_000_000)
for source in extra_sources:
Source.objects.get(id=source).delete()
print(f"Extra source removed: {source}")
Expand All @@ -368,7 +370,7 @@ def make_dummy_source() -> None:
pass

cantus_segment = Segment.objects.get(id=4063)
dummy_source = Source.objects.create(
Source.objects.create(
segment=cantus_segment,
siglum="DUMMY",
published=False,
Expand All @@ -381,6 +383,7 @@ def make_dummy_source() -> None:
"1,000,000 has been created, this dummy source may be safely deleted."
),
)
dummy_source = Source.objects.filter(siglum="DUMMY")
dummy_source.update(id=1_000_000)
return dummy_source

Expand All @@ -406,7 +409,6 @@ def handle(self, *args, **options):
for source_id in all_sources:
print(source_id)
source = get_new_source(source_id)
make_dummy_source()
else:
new_source = get_new_source(id)
print(new_source.title)
Expand Down
14 changes: 9 additions & 5 deletions django/cantusdb_project/main_app/views/chant.py
Original file line number Diff line number Diff line change
Expand Up @@ -1389,12 +1389,16 @@ def get_context_data(self, **kwargs):

# 4064 is the id for the sequence database
if source.segment.id == 4064:
queryset = source.sequence_set.annotate(
record_type=Value("sequence")
).order_by("s_sequence")
queryset = (
source.sequence_set.annotate(record_type=Value("sequence"))
.order_by("s_sequence")
.select_related("genre")
)
else:
queryset = source.chant_set.annotate(record_type=Value("chant")).order_by(
"folio", "c_sequence"
queryset = (
source.chant_set.annotate(record_type=Value("chant"))
.order_by("folio", "c_sequence")
.select_related("feast", "office", "genre")
)

context["source"] = source
Expand Down
16 changes: 9 additions & 7 deletions django/cantusdb_project/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ <h5>Contact Us</h5>
</a>
</div>
</div>
<img
class="img-fluid p-2"
style="max-width: 100%;"
src="{% static "sshrc-logo.jpg" %}"
alt="Social Sciences and Humanities Research Council Logo"
title="Social Sciences and Humanities Research Council of Canada"
loading="lazy">
<a href="https://www.sshrc-crsh.gc.ca" target="_blank">
<img
class="img-fluid p-2"
style="max-width: 100%;"
src="{% static "sshrc-logo.jpg" %}"
alt="Social Sciences and Humanities Research Council Logo"
title="Social Sciences and Humanities Research Council of Canada"
loading="lazy">
</a>
<a href="https://alliancecan.ca/" target="_blank">
<img
class="img-fluid p-2"
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- 3000:3000
depends_on:
- postgres
restart: always

nginx:
build:
Expand All @@ -23,6 +24,7 @@ services:
- ./config/nginx/conf.d:/etc/nginx/conf.d
- static_volume:/resources/static
- media_volume:/resources/media
restart: always
depends_on:
- django

Expand All @@ -32,6 +34,7 @@ services:
env_file: ./config/envs/dev_env
volumes:
- postgres_data:/var/lib/postgresql/data/
restart: always

volumes:
postgres_data:
Expand Down

0 comments on commit af465e5

Please # to comment.