UHaifa-IS / whgazetteer-mehdie

World Historical Gazetteer - MEHDIE version
http://whgazetteer.org
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

Description not showing in the matching interface #124

Closed ElectricFrogy closed 1 year ago

ElectricFrogy commented 1 year ago

When trying to match between locations from two different datasets (Yaqut and Benjamin of Tudela), the descriptions for locations of the latter dataset are not showing. the Dataset of benjamin of Tudela was undoubtably uploaded with a description column. However, they are not showing. here as an image of the described issue:

Sagi5

On the right hand side, descriptions for locations are missing.

Here is a link to the Benjamin of Tudela Dataset

tomersagi commented 1 year ago

Using this query verified that place id 109331 has a description:

select pd.* from place_description pd join places p on pd.place_id = p.id join datasets D on p.dataset = D."label" where D.id = 257 and pd.place_id = 109331;

On screen no description is shown: image

tomersagi commented 1 year ago

URL is review

tomersagi commented 1 year ago

backend code is in views.pymethod review

tomersagi commented 1 year ago

ok, problem is centered around the fact that the matches are displayed by reading the results from a json in the hits table which does not contain the description as this is not returned from the matching service. We need to modify the HitFormSet constructor. Here are the instructions:

Update the HitModelForm to Handle Descriptions:

We need to modify HitModelForm to include additional logic that fetches the PlaceDescription for the relevant IDs in its json field. We'll add a custom property to the form named descriptions to hold this data.

class HitModelForm(forms.ModelForm):

    class Meta:
        model = Hit
        fields = [...]  # the fields you've defined previously

    def __init__(self, *args, **kwargs):
        super(HitModelForm, self).__init__(*args, **kwargs)

        # Initialize descriptions to an empty list by default
        self.descriptions = []

        # Extract relevant IDs from the json field (adjust extraction logic as per your data structure)
        if self.instance and self.instance.json:
            relevant_ids = self.instance.json.get('relevant_key', [])  # replace 'relevant_key' with the actual key

            # Fetch PlaceDescription entries for the extracted IDs
            self.descriptions = PlaceDescription.objects.filter(id__in=relevant_ids)

Update the Template:

Now, in the template, you can access form.descriptions for each form in the formset. Adjust your template logic accordingly:


{% for form in formset %}
    {% for desc in form.descriptions %}
        <p>{{ desc.jsonb.value }}</p>  {# or however your PlaceDescription model's field is structured #}
    {% endfor %}
{% endfor %}

Ensure Formset Creation Remains Unchanged:

The way you create and pass the formset to the template doesn't need to change. Your existing logic should work:

HitFormset = modelformset_factory(
    Hit,
    fields=('id', 'authority', 'authrecord_id', 'query_pass', 'score', 'json', 'relation_type', 'explanations'),
    form=HitModelForm, extra=0)
formset = HitFormset(request.POST or None, queryset=raw_hits)
context['formset'] = formset

This way, each form in the HitFormset will have access to its associated PlaceDescription records via the descriptions property. You can then display them in your template as needed.

tomersagi commented 1 year ago

Fixed: image