Skip to content

Commit

Permalink
Merge branch 'master' into work
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio Brito committed Mar 22, 2019
2 parents b375565 + 14fe7d7 commit 04b38ef
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
28 changes: 13 additions & 15 deletions bireme/biblioref/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ def __init__(self, *args, **kwargs):
self.fields['publisher'].widget = widgets.HiddenInput()
self.fields['isbn'].widget = widgets.HiddenInput()


# load serial titles for serial analytic
if self.document_type == 'S' and not self.reference_source:
title_objects = Title.objects.all()
Expand Down Expand Up @@ -918,6 +917,17 @@ def save(self, *args, **kwargs):
if self.document_type == 'Tm':
obj.publisher = 's.n'

# check if reference doesn't have indexer_cc_code info
if not obj.indexer_cc_code:
ctype = obj.get_content_type_id()
# check if user has indexed this document
has_indexed = Descriptor.objects.filter(object_id=obj.id, content_type_id=ctype,
created_by=self.user).exists()

if has_indexed:
# update reference indexer_cc_code field
obj.indexer_cc_code = self.user_data.get('user_cc','')

# save object
obj.save()

Expand Down Expand Up @@ -952,13 +962,13 @@ def save(self, *args, **kwargs):
class BiblioRefSourceForm(BiblioRefForm):
class Meta:
model = ReferenceSource
exclude = ('cooperative_center_code',)
exclude = ('cooperative_center_code', 'indexer_cc_code')


class BiblioRefAnalyticForm(BiblioRefForm):
class Meta:
model = ReferenceAnalytic
exclude = ('source', 'cooperative_center_code',)
exclude = ('source', 'cooperative_center_code', 'indexer_cc_code')


class AttachmentForm(forms.ModelForm):
Expand Down Expand Up @@ -1040,19 +1050,7 @@ def save(self, *args, **kwargs):
obj = super(DescriptorForm, self).save(commit=False)
# for bibliographic default value for descriptor is admited
obj.status = 1

obj.save()
# if is first center to index the reference save the code in indexer_cc_code
reference = Reference.objects.get(id=obj.object_id)
# check if reference already have indexer_cc_code info
if not reference.indexer_cc_code:
# get user profile cc code
user = obj.created_by
user_data = simplejson.loads(user.profile.data)
# fill reference field
reference.indexer_cc_code = user_data.get('cc','')
# update record
reference.save()

# definition of inline formsets
DescriptorFormSet = generic_inlineformset_factory(Descriptor, form=DescriptorForm,
Expand Down
4 changes: 2 additions & 2 deletions bireme/leisref/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ def __unicode__(self):
else:
if self.issue_date:
act_date = _date(self.issue_date, "d \d\e F \d\e Y")
act_title = u"{0} {1}, de {2}".format(self.act_type, self.act_number, act_date)
act_title = u"{0} {1} - {2}".format(self.act_type, self.act_number, act_date)
else:
act_title = u"{0} {1}".format(self.act_type, self.act_number)
act_title = u"{0} {1}".format(self.act_type, self.act_number)

return act_title

Expand Down
51 changes: 42 additions & 9 deletions bireme/leisref/search_indexes.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#! coding: utf-8
import datetime
from haystack import indexes
from main.models import Descriptor, ResourceThematic
from models import *
from attachments.models import Attachment
from django.conf import settings

from django.template.defaultfilters import date as _date
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import activate

from main.models import Descriptor, ResourceThematic
from models import *

class LeisRefIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
title = indexes.CharField(model_attr='title')
reference_title = indexes.CharField()
status = indexes.IntegerField(model_attr='status')
scope_region = indexes.CharField()
act_type = indexes.CharField()
Expand Down Expand Up @@ -41,6 +44,31 @@ class LeisRefIndex(indexes.SearchIndex, indexes.Indexable):
def get_model(self):
return Act

def prepare_reference_title(self, obj):
'''
Used for search purpose, index act title different languages
'''
ref_title_list = []
act_type_trans = obj.act_type.get_translations()

if not obj.title:
if obj.issue_date:
for act_type in act_type_trans:
act_type_lang = act_type.split('^')[0]
act_type_label = act_type.split('^')[1]
activate(act_type_lang)
act_date = _date(obj.issue_date, "d \d\e F \d\e Y")

act_title = u"{0} Nº {1} - {2}".format(act_type_label, obj.act_number, act_date)
ref_title_list.append(act_title)
else:
for act_type in act_type_trans:
act_type_label = act_type.split('^')[1]
act_title = u"{0} Nº {1}".format(act_type_label, obj.act_number)
ref_title_list.append(act_title)

return ref_title_list

def prepare_scope_region(self, obj):
if obj.scope_region:
translations = obj.scope_region.get_translations()
Expand Down Expand Up @@ -102,8 +130,9 @@ def prepare_relationship_active(self, obj):
ref_number = act.act_referred.act_number
ref_date = act.act_referred.issue_date
ref_lnk = "leisref.act.{0}".format(act.act_referred.id) if act.act_referred.status in [-2, 1] else ''
active_relation = u"{0}@{1}@{2}@{3}@{4}@{5}".format(label_present, ref_type, ref_number,
ref_date, act.act_apparatus, ref_lnk)
ref_title = act.act_referred.title
active_relation = u"{0}@{1}@{2}@{3}@{4}@{5}@{6}".format(label_present, ref_type, ref_number,
ref_date, act.act_apparatus, ref_lnk, ref_title)
active_relationships.append(active_relation)

return active_relationships
Expand All @@ -113,10 +142,14 @@ def prepare_relationship_passive(self, obj):
act_list = ActRelationship.objects.filter(act_referred=obj.pk)
for act in act_list:
label_past = "|".join(act.relation_type.get_label_past_translations())
act_type = "|".join(obj.act_type.get_translations())
ref_lnk = "leisref.act.{0}".format(act.act_related.id) if act.act_related.status in [-2, 1] else ''
passive_relation = u"{0}@{1}@{2}@{3}@{4}".format(label_past, act_type, act.act_related.act_number,
act.act_related.issue_date, ref_lnk)
rel_type = "|".join(obj.act_type.get_translations())
rel_number = act.act_related.act_number
rel_date = act.act_related.issue_date
rel_lnk = "leisref.act.{0}".format(act.act_related.id) if act.act_related.status in [-2, 1] else ''
rel_title = act.act_related.title
rel_apparatus = act.act_apparatus
passive_relation = u"{0}@{1}@{2}@{3}@{4}@{5}@{6}".format(label_past, rel_type, rel_number, rel_date,
rel_lnk, rel_title, rel_apparatus)
passive_relationships.append(passive_relation)

return passive_relationships
Expand Down

0 comments on commit 04b38ef

Please sign in to comment.