Commit aa616a2a authored by Florent Chehab's avatar Florent Chehab

Corrected usefull => useful

and return model
parent 7768f71e
# Generated by Django 2.0.3 on 2018-09-11 14:22
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('backend', '0008_auto_20180911_1147'),
]
operations = [
migrations.RenameField(
model_name='campus',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='campustaggeditem',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='citytaggeditem',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='countrydri',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='countryscholarship',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='countrytaggeditem',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='universitydri',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='universityinfo',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='universityscholarship',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='universitysemestersdates',
old_name='usefull_links',
new_name='useful_links',
),
migrations.RenameField(
model_name='universitytaggeditem',
old_name='usefull_links',
new_name='useful_links',
),
]
...@@ -14,7 +14,7 @@ IMPORTANCE_LEVEL = ( ...@@ -14,7 +14,7 @@ IMPORTANCE_LEVEL = (
class BasicModule(MyModelVersionned): class BasicModule(MyModelVersionned):
comment = models.TextField(blank=True, default="") comment = models.TextField(blank=True, default="")
usefull_links = JSONField(default=list) useful_links = JSONField(default=list)
importance_level = models.CharField( importance_level = models.CharField(
max_length=2, max_length=2,
choices=IMPORTANCE_LEVEL, choices=IMPORTANCE_LEVEL,
...@@ -28,8 +28,8 @@ class BasicModule(MyModelVersionned): ...@@ -28,8 +28,8 @@ class BasicModule(MyModelVersionned):
class BasicModuleSerializer(MyModelVersionnedSerializer): class BasicModuleSerializer(MyModelVersionnedSerializer):
def my_validate(self, attrs): def my_validate(self, attrs):
content = {'usefull_links': attrs['usefull_links']} content = {'useful_links': attrs['useful_links']}
config = {'usefull_links': USEFULL_LINKS_CONFIG} config = {'useful_links': USEFULL_LINKS_CONFIG}
validate_content_against_config(config, content) validate_content_against_config(config, content)
return attrs return attrs
......
...@@ -34,7 +34,7 @@ class MyModelSerializer(MySerializerWithJSON): ...@@ -34,7 +34,7 @@ class MyModelSerializer(MySerializerWithJSON):
model_config = serializers.SerializerMethodField() model_config = serializers.SerializerMethodField()
# For easier handling on the client side, we force an id field # For easier handling on the client side, we force an id field
# this is usefull when a model has a dedicated primary key # this is useful when a model has a dedicated primary key
id = serializers.SerializerMethodField() id = serializers.SerializerMethodField()
def get_model_config(self, obj=None): def get_model_config(self, obj=None):
......
...@@ -15,7 +15,7 @@ class PreviousDeparture(MyModel): ...@@ -15,7 +15,7 @@ class PreviousDeparture(MyModel):
university = models.ForeignKey(University, on_delete=models.PROTECT) university = models.ForeignKey(University, on_delete=models.PROTECT)
specialty = models.ForeignKey(Specialty, on_delete=models.PROTECT) specialty = models.ForeignKey(Specialty, on_delete=models.PROTECT)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True) user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
# Usefull to relink a departure with a user # Useful to relink a departure with a user
Utc_departure_id = models.IntegerField() Utc_departure_id = models.IntegerField()
is_anonymous = models.BooleanField() is_anonymous = models.BooleanField()
......
...@@ -221,7 +221,7 @@ class ModerationTestCase(WithUserTestCase): ...@@ -221,7 +221,7 @@ class ModerationTestCase(WithUserTestCase):
data = { data = {
"comment": "", "comment": "",
"usefull_links": [], "useful_links": [],
"universities": [c.pk] "universities": [c.pk]
} }
api_end_point = "/api/" + \ api_end_point = "/api/" + \
......
...@@ -9,7 +9,7 @@ class ScholarshipTestCase(TestCase): ...@@ -9,7 +9,7 @@ class ScholarshipTestCase(TestCase):
def test_scholarhip_validation(self): def test_scholarhip_validation(self):
ser = ScholarshipSerializer() ser = ScholarshipSerializer()
attrs = { attrs = {
'usefull_links': [], 'useful_links': [],
'comment': '' 'comment': ''
} }
with pytest.raises(ValidationError): with pytest.raises(ValidationError):
......
...@@ -13,7 +13,7 @@ class SemesterDatesTestCase(TestCase): ...@@ -13,7 +13,7 @@ class SemesterDatesTestCase(TestCase):
def build(l): def build(l):
tmp = {sem: val for sem, val in zip(semesters, l)} tmp = {sem: val for sem, val in zip(semesters, l)}
tmp['comment'] = "" tmp['comment'] = ""
tmp['usefull_links'] = [] tmp['useful_links'] = []
return tmp return tmp
def _test_attrs_error(attrs): def _test_attrs_error(attrs):
......
...@@ -6,6 +6,9 @@ def get_model_config(model): ...@@ -6,6 +6,9 @@ def get_model_config(model):
for obj in api_config: for obj in api_config:
if obj['model'] == model: if obj['model'] == model:
return {"moderation_level": obj["moderation_level"]} return {
"moderation_level": obj["moderation_level"],
"model": model
}
raise Exception("Model not found in API configuraiton, cannot process !") raise Exception("Model not found in API configuraiton, cannot process !")
...@@ -36,7 +36,7 @@ def validate_content_against_config(config, content): ...@@ -36,7 +36,7 @@ def validate_content_against_config(config, content):
elif field_type == 'photos': elif field_type == 'photos':
validate_content_against_config({"photos": PHOTOS_TAG_CONFIG}, { validate_content_against_config({"photos": PHOTOS_TAG_CONFIG}, {
"photos": field_submitted}) "photos": field_submitted})
elif field_type == 'usefull_links': elif field_type == 'useful_links':
validate_content_against_config({"ul": USEFULL_LINKS_CONFIG}, { validate_content_against_config({"ul": USEFULL_LINKS_CONFIG}, {
"ul": field_submitted}) "ul": field_submitted})
elif field_type == 'array': elif field_type == 'array':
......
from .photos import PHOTOS_TAG_CONFIG # noqa: F401 from .photos import PHOTOS_TAG_CONFIG # noqa: F401
from .usefull_links import USEFULL_LINKS_CONFIG # noqa: F401 from .useful_links import USEFULL_LINKS_CONFIG # noqa: F401
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment