Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/github/codeql-ac…
Browse files Browse the repository at this point in the history
…tion-3
  • Loading branch information
fsbraun authored Mar 5, 2024
2 parents 91dedf9 + 2d22c0d commit a898b23
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 65 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
python-version: '3.11'
cache: 'pip'
- name: Cache dependencies
uses: actions/cache@v3.3.3
uses: actions/cache@v4.0.1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
Expand All @@ -44,7 +44,7 @@ jobs:
python-version: '3.11'
cache: 'pip'
- name: Cache dependencies
uses: actions/cache@v3.3.3
uses: actions/cache@v4.0.1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('docs/requirements.txt') }}
Expand Down
31 changes: 11 additions & 20 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
name: Lint
name: Ruff

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
push:
pull_request:

jobs:
ruff:
name: ruff
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: 'pip'
- run: |
python -m pip install --upgrade pip
pip install ruff
- name: Run Ruff
run: |
ruff djangocms_versioning tests
- uses: actions/checkout@v4

- run: python -Im pip install --user ruff

- name: Run ruff
run: ruff --output-format=github djangocms_versioning tests
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: coverage run setup.py test

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4

postgres:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
DATABASE_URL: postgres://postgres:[email protected]/postgres

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4

mysql:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
DATABASE_URL: mysql://[email protected]/djangocms_test

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4

cms-develop-sqlite:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -161,7 +161,7 @@ jobs:
run: coverage run setup.py test

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4

sqlite-django-main:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -197,4 +197,4 @@ jobs:
run: coverage run setup.py test

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ repos:
- id: check-merge-conflict
- id: mixed-line-ending

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.264"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
4 changes: 3 additions & 1 deletion djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@ class VersionAdmin(ChangeListActionsMixin, admin.ModelAdmin, metaclass=MediaDefi
# def get_queryset(self, request):
# return super().get_queryset(request).prefetch_related('content')

class Media:
js = ["djangocms_versioning/js/versioning.js"]

def get_changelist(self, request, **kwargs):
return VersionChangeList

Expand Down Expand Up @@ -969,7 +972,6 @@ def publish_view(self, request, object_id):

# Redirect to published?
if conf.ON_PUBLISH_REDIRECT == "published":
redirect_url = None
if hasattr(version.content, "get_absolute_url"):
redirect_url = version.content.get_absolute_url() or redirect_url

Expand Down
4 changes: 2 additions & 2 deletions djangocms_versioning/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def _add_unlock_button(self):
if LOCK_VERSIONS and self._is_versioned():
item = ButtonList(side=self.toolbar.RIGHT)
proxy_model = self._get_proxy_model()
version = Version.objects.get_for_content(self.toolbar.obj)
if version.check_unlock.as_bool(self.request.user):
version = Version.objects.filter_by_content_grouping_values(self.toolbar.obj).filter(state=DRAFT).first()
if version and version.check_unlock.as_bool(self.request.user):
unlock_url = reverse(
f"admin:{proxy_model._meta.app_label}_{proxy_model.__name__.lower()}_unlock",
args=(version.pk,),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,3 @@ ins.cms-diff img {
.cms-select::-ms-expand {
opacity: 0;
}
input.button.revert-button {
margin: 5px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(function () {
"use strict";

function closeSideFrame() {
try {
window.top.CMS.API.Sideframe.close();
} catch (err) {}
}

document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('form.js-close-sideframe').forEach(el => {
el.addEventListener("submit", (ev) => {
ev.preventDefault();
closeSideFrame();
const form = window.top.document.body.appendChild(ev.target);
form.style.display = 'none';
form.submit();
});
});
});
})();
37 changes: 37 additions & 0 deletions djangocms_versioning/static/djangocms_versioning/js/versioning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(function() {
var firstChecked, lastChecked;

function handleVersionSelection(event) {
if (firstChecked instanceof HTMLInputElement && firstChecked.checked) {
firstChecked.checked = false;
firstChecked.closest('tr').classList.remove('selected');
firstChecked = lastChecked;
}
if (event.target instanceof HTMLInputElement) {
if (event.target.checked) {
firstChecked = lastChecked;
lastChecked = event.target;
} else if (firstChecked === event.target) {
firstChecked = null;
} else {
lastChecked = null;
}
}
}

document.addEventListener('DOMContentLoaded', function(){
var selectedVersions = document.querySelectorAll('#result_list input[type="checkbox"].action-select');
var selectElement = document.querySelector('#changelist-form select[name="action"]');
if (selectElement instanceof HTMLSelectElement) {
for (var i = 0; i < selectElement.options.length; i++) {
if (selectElement.options[i].value && selectElement.options[i].value !== 'compare_versions') {
// for future safety: do not restrict on two selected versions, since there might be other actions
return;
}
}
}
selectedVersions.forEach(function(selectedVersion){
selectedVersion.addEventListener('change', handleVersionSelection);
});
});
})();
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{{ block.super }}
{{ media }}
<script type="text/javascript" src="{% static 'admin/js/cancel.js' %}"></script>
<script type="text/javascript" src="{% static 'djangocms_versioning/js/admin/versioning-actions.js' %}"></script>
{% endblock %}

{% block breadcrumbs %}{% endblock %}
Expand All @@ -15,15 +16,17 @@
<p>{% translate "Are you sure you want to archive the following version?" %}</p>
<h3>{{ object_name }}</h3>
<h4>{% blocktrans %} Version number: {{ version_number }}{% endblocktrans %}</h4>
<form action="" method="POST">
<form action="" method="POST" class="js-close-sideframe">
{% csrf_token %}
<input class="button confirm-link js-versioning-keep-sideframe"
type="submit"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
<input type="button"
class="button js-versioning-keep-sideframe"
value="{% translate 'No, take me back' %}">
</a>
<div class="submit-row">
<input class="button confirm-link"
type="submit"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
<input type="button"
class="button js-versioning-keep-sideframe"
value="{% translate 'No, take me back' %}">
</a>
</div>
</form>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{{ media }}
<link rel="stylesheet" href="{% static 'djangocms_versioning/css/versioning.css' %}">
<script type="text/javascript" src="{% static 'admin/js/cancel.js' %}"></script>
<script type="text/javascript" src="{% static 'djangocms_versioning/js/admin/versioning-actions.js' %}"></script>
{% endblock %}

{% block breadcrumbs %}{% endblock %}
Expand All @@ -22,20 +23,20 @@ <h1>{% block title %}{% translate "Revert Confirmation" %}{% endblock %}</h1>
</p>
<h3>{{ object_name }}</h3>
<h4>{% blocktrans %}Version number: {{ version_number }}{% endblocktrans %}</h4>
<form action="" method="POST">
<form action="" method="POST" class="js-close-sideframe">
{% csrf_token %}
<div class="submit-row">
{% if draft_version %}
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
<input class="button revert-button confirm-link"
type="submit"
name="discard"
value="{% translate 'Discard existing draft and Revert' %}">
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
<input class="button revert-button confirm-link"
name="archive"
type="submit"
value="{% translate 'Archive existing draft and Revert' %}">
{% else %}
<input class="button revert-button confirm-link js-versioning-keep-sideframe"
<input class="button revert-button confirm-link"
type="submit"
name="revert"
value="{% translate "Yes, I'm sure" %}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{ block.super }}
{{ media }}
<script type="text/javascript" src="{% static 'admin/js/cancel.js' %}"></script>
<script type="text/javascript" src="{% static 'djangocms_versioning/js/admin/versioning-actions.js' %}"></script>
{% endblock %}

{% block breadcrumbs %}{% endblock %}
Expand All @@ -20,10 +21,10 @@ <h4>{% blocktrans %} Version number: {{ version_number }}{% endblocktrans %}</h4
<p>{{thing}}</p>
{% endfor %}
</div>
<form action="" method="POST">
<form action="" method="POST" class="js-close-sideframe">
{% csrf_token %}
<div class="submit-row">
<input class="button confirm-link js-versioning-keep-sideframe"
<input class="button confirm-link"
type="submit"
value="{% translate "Yes, I'm sure" %}">
<a href="{{ back_url }}">
Expand Down
31 changes: 16 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
[tool.ruff]
# https://beta.ruff.rs/docs/configuration/
exclude = [
".eggs",
".git",
".mypy_cache",
".ruff_cache",
".env",
".venv",
"**migrations/**",
"node_modules",
"venv",
]
line-length = 120

[tool.ruff.lint]
# https://beta.ruff.rs/docs/configuration/
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
Expand All @@ -15,18 +28,6 @@ select = [
"UP", # pyupgrade
]

exclude = [
".eggs",
".git",
".mypy_cache",
".ruff_cache",
".env",
".venv",
"**migrations/**",
"node_modules",
"venv",
]

ignore = [
"B006", # Do not use mutable data structures for argument defaults
"B011", # tests use assert False
Expand All @@ -43,12 +44,12 @@ ignore = [
"UP007", # Use `X | Y` for type annotations
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = [
"F401" # unused-import
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = [
"djangocms_versioning",
Expand Down

0 comments on commit a898b23

Please sign in to comment.