Skip to content

Commit

Permalink
Merge pull request #761 from c2corg/feature/improve_serac
Browse files Browse the repository at this point in the history
update SERAC interface
  • Loading branch information
brunobesson authored Apr 19, 2020
2 parents ca923d9 + 9d7d185 commit cdfae83
Show file tree
Hide file tree
Showing 13 changed files with 4,727 additions and 94 deletions.
601 changes: 601 additions & 0 deletions alembic_migration/versions/06d2a35e39c8_improve_serac_database.py

Large diffs are not rendered by default.

4,000 changes: 4,000 additions & 0 deletions alembic_migration/versions/06d2a35e39c8_improve_serac_database_data.csv

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions c2corg_api/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,16 @@ def enum(name, types):
'feed_change_type', attributes.feed_change_types)
event_type = enum(
'event_type', attributes.event_types)
event_activity = enum(
'event_activity', attributes.event_activities)
author_status = enum(
'author_status', attributes.author_statuses)
activity_rate = enum(
'activity_rate', attributes.activity_rates)
nb_outings = enum(
'nb_outings', attributes.nb_outings)
supervision = enum(
'supervision', attributes.supervision)
qualification = enum(
'qualification', attributes.qualification)
gender = enum(
'gender', attributes.genders)
previous_injuries = enum(
Expand Down
5 changes: 2 additions & 3 deletions c2corg_api/models/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from c2corg_api.models.user import User
from c2corg_api.models.user_profile import USERPROFILE_TYPE
from c2corg_api.models.utils import ArrayOfEnum
from c2corg_api.models.xreport import XREPORT_TYPE
from c2corg_api.views.validation import association_keys
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql.array import ARRAY
Expand Down Expand Up @@ -207,7 +206,7 @@ def update_feed_document_create(document, user_id):

activities = []
if document.type in [ARTICLE_TYPE, OUTING_TYPE, ROUTE_TYPE,
BOOK_TYPE, XREPORT_TYPE]:
BOOK_TYPE]:
activities = document.activities

langs = [locale.lang for locale in document.locales]
Expand Down Expand Up @@ -262,7 +261,7 @@ def update_feed_document_update(document, user_id, update_types):

# updates activities
if document.type in [ARTICLE_TYPE, OUTING_TYPE, ROUTE_TYPE,
BOOK_TYPE, XREPORT_TYPE] and \
BOOK_TYPE] and \
UpdateType.FIGURES in update_types:
update_activities_of_changes(document)

Expand Down
25 changes: 11 additions & 14 deletions c2corg_api/models/xreport.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import colander
from c2corg_api.models.schema_utils import restrict_schema,\
get_update_schema, get_create_schema
from c2corg_common.fields_xreport import fields_xreport
Expand All @@ -15,7 +14,6 @@
from colanderalchemy import SQLAlchemySchemaNode

from c2corg_api.models import schema, Base
from c2corg_api.models.utils import ArrayOfEnum
from c2corg_api.models.utils import copy_attributes
from c2corg_api.models.document import (
ArchiveDocument,
Expand All @@ -38,9 +36,9 @@ class _XreportMixin(object):
date = Column(Date)

# Type d'évènement
event_type = Column(ArrayOfEnum(enums.event_type))
event_type = Column(enums.event_type)

activities = Column(ArrayOfEnum(enums.activity_type), nullable=False)
event_activity = Column(enums.event_activity, nullable=False)

# Nombre de participants
nb_participants = Column(SmallInteger)
Expand All @@ -66,9 +64,6 @@ class _XreportMixin(object):
# Frequency practical activity-Fréquence de pratique de l'activité
activity_rate = Column(enums.activity_rate)

# Total trips made during the year-Nombre sorties réalisées dans l'année
nb_outings = Column(enums.nb_outings)

age = Column(SmallInteger)

gender = Column(enums.gender)
Expand All @@ -78,21 +73,26 @@ class _XreportMixin(object):

autonomy = Column(enums.autonomy)

supervision = Column(enums.supervision)

qualification = Column(enums.qualification)

disable_comments = Column(Boolean)

anonymous = Column(Boolean)


attributes = [
'elevation', 'date', 'event_type', 'activities',
'elevation', 'date', 'event_type', 'event_activity',
'nb_participants', 'nb_impacted', 'rescue',
'avalanche_level', 'avalanche_slope', 'severity',
'author_status', 'activity_rate', 'nb_outings', 'age', 'gender',
'previous_injuries', 'autonomy', 'disable_comments', 'anonymous'
'author_status', 'activity_rate', 'age', 'gender',
'previous_injuries', 'autonomy', 'supervision', 'qualification',
'disable_comments', 'anonymous'
]

attributes_without_personal = [
'elevation', 'date', 'event_type', 'activities',
'elevation', 'date', 'event_type', 'event_activity',
'nb_participants', 'nb_impacted', 'rescue',
'avalanche_level', 'avalanche_slope', 'severity',
'disable_comments', 'anonymous'
Expand Down Expand Up @@ -261,9 +261,6 @@ class ArchiveXreportLocale(_XreportLocaleMixin, ArchiveDocumentLocale):
'locales': {
'children': [schema_xreport_locale],
},
'activities': {
'validator': colander.Length(min=1)
},
'geometry': get_geometry_schema_overrides(['POINT'])
})

Expand Down
8 changes: 4 additions & 4 deletions c2corg_api/search/mappings/xreport_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class SearchXreport(SearchDocument):
class Meta(BaseMeta):
doc_type = XREPORT_TYPE

activities = QEnumArray(
'act', model_field=Xreport.activities)
event_activity = QEnumArray(
'act', model_field=Xreport.event_activity)
date = QDate('xdate', 'date')
event_type = QEnumArray(
'xtyp', model_field=Xreport.event_type)
Expand All @@ -33,8 +33,8 @@ class Meta(BaseMeta):
'xalt', range=True)

FIELDS = [
'activities', 'date', 'event_type', 'nb_participants',
'nb_impacted', 'elevation'
'date', 'event_activity', 'event_type', 'nb_participants',
'nb_impacted', 'elevation'
]

ENUM_RANGE_FIELDS = [
Expand Down
8 changes: 4 additions & 4 deletions c2corg_api/tests/models/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class TestXreport(BaseTestCase):
def test_to_archive(self):
xreport = Xreport(
document_id=1,
activities=['skitouring'],
event_type=['avalanche'],
event_activity='skitouring',
event_type='avalanche',
nb_participants=5,
elevation=1200,
locales=[
Expand All @@ -31,13 +31,13 @@ def test_to_archive(self):
self.assertIsNone(xreport_archive.id)
self.assertEqual(xreport_archive.document_id, xreport.document_id)
self.assertEqual(
xreport_archive.activities, xreport.activities)
xreport_archive.event_activity, xreport.event_activity)
self.assertEqual(xreport_archive.event_type, xreport.event_type)
self.assertEqual(
xreport_archive.nb_participants, xreport.nb_participants)
self.assertEqual(xreport_archive.elevation, xreport.elevation)

self.assertIsNotNone(xreport_archive.activities)
self.assertIsNotNone(xreport_archive.event_activity)
self.assertIsNotNone(xreport_archive.event_type)
self.assertIsNotNone(xreport_archive.nb_participants)

Expand Down
4 changes: 2 additions & 2 deletions c2corg_api/tests/scripts/es/test_fill_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def test_fill_index(self):

self.session.add(Xreport(
document_id=71178,
event_type=['roped_fall'],
activities=['skitouring'],
event_type='person_fall',
event_activity='skitouring',
nb_participants=10,
elevation=1500,
date=datetime.date(2016, 1, 1),
Expand Down
4 changes: 4 additions & 0 deletions c2corg_api/tests/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def assertCorniceMissing(self, error, key): # noqa
self.assertEqual(error.get('description'), key + ' is missing')
self.assertEqual(error.get('name'), key)

def assertCorniceNotInEnum(self, error, key): # noqa
self.assertIn('is not one of', error.get('description'))
self.assertEqual(error.get('name'), key)

def assertCorniceRequired(self, error, key): # noqa
self.assertEqual(error.get('description'), 'Required')
self.assertEqual(error.get('name'), key)
Expand Down
2 changes: 1 addition & 1 deletion c2corg_api/tests/views/test_association.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ def _add_test_data(self):
DocumentRest.create_new_version(self.article2, user_id)

self.report1 = Xreport(
activities=['hiking'],
event_activity='alpine_climbing',
locales=[XreportLocale(lang='en', title='Lac d\'Annecy')])
self.session.add(self.report1)
self.session.flush()
Expand Down
2 changes: 1 addition & 1 deletion c2corg_api/tests/views/test_document_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def setUp(self): # noqa
self.session.flush()

self.xreport1 = Xreport(
activities=['hiking'], event_type=['stone_fall'],
event_activity='alpine_climbing', event_type='stone_ice_fall',
locales=[
XreportLocale(
lang='en', title='Lac d\'Annecy',
Expand Down
Loading

0 comments on commit cdfae83

Please sign in to comment.