Skip to content

Commit

Permalink
Merge pull request #403 from PnX-SI/dev
Browse files Browse the repository at this point in the history
prepare v1.1.0
  • Loading branch information
lpofredc authored Mar 28, 2024
2 parents a8a23bc + 3684e38 commit a1cec5b
Show file tree
Hide file tree
Showing 110 changed files with 1,108 additions and 682 deletions.
2 changes: 1 addition & 1 deletion .angulardoc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"repoId": "2b14cce7-db7a-476a-a8b9-f41927e3728b",
"lastSync": 0
}
}
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ exclude =
build,
dist,
migrations
max-complexity = 10
max-complexity = 10
80 changes: 80 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: "📚 Documentation"

on:
push:
branches:
- master
paths:
- ".github/workflows/documentation.yml"
- "docs/*/**"
tags:
- "*"

pull_request:
branches:
- master
paths:
- ".github/workflows/documentation.yml"
- docs/**/*

workflow_dispatch:

# Allow one concurrent deployment per branch/pr
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
PYTHON_VERSION: 3.11

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Get source code
uses: actions/checkout@v4

- name: Run image
uses: abatilo/actions-poetry@v3
#------------------------------------
# ----- Install dependencies -----
#------------------------------------
- name: Install dependencies
run: |
cd backend
poetry install --only=docs
- name: Build doc using Sphinx
run: |
cd backend
poetry run sphinx-build -b html -d ../docs/_build/cache -j auto ../docs ../docs/_build/html
- name: Save build doc as artifact
uses: actions/upload-artifact@v4
with:
name: documentation
path: docs/_build/html/*
if-no-files-found: error
retention-days: 30

- name: Setup Pages
uses: actions/configure-pages@v4
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')
with:
path: docs/_build/html/

- name: Deploy to GitHub Pages
id: deployment
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')
uses: actions/deploy-pages@v4
57 changes: 57 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "✅ Linter"

on:
push:
branches: [master, dev]
paths:
- "backend/**/*.py"
- "frontend/*"

pull_request:
branches: [master, dev]
paths:
- "backend/**/*.py"
- "frontend/*"

env:
BACKEND_FOLDER: "backend"
FRONTEND_FOLDER: "frontend"
PYTHON_VERSION: 3.9

jobs:
lint-py:
name: Python 🐍

runs-on: ubuntu-latest

steps:
- name: Get source code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install project requirements
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -U flake8
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 ${{ env.BACKEND_FOLDER }} --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 ${{ env.BACKEND_FOLDER }} --count --exit-zero --statistics
lint-node:
name: NodeJS 🐍
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: "${{ env.FRONTEND_FOLDER }}/.nvmrc"
- run: cd ${{ env.FRONTEND_FOLDER }} && npm ci
- run: cd ${{ env.FRONTEND_FOLDER }} && npm run lint
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
exclude: ".venv|__pycache__|tests/dev/|tests/fixtures/"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ["--maxkb=500"]
- id: check-case-conflict
- id: check-xml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: fix-encoding-pragma
args: [--remove]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black

# - repo: https://github.com/pycqa/isort
# rev: 5.13.2
# hooks:
# - id: isort
# args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
files: ^pyqgis_resource_browser/.*\.py$
additional_dependencies: ["flake8-qgis<2"]
args:
[
"--config=setup.cfg",
"--select=E9,F63,F7,F82,QGS101,QGS102,QGS103,QGS104,QGS106",
]

ci:
autoupdate_schedule: quarterly
skip: []
submodules: false
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV LANG fr_FR.utf8
ENV TERM xterm

RUN adduser --uid 1001 --gecos "" --disabled-password appuser
RUN usermod -aG sudo appuser
RUN usermod -aG sudo appuser
RUN echo "appuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

COPY . /home/appuser/citizen
Expand Down
2 changes: 1 addition & 1 deletion backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tests
.venv
__pycache__
__pycache__
4 changes: 2 additions & 2 deletions backend/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ WORKDIR /app

RUN pip install --upgrade pip \
&& pip install poetry
CMD poetry install; poetry run python3 wsgi.py

CMD poetry install; poetry run python3 wsgi.py
3 changes: 1 addition & 2 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Moteur de la plateforme
# Moteur de la plateforme

Déployé avec le framework python Flask

4 changes: 3 additions & 1 deletion backend/gncitizen/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""gncitizen __init__ to retrieve VERSION"""

from pathlib import Path

ROOT_DIR = Path(__file__).absolute().parent.parent.parent

with open(str((ROOT_DIR / "VERSION"))) as v:
with open(str((ROOT_DIR / "VERSION")), encoding="utf-8") as v:
__version__ = v.read()
1 change: 0 additions & 1 deletion backend/gncitizen/core/commons/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python3
# -*- coding:utf-8 -*-
from flask import current_app, flash
from flask_admin.contrib.sqla.view import ModelView
from flask_admin.form.upload import FileUploadField
Expand Down
24 changes: 15 additions & 9 deletions backend/gncitizen/core/commons/models.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""Commons models"""

import json
import os
import uuid
import xml.etree.ElementTree as ET
from datetime import datetime

from flask import url_for
from geoalchemy2 import Geometry
from geoalchemy2.functions import ST_GeomFromGeoJSON, ST_GeomFromKML, ST_SetSRID
from geoalchemy2.shape import to_shape
from geojson import Feature
from sqlalchemy import ForeignKey
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property
from sqlalchemy.orm import relationship
from sqlalchemy.sql import expression
from utils_flask_sqla_geo.serializers import geoserializable, serializable

from gncitizen.utils.env import MEDIA_DIR, db


class TimestampMixinModel(object):
class TimestampMixinModel:
"""Structure commune de suivi des modifications d'une table"""

@declared_attr
def timestamp_create(cls):
def timestamp_create(self):
"""Auto timestamp create"""
return db.Column(db.DateTime, nullable=False, default=datetime.utcnow)

@declared_attr
def timestamp_update(cls):
def timestamp_update(self):
"""Auto timestamp update"""
return db.Column(
db.DateTime,
nullable=True,
Expand Down Expand Up @@ -163,7 +163,9 @@ class ProgramsModel(TimestampMixinModel, db.Model):
unique_id_program = db.Column(
UUID(as_uuid=True), default=uuid.uuid4, unique=True, nullable=False
)
id_project = db.Column(db.Integer, db.ForeignKey(ProjectModel.id_project), nullable=False)
id_project = db.Column(
db.Integer, db.ForeignKey(ProjectModel.id_project), nullable=False
)
title = db.Column(db.String(50), nullable=False)
short_desc = db.Column(db.String(200), nullable=False)
long_desc = db.Column(db.Text(), nullable=False)
Expand All @@ -184,8 +186,12 @@ class ProgramsModel(TimestampMixinModel, db.Model):
is_active = db.Column(
db.Boolean(), server_default=expression.true(), default=True, nullable=False
)
id_geom = db.Column(db.Integer, db.ForeignKey(GeometryModel.id_geom), nullable=False)
id_form = db.Column(db.Integer, db.ForeignKey(CustomFormModel.id_form), nullable=True)
id_geom = db.Column(
db.Integer, db.ForeignKey(GeometryModel.id_geom), nullable=False
)
id_form = db.Column(
db.Integer, db.ForeignKey(CustomFormModel.id_form), nullable=True
)
custom_form = relationship("CustomFormModel")
geometry = relationship("GeometryModel")
project = relationship("ProjectModel")
Expand Down
10 changes: 4 additions & 6 deletions backend/gncitizen/core/commons/routes.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from flask import Blueprint, current_app, request, send_from_directory
from flask_admin.contrib.fileadmin import FileAdmin
from flask_jwt_extended import jwt_required
from geojson import FeatureCollection
from sqlalchemy import and_, case, desc, distinct
from sqlalchemy.sql import func
from utils_flask_sqla.response import json_resp

from gncitizen.core.observations.models import ObservationMediaModel, ObservationModel
from gncitizen.core.sites.admin import SiteTypeView
from gncitizen.core.sites.models import (
Expand All @@ -23,6 +18,9 @@
from gncitizen.utils.helpers import get_filter_by_args, set_media_links
from gncitizen.utils.jwt import get_id_role_if_exists
from server import db
from sqlalchemy import and_, case, desc, distinct
from sqlalchemy.sql import func
from utils_flask_sqla.response import json_resp

from .admin import CustomFormView, GeometryView, ProgramView, ProjectView
from .models import (
Expand Down Expand Up @@ -425,7 +423,7 @@ def get_medias():
)
.filter(
(func.coalesce(ObservationModel.id_observation, MediaOnVisitModel.id_data_source))
!= None
is not None
)
.with_entities(
MediaModel.id_media,
Expand Down
8 changes: 6 additions & 2 deletions backend/gncitizen/core/observations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ class ObservationView(CustomTileView):
"id_program",
"program_ref.title",
"program_ref.unique_id_program",
"program_ref.project.name",
"program_ref.project.unique_id_project",
"municipality",
)
column_searchable_list = (
"email",
"date",
"program_ref.title",
"program_ref.unique_id_program",
"cd_nom",
"name",
"municipality",
"obs_txt",
"email",
)
can_create = False

Expand Down
Loading

0 comments on commit a1cec5b

Please sign in to comment.