Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 2 deletions applications/composer/backend/composer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,14 +1218,14 @@ def get_count_sentences_created_since_this_export(self):
@property
def get_count_connectivity_statements_created_since_this_export(self):
return ConnectivityStatement.objects.filter(
created_date__gt=self.created_at, state=CSState.NPO_APPROVED
created_date__gt=self.created_at
).count()

@property
def get_count_connectivity_statements_modified_since_this_export(self):
return (
ConnectivityStatement.objects.filter(
modified_date__gt=self.created_at, state=CSState.NPO_APPROVED
modified_date__gt=self.created_at
)
.exclude(state=CSState.EXPORTED)
.count()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from django.db import transaction
from django.db.models import QuerySet

from composer.enums import CSState
from composer.services.export.helpers.csv import create_csv
from composer.services.export.helpers.export_batch import (
create_export_batch,
transition_statements_to_exported,
)
from composer.models import (
ConnectivityStatement,
ExportBatch,
)

Expand All @@ -19,6 +21,8 @@ def export_connectivity_statements(
with transaction.atomic():
export_batch = create_export_batch(user)
export_batch = transition_statements_to_exported(export_batch, qs, user)
all_statement_ids = ConnectivityStatement.all_objects.exclude(state=CSState.DEPRECATED).values_list('pk', flat=True)
export_batch.connectivity_statements.set(all_statement_ids)

export_file = create_csv(export_batch, output_path)
return export_file, export_batch
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,16 @@ def transition_statements_to_exported(export_batch: ExportBatch, qs: QuerySet, u
"""Transitions only eligible ConnectivityStatements"""
system_user = User.objects.get(username="system")

transitioned_statements = []

for cs in qs.order_by("id"):
service = ConnectivityStatementStateService(cs)
try:
service.do_transition(
CSState.EXPORTED.value, system_user, user
)
cs.save()
transitioned_statements.append(cs)
except Exception as exc:
pass

# Add successfully transitioned statements to the export batch
export_batch.connectivity_statements.set(transitioned_statements)
return export_batch

def compute_metrics(export_batch: ExportBatch):
Expand All @@ -55,7 +50,7 @@ def compute_metrics(export_batch: ExportBatch):
# Compute the metrics for this export
if last_export_batch_created_at:
sentences_created_qs = Sentence.objects.filter(
created_date__gt=last_export_batch_created_at,
created_date__gt=last_export_batch_created_at
)
else:
sentences_created_qs = Sentence.objects.all()
Expand All @@ -67,11 +62,14 @@ def compute_metrics(export_batch: ExportBatch):
)
else:
connectivity_statements_created_qs = ConnectivityStatement.objects.all()

connectivity_statements_created_qs = connectivity_statements_created_qs.exclude(
state=CSState.DRAFT
) # skip draft statements
export_batch.connectivity_statements_created = connectivity_statements_created_qs.count()

export_batch.save(update_fields=['sentences_created', 'connectivity_statements_created'])

# Compute the state metrics for this export
connectivity_statement_metrics = list(
ConnectivityStatement.objects.values("state").annotate(count=Count("state"))
Expand Down
2 changes: 1 addition & 1 deletion applications/composer/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "5.0.0",
"private": true,
"main": "index.js",
"proxy": "https://localhost:8000/",
"proxy": "https://127.0.0.1:8000/",
"dependencies": {
"@babel/preset-env": "^7.21.5",
"@dnd-kit/core": "^6.0.8",
Expand Down