Skip to content

Commit

Permalink
Updatesf from testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajrbyers committed Aug 3, 2021
1 parent 6bd1c31 commit b8587ce
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
15 changes: 6 additions & 9 deletions src/core/homepage_elements/news/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ def yield_homepage_element_context(request, homepage_elements):
return {'news_items': request.press.carousel_news_items.all()}

plugin = utils_models.Plugin.objects.get(name='News')
try:
number_of_articles = setting_handler.get_plugin_setting(
plugin,
'number_of_articles',
request.journal if request.journal else None).value
number_of_articles = int(
number_of_articles) if number_of_articles else 0
except IndexError:
number_of_articles = 0
number_of_articles = setting_handler.get_plugin_setting(
plugin,
'number_of_articles',
request.journal if request.journal else None).value
number_of_articles = int(
number_of_articles) if number_of_articles else 2

news_items = comms_models.NewsItem.objects.filter(
(Q(content_type=request.model_content_type) & Q(
Expand Down
12 changes: 10 additions & 2 deletions src/core/homepage_elements/news/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
@editor_user_required
def news_config(request):
plugin = models.Plugin.objects.get(name='News')
number_of_articles = setting_handler.get_plugin_setting(plugin, 'number_of_articles', request.journal, create=True,
pretty='Number of Articles').value
number_of_articles = setting_handler.get_plugin_setting(
plugin,
'number_of_articles',
request.journal,
create=True,
pretty='Number of Articles',
).value
number_of_articles = int(
number_of_articles
) if number_of_articles else 2
if request.POST:
number_of_articles = request.POST.get('number_of_articles')
setting_handler.save_plugin_setting(plugin, 'number_of_articles', number_of_articles, request.journal)
Expand Down
7 changes: 4 additions & 3 deletions src/core/migrations/0047_remove_dots_from_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ def replace_setting_urls(apps, schema_editor):
setting.value = setting.value.replace("url }}.", "url }} ")
setting.save()
except LookupError:
with translation.activate(django_settings.LANGUAGE_CODE):
with translation.override(django_settings.LANGUAGE_CODE):
SettingValue = apps.get_model('core', 'SettingValue')
settings = SettingValue.objects.filter(setting__group__name="email")
for setting in settings:
setting.value = setting.value.replace("url }}.", "url }} ")
setting.save()
if setting.value:
setting.value = setting.value.replace("url }}.", "url }} ")
setting.save()


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def update_setting_values(apps, schema_editor):
setting.value += ("<br/>{{ article_details }}")
setting.save()
except LookupError:
with translation.activate(django_settings.LANGUAGE_CODE):
with translation.override(django_settings.LANGUAGE_CODE):
SettingValue = apps.get_model('core', 'SettingValue')
setting_values = SettingValue.objects.filter(
setting__name='review_assignment',
Expand Down
24 changes: 15 additions & 9 deletions src/utils/migrations/0020_auto_20210222_1750.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
from __future__ import unicode_literals

from django.db import migrations
from django.conf import settings
from django.utils import translation as _translation


def migrate_plugin_settings(apps, schema_editor):
PluginSetting = apps.get_model('utils', 'PluginSetting')
PluginSettingValue = apps.get_model('utils', 'PluginSettingValue')
PluginSettingValueTranslation = apps.get_model('utils', 'PluginSettingValueTranslation')
SettingGroup = apps.get_model('core', 'SettingGroup')
Setting = apps.get_model('core', 'Setting')
SettingValue = apps.get_model('core', 'SettingValue')

plugin_settings = PluginSetting.objects.all()


translations = PluginSettingValueTranslation.objects.all()

for translation in translations:
Expand All @@ -40,11 +38,19 @@ def migrate_plugin_settings(apps, schema_editor):
description=plugin_setting.description,
is_translatable=plugin_setting.is_translatable,
)
setting_value, c = SettingValue.objects.get_or_create(
journal=plugin_setting_value.journal,
setting=setting,
)
setattr(setting_value, 'value_{}'.format(translation.language_code), translation.value)
with _translation.override(settings.LANGUAGE_CODE):
setting_value, c = SettingValue.objects.get_or_create(
journal=plugin_setting_value.journal if plugin_setting_value.journal else None,
setting=setting,
value=translation.value,
)
if c:
print(
"PluginSetting {} moved to Setting {}".format(
plugin_setting.name,
setting.name,
)
)


class Migration(migrations.Migration):
Expand Down

0 comments on commit b8587ce

Please sign in to comment.