Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fsbraun/djangocms-alias
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/test_models.py
  • Loading branch information
fsbraun committed Nov 12, 2023
2 parents 5b15e0b + 7ab8cd6 commit 1591a8a
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ ci:

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.8.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]

- repo: https://github.com/adamchainz/django-upgrade
rev: '1.14.0'
rev: '1.15.0'
hooks:
- id: django-upgrade
args: [--target-version, "3.2"]

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

2.0.0rc2
========
* fix: Migration dependency on latest django-cms migration.
* fix: Allow using a variable as the identifier in static_alias template tag

2.0.0rc1
========
* Django 4.0, 4.1, and 4.2 support added
Expand Down
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Security Policy

## Reporting a Vulnerability

As ever, we remind our users and contributors that all security reports, patches and concerns be addressed only to our security team by email, at [email protected].
2 changes: 1 addition & 1 deletion djangocms_alias/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.0rc1'
__version__ = '2.0.0rc2'
28 changes: 28 additions & 0 deletions djangocms_alias/migrations/0003_auto_20230725_1547.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.1.8 on 2023-07-25 15:47

from django.db import migrations, models
import django.db.models.deletion

class Migration(migrations.Migration):

dependencies = [
('cms', '__first__'),
('djangocms_alias', '0002_auto_20200723_1424'),
]

operations = [
migrations.AlterField(
model_name='aliasplugin',
name='cmsplugin_ptr',
field=models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='%(app_label)s_%(class)s', serialize=False, to='cms.cmsplugin'),
),
migrations.AlterField(
model_name='categorytranslation',
name='name',
field=models.CharField(max_length=120, verbose_name='name'),
),
migrations.AlterUniqueTogether(
name='categorytranslation',
unique_together={('language_code', 'master'), ('name', 'language_code')},
),
]
19 changes: 19 additions & 0 deletions djangocms_alias/migrations/0004_alter_aliascontent_language.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.20 on 2023-07-26 13:43

from django.db import migrations, models
import django.utils.translation


class Migration(migrations.Migration):

dependencies = [
('djangocms_alias', '0003_auto_20230725_1547'),
]

operations = [
migrations.AlterField(
model_name='aliascontent',
name='language',
field=models.CharField(default=django.utils.translation.get_language, max_length=10),
),
]
7 changes: 5 additions & 2 deletions djangocms_alias/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Category(TranslatableModel):
name=models.CharField(
verbose_name=_('name'),
max_length=120,
unique=True,
),
meta={'unique_together': [('name', 'language_code')]},
)

class Meta:
Expand Down Expand Up @@ -256,7 +256,6 @@ class AliasContent(models.Model):
placeholder_slotname = 'content'
language = models.CharField(
max_length=10,
choices=settings.LANGUAGES,
default=get_language,
)

Expand All @@ -266,6 +265,10 @@ class Meta:
verbose_name = _('alias content')
verbose_name_plural = _('alias contents')

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._meta.get_field('language').choices = settings.LANGUAGES

def __str__(self):
return f'{self.name} ({self.language})'

Expand Down
2 changes: 1 addition & 1 deletion djangocms_alias/templatetags/djangocms_alias_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class StaticAlias(Tag):
"""
name = 'static_alias'
options = PlaceholderOptions(
Argument('static_code', resolve=False),
Argument('static_code', resolve=True),
MultiValueArgument('extra_bits', required=False, resolve=False),
blocks=[
('endstatic_alias', 'nodelist'),
Expand Down
29 changes: 28 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django import get_version
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.urls import reverse

from cms.api import add_plugin, create_title
Expand Down Expand Up @@ -408,7 +409,7 @@ def test_delete(self):
alias.save() # Django 4.1+ disallows to use relations (cmsplugins) of unsaved objects.
self.assertEqual(alias.cms_plugins.count(), 0)

def test_category_get_absolute_url(self):
def test_category_get_edit_url(self):
"""
Category uses the admin change view as its absolute url
"""
Expand All @@ -420,3 +421,29 @@ def test_category_get_absolute_url(self):
)

self.assertEqual(category.get_edit_url(), expected)

def test_category_name_same_across_languages(self):
"""
Category name may be the same across languages
"""
category = Category.objects.create(name='Samename A')
category.set_current_language('de')
category.name = "Samename A"
try:
category.validate_unique()
except ValidationError:
self.fail("Same Category name should be allowed across two languages.")

category.set_current_language('en')
self.assertEqual(category.name, 'Samename A')
category.set_current_language('de')
self.assertEqual(category.name, 'Samename A')

def test_category_name_unique_for_language(self):
"""
Category name can't be the same in one language for two different categories
"""
with self.login_user_context(self.superuser):
Category.objects.create(name='Samename B')
c = Category(name='Samename B')
self.assertRaises(ValidationError, c.validate_unique)
19 changes: 19 additions & 0 deletions tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,22 @@ def page_edit_url(lang):

self.assertIsNotNone(alias.get_content("en", show_draft_content=True))
self.assertIsNotNone(alias.get_content("de", show_draft_content=True))

def test_alias_rendered_when_identifier_is_variable(self):
alias_template = """{% load djangocms_alias_tags %}{% static_alias foo_variable %}""" # noqa: E501

alias = self._create_alias(static_code="some_unique_id")
add_plugin(
alias.get_placeholder(self.language),
'TextPlugin',
language=self.language,
body='Content Alias 1234',
)

output = self.render_template_obj(
alias_template,
{'foo_variable': "some_unique_id"},
self.get_request('/'),
)

self.assertEqual(output, "Content Alias 1234")

0 comments on commit 1591a8a

Please sign in to comment.