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

story/VOGRE-7 #15

Closed
wants to merge 114 commits into from
Closed
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
d6db439
[VOGRE-2] Changed from github auth to local auth
Girik1105 Aug 10, 2024
ee7966e
Refined local auth settings
Girik1105 Aug 12, 2024
2d8f1dd
Made auth templates pretty
Girik1105 Aug 12, 2024
b5ac38b
Fixed allauth setting, user bool error view(because of 1.8 to 2.2 dja…
Girik1105 Aug 12, 2024
0daa957
Fixed local env settings, Changed Email config in settings
Girik1105 Aug 15, 2024
257d6a2
[VOGRE-2] Removed DS_Store
Girik1105 Aug 15, 2024
50002d0
[VOGRE-2] Added missing stylesheet, fixed module Not Found error (dja…
Girik1105 Aug 16, 2024
b8fdfbc
Merge branch 'develop' into story/VOGRE-2
Girik1105 Aug 16, 2024
2036802
[VOGRE-2] DS_Store
Girik1105 Aug 16, 2024
9d8c2fe
Added Missing stylesheets
Girik1105 Aug 16, 2024
571835a
[VOGRE-2] Added account email required setting
Girik1105 Aug 16, 2024
7a3167d
Merge branch 'develop' into story/VOGRE-2
Girik1105 Aug 20, 2024
cbc0e75
[VOGRE-3] Removed goat endpoints and replaced it with Conceptpower
Girik1105 Aug 30, 2024
9c3a18d
[VOGRE-4] Added conceptpower creds in settings
Girik1105 Sep 3, 2024
7875785
[VOGRE-3] Merged develop
Girik1105 Sep 3, 2024
10c20f1
[VOGRE-3] Added variables to env-example, fixed previous merge files
Girik1105 Sep 3, 2024
afeaa35
[VOGRE-3] Added import texts to vogon using citesphere
Girik1105 Sep 5, 2024
dfe83fb
[VOGRE-3] Repository model changes and working details page
Girik1105 Sep 6, 2024
7a86c66
[VOGRE-3] Repository views for collections and collection changed inc…
Girik1105 Sep 6, 2024
c8f63e3
[VOGRE-3] Working views: repository groups, collections, items, need …
Girik1105 Sep 10, 2024
0b00565
[VOGRE-3] Workflow working groups -> collections -> items -> repo item
Girik1105 Sep 10, 2024
857a7d4
[VOGRE-3] Refactored code with correct id names in views, urls, templ…
Girik1105 Sep 12, 2024
4e40f83
[VOGRE-3] Fixed repository search, split repository text into reposit…
Girik1105 Sep 12, 2024
b71ec91
[VOGRE-3] Add to project complete
Girik1105 Sep 12, 2024
e70c80a
[VOGRE-3] removed debug print statement
Girik1105 Sep 12, 2024
25539a9
[VOGRE-3] Giles util function to pull erxtracted data and use in text…
Girik1105 Sep 12, 2024
c166b18
[VOGRE-3] Giles data successfully being added to texts
Girik1105 Sep 13, 2024
886aea6
[VOGRE-3] Individual texts reaching annotation page
Girik1105 Sep 13, 2024
140a943
[VOGRE-3] fixing js errors for annotations to work
Girik1105 Sep 17, 2024
86a445b
[VOGRE-3] Annotations WORKKKKKK
Girik1105 Sep 19, 2024
becb10e
[VOGRE-3] Fixed Content rendering to show just text
Girik1105 Sep 19, 2024
bf36114
[VOGRE-3] Removed duplicate imports, added comments explaining imports
Girik1105 Sep 19, 2024
01d2c98
[VOGRE-3] Fixed template add renderer error
Girik1105 Sep 19, 2024
d85da33
[VOGRE-3] resources csrf token fix
Girik1105 Sep 20, 2024
b4857ab
[VOGRE-3] Fixed endpoints, and bootstrap import in vue.html template
Girik1105 Sep 20, 2024
fd782ac
[VOGRE-3] Templates fix
Girik1105 Sep 20, 2024
cf77a29
[VOGRE-3] Concept power correct callgit add .
Girik1105 Sep 20, 2024
9657134
[VOGRE-3] Create appelationViewSet still gives error
Girik1105 Sep 20, 2024
cb48a59
[VOGRE-3] AppelationViewSet Fix to incorporate Concept CRUD
Girik1105 Sep 26, 2024
4c9f124
[VOGRE-3] Fixed templates
Girik1105 Sep 26, 2024
210c734
[VOGRE-3] Relations work
Girik1105 Sep 26, 2024
3f3d416
[VOGRE-3] Label debug, to show in relation
Girik1105 Sep 26, 2024
216e6cb
[VOGRE-3] Added concept data on relation template selection
Girik1105 Sep 27, 2024
8b12b30
[VOGRE-3] Labels added in appelation and relation list, removed debug…
Girik1105 Sep 27, 2024
ca4a497
[VOGRE-3] Labels workkkkk
Girik1105 Sep 27, 2024
b2a038b
[VOGRE-3] Labels fix, removed button to submit appellations and relat…
Girik1105 Sep 27, 2024
d88c44f
[VOGRE-3] Removed debug print statements
Girik1105 Sep 27, 2024
859ac9a
[VOGRE-7] Added view to manually submit quadruples, updates env examples
Girik1105 Oct 1, 2024
63c4884
[VOGRE-3] Repository Manager uses Repository enpoint instead of setti…
Girik1105 Oct 3, 2024
94b23d7
[VOGRE-3] Removed redundancy, texts imports and existing texts direct…
Girik1105 Oct 3, 2024
40f16b2
[VOGRE-3] Impoved annotation code, fixed absolute url in model and ur…
Girik1105 Oct 3, 2024
f0ef866
[VOGRE-3] Created date fixed
Girik1105 Oct 3, 2024
9e0d4d8
[VOGRE-3] Template fixes and removed debug print statements
Girik1105 Oct 3, 2024
08aa08f
[VOGRE-3] Removed duplicate code and hardcoded url
Girik1105 Oct 3, 2024
0ba651d
Merge branch 'story/VOGRE-3' into story/VOGRE-7
Girik1105 Oct 3, 2024
63282ba
[VOGRE-7] Added url, updates submit quadruple view
Girik1105 Oct 3, 2024
8083295
[VOGRE-7] Fixed view to send json data, added button in vue.html
Girik1105 Oct 4, 2024
8a5cf40
[VOGRE-7] Removed all instances of celery
Girik1105 Oct 4, 2024
19207f6
[VOGRE-7] Fixed merge conflict with develop
Girik1105 Oct 18, 2024
d32e852
[VOGRE-7] Fixed merge conflict from develop pt2
Girik1105 Oct 18, 2024
c09d999
[VOGRE-7] Fixed merge conflict from develop pt3
Girik1105 Oct 18, 2024
7b4a4e5
[VOGRE-7] sending quadruple views with citesphere access token
Girik1105 Oct 18, 2024
7f6c36b
[VOGRE-7] Tried changing auth and running locally, quadruples still n…
Girik1105 Oct 24, 2024
5a597c6
[VOGRE-7] Quadruples being submitted succesfully
Girik1105 Oct 25, 2024
d4de827
[VOGRE-7] Quadruples being sent successfully, refined function, need …
Girik1105 Oct 25, 2024
ef34605
[VOGRE-7] Synced template and view to show correct messages
Girik1105 Oct 29, 2024
432d822
[VOGRE-7] Added status field in relationsets and made migrations
Girik1105 Oct 29, 2024
71fd5c8
[VOGRE-7] Added async function middleware to update status of relatio…
Girik1105 Oct 29, 2024
38a1ec6
[VOGRE-7] Added comments in middleware
Girik1105 Oct 29, 2024
e72c33b
[VOGRE-7] Removed obselete code
Girik1105 Oct 29, 2024
2ac467a
[VOGRE-7] optimized middleware
Girik1105 Oct 31, 2024
a32996a
[VOGRE-7] Added checkboxes in frontend
Girik1105 Nov 1, 2024
84e781a
[VOGRE-7] correct selection of quadruples
Girik1105 Nov 1, 2024
d056567
[VOGRE-7] Front end and backend sync
Girik1105 Nov 1, 2024
91c666b
[VOGRE-7] Quadruples being submitted
Girik1105 Nov 1, 2024
42ea4eb
[VOGRE-7] Multiple quadruples being sent SUCCESSFULLY
Girik1105 Nov 1, 2024
e29cbce
[VOGRE-7] Removed debug code, removed obselet view and url
Girik1105 Nov 1, 2024
3f7840c
[VOGRE-7] Removed dev comments
Girik1105 Nov 1, 2024
a3f7376
[VOGRE-7] UI improvements
Girik1105 Nov 1, 2024
2719e04
[VOGRE-7] Further UI improvements
Girik1105 Nov 1, 2024
d62cfd8
[VOGRE-7] Removed obselete code
Girik1105 Nov 1, 2024
cb0ffa0
[VOGRE-7] Fixed breaking UI
Girik1105 Nov 2, 2024
c03e3a3
[VOGRE-7] Bug fixes
Girik1105 Nov 2, 2024
22cfa8b
[VOGRE-7] Messages added
Girik1105 Nov 2, 2024
802b3cb
[VOGRE-7] Removed extra imports, obselete code, fixed startup script
Girik1105 Nov 2, 2024
f2041ec
[VOGRE-7] Improved error messages and Improved submitting/rendering UI
Girik1105 Nov 4, 2024
3a26b3c
[VOGRE-7] Merged Develop and fixed merge conflicts
Girik1105 Nov 5, 2024
bea39e2
[VOGRE-7] Merged develop
Girik1105 Nov 8, 2024
a3a0dc8
[VOGRE-7] Relationset status middleware now uses setting variable to …
Girik1105 Nov 8, 2024
1feec8a
[VOGRE-7] Configured quadriga submissions to use project quadriga id …
Girik1105 Nov 8, 2024
36b90e8
[VOGRE-7] Removed duplicate graph data function
Girik1105 Nov 8, 2024
11ea9fc
[VOGRE-7] Added source uri and creation time from appelation and remo…
Girik1105 Nov 8, 2024
b928c83
[VOGRE-7] Removed collection id from example env file
Girik1105 Nov 8, 2024
3705a91
[VOGRE-7] Removed collection id from settings
Girik1105 Nov 8, 2024
cfe6e1e
[VOGRE-7] Removed dev print statement
Girik1105 Nov 15, 2024
d55084f
[VOGRE-7] Merged develop
Girik1105 Nov 20, 2024
21de855
[VOGRE-7]
Girik1105 Nov 20, 2024
14cd882
[VOGRE-7] removed obselete code
Girik1105 Nov 20, 2024
25cc5b8
[VOGRE-7] removed all functions with todo to retire
Girik1105 Nov 20, 2024
29ef265
[VOGRE-7] Removed obselete file
Girik1105 Nov 20, 2024
9ce5df5
[VOGRE-7] Removed celery instances in concepts app
Girik1105 Nov 21, 2024
6f59886
[VOGRE-7] Merge develop
Girik1105 Dec 6, 2024
fc3873f
[VOGRE-7] Used model static variables
Girik1105 Dec 6, 2024
250426e
[VOGRE-7] shifted quadriga specific functions from utils to quadriga…
Girik1105 Dec 6, 2024
5f5e972
[VOGRE-7] Comments
Girik1105 Dec 6, 2024
a5a6370
[VOGRE-7] Removed tasks.py celery file
Girik1105 Dec 6, 2024
4f64d6d
[VOGRE-7] Updated queryset to check for readiness when called - TODO:…
Girik1105 Dec 6, 2024
429b67d
[VOGRE-7] Added tokenize in serializers, tested without middleware
Girik1105 Dec 11, 2024
4336950
[VOGRE-7] Got rid of middleware
Girik1105 Dec 11, 2024
9c2def5
[VOGRE-7] Removed commented code
Girik1105 Dec 11, 2024
f6db813
[VOGRE-7] Merged develop
Girik1105 Dec 13, 2024
754be0b
[VOGRE-7] Migrations
Girik1105 Dec 13, 2024
c2f1bf4
Merge branch 'develop' into story/VOGRE-7
Girik1105 Dec 13, 2024
80530ca
Merge branch 'develop' into story/VOGRE-7
jophals Dec 20, 2024
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
4 changes: 3 additions & 1 deletion .env_app-example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ CONCEPTPOWER_USERID=
CONCEPTPOWER_PASSWORD=
CONCEPTPOWER_ENDPOINT=
CONCEPTPOWER_NAMESPACE=
BASE_URL=http://localhost:8000/
BASE_URL=http://localhost:8000/
QUADRIGA_ENDPOINT=
QUADRIGA_COLLECTION_ID=
Copy link
Member

Choose a reason for hiding this comment

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

this is something that needs to be set for each project. Every project can have a different collection it submits quadruples to.

72 changes: 1 addition & 71 deletions annotations/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.contrib import admin
from annotations.forms import *
from annotations.models import *
from annotations.tasks import submit_relationsets_to_quadriga

from itertools import groupby

Expand Down Expand Up @@ -50,81 +49,12 @@ def created_by(self, obj):
return obj.createdBy


def submit_relationsets(modeladmin, request, queryset):
"""
Submit selected :class:`.RelationSet`\s to Quadriga.

Will quietly skip any :class:`.RelationSet`\s that have already been
submitted.
"""

queryset = queryset.filter(submitted=False, pending=False)

# Do not submit a relationset to Quadriga if the constituent interpretations
# involve concepts that are not resolved.
all_rsets = [rs for rs in queryset if rs.ready()]

project_grouper = lambda rs: getattr(rs.project, 'quadriga_id', -1)
for project_id, project_group in groupby(sorted(all_rsets, key=project_grouper), key=project_grouper):
for text_id, text_group in groupby(project_group, key=lambda rs: rs.occursIn.id):
text = Text.objects.get(pk=text_id)
for user_id, user_group in groupby(text_group, key=lambda rs: rs.createdBy.id):
user = VogonUser.objects.get(pk=user_id)
# We lose the iterator after the first pass, so we want a list here.
rsets = []
for rs in user_group:
rsets.append(rs.id)
rs.pending = True
rs.save()
kwargs = {}
if project_id:
kwargs.update({
'project_id': project_id,
})
submit_relationsets_to_quadriga.delay(rsets, text.id, user.id, **kwargs)


def submit_relationsets_synch(modeladmin, request, queryset):
"""
Submit selected :class:`.RelationSet`\s to Quadriga.

Will quietly skip any :class:`.RelationSet`\s that have already been
submitted.
"""

queryset = queryset.filter(submitted=False, pending=False)

# Do not submit a relationset to Quadriga if the constituent interpretations
# involve concepts that are not resolved.
all_rsets = [rs for rs in queryset if rs.ready()]

project_grouper = lambda rs: getattr(rs.project, 'quadriga_id', -1)
for project_id, project_group in groupby(sorted(all_rsets, key=project_grouper), key=project_grouper):
for text_id, text_group in groupby(project_group, key=lambda rs: rs.occursIn.id):
text = Text.objects.get(pk=text_id)
for user_id, user_group in groupby(text_group, key=lambda rs: rs.createdBy.id):
user = VogonUser.objects.get(pk=user_id)
# We lose the iterator after the first pass, so we want a list here.
rsets = []
for rs in user_group:
rsets.append(rs.id)
rs.pending = True
rs.save()
kwargs = {}
if project_id and project_id > 0:
kwargs.update({
'project_id': project_id,
})
submit_relationsets_to_quadriga(rsets, text.id, user.id, **kwargs)


class RelationSetAdmin(admin.ModelAdmin):
class Meta:
model = RelationSet

list_display = ('id', 'createdBy', 'occursIn', 'created', 'ready',
'pending', 'submitted', )
actions = (submit_relationsets, submit_relationsets_synch)
'submitted', 'status',)


class AppellationAdmin(admin.ModelAdmin):
Expand Down
58 changes: 58 additions & 0 deletions annotations/middleware.py
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is the right approach. It is likely to cause memory issues once there are sufficiently many relationsets. It also seems unnecessary. The only time we care about the readiness of a relation to be submitted is when we want to submit them or maybe when we look at a text. So it really only needs to be checked when the page shows all relations, and then only the relations that are relevant (not all of them).

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 don't think this is the right approach. It is likely to cause memory issues once there are sufficiently many relationsets. It also seems unnecessary. The only time we care about the readiness of a relation to be submitted is when we want to submit them or maybe when we look at a text. So it really only needs to be checked when the page shows all relations, and then only the relations that are relevant (not all of them).

If we only show the relations that can be submitted, then the user will not be able to see all relations that they have created on the text. Can we still show the relations that cannot be submitted with the disabled checkbox? I'll change the way we check for ready relations.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from django.utils.deprecation import MiddlewareMixin
from annotations.models import RelationSet
from asgiref.sync import async_to_sync, sync_to_async
from django.utils import timezone
from datetime import timedelta

class CheckRelationSetStatusMiddleware(MiddlewareMixin):
"""
Middleware to ensure that RelationSets are correctly marked as ready to submit.
This middleware runs before each request to check and update the status of
RelationSets. RelationSets must have one of three statuses:

- 'not_ready': Concepts are not yet resolved or merged.
- 'ready_to_submit': All concepts are resolved and the RelationSet is ready for submission.
- 'submitted': This is handled separately in the submission workflow and does not need to
be updated here.

The purpose of this middleware is to automate the readiness check and ensure that
RelationSets are always in the correct state before they can be submitted to Quadriga.
"""

# Cache the last check time to reduce query frequency
last_check_time = None
check_interval = timedelta(minutes=5) # Adjust the interval as needed
Copy link
Member

Choose a reason for hiding this comment

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

needs to be configurable through settings


def process_request(self, request):
"""
Synchronous method called before each request. It triggers the status check
asynchronously, with a rate limit based on `check_interval` to reduce load.
"""
if self.should_run_check():
async_to_sync(self.check_and_update_relation_sets)()

def should_run_check(self):
"""
Determines whether the status check should be run based on the defined interval.
"""
current_time = timezone.now()
if not self.last_check_time or (current_time - self.last_check_time) > self.check_interval:
self.last_check_time = current_time
return True
return False

async def check_and_update_relation_sets(self):
"""
This asynchronous function is responsible for checking and updating the
statuses of RelationSets in bulk. It uses the `update_status` method of
each RelationSet instance to evaluate and adjust their status based on
readiness conditions.
"""
# Fetch RelationSets that need a status check asynchronously
relation_sets = await sync_to_async(list)(
RelationSet.objects.filter(status__in=['not_ready', 'ready_to_submit'])
)

# Update statuses for each RelationSet using the update_status method from Relationset model
for relation_set in relation_sets:
await sync_to_async(relation_set.update_status)()
18 changes: 18 additions & 0 deletions annotations/migrations/0042_relationset_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.20 on 2024-10-29 16:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('annotations', '0041_delete_importedcitesphereitem'),
]

operations = [
migrations.AddField(
model_name='relationset',
name='status',
field=models.CharField(choices=[('not_ready', 'Not Ready'), ('ready_to_submit', 'Ready to Submit'), ('submitted', 'Submitted')], default='not_ready', max_length=20),
),
]
17 changes: 17 additions & 0 deletions annotations/migrations/0043_remove_relationset_pending.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.2.20 on 2024-10-29 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('annotations', '0042_relationset_status'),
]

operations = [
migrations.RemoveField(
model_name='relationset',
name='pending',
),
]
28 changes: 21 additions & 7 deletions annotations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,15 @@ class RelationSet(models.Model):
occursIn = models.ForeignKey('Text', related_name='relationsets', on_delete=models.CASCADE)
"""The text on which this RelationSet is based."""

pending = models.BooleanField(default=False)
"""
A :class:`.RelationSet` is pending if it has been selected for submission,
but the submission process has not yet completed. The primary purpose of
this field is to prevent duplicate submissions.
"""
STATUS_CHOICES = [
('not_ready', 'Not Ready'),
Copy link
Member

Choose a reason for hiding this comment

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

the first value here should be defined in constants, so the constants can be used elsewhere (see below)

('ready_to_submit', 'Ready to Submit'),
('submitted', 'Submitted'),
]

status = models.CharField(
max_length=20, choices=STATUS_CHOICES, default='not_ready'
)

submitted = models.BooleanField(default=False)
"""
Expand Down Expand Up @@ -908,6 +911,17 @@ def ready(self):
return all(map(criteria, values))
ready.boolean = True # So that we can display a nifty icon in changelist.

def update_status(self):
"""
Check if the RelationSet is ready and update the status accordingly.
"""
if self.ready(): # Check readiness based on the concepts
if self.status != 'submitted': # Avoid overriding submitted status
self.status = 'ready_to_submit'
else:
self.status = 'not_ready'
Copy link
Member

Choose a reason for hiding this comment

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

in line 920 and 922 the constants defined above should be sued

self.save()

def appellations(self):
"""
Get all non-predicate appellations in child :class:`.Relation`\s.
Expand Down Expand Up @@ -1148,4 +1162,4 @@ class DocumentPosition(models.Model):

If :attr:`.position_type` is :attr:`.WHOLE_DOCUMENT`\, then this can be
blank.
"""
"""
20 changes: 0 additions & 20 deletions annotations/quadriga.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,6 @@ def to_quadruples(relationsets, text, user, network_label=None,
return project, params


def submit_relationsets(relationsets, text, user,
userid=settings.QUADRIGA_USERID,
password=settings.QUADRIGA_PASSWORD,
endpoint=settings.QUADRIGA_ENDPOINT, **kwargs):
"""
Submit the :class:`.RelationSet`\s in ``relationsets`` to Quadriga.
"""
payload, params = to_quadruples(relationsets, text, user, toString=True, **kwargs)
auth = HTTPBasicAuth(userid, password)
headers = {'Accept': 'application/xml'}
r = requests.post(endpoint, data=payload, auth=auth, headers=headers)

if r.status_code == requests.codes.ok:
response_data = parse_response(r.text)
response_data.update(params)
return True, response_data

return False, r.text


def parse_response(raw_response):
QDNS = '{http://www.digitalhps.org/Quadriga}'
root = ET.fromstring(raw_response)
Expand Down
2 changes: 1 addition & 1 deletion annotations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Meta:
model = RelationSet
fields = ('id', 'label', 'created', 'template', 'createdBy',
'occursIn', 'appellations', 'concepts', 'project',
'representation', 'date_appellations') #
'representation', 'date_appellations', 'status') #


class TemporalBoundsSerializer(serializers.ModelSerializer):
Expand Down
4 changes: 4 additions & 0 deletions annotations/static/annotations/css/annotators/text.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,7 @@
border: 0;
background-color: rgb(250, 250, 250);
}

.relation-submitted {
border-left: 4px solid #7aef7a;
}
Loading