-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #758 from samuelveigarangel/feature/article-license
Adiciona um novo campo em Article para representar licença do artigo.
- Loading branch information
Showing
13 changed files
with
179 additions
and
49 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Generated by Django 5.0.3 on 2024-05-28 18:09 | ||
|
||
from django.db import migrations, models | ||
|
||
def transfer_license_statements_fk_to_article_license(apps, schema_editor): | ||
Article = apps.get_model('article', 'Article') | ||
|
||
articles_to_update = [] | ||
for instance in Article.objects.all(): | ||
|
||
new_license = None | ||
if instance.license_statements.exists() and instance.license_statements.first().url: | ||
new_license = instance.license_statements.first().url | ||
elif instance.license and instance.license.license_type: | ||
new_license = instance.license.license_type | ||
|
||
if new_license: | ||
instance.article_license = new_license | ||
articles_to_update.append(instance) | ||
|
||
if articles_to_update: | ||
Article.objects.bulk_update(articles_to_update, ['article_license']) | ||
|
||
|
||
def reverse_transfer_license_statements_fk_to_article_license(apps, schema_editor): | ||
Article = apps.get_model('article', 'Article') | ||
|
||
articles_to_update = [] | ||
for instance in Article.objects.all(): | ||
instance.article_license = None | ||
articles_to_update.append(instance) | ||
|
||
if articles_to_update: | ||
Article.objects.bulk_update(articles_to_update, ['article_license']) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("article", "0012_alter_article_publisher"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="article", | ||
name="article_license", | ||
field=models.CharField(blank=True, max_length=255, null=True), | ||
), | ||
migrations.RunPython( | ||
transfer_license_statements_fk_to_article_license, | ||
reverse_transfer_license_statements_fk_to_article_license, | ||
), | ||
] |
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 |
---|---|---|
@@ -1,3 +1,20 @@ | ||
from django.test import TestCase | ||
from django_test_migrations.migrator import Migrator | ||
|
||
# Create your tests here. | ||
class TestArticleMigration(TestCase): | ||
def test_migration_0013_article_article_license(self): | ||
migrator = Migrator(database='default') | ||
old_state = migrator.apply_initial_migration(('article', '0012_alter_article_publisher')) | ||
Article = old_state.apps.get_model('article', 'Article') | ||
LicenseStatement = old_state.apps.get_model('core', 'LicenseStatement') | ||
article = Article.objects.create() | ||
license_statement = LicenseStatement.objects.create(url="https://www.teste.com.br") | ||
article.license_statements.add(license_statement) | ||
|
||
new_state = migrator.apply_tested_migration(('article', '0013_article_article_license')) | ||
|
||
Article = new_state.apps.get_model('article', 'Article') | ||
|
||
article = Article.objects.first() | ||
self.assertEqual(article.article_license, 'https://www.teste.com.br') | ||
migrator.reset() |
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
19 changes: 19 additions & 0 deletions
19
core/migrations/0004_language_core_langua_code2_4f7261_idx.py
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,19 @@ | ||
# Generated by Django 5.0.3 on 2024-05-27 17:45 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0003_gender_created_gender_creator_gender_updated_and_more"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.AddIndex( | ||
model_name="language", | ||
index=models.Index(fields=["code2"], name="core_langua_code2_4f7261_idx"), | ||
), | ||
] |
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
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
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,3 +1,18 @@ | ||
from django.test import TestCase | ||
from django.test import SimpleTestCase | ||
|
||
# Create your tests here. | ||
from researcher.models import PersonName | ||
|
||
|
||
class PersonNameJoinNameTest(SimpleTestCase): | ||
def test_person_name_join_name(self): | ||
test_cases = [ | ||
(['Palavra1', None, None], 'Palavra1'), | ||
(['Palavra1', 'Palavra2', None], 'Palavra1 Palavra2' ), | ||
(['Palavra1', 'Palavra2', 'Palavra3'], 'Palavra1 Palavra2 Palavra3'), | ||
] | ||
|
||
for text, expected in test_cases: | ||
with self.subTest(text=text, excepted=expected): | ||
result = PersonName.join_names(*text) | ||
self.assertEqual(expected, result) |