Skip to content

Commit

Permalink
Merge pull request #681 from upconsulting/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jdamerow authored Feb 15, 2021
2 parents bfc4c00 + c242644 commit 1e1b61c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
24 changes: 24 additions & 0 deletions isiscb/curation/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,28 @@ def apply(self, user, filter_params_raw, value, **extra):
task.save()
return task.id

class DeleteDuplicateAttributes(BaseAction):
model = Authority
label = u'Delete Duplicate Attributes'

default_value_field = forms.CharField
default_value_field_kwargs = {
'label': 'Delete Duplicate Attributes',
'widget': forms.widgets.Textarea(attrs={'class': 'action-value', 'readonly': True, 'initial': 'Delete Duplicate Attributes'}),
}

def apply(self, user, filter_params_raw, value, **extra):
task = AsyncTask.objects.create()

result = atasks.delete_duplicate_attributes.delay(user.id, filter_params_raw, task.id)

# We can use the AsyncResult's UUID to access this task later, e.g.
# to check the return value or task state.
task.async_uuid = result.id
task.value = ('delete_duplicate_attributes', value)
task.label = 'Deleting Duplicate Attributes: ' + _build_filter_label(filter_params_raw)
task.save()
return task.id

AVAILABLE_ACTIONS = [SetRecordStatus, SetRecordStatusExplanation, SetTrackingStatus, PrependToRecordHistory, StoreCreationDataToModel, ReindexCitation]
AVAILABLE_ACTIONS_AUTHORITY = [StoreCreationDataToModel, ReindexAuthorities, DeleteDuplicateAttributes]
2 changes: 1 addition & 1 deletion isiscb/curation/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def bulk_action_form_factory(form=BulkActionForm, **kwargs):
action_choices = []
extra_data = {}
# hack until we also make tracking status work
avail_actions = [actions.StoreCreationDataToModel, actions.ReindexAuthorities] if object_type == 'AUTHORITY' else actions.AVAILABLE_ACTIONS
avail_actions = actions.AVAILABLE_ACTIONS_AUTHORITY if object_type == 'AUTHORITY' else actions.AVAILABLE_ACTIONS
for action_class in avail_actions:
if hasattr(action_class, 'extra_js'):
media_attrs['js'] = tuple(list(media_attrs['js']) + [action_class.extra_js])
Expand Down
29 changes: 29 additions & 0 deletions isiscb/curation/taskslib/authority_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@

logger = logging.getLogger(__name__)

@shared_task
def delete_duplicate_attributes(user_id, filter_params_raw, task_id=None, object_type='AUTHORITY'):
queryset, task = _get_task(filter_params_raw, user_id, task_id, object_type)
current_count = 0
for i, obj in enumerate(queryset):
existing_attributes = []
for attribute in obj.attributes.all():
attr_type = attribute.type_controlled
key = attr_type.name + "_" + str(attribute.value.cvalue()) + str(attribute.value_freeform)
if key not in existing_attributes:
existing_attributes.append(key)
else:
# attribute with same values already exist, so remove it
print("Deleting attribute " + attribute.pk + " on object " + obj.pk)
attribute.delete()
current_count = _update_count(current_count, task)

@shared_task
def reindex_authorities(user_id, filter_params_raw, task_id=None, object_type='AUTHORITY'):

Expand Down Expand Up @@ -270,6 +287,18 @@ def add_attributes_to_authority(file_path, error_path, task_id, user_id):
task.state = 'SUCCESS'
task.save()

def _get_task(filter_params_raw, user_id, task_id, object_type):
queryset, _ = _get_filtered_object_queryset(filter_params_raw, user_id, object_type)
if task_id:
task = AsyncTask.objects.get(pk=task_id)
task.max_value = queryset.count()
_inc = max(2, math.floor(old_div(task.max_value, 200.)))
task.save()
else:
task = None

return queryset, task

def _add_creation_note(properties, task_id, user_id, created_on):
user = User.objects.get(pk=user_id)
mod_time = created_on.strftime("%m/%d/%y %r %Z")
Expand Down
6 changes: 6 additions & 0 deletions isiscb/isisdata/templates/isisdata/citation.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,15 @@ <h4>Has Response</h4>
{% if related_citations_as %}
<h4>Associated with</h4>
{% for cc_rel in related_citations_as %}
{% if cc_rel.subject.id == citation.id %}
{% with cc_rel.object as citation_object %}
{% include "isisdata/citation_entry.html" %}
{% endwith %}
{% else %}
{% with cc_rel.subject as citation_object %}
{% include "isisdata/citation_entry.html" %}
{% endwith %}
{% endif %}
{% endfor %}
{% endif %}

Expand Down
8 changes: 8 additions & 0 deletions isiscb/zotero/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ def handle_isPartOf(self, predicate, node):
return predicate, dict(parent_document)

def handle_subjects(self, predicate, node):
# IEXP-24: somtimes/potentially always, the subject node contains an
# anonymous node that will display its idea if we don't traverse further
# e.g
# <dc:subject>
# <z:AutomaticTag><rdf:value>Australia</rdf:value></z:AutomaticTag>
# </dc:subject>
if type(node) == BNode:
node = self.graph.value(subject=node, predicate=RDF.value)
match = re.match('([^\[]+)\[([A-Z0-9\w]+)\]', node.toPython())
if match:
name, identifier = match.groups()
Expand Down

0 comments on commit 1e1b61c

Please sign in to comment.