Skip to content

Commit

Permalink
Merge branch 'main' into pv-2023-11-react-maps
Browse files Browse the repository at this point in the history
  • Loading branch information
vellip authored Feb 14, 2024
2 parents f2c7a29 + ba79db4 commit 1155aa8
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 71 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Setup Postgres
Expand All @@ -39,7 +39,7 @@ jobs:
psql -c 'create database django;' -U postgres
psql -c 'create database django_test;' -U postgres
- name: Cache node modules
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-node-modules
with:
Expand All @@ -50,7 +50,7 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-
- name: Cache pip packages
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: cache-pip-packages
with:
Expand Down Expand Up @@ -83,8 +83,3 @@ jobs:
- name: Run Frontend Tests
run: |
npm test
- name: Frontend Coverage
uses: artiomtr/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'pull_request'
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

make lint-quick
66 changes: 58 additions & 8 deletions adhocracy4/dashboard/mixins.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import warnings
from copy import deepcopy
from pathlib import Path

from django.apps import apps
from django.conf import settings
from django.contrib import messages
from django.core.exceptions import PermissionDenied
from django.core.files.base import ContentFile
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.urls import NoReverseMatch
Expand Down Expand Up @@ -107,29 +110,61 @@ def get_context_data(self, **kwargs):


class DashboardComponentFormSignalMixin(edit.FormMixin):
"""Mixin which sends a project_component_updated or module_component_updated signal
when creating, updating or deleting an object via the HTTP POST method
(e.g. from the dashboard).
"""

def form_valid(self, form):
# The call to super.form_valid() may delete self.project or self.module,
# to be able to still reference them below we need to store them in separate
# variables before they are deleted.
project = self.project
module = self.module

response = super().form_valid(form)

component = self.component
if component.identifier in components.projects:
signals.project_component_updated.send(
sender=component.__class__,
project=self.project,
project=project,
component=component,
user=self.request.user,
)
else:
signals.module_component_updated.send(
sender=component.__class__,
module=self.module,
module=module,
component=component,
user=self.request.user,
)
return response


class DashboardComponentDeleteSignalMixin(edit.DeletionMixin):
"""Deprecated, use DashboardComponentFormSignalMixin for POST requests instead.
This mixin will be removed in the next version.
"""

def __init__(self):
warnings.warn(
"dashboard.mixins.DashboardComponentDeleteSignalMixin is deprecated, "
"use dashboard.mixins.DashboardComponentFormSignalMixin for forms / POST "
"requests. This mixin will be removed in the next version.",
DeprecationWarning,
)

super().__init__()

def delete(self, request, *args, **kwargs):
warnings.warn(
"dashboard.mixins.DashboardComponentDeleteSignalMixin.delete()"
"is deprecated, use dashboard.mixins.DashboardComponentFormSignalMixin "
"for forms / POST requests. This mixin will be removed in the next "
"version.",
DeprecationWarning,
)
# Project and module have to be stored before delete is called as
# they may rely on the still existing db object.
project = self.project
Expand Down Expand Up @@ -167,16 +202,31 @@ def post(self, request, *args, **kwargs):

project_clone = deepcopy(project)
project_clone.pk = None
if project_clone.tile_image:
project_clone.tile_image.save(
project.tile_image.name, project.tile_image, False
)
if project_clone.image:
project_clone.image.save(project.image.name, project.image, False)
project_clone.created = timezone.now()
project_clone.is_draft = True
project_clone.is_archived = False

if project.tile_image:
# django's image.name contains the file storage location defined in 'upload_to'
tile_file_name = Path(
project.tile_image.name
).name # retreives only the filename
tile_copy = ContentFile(
project.tile_image.read()
) # retreives the image bytes
project_clone.tile_image.save(tile_file_name, tile_copy, False)

if project.image:
# django's image.name contains the file storage location defined in 'upload_to'
image_file_name = Path(project.image.name).name
image_copy = ContentFile(project.image.read())
project_clone.image.save(image_file_name, image_copy, False)

project_clone.save()
if project.topics:
for topic in project.topics.all():
project_clone.topics.add(topic)

signals.project_created.send(
sender=None, project=project_clone, user=self.request.user
)
Expand Down
2 changes: 1 addition & 1 deletion adhocracy4/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(
):
label = kwargs.get("label", None)
time_label = ""
if type(label) == tuple:
if isinstance(label, tuple):
date_label, time_label = label
kwargs["label"] = date_label
elif label:
Expand Down
3 changes: 1 addition & 2 deletions adhocracy4/phases/contents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class PhaseContent:

features = {}

@property
Expand All @@ -17,7 +16,7 @@ class PhaseContents:
_registry = {}

def __getitem__(self, identifier):
if type(identifier) != str:
if not isinstance(identifier, str):
raise TypeError("Phase identifier must be str")
return self._registry[identifier]

Expand Down
4 changes: 1 addition & 3 deletions adhocracy4/polls/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class PollCommentExportView(
export_mixins.CommentExportWithRepliesToMixin,
export_views.BaseItemExportView,
):

model = Comment

fields = ["id", "comment", "created"]
Expand All @@ -47,7 +46,6 @@ def raise_exception(self):


class PollExportView(PermissionRequiredMixin, export_views.BaseItemExportView):

permission_required = "a4polls.change_poll"

def get_permission_object(self):
Expand Down Expand Up @@ -112,7 +110,7 @@ def get_field_data(self, item, field):

else:
field_object, is_text_field = field
if type(field_object) == poll_models.Choice:
if isinstance(field_object, poll_models.Choice):
votes_qs = poll_models.Vote.objects.filter(
choice=field_object, creator=user
)
Expand Down
2 changes: 1 addition & 1 deletion adhocracy4/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def get_module_cluster_index(self, module):
for idx, val in enumerate(self.participation_dates):
if "modules" in val and module in val["modules"]:
return idx
if self.project.get_current_participation_date():
if hasattr(self, "project") and self.project.get_current_participation_date():
return self.project.get_current_participation_date()
return 0

Expand Down
3 changes: 3 additions & 0 deletions changelog/1521.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Fixed

- delete logic moved to form_valid method after django upgrade in dashboard component mixin
3 changes: 3 additions & 0 deletions changelog/1527.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- duplicated image path when a project gets duplicated in the dashboard
3 changes: 3 additions & 0 deletions changelog/1528.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- retreival of image name to save as new image instance when project is duplicated
7 changes: 7 additions & 0 deletions changelog/_00010.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Changed

- **Breaking Change** Deprecated
dashboard.mixins.DashboardComponentDeleteSignalMixin,
for forms / POST requests use
dashboard.mixins.DashboardComponentFormSignalMixin instead.
DashboardComponentDeleteSignalMixin will be removed in the next version.
4 changes: 4 additions & 0 deletions changelog/_5555.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- fix an error when opening a module which is marked as draft in a multimodule
project
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,45 @@
"maplibregl-mapbox-request-transformer": "0.0.2"
},
"devDependencies": {
"@babel/eslint-parser": "7.22.15",
"@babel/plugin-transform-runtime": "7.23.2",
"@babel/preset-env": "7.23.2",
"@babel/preset-react": "7.22.15",
"@babel/eslint-parser": "7.23.10",
"@babel/plugin-transform-runtime": "7.23.9",
"@babel/preset-env": "7.23.9",
"@babel/preset-react": "7.23.3",
"@maplibre/maplibre-gl-leaflet": "0.0.20",
"@react-leaflet/core": "^2.1.0",
"@testing-library/jest-dom": "6.1.5",
"@testing-library/react": "14.0.0",
"eslint": "8.47.0",
"@testing-library/jest-dom": "6.4.2",
"@testing-library/react": "14.2.1",
"eslint": "8.56.0",
"eslint-config-standard": "17.1.0",
"eslint-config-standard-jsx": "11.0.0",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-jest": "27.2.3",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-n": "16.0.2",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "27.8.0",
"eslint-plugin-jsx-a11y": "6.8.0",
"eslint-plugin-n": "16.6.2",
"eslint-plugin-promise": "6.1.1",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"esquery": "1.5.0",
"husky": "8.0.3",
"husky": "9.0.10",
"immutability-helper": "3.1.1",
"jest": "29.6.3",
"jest-environment-jsdom": "29.6.3",
"jquery": "3.7.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"jquery": "3.7.1",
"leaflet": "1.9.4",
"leaflet-draw": "1.0.4",
"leaflet.markercluster": "git+https://github.com/liqd/Leaflet.markercluster#liqd2212",
"lint-staged": "13.3.0",
"lint-staged": "15.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-flip-move": "3.0.5",
"react-leaflet": "^4.2.1",
"react-markdown": "8.0.7",
"react-slick": "0.29.0",
"react-markdown": "9.0.1",
"react-slick": "0.30.1",
"shpjs": "4.0.4"
},
"peerDependencies": {
"immutability-helper": "3.1.1",
"jquery": "3.7.0",
"jquery": "3.7.1",
"js-cookie": "3.0.5",
"leaflet": "1.9.4",
"leaflet-draw": "1.0.4",
Expand All @@ -67,8 +67,8 @@
"react": "18.2.0",
"react-dom": "18.2.0",
"react-flip-move": "3.0.5",
"react-markdown": "8.0.7",
"react-slick": "0.29",
"react-markdown": "9.0.1",
"react-slick": "0.29 || 0.30",
"shpjs": "4.0.4",
"slick-carousel": "git+https://github.com/liqd/slick.git#pm-2019-07-overwrites"
},
Expand All @@ -80,7 +80,7 @@
"lint": "eslint adhocracy4 --ext .js,.jsx",
"lint-staged": "lint-staged",
"lint-fix": "eslint --fix --ext .js,.jsx .",
"prepare": "husky install",
"prepare": "husky",
"test": "jest",
"testDebug": "jest -o --coverage=false",
"testNoCov": "jest --coverage=false",
Expand Down
18 changes: 9 additions & 9 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
beautifulsoup4==4.12.2
bleach[css]==6.0.0
Django==4.2
django-allauth==0.55.0
beautifulsoup4==4.12.3
bleach[css]==6.1.0
Django==4.2.10
django-allauth==0.61.1
git+https://github.com/liqd/django-autoslug.git@liqd2212#egg=django-autoslug
https://github.com/liqd/django-ckeditor-5/releases/download/v0.2.11-liqd/django_ckeditor_5-0.2.11-py3-none-any.whl
django-ckeditor==6.6.1
django-ckeditor==6.7.1
django-enumfield==3.1
django-filter==22.1
django-widget-tweaks==1.4.12
django-filter==23.5
django-widget-tweaks==1.5.0
djangorestframework==3.14.0
easy-thumbnails[svg]==2.8.5
html5lib==1.1
jsonfield==3.1.0
python-dateutil==2.8.2
python-magic==0.4.27
rules==3.3
XlsxWriter==3.1.2
celery==5.3.1
XlsxWriter==3.1.9
celery==5.3.6
20 changes: 10 additions & 10 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
-r base.txt
black==23.7.0
factory-boy==3.2.1
Faker==19.1.0
flake8==6.0.0
freezegun==1.2.2
isort==5.12.0
psycopg[binary]==3.1.12
pytest==7.4.0
black==24.2.0
factory-boy==3.3.0
Faker==23.1.0
flake8==7.0.0
freezegun==1.4.0
isort==5.13.2
psycopg[binary]==3.1.18
pytest==8.0.0
pytest-cov==4.1.0
pytest-django==4.5.2
pytest-factoryboy==2.5.1
pytest-django==4.8.0
pytest-factoryboy==2.6.0
1 change: 1 addition & 0 deletions tests/actions/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ class Meta:
def project(obj, create, extracted, **kwargs):
if obj.obj:
obj.project = obj.obj.project
obj.save()
Loading

0 comments on commit 1155aa8

Please sign in to comment.