diff --git a/seshat/apps/core/management/commands/populate_instability_events.py b/seshat/apps/core/management/commands/populate_instability_events.py new file mode 100644 index 000000000..bd2a3f943 --- /dev/null +++ b/seshat/apps/core/management/commands/populate_instability_events.py @@ -0,0 +1,88 @@ +from django.core.management.base import BaseCommand +from django.db import connection +from django.apps import apps + +from seshat.apps.core.models import Polity, ScpThroughCtn, Reference, Citation, Seshat_Expert, SeshatCommentPart, SeshatComment, SeshatPrivateComment + + +from seshat.apps.general.models import Polity_expert, Polity_original_name, Polity_alternative_name + +from seshat.apps.crisisdb.models import Instability_event, Instability_type, Instability_ref + +from seshat.apps.crisisdb.instability_events_dic_list import ultimate_dics_list + +from django.db import transaction + +EVENTS_DATA = [ + { + 'event': 'Revolt of Datames', + 'year_from': -382, + 'year_to': -362, + 'llm_description': 'Datames, satrap of Cappadocia, rebelled against Artaxerxes II, seeking autonomy. He was assassinated in 362 BCE after a decade of resistance.', + 'all_types': ['Assassination', 'Separatist Rebellion'], + 'all_refs': ['Cornelius Nepos, Lives of Eminent Commanders 14 (Datames)', + 'Diodorus Siculus, Library of History 15.91.'], + 'is_real': True, + 'polity': 'ir_achaemenid_emp', + 'extent': 6, + 'intensity': 6, + 'class_cot': 'Okay, let\'s tackle this for Intensity.', + 'sorokin': 'Extent 6 as the revolt was led by a satrap (provincial governor) in Cappadocia, indicating provincial-level involvement. Intensity 4 due to likely military engagements over a decade, though exact casualty figures are unspecified but consistent with regional rebellion scale.', + 'general_cot': 'Okay, references are academic sources.' + } +] + +class Command(BaseCommand): + help = "Populate the Instability_event model with sample data" + + @transaction.atomic # Ensures atomic DB transactions + def handle(self, *args, **kwargs): + self.stdout.write(self.style.SUCCESS("Starting data import...")) + + #for event_data in EVENTS_DATA: + for event_data in ultimate_dics_list: + # Create or get Instability_type records + instability_types = [] + for type_name in event_data['all_types']: + if type_name in ['Execution (contextually framed as a consequence of rebellion)','Execution (linked to military failure/revolt)',]: + type_name= 'Execution' + inst_type, created = Instability_type.objects.get_or_create(name=type_name) + instability_types.append(inst_type) + + # Create or get Instability_ref records + instability_refs = [] + for ref_name in event_data['all_refs']: + inst_ref, created = Instability_ref.objects.get_or_create(name=ref_name, is_real=False) + instability_refs.append(inst_ref) + + # Polity + try: + my_pol = Polity.objects.get(new_name=event_data['polity']) + my_pc = SeshatPrivateComment.objects.create() + except: + #print('Bad Pol') + continue + #print(my_pol) + # Create Instability_event + event = Instability_event.objects.create( + name=event_data['event'], + year_from=event_data['year_from'], + year_to=event_data['year_to'], + llm_description=event_data['llm_description'], + inst_extent=event_data['extent'], + inst_intensity=event_data['intensity'], + classification_cot=event_data['class_cot'], + sorokin_rationale=event_data['sorokin'], + general_cot=event_data['general_cot'], + real_event_check=event_data['is_real'], + polity_id=my_pol.id, + private_comment_id=my_pc.id, + ) + + # Add ManyToMany relations + event.inst_type.set(instability_types) + event.inst_llm_ref.set(instability_refs) + + self.stdout.write(self.style.SUCCESS(f"Added event: {event.name}")) + + self.stdout.write(self.style.SUCCESS("Data import completed successfully!")) \ No newline at end of file diff --git a/seshat/apps/core/templates/core/description_snippet.html b/seshat/apps/core/templates/core/description_snippet.html index c74f047ac..cbcb71dcf 100644 --- a/seshat/apps/core/templates/core/description_snippet.html +++ b/seshat/apps/core/templates/core/description_snippet.html @@ -13,6 +13,8 @@ {% elif obj.llm_description %}
+ LLM Description: +
{{ obj.llm_description }}
LLM References: diff --git a/seshat/apps/core/templates/core/form_base_llm.html b/seshat/apps/core/templates/core/form_base_llm.html index fdec350ff..9133b8e0c 100644 --- a/seshat/apps/core/templates/core/form_base_llm.html +++ b/seshat/apps/core/templates/core/form_base_llm.html @@ -270,8 +270,8 @@ .bg-secondary-light { background: #fffdf2; - color: lightcoral; - border: 1px solid lightcoral; + color: crimson; + border: 1px solid crimson; } @@ -435,28 +435,37 @@ {% if form.instance.year_from == None %} {% elif form.instance.year_from == form.instance.year_to %} {% if form.instance.year_from < 0 %} - {{ form.instance.year_from|abs|intcomma }} BCE + {{ form.instance.year_from|abs|intcomma }} BCE {% else %} - {{ form.instance.year_from }} CE + {{ form.instance.year_from }} CE {% endif %} {% elif form.instance.year_to == None %} {% if form.instance.year_from < 0 %} - {{ form.instance.year_from|abs }} BCE + {{ form.instance.year_from|abs }} BCE {% else %} - {{ form.instance.year_from }} CE + {{ form.instance.year_from }} CE {% endif %} {% elif form.instance.year_to == None and form.instance.year_from == None %} - + {% else %} {% if form.instance.year_from < 0 and form.instance.year_to < 0 %} - {{ form.instance.year_from|abs }} BCE {{ form.instance.year_to|abs }} BCE + {{ form.instance.year_from|abs }} BCE {{ form.instance.year_to|abs }} BCE {% elif form.instance.year_from < 0 and form.instance.year_to >= 0 %} - {{ form.instance.year_from|abs }} BCE {{ form.instance.year_to }} CE + {{ form.instance.year_from|abs }} BCE {{ form.instance.year_to }} CE {% else %} - {{ form.instance.year_from }} CE {{ form.instance.year_to }} CE + {{ form.instance.year_from }} CE {{ form.instance.year_to }} CE {% endif %} {% endif %} - + + +
+ Types: + + {% autoescape off %} + + {{ form.instance.get_instability_types }} + {% endautoescape %} +
Polity: @@ -465,7 +474,7 @@ - -
+
LLM Description: {{ form.instance.llm_description}}
- LLM REFS:
+ LLM REFS:
{% autoescape off %} - - {{ form.instance.get_instability_refs}} + + {{ form.instance.get_instability_refs}} + {% endautoescape %}
@@ -509,11 +519,14 @@
Intensity: - {{ form.instance.inst_intensity}}
{{ form.instance.get_inst_intensity_display }} + {{ form.instance.inst_intensity}}
+ {{ form.instance.get_inst_intensity_display }} +
Extent: - {{ form.instance.inst_extent}}
{{ form.instance.get_inst_extent_display }} + {{ form.instance.inst_extent}}
+ {{ form.instance.get_inst_extent_display }}
Sorokin Rationale: diff --git a/seshat/apps/core/templates/core/generic_templates/generic_list_all.html b/seshat/apps/core/templates/core/generic_templates/generic_list_all.html index a1dfcd4b8..2e46b6581 100644 --- a/seshat/apps/core/templates/core/generic_templates/generic_list_all.html +++ b/seshat/apps/core/templates/core/generic_templates/generic_list_all.html @@ -57,13 +57,13 @@ {% block update_button %} {% if obj.description and obj.description != 'None' %} - + {% else %} - + diff --git a/seshat/apps/core/templates/core/generic_templates/generic_list_llm.html b/seshat/apps/core/templates/core/generic_templates/generic_list_llm.html new file mode 100644 index 000000000..06cb612cb --- /dev/null +++ b/seshat/apps/core/templates/core/generic_templates/generic_list_llm.html @@ -0,0 +1,124 @@ +{% extends "core/list_base_for_new_approach.html" %} +{% load crispy_forms_tags %} +{% load static %} +{% load humanize %} +{% load custom_filters %} +{% load mathfilters %} + + + + +{% block myheadings_list %} + + + Event Name + + + + + + Types + + + + + Intensity + + + + + Extent + + + + + + Ra Checks + + +{% endblock myheadings_list %} + +{% block extra_vars_list %} + + {% autoescape off %} + {{obj.name}} + {% endautoescape %} + + + + {% if obj.year_from == None %} + +{% elif obj.year_from == obj.year_to %} + {% if obj.year_from < 0 %} + {{ obj.year_from|abs|intcomma }} BCE + {% else %} + {{ obj.year_from }} CE + {% endif %} +{% elif obj.year_to == None %} + {% if obj.year_from < 0 %} + {{ obj.year_from|abs }} BCE + {% else %} + {{ obj.year_from }} CE + {% endif %} +{% elif obj.year_to == None and obj.year_from == None %} + +{% else %} + {% if obj.year_from < 0 and obj.year_to < 0 %} + {{ obj.year_from|abs }} BCE {{ obj.year_to|abs }} BCE + {% elif obj.year_from < 0 and obj.year_to >= 0 %} + {{ obj.year_from|abs }} BCE {{ obj.year_to }} CE + {% else %} + {{ obj.year_from }} CE {{ obj.year_to }} CE + {% endif %} +{% endif %} + + + + + + + + + {% autoescape off %} + {{obj.get_instability_types}} + {% endautoescape %} + + + + {% autoescape off %} + {{obj.inst_intensity}} + {% endautoescape %} + + + + {% autoescape off %} + {{obj.inst_extent}} + {% endautoescape %} + + + + {% autoescape off %} + {{obj.get_instability_checks}} + {% endautoescape %} + + +{% endblock extra_vars_list %} + + + +{% block update_button %} +{% if obj.description and obj.description != 'None' %} + + + + + +{% else %} + + + + + +{% endif %} + +{% endblock update_button %} diff --git a/seshat/apps/core/templates/core/list_base_for_new_approach.html b/seshat/apps/core/templates/core/list_base_for_new_approach.html index a20ca3641..95825fe17 100644 --- a/seshat/apps/core/templates/core/list_base_for_new_approach.html +++ b/seshat/apps/core/templates/core/list_base_for_new_approach.html @@ -43,6 +43,77 @@ background-color:#fefae6; /* fffdf2 fefae6*/ background-image: linear-gradient(to right, rgb(246, 127, 127, 0.216),rgb(242, 199, 119, 0.216),rgb(151, 230, 151, 0.216)); } + + + .bg-absent-light { + background: #fffdf2; /* rgb(134, 134, 134);*/ + color: gray; + border: 1px solid lightgray; + } + + + + + + .bg-info-light { + background: #fffdf2; /* rgb(134, 134, 134);*/ + color: dodgerblue; + border: 1px solid dodgerblue; + } + + .bg-danger-light { + background: lightpink; + + } + + .my_small_link:hover { + color:navajowhite; + } + + .bg-success-light { + background: #fffdf2; /* rgb(134, 134, 134);*/ + color: teal; + border: 1px solid teal; + } + + .bg-warning-light { + background: #fffdf2; /* rgb(134, 134, 134);*/ + color: darkorange; + border: 1px solid goldenrod; + } + + .bg-uncoded-light { + background: #fffdf2; /* rgb(134, 134, 134);*/ + color: darkred; + border: 1px solid rosybrown; + } + + .bg-trans-light { + background: cadetblue; + + } + + .custom-right-align { + margin-left: auto !important; /* Pushes the column to the right */ + text-align: right !important; /* Aligns inner content to the right */ + } + + .bg-unknown-light { + background: #fffdf2; /* rgb(134, 134, 134);*/ + color: hotpink; + border: 1px solid hotpink; + } + + .bg-secondary-light { + background: #fffdf2; + color: lightcoral; + border: 1px solid lightcoral; + + + } + + +
{% if object_list %} @@ -90,15 +161,17 @@
< # - +  Polity {% block myheadings_list %} {% endblock myheadings_list %} + {% if var_name_display != 'Instability Event' %} Tags + {% endif %} - {% if var_name_display != 'Polity Duration' and var_name_display != 'Polity Peak Years' %} + {% if var_name_display != 'Polity Duration' and var_name_display != 'Polity Peak Years' and var_name_display != 'Instability Event' %} @@ -119,7 +192,7 @@
<
- + {{ forloop.counter }} {% if obj.comment and obj.comment.id > 1 %} * @@ -128,7 +201,7 @@
< {% if obj.polity %} - + {% if obj.polity.long_name %} {{ obj.polity.long_name }} @@ -147,19 +220,21 @@
< {% block extra_vars_list %} {% endblock extra_vars_list %} - {% include "core/partials/_all_tags_inline_obj.html" %} + {% if var_name_display != 'Instability Event' %} + {% include "core/partials/_all_tags_inline_obj.html" %} + {% endif %} - {% if var_name_display != 'Polity Duration' and var_name_display != 'Polity Peak Years' %} + {% if var_name_display != 'Polity Duration' and var_name_display != 'Polity Peak Years' and var_name_display != 'Instability Event' %} {% include "core/partials/_years_block_new_obj.html" %} {% endif %} {% block update_button %} {% endblock update_button %} -
- +
Loading... diff --git a/seshat/apps/core/templates/core/partials/_private_comment_inline_accordion.html b/seshat/apps/core/templates/core/partials/_private_comment_inline_accordion.html index 482af5264..fe0b0cdcb 100644 --- a/seshat/apps/core/templates/core/partials/_private_comment_inline_accordion.html +++ b/seshat/apps/core/templates/core/partials/_private_comment_inline_accordion.html @@ -14,7 +14,7 @@
+
@@ -141,12 +141,42 @@
+ href="{% url 'create_private_subcomment_new' app_name='crisisdb' model_name='instability_event' instance_id=form.instance.id %}"> + + + {% if user.is_authenticated and 'core.add_seshatprivatecommentpart' in user.get_all_permissions %} +
+ {% csrf_token %} +
+ +
+ + + + {% if user.full_name %} + {{user.full_name}} + {% else %} + {{user}} + {% endif %} + : + + {{ another_form.private_comment_part_text }} + +
+
+ Researchers or Experts to be informed: + {{ another_form.private_comment_reader }} + +
+ +
+
+ {% endif %} {% endif %}
diff --git a/seshat/apps/core/templates/core/polity/polity_detail.html b/seshat/apps/core/templates/core/polity/polity_detail.html index 77d64b56f..73648382a 100644 --- a/seshat/apps/core/templates/core/polity/polity_detail.html +++ b/seshat/apps/core/templates/core/polity/polity_detail.html @@ -57,7 +57,7 @@ .custom-border-tight { - border-left: 10px solid teal; /* Adjust the border color and thickness as desired */ + border-left: 2px solid teal; /* Adjust the border color and thickness as desired */ padding-left: 5px; /* Adjust the padding to create spacing between the border and content */ } @@ -418,6 +418,13 @@

{{ object.long_name }}

{% endif %} + {% if all_instability_data %} + + IN + + {% endif %} + + {% if all_power_transitions_data %} PT @@ -721,7 +728,7 @@

{{ object.long_name }}

{% if all_general_data %}
- + General Variables @@ -753,7 +760,7 @@

{{ object.long_name }}

{% else %} #ffc10712 {% endif %} - ; border-left: 10px solid #ffc10742;"> + ; border-left: 2px solid #ffc10742;">
{% if key == "Polity_preceding_entity" %} @@ -915,7 +922,7 @@

{{ object.long_name }}

{% if all_sc_data %}
- + Social Complexity Variables @@ -941,7 +948,7 @@

{{ object.long_name }}

{% for key, values in values_m.items %} {% if values %} - +
{{ values.0.clean_name_spaced}} @@ -1061,7 +1068,7 @@

{{ object.long_name }}

{% if all_wf_data %}
- + Warfare Variables (Military Technologies) @@ -1096,7 +1103,7 @@

{{ object.long_name }}

{% for key, values in values_m.items %} {% if values %} - +
{{ values.0.clean_name_spaced}} @@ -1215,7 +1222,7 @@

{{ object.long_name }}

{% if all_ec_data %}
- + Economy Variables (Luxury Goods) @@ -1250,7 +1257,7 @@

{{ object.long_name }}

{% for key, values in values_m.items %} {% if values %} - +
{{ values.0.clean_name_spaced}} @@ -1375,7 +1382,7 @@

{{ object.long_name }}

{% if all_rt_data and 'core.view_capital' in user.get_all_permissions or object.new_name == "kh_chenla" or object.new_name == "pe_wari_emp" or object.new_name == "in_kampili_k" or object.new_name == "in_kalyani_chalukya_emp" or object.new_name == "in_hoysala_k" or object.new_name == "et_aksum_emp_3" or object.new_name == "et_aksum_emp_2" or object.new_name == "ni_proto_yoruboid" or object.new_name == "ni_sokoto" or object.new_name == "gm_kaabu_emp" %}
- + Religion Variables @@ -1410,7 +1417,7 @@

{{ object.long_name }}

{% for key, values in values_m.items %} {% if values %} - +
{{ values.0.clean_name_spaced}} @@ -1662,7 +1669,7 @@

{{ object.long_name }}

NGA Settlements:

- +
@@ -2333,7 +2340,7 @@
- Instability Data + Instability Data
@@ -2352,7 +2359,7 @@
{% for obj in values%} - + {% if values %}
diff --git a/seshat/apps/core/templates/core/seshatcomments/seshatprivatecomment_update.html b/seshat/apps/core/templates/core/seshatcomments/seshatprivatecomment_update.html index 879c154e9..9ea880f93 100644 --- a/seshat/apps/core/templates/core/seshatcomments/seshatprivatecomment_update.html +++ b/seshat/apps/core/templates/core/seshatcomments/seshatprivatecomment_update.html @@ -564,16 +564,13 @@
(Only visible to Selected Seshat Experts/RAs)
- @@ -594,17 +591,12 @@
{% endif %}
-
{{ subcom.private_comment_part_text }}
- - - -
Year Range
Target Experts or Researchers - - - - - + + +
{% for an_expert in subcom.private_comment_reader.all %} diff --git a/seshat/apps/core/views.py b/seshat/apps/core/views.py index a87374135..993a95d05 100644 --- a/seshat/apps/core/views.py +++ b/seshat/apps/core/views.py @@ -1694,7 +1694,13 @@ def seshat_private_comment_part_create_from_null_view(request, private_com_id): form = SeshatPrivateCommentPartForm(request.POST) oopsi = request.POST.getlist('selected_items') #print("ooopsiiiiiiiiiiiiiiii,", oopsi) - big_father = SeshatPrivateComment.objects.get(id=private_com_id) + if private_com_id == 0: + big_father = SeshatPrivateComment.objects.create() + else: + big_father = SeshatPrivateComment.objects.get(id=private_com_id) + + big_father_id = big_father.id + #print(big_father_id) if form.is_valid(): private_comment_part_text = form.cleaned_data['private_comment_part_text'] @@ -1712,7 +1718,7 @@ def seshat_private_comment_part_create_from_null_view(request, private_com_id): seshat_private_comment_part.private_comment_reader.add(*my_private_comment_readers) - return redirect(request.META.get('HTTP_REFERER', reverse('seshatprivatecomment-update', kwargs={'pk': private_com_id}))) + return redirect(request.META.get('HTTP_REFERER', reverse('seshatprivatecomment-update', kwargs={'pk': big_father_id}))) #return redirect(reverse('seshatprivatecomment-update', kwargs={'pk': private_com_id})) else: diff --git a/seshat/apps/crisisdb/models.py b/seshat/apps/crisisdb/models.py index 4b07b25b7..3b29e4dfa 100644 --- a/seshat/apps/crisisdb/models.py +++ b/seshat/apps/crisisdb/models.py @@ -381,7 +381,7 @@ def clean_name(self): return "instability_event" def show_value(self): - return f"instability_event {self.name} - {self.inst_intensity}, {self.inst_extent}..." + return f"{self.name} {self.get_instability_types()} {self.inst_intensity}, {self.inst_extent}" def get_instability_types(self): return " ".join(str(t) for t in self.inst_type.all()) diff --git a/seshat/apps/general/views.py b/seshat/apps/general/views.py index 9cded15f2..744a2863b 100644 --- a/seshat/apps/general/views.py +++ b/seshat/apps/general/views.py @@ -7976,7 +7976,9 @@ def dynamic_update_view_old(request, object_id, form_class, model_class, x_name, action = request.POST.get('action') if action == 'redirect_one': - return redirect("polity-detail-main", pk=new_object.polity.id) + url = reverse("polity-detail-main", kwargs={'pk': new_object.polity.id}) + f"#{x_name}_{new_object.id}" + return redirect(url) + #return redirect("polity-detail-main", pk=new_object.polity.id) elif action == 'redirect_two': # if the object has some description already if new_object.comment: @@ -8278,7 +8280,9 @@ def dynamic_update_view(request, object_id, form_class, model_class, x_name, cod action = request.POST.get('action') if action == 'redirect_one': - return redirect("polity-detail-main", pk=new_object.polity.id) + url = reverse("polity-detail-main", kwargs={'pk': new_object.polity.id}) + f"#{x_name}_{new_object.id}" + return redirect(url) + #return redirect("polity-detail-main", pk=new_object.polity.id) + "#{x_name}" elif action == 'redirect_two': # if the object has some description already if new_object.comment: @@ -8630,7 +8634,7 @@ def generic_list_view(request, model_class, var_name, coded_value, var_name_disp #return HttpResponseForbidden("You do not have permission to access this data.") return render(request, 'core/permission_denied.html', status=403) - if var_name in ['human_sacrifice', 'power_transition'] and not request.user.has_perm('core.add_capital'): + if var_name in ['human_sacrifice', 'power_transition', 'instability_event'] and not request.user.has_perm('core.add_capital'): #return HttpResponseForbidden("You do not have permission to access this data.") return render(request, 'core/permission_denied.html', status=403) @@ -8684,7 +8688,11 @@ def generic_list_view(request, model_class, var_name, coded_value, var_name_disp 'choices': 'ABSENT_PRESENT_CHOICES', 'null_meaning': None}} - return render(request, 'core/generic_templates/generic_list_all.html', context) + if coded_value in ['instability_event']: + return render(request, 'core/generic_templates/generic_list_llm.html', context) + else: + return render(request, 'core/generic_templates/generic_list_all.html', context) + #return render(request, 'core/generic_templates/generic_list_all.html', context) diff --git a/seshat/utils/utils.py b/seshat/utils/utils.py index 69d7296e5..79a3c8352 100644 --- a/seshat/utils/utils.py +++ b/seshat/utils/utils.py @@ -688,7 +688,7 @@ def get_all_rt_data_for_a_polity(request, polity_id): this_polity = Polity.objects.get(id=polity_id) this_polity_new_name = this_polity.new_name - print(this_polity_new_name) + #print(this_polity_new_name) has_any_data = False all_vars_grouped_rt = {} @@ -738,10 +738,10 @@ def get_all_rt_data_for_a_polity(request, polity_id): print(f"--------xxx-----{my_s},") if user and user.has_perm('core.add_capital'): - print("hooooy") + #print("hooooy") hs_data = Human_sacrifice.objects.filter(polity = polity_id) if hs_data: - print(hs_data) + #print(hs_data) has_any_data = True my_s = 'Human Sacrifice' all_vars_grouped_rt[my_s]["None"]['Human_sacrifice'] = hs_data