Skip to content

Commit

Permalink
Renamed json field to metadata and migrations merge as requested in d…
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloxnet committed Nov 15, 2017
1 parent 0e668b6 commit f47775c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 30 deletions.
2 changes: 1 addition & 1 deletion djangoproject/templates/docs/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h2 class="result-title">
<a href="{% url 'document-detail' lang=result.release.lang version=result.release.version url=result.path host 'docs' %}">{{ result.title }}</a>
</h2>
<span class="meta breadcrumbs">
{% for breadcrumb in result.json.breadcrumbs %}
{% for breadcrumb in result.metadata.breadcrumbs %}
<a href="{% url 'document-detail' lang=result.release.lang version=result.release.version url=breadcrumb.path host 'docs' %}">{{ breadcrumb.title }}</a>{% if not forloop.last %} <span class="arrow">»</span>{% endif %}
{% endfor %}
</span>
Expand Down
8 changes: 4 additions & 4 deletions docs/management/commands/update_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def handle(self, *args, **options):
path__startswith='ref/class-based-views/flattened-index'
)
for document in documents:
document.json['breadcrumbs'] = list(
document.metadata['breadcrumbs'] = list(
Document.objects.breadcrumbs(document).values('title', 'path'))
document.json['slug'] = Path(document.path).parts[-1]
document.json['parents'] = ' '.join(Path(document.path).parts[:-1])
document.save(update_fields=('json',))
document.metadata['slug'] = Path(document.path).parts[-1]
document.metadata['parents'] = ' '.join(Path(document.path).parts[:-1])
document.save(update_fields=('metadata',))
updated = documents.update(search=DOCUMENT_SEARCH_VECTOR)
self.log('Successfully indexed %s item' % updated)
4 changes: 3 additions & 1 deletion docs/migrations/0003_auto_20171107_1513.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import django.contrib.postgres.fields.jsonb
import django.contrib.postgres.indexes
import django.contrib.postgres.search
from django.contrib.postgres.operations import TrigramExtension
from django.db import migrations


Expand All @@ -17,7 +18,7 @@ class Migration(migrations.Migration):
operations = [
migrations.AddField(
model_name='document',
name='json',
name='metadata',
field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
),
migrations.AddField(
Expand All @@ -29,4 +30,5 @@ class Migration(migrations.Migration):
model_name='document',
index=django.contrib.postgres.indexes.GinIndex(fields=['search'], name='docs_docume_search_5dc895_gin'),
),
TrigramExtension(),
]
17 changes: 0 additions & 17 deletions docs/migrations/0004_auto_20171108_0433.py

This file was deleted.

6 changes: 3 additions & 3 deletions docs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def sync_to_db(self, decoded_documents):
release=self,
path=_clean_document_path(document['current_page_name']),
title=unescape_entities(strip_tags(document['title'])),
json=document
metadata=document
)


Expand Down Expand Up @@ -239,7 +239,7 @@ class Document(models.Model):
)
path = models.CharField(max_length=500)
title = models.CharField(max_length=500)
json = JSONField(default=dict)
metadata = JSONField(default=dict)
search = SearchVectorField(null=True, editable=False)

objects = DocumentManager()
Expand All @@ -258,7 +258,7 @@ def get_absolute_url(self):

@cached_property
def content_raw(self):
return strip_tags(unescape_entities(self.json['content']).replace(u'¶', ''))
return strip_tags(unescape_entities(self.metadata['content']).replace(u'¶', ''))

@cached_property
def root(self):
Expand Down
8 changes: 4 additions & 4 deletions docs/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

DOCUMENT_SEARCH_VECTOR = (
SearchVector('title', weight='A') +
SearchVector(Coalesce(KeyTextTransform('slug', 'json'), Value('')), weight='A') +
SearchVector(Coalesce(KeyTextTransform('toc', 'json'), Value('')), weight='B') +
SearchVector(Coalesce(KeyTextTransform('body', 'json'), Value('')), weight='C') +
SearchVector(Coalesce(KeyTextTransform('parents', 'json'), Value('')), weight='D')
SearchVector(Coalesce(KeyTextTransform('slug', 'metadata'), Value('')), weight='A') +
SearchVector(Coalesce(KeyTextTransform('toc', 'metadata'), Value('')), weight='B') +
SearchVector(Coalesce(KeyTextTransform('body', 'metadata'), Value('')), weight='C') +
SearchVector(Coalesce(KeyTextTransform('parents', 'metadata'), Value('')), weight='D')
)

0 comments on commit f47775c

Please sign in to comment.