Ejemplo n.º 1
0
 def test_save_translated_setting_without_default_lang(self):
     setting_name = "test_save_translated_setting_without_default_lang"
     setting_value = "plátano"
     expected_result = ""
     setting = setting_handler.create_setting(
         "test_group",
         setting_name,
         type="text",
         pretty_name="Pretty Name",
         description=None,
         is_translatable=True,
     )
     setting_handler.save_setting(
         "test_group",
         setting_name,
         journal=self.journal_one,
         value=setting_value,
     )
     with helpers.activate_translation(settings.LANGUAGE_CODE):
         result = setting_handler.get_setting(
             "test_group",
             setting_name,
             journal=self.journal_one,
         )
     self.assertEqual(result.value, expected_result)
Ejemplo n.º 2
0
    def save(self, journal, commit=True):
        title = self.cleaned_data.get('title')
        description = self.cleaned_data.get('description')

        if commit:
            setting_handler.save_plugin_setting(
                plugin_settings.get_self(),
                'about_title',
                title,
                journal,
            )

            setting_handler.save_setting(
                'general',
                'journal_description',
                journal,
                description,
            )
Ejemplo n.º 3
0
def journal(name, code, base_url, delete):
    """ Installs a journal into the system.

    :param name: the name of the new journal
    :param code: the journal's short codename
    :param base_url: the full sub domain at which the journal will reside. E.g. sub domain.domain.org
    :param delete: if true, deletes the journal if it exists
    :return: None
    """

    if delete:
        try:
            models.Journal.objects.get(code=code, domain=base_url).delete()
        except models.Journal.DoesNotExist:
            print('Journal not found, nothing to delete')

    journal_object = models.Journal.objects.create(code=code, domain=base_url)
    update_settings(journal_object, management_command=True)
    setting_handler.save_setting('general', 'journal_name', journal_object, name)
Ejemplo n.º 4
0
    def test_save_translated_setting_with_default_lang(self):
        setting_name = "test_save_translated_setting_with_default_lang"
        setting_value = "banana"
        xl_setting_value = "plátano"
        setting = setting_handler.create_setting(
            "test_group",
            setting_name,
            type="text",
            pretty_name="Pretty Name",
            description=None,
            is_translatable=True,
        )
        #Save the setting on the default language
        setting_handler.save_setting(
            "test_group",
            setting_name,
            journal=self.journal_one,
            value=setting_value,
        )
        #Save the translated value
        with helpers.activate_translation("es"):
            setting_handler.save_setting(
                "test_group",
                setting_name,
                journal=self.journal_one,
                value=xl_setting_value,
            )
        result = setting_handler.get_setting(
            "test_group",
            setting_name,
            journal=self.journal_one,
        ).value
        with helpers.activate_translation("es"):
            xl_result = setting_handler.get_setting(
                "test_group",
                setting_name,
                journal=self.journal_one,
            ).value

        self.assertEqual(result, setting_value)
        self.assertEqual(xl_result, xl_setting_value)
Ejemplo n.º 5
0
def import_submission_settings(request, reader):
    row_list = [row for row in reader]
    row_list.remove(row_list[0])

    for row in row_list:
        journal = journal_models.Journal.objects.get(code=row[0])
        setting_handler.save_setting('general', 'copyright_notice', journal,
                                     linebreaksbr(row[1]))
        setting_handler.save_setting('general', 'submission_checklist',
                                     journal, linebreaksbr(row[2]))
        setting_handler.save_setting('general', 'publication_fees', journal,
                                     linebreaksbr(row[3]))
        setting_handler.save_setting('general', 'reviewer_guidelines', journal,
                                     linebreaksbr(row[4]))
Ejemplo n.º 6
0
 def test_set_and_get_journal_setting(self):
     setting_name = "test_get_setting"
     setting_value = "banana"
     setting = setting_handler.create_setting(
         "test_group",
         "test_get_setting",
         type="text",
         pretty_name="Some Name",
         description=None,
     )
     setting_handler.save_setting(
         "test_group",
         "test_get_setting",
         journal=self.journal_one,
         value=setting_value,
     )
     result = setting_handler.get_setting(
         "test_group",
         "test_get_setting",
         journal=self.journal_one,
     )
     self.assertEqual(result.value, setting_value)
Ejemplo n.º 7
0
 def test_get_journal_setting_with_lang_and_default_fallback(self):
     setting_name = "test_get_default_fallback_for_lang_setting"
     setting_value = "banana"
     setting = setting_handler.create_setting(
         "test_group",
         setting_name,
         type="text",
         pretty_name="Pretty Name",
         description=None,
         is_translatable=True,
     )
     setting_handler.save_setting("test_group",
                                  setting_name,
                                  journal=None,
                                  value=setting_value)
     with helpers.activate_translation("es"):
         result = setting_handler.get_setting(
             "test_group",
             setting_name,
             journal=self.journal_one,
             fallback=True,
         )
     self.assertEqual(result.value, setting_value)
Ejemplo n.º 8
0
 def test_save_setting(self):
     setting_name = "test_save_setting"
     setting_value = "This is the setting"
     setting = setting_handler.create_setting(
         "test_group",
         setting_name,
         type="text",
         pretty_name="Pretty Name",
         description=None,
         is_translatable=True,
     )
     setting_handler.save_setting(
         "test_group",
         setting_name,
         journal=self.journal_one,
         value=setting_value,
     )
     result = setting_handler.get_setting(
         "test_group",
         setting_name,
         journal=self.journal_one,
     )
     self.assertEqual(result.value, setting_value)
Ejemplo n.º 9
0
 def test_get_journal_setting_with_default_fallback(self):
     setting_name = "test_get_default_setting"
     setting_value = "default_banana"
     setting = setting_handler.create_setting(
         "test_group",
         setting_name,
         type="text",
         pretty_name="Pretty Name",
         description=None,
         is_translatable=False,
     )
     setting_handler.save_setting(
         "test_group",
         setting_name,
         journal=None,
         value=setting_value,
     )
     result = setting_handler.get_setting(
         "test_group",
         setting_name,
         journal=self.journal_one,
         fallback=True,
     )
     self.assertEqual(result.value, setting_value)
Ejemplo n.º 10
0
def create_template(request, reminder_id, template_name):
    """
    If a new Reminder.template doesn't exist, they are redirected here to create a new one.
    :param request: HttpRequest object
    :param reminder_id: Reminder object PK
    :param template_name: string, Reminder.template string
    :return: if POST HttpRedirect otherwise HttpResponse
    """
    reminder = get_object_or_404(models.Reminder, journal=request.journal, pk=reminder_id)

    if request.POST:
        template = request.POST.get('template')
        setting_handler.create_setting('email', template_name, 'rich-text', reminder.subject, '', is_translatable=True)
        setting_handler.save_setting('email', template_name, request.journal, template)

        return redirect(reverse('cron_reminders'))

    template = 'cron/create_template.html'
    context = {
        'reminder': reminder,
        'template_name': template_name,
    }

    return render(request, template, context)
Ejemplo n.º 11
0
 def save(self, request, commit=True):
     for setting_name, setting_value in self.cleaned_data.items():
         test = setting_handler.save_setting('general', setting_name,
                                             request.journal, setting_value)
Ejemplo n.º 12
0
 def issn(self, value):
     setting_handler.save_setting('general', 'journal_issn', self, value)
Ejemplo n.º 13
0
 def publisher(self, value):
     setting_handler.save_setting('general', 'publisher_name', self, value)
Ejemplo n.º 14
0
 def name(self, value):
     setting_handler.save_setting('general', 'journal_name', self, value)
Ejemplo n.º 15
0
 def test_setting_validation(self, mock_method):
     from utils import setting_handler
     setting_handler.save_setting(
         'email', 'editor_assignment', self.journal_one, 'test'
     )
     mock_method.assert_called()
Ejemplo n.º 16
0
 def save(self, journal, group, commit=True):
     for setting_name, setting_value in self.cleaned_data.items():
         setting_handler.save_setting('general', setting_name, journal,
                                      setting_value)
Ejemplo n.º 17
0
def configure(request):
    token = setting_handler.get_setting("plugin",
                                        "doaj_api_token",
                                        journal=request.journal)
    journals = {}
    push_enabled = False
    if request.journal:
        push_enabled = setting_handler.get_setting(
            "plugin",
            "doaj_publish_push",
            journal=request.journal,
            default=False,
        )
    else:
        for journal in request.press.journals():
            enabled = setting_handler.get_setting(
                "plugin",
                "doaj_publish_push",
                journal=journal,
                default=False,
            )
            if enabled:
                journals[journal] = True
            else:
                journals[journal] = False

    if token.journal == request.journal:
        initial_token = token.value
    else:
        initial_token = None
    token_form = core_forms.EditKey(
        key_type=token.setting.types,
        value=initial_token or None,
    )
    if request.POST:
        token_form
        posted_codes = set(request.POST.getlist("journal_push", []))
        posted_token = request.POST.get("value")
        if posted_token:
            setting_handler.save_setting("plugin",
                                         "doaj_api_token",
                                         journal=request.journal,
                                         value=posted_token)
        if request.journal:
            #If blank, delete potential override
            if not posted_token and token.journal:
                token.delete()
            if request.journal.code in posted_codes:
                setting_handler.save_setting(
                    "plugin",
                    "doaj_publish_push",
                    journal=request.journal,
                    value=True,
                )
            else:
                push_enabled = setting_handler.get_setting(
                    "plugin",
                    "doaj_publish_push",
                    journal=request.journal,
                    default=False,
                )
                if push_enabled:
                    push_enabled.delete()
        else:
            for journal in request.press.journals():
                if journal.code in posted_codes:
                    setting_handler.save_setting(
                        "plugin",
                        "doaj_publish_push",
                        journal=journal,
                        value=True,
                    )
                else:
                    enabled = setting_handler.get_setting(
                        "plugin",
                        "doaj_publish_push",
                        journal=journal,
                        default=False,
                    )
                    if enabled:
                        enabled.delete()
        return redirect(reverse("doaj_configure"))

    template = 'doaj_transporter/configure.html'
    context = {
        "token_form": token_form,
        "token": token,
        "journals": journals,
        "push_enabled": push_enabled,
    }

    return render(request, template, context)