-
Notifications
You must be signed in to change notification settings - Fork 4
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
Allow content edit and translation #162
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 2.1.7 on 2019-05-31 23:22 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("dips", "0008_alter_dip_objectszip")] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Content", | ||
fields=[ | ||
( | ||
"key", | ||
models.CharField(max_length=50, primary_key=True, serialize=False), | ||
), | ||
("content", models.TextField(blank=True, verbose_name="content")), | ||
( | ||
"content_en", | ||
models.TextField(blank=True, null=True, verbose_name="content"), | ||
), | ||
( | ||
"content_fr", | ||
models.TextField(blank=True, null=True, verbose_name="content"), | ||
), | ||
], | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.db import migrations | ||
|
||
from dips.models import Content | ||
|
||
|
||
def add(apps, schema_editor): | ||
home_en = ( | ||
"## Digital Archives Access Interface\n\n" | ||
"You can search digital files by using the search " | ||
"bar below or you can browse our collections. \n" | ||
"If you need help, please use our FAQ page in the menu above." | ||
) | ||
home_fr = ( | ||
"## Interface d'accès aux archives numériques\n\n" | ||
"Pour effectuer une recherche dans les fichiers, utiliser la barre de " | ||
"recherche ci-dessous ou naviguer dans nos collections. \n" | ||
"Consulter la FAQ si vous avez besoin d'aide." | ||
) | ||
data = [ | ||
("01_home", {"en": home_en, "fr": home_fr}), | ||
("02_login", {"en": "", "fr": ""}), | ||
("03_faq", {"en": "", "fr": ""}), | ||
] | ||
for key, content in data: | ||
Content.objects.create( | ||
key=key, content_en=content["en"], content_fr=content["fr"] | ||
) | ||
|
||
|
||
def remove(apps, schema_editor): | ||
Content.objects.all().delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [("dips", "0009_content")] | ||
|
||
operations = [migrations.RunPython(add, remove)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from django.contrib.auth.models import Group | ||
cole marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from django.db.migrations.executor import MigrationExecutor | ||
from django.db import connection | ||
from django.test import TransactionTestCase | ||
|
||
from dips.models import Content | ||
|
||
|
||
class TestMigrations(TransactionTestCase): | ||
"""Uses TransactionTestCase to perform rollbacks.""" | ||
|
||
def setUp(self): | ||
self.executor = MigrationExecutor(connection) | ||
|
||
def test_rollbacks(self): | ||
"""Checks that migration rollbacks run correctly. | ||
|
||
Perform all rollbacks in order in the same test to maintain DB status. | ||
""" | ||
# Initial counts | ||
self.assertEqual(Group.objects.count(), 3) | ||
self.assertEqual(Content.objects.count(), 3) | ||
|
||
# Content removal | ||
self.executor.migrate([("dips", "0009_content")]) | ||
self.assertEqual(Content.objects.count(), 0) | ||
|
||
# Groups removal | ||
self.executor.migrate([("dips", "0001_initial")]) | ||
self.assertEqual(Group.objects.count(), 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
from django.test import TestCase | ||
from unittest.mock import patch | ||
|
||
from dips.models import User | ||
from dips.models import Content, User | ||
|
||
|
||
class ViewsTests(TestCase): | ||
def setUp(self): | ||
self.user = User.objects.create_superuser("admin", "[email protected]", "admin") | ||
self.client.login(username="admin", password="admin") | ||
self.faq = Content.objects.get(key="03_faq") | ||
|
||
@patch("elasticsearch_dsl.Search.execute") | ||
@patch("elasticsearch_dsl.Search.count", return_value=0) | ||
|
@@ -26,3 +27,81 @@ def test_search_wrong_dates(self, mock_msg_error, mock_es_count, mock_es_exec): | |
self.assertEqual(response.context["filters"], expected_filters) | ||
# But the errors should be added to the messages | ||
self.assertEqual(mock_msg_error.call_count, 2) | ||
|
||
def test_content_get_en(self): | ||
response = self.client.get("/content/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertEqual(len(response.context["formset"]), 3) | ||
self.assertContains(response, "## Digital Archives Access Interface") | ||
|
||
def test_content_get_fr(self): | ||
response = self.client.get("/content/", HTTP_ACCEPT_LANGUAGE="fr") | ||
self.assertEqual(len(response.context["formset"]), 3) | ||
self.assertContains( | ||
response, "## Interface d'accès aux archives numériques" | ||
) | ||
|
||
def test_content_post_en(self): | ||
data = { | ||
"form-TOTAL_FORMS": ["3"], | ||
"form-INITIAL_FORMS": ["3"], | ||
"form-MIN_NUM_FORMS": ["0"], | ||
"form-MAX_NUM_FORMS": ["1000"], | ||
"form-0-content": ["New English content"], | ||
"form-0-key": ["01_home"], | ||
"form-1-content": [""], | ||
"form-1-key": ["02_login"], | ||
"form-2-content": [""], | ||
"form-2-key": ["03_faq"], | ||
} | ||
self.client.post("/content/", data, HTTP_ACCEPT_LANGUAGE="en") | ||
content = Content.objects.get(key="01_home") | ||
self.assertEqual(content.content_en, "New English content") | ||
|
||
def test_content_post_fr(self): | ||
data = { | ||
"form-TOTAL_FORMS": ["3"], | ||
"form-INITIAL_FORMS": ["3"], | ||
"form-MIN_NUM_FORMS": ["0"], | ||
"form-MAX_NUM_FORMS": ["1000"], | ||
"form-0-content": ["New French content"], | ||
"form-0-key": ["01_home"], | ||
"form-1-content": [""], | ||
"form-1-key": ["02_login"], | ||
"form-2-content": [""], | ||
"form-2-key": ["03_faq"], | ||
} | ||
self.client.post("/content/", data, HTTP_ACCEPT_LANGUAGE="fr") | ||
content = Content.objects.get(key="01_home") | ||
self.assertEqual(content.content_fr, "New French content") | ||
|
||
def test_faq_deleted(self): | ||
self.faq.delete() | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_faq_markdown(self): | ||
self.faq.content_en = "## Header" | ||
self.faq.save() | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertContains(response, "<h2>Header</h2>") | ||
|
||
def test_faq_html(self): | ||
self.faq.content_en = "<h2>Header</h2>" | ||
self.faq.save() | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertContains(response, "<h2>Header</h2>") | ||
|
||
def test_faq_langs(self): | ||
self.faq.content_en = "English content" | ||
self.faq.save() | ||
# English | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="en") | ||
self.assertContains(response, "English content") | ||
# Fallback | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="fr") | ||
self.assertContains(response, "English content") | ||
# French | ||
self.faq.content_fr = "French content" | ||
self.faq.save() | ||
response = self.client.get("/faq/", HTTP_ACCEPT_LANGUAGE="fr") | ||
self.assertContains(response, "French content") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from modeltranslation.translator import register, TranslationOptions | ||
|
||
from .models import Content | ||
|
||
|
||
@register(Content) | ||
class ContentTranslationOptions(TranslationOptions): | ||
fields = ("content",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jraddaoui , wouldn't be a good idea to have the model mapped out after the concept of a "Page"? E.g. a model where you can also fit the title of the page or in the future things like its permalink? Or you're thinking on something more generic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point @sevein! I didn't go that way because some of the contents are added as part of a page, where other elements already exist. There are some follow-ups in #96 about those "static content" sections.