Commit 8a8e8cf6 authored by Florent Chehab's avatar Florent Chehab
Browse files

Merge branch 'frontend' into 'master'

New Frontend initialize

Closes #11

See merge request chehabfl/outgoing_rex!15
parents f7b3fc08 a157cc69
# Generated by Django 2.0.3 on 2018-08-27 08:26
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('backend', '0019_auto_20180827_1010'),
]
operations = [
migrations.AlterField(
model_name='userdata',
name='owner',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
from django.db import models
from rest_framework import serializers, permissions
from backend.models.tools import DictModeViewSet
from rest_framework import serializers
from backend.models.location import Country
from backend.models.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/
class City(models.Model):
class City(MyModel):
name = models.CharField(max_length=200)
local_name = models.CharField(max_length=200, null=True, blank=True)
# We add an area to distinguish similarly named cities
......@@ -21,7 +18,7 @@ API RELATED STUFF BELLOW
"""
class CitySerializer(serializers.ModelSerializer):
class CitySerializer(MyModelSerializer):
country_url = serializers.SerializerMethodField()
def get_country_url(self, obj):
......@@ -36,7 +33,6 @@ class CitySerializer(serializers.ModelSerializer):
fields = '__all__'
class CityViewSet(DictModeViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CityViewSet(MyModelVersionnedViewSet):
queryset = City.objects.all() # pylint: disable=E1101
serializer_class = CitySerializer
from django.db import models
from backend.models.module import BasicModule
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import City
from rest_framework import viewsets, permissions
from backend.models.module import BasicModuleSerializer
####################
......@@ -20,8 +18,8 @@ class CityTransportSerializer(BasicModuleSerializer):
fields = '__all__'
class CityTransportViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CityTransportViewSet(BasicModuleViewSet):
queryset = CityTransport.objects.all() # pylint: disable=E1101
serializer_class = CityTransportSerializer
......@@ -45,8 +43,8 @@ class CityTourismSerializer(BasicModuleSerializer):
fields = '__all__'
class CityTourismViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CityTourismViewSet(BasicModuleViewSet):
queryset = CityTourism.objects.all() # pylint: disable=E1101
serializer_class = CityTourismSerializer
......@@ -70,8 +68,7 @@ class CityOtherStuffSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CityOtherStuffViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CityOtherStuffViewSet(BasicModuleViewSet):
queryset = CityOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = CityOtherStuffSerializer
from django.db import models
from backend.models.location import City
from backend.models.module import VersionnedModuleSerializer
from backend.models.module import Photo
from rest_framework import viewsets, permissions
from backend.models.module import Photo, PhotoSerializer, PhotoViewSet
class CityPhoto(Photo):
......@@ -16,14 +14,13 @@ class CityPhoto(Photo):
unique_together = ('city', 'photo')
class CityPhotoSerializer(VersionnedModuleSerializer):
class CityPhotoSerializer(PhotoSerializer):
class Meta:
model = CityPhoto
fields = '__all__'
class CityPhotoViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CityPhotoViewSet(PhotoViewSet):
queryset = CityPhoto.objects.all() # pylint: disable=E1101
serializer_class = CityPhotoSerializer
from django.db import models
from rest_framework import serializers, permissions
from backend.models.tools import DictModeViewSet
from backend.models.my_model import MyModel, MyModelSerializer, MyModelVersionnedViewSet
# Data model based on : https://unstats.un.org/unsd/methodology/m49/overview/
class Country(models.Model):
class Country(MyModel):
name = models.CharField(max_length=200)
iso_alpha2_code = models.CharField(primary_key=True, max_length=2)
iso_alpha3_code = models.CharField(
......@@ -20,19 +19,13 @@ class Country(models.Model):
max_length=3, null=True, blank=True)
"""
API RELATED STUFF BELLOW
"""
class CountrySerializer(serializers.ModelSerializer):
class CountrySerializer(MyModelSerializer):
class Meta:
model = Country
fields = '__all__'
class CountryViewSet(DictModeViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryViewSet(MyModelVersionnedViewSet):
queryset = Country.objects.all() # pylint: disable=E1101
serializer_class = CountrySerializer
from django.db import models
from backend.models.module import BasicModule
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from backend.models.location import Country
from rest_framework import viewsets, permissions
from backend.models.module import BasicModuleSerializer
####################
......@@ -20,9 +18,8 @@ class CountryVisaAdministrativeSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CountryVisaAdministrativeViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryVisaAdministrativeViewSet(BasicModuleViewSet):
queryset = CountryVisaAdministrative.objects.all() # pylint: disable=E1101
serializer_class = CountryVisaAdministrativeSerializer
......@@ -47,9 +44,8 @@ class CountryHealthInsuranceSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CountryHealthInsuranceViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryHealthInsuranceViewSet(BasicModuleViewSet):
queryset = CountryHealthInsurance.objects.all() # pylint: disable=E1101
serializer_class = CountryHealthInsuranceSerializer
......@@ -73,9 +69,8 @@ class CountryOtherInsuranceSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CountryOtherInsuranceViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryOtherInsuranceViewSet(BasicModuleViewSet):
queryset = CountryOtherInsurance.objects.all() # pylint: disable=E1101
serializer_class = CountryOtherInsuranceSerializer
......@@ -98,8 +93,8 @@ class CountryCultureSerializer(BasicModuleSerializer):
fields = '__all__'
class CountryCultureViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CountryCultureViewSet(BasicModuleViewSet):
queryset = CountryCulture.objects.all() # pylint: disable=E1101
serializer_class = CountryCultureSerializer
......@@ -122,8 +117,8 @@ class CountryTransportSerializer(BasicModuleSerializer):
fields = '__all__'
class CountryTransportViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CountryTransportViewSet(BasicModuleViewSet):
queryset = CountryTransport.objects.all() # pylint: disable=E1101
serializer_class = CountryTransportSerializer
......@@ -147,8 +142,8 @@ class CountryTourismSerializer(BasicModuleSerializer):
fields = '__all__'
class CountryTourismViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CountryTourismViewSet(BasicModuleViewSet):
queryset = CountryTourism.objects.all() # pylint: disable=E1101
serializer_class = CountryTourismSerializer
......@@ -172,8 +167,7 @@ class CountryOtherStuffSerializer(BasicModuleSerializer):
fields = '__all__'
# TODO switch to dict
class CountryOtherStuffViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryOtherStuffViewSet(BasicModuleViewSet):
queryset = CountryOtherStuff.objects.all() # pylint: disable=E1101
serializer_class = CountryOtherStuffSerializer
from django.db import models
from backend.models.location import Country
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer
from rest_framework import viewsets, permissions
from backend.models.module import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet
class CountryDri(DriRestrictedModule):
......@@ -16,7 +15,6 @@ class CountryDriSerializer(DriRestrictedModuleSerializer):
fields = '__all__'
class CountryDriViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryDriViewSet(DriRestrictedModuleViewSet):
queryset = CountryDri.objects.all() # pylint: disable=E1101
serializer_class = CountryDriSerializer
from django.db import models
from backend.models.location import Country
from backend.models.module import VersionnedModuleSerializer
from backend.models.module import Photo
from rest_framework import viewsets, permissions
from backend.models.module import Photo, PhotoSerializer, PhotoViewSet
class CountryPhoto(Photo):
......@@ -16,14 +14,13 @@ class CountryPhoto(Photo):
unique_together = ('country', 'photo')
class CountryPhotoSerializer(VersionnedModuleSerializer):
class CountryPhotoSerializer(PhotoSerializer):
class Meta:
model = CountryPhoto
fields = '__all__'
class CountryPhotoViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,)
class CountryPhotoViewSet(PhotoViewSet):
queryset = CountryPhoto.objects.all() # pylint: disable=E1101
serializer_class = CountryPhotoSerializer
from django.db import models
from backend.models.location import Country
from backend.models.module import Scholarship, BasicModuleSerializer
from rest_framework import viewsets, permissions
from backend.models.module import Scholarship, ScholarshipSerializer, ScholarshipViewSet
class CountryScholarship(Scholarship):
......@@ -9,14 +8,13 @@ class CountryScholarship(Scholarship):
Country, related_name="country_scholarhip")
class CountryScholarshipSerializer(BasicModuleSerializer):
class CountryScholarshipSerializer(ScholarshipSerializer):
class Meta:
model = CountryScholarship
fields = '__all__'
class CountryScholarshipViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissions,)
class CountryScholarshipViewSet(ScholarshipViewSet):
queryset = CountryScholarship.objects.all() # pylint: disable=E1101
serializer_class = CountryScholarshipSerializer
from .versionnedModule import VersionnedModule, VersionnedModuleSerializer # noqa: F401
from .basicModule import BasicModule, BasicModuleSerializer # noqa: F401
from .scholarship import Scholarship # noqa: F401
from .photo import Photo # noqa: F401
from .driRestrictedModule import DriRestrictedModule, DriRestrictedModuleSerializer # noqa: F401
from .basicModule import BasicModule, BasicModuleSerializer, BasicModuleViewSet # noqa: F401
from .scholarship import Scholarship, ScholarshipSerializer, ScholarshipViewSet # noqa: F401
from .photo import Photo, PhotoSerializer, PhotoViewSet # noqa: F401
from .driRestrictedModule import DriRestrictedModule, DriRestrictedModuleSerializer, DriRestrictedModuleViewSet # noqa: F401
from .currency import Currency, CurrencyViewSet, CurrencySerializer # noqa: F401
# MyModelVersionned, MyModelVersionnedSerializer # noqa: F401
from django.db import models
from backend.models.tools import UsefullLinksField
from backend.models.module import VersionnedModule, VersionnedModuleSerializer
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
class BasicModule(VersionnedModule):
class BasicModule(MyModelVersionned):
comment = models.TextField(blank=True)
usefull_links = UsefullLinksField(blank=True)
......@@ -12,8 +12,12 @@ class BasicModule(VersionnedModule):
abstract = True
class BasicModuleSerializer(VersionnedModuleSerializer):
class BasicModuleSerializer(MyModelVersionnedSerializer):
class Meta:
model = BasicModule
fields = '__all__'
class BasicModuleViewSet(MyModelVersionnedViewSet):
serializer_class = BasicModuleSerializer
from django.db import models
from rest_framework import serializers, viewsets, permissions
from rest_framework import permissions
from django.core.validators import MinValueValidator
from backend.models.my_model import MyModel, MyModelSerializer, MyModelViewSet
class Currency(models.Model):
class Currency(MyModel):
code = models.CharField(primary_key=True, max_length=15)
name = models.CharField(max_length=100)
symbol = models.CharField(max_length=5)
......@@ -14,13 +15,13 @@ class Currency(models.Model):
)
class CurrencySerializer(serializers.ModelSerializer):
class CurrencySerializer(MyModelSerializer):
class Meta:
model = Currency
fields = '__all__'
class CurrencyViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.IsAdminUser,)
class CurrencyViewSet(MyModelViewSet):
permission_classes = (permissions.IsAdminUser,) # TODO : change
queryset = Currency.objects.all() # pylint: disable=E1101
serializer_class = CurrencySerializer
from backend.models.module import BasicModule, BasicModuleSerializer
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
class DriRestrictedModule(BasicModule):
......@@ -8,5 +8,9 @@ class DriRestrictedModule(BasicModule):
class DriRestrictedModuleSerializer(BasicModuleSerializer):
# TODO Check edit restrictions
pass
class Meta:
model = DriRestrictedModule
class DriRestrictedModuleViewSet(BasicModuleViewSet):
serializer_class = DriRestrictedModuleSerializer
from django.db import models
from backend.models.module import VersionnedModule
from backend.models.my_model import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
from backend.utils.friendly_path import friendly_path
path_and_rename = friendly_path("uploads/universities/photos/", 'title')
class Photo(VersionnedModule):
class Photo(MyModelVersionned):
photo = models.ImageField(upload_to=path_and_rename, max_length=250,
default='path/to/my/default/image.jpg') # TODO CHANGE !
......@@ -15,3 +15,14 @@ class Photo(VersionnedModule):
class Meta:
abstract = True
class PhotoSerializer(MyModelVersionnedSerializer):
class Meta:
model = Photo
fields = '__all__'
class PhotoViewSet(MyModelVersionnedViewSet):
serializer_class = PhotoSerializer
from django.db import models
from backend.models.module import BasicModule
from backend.models.module import BasicModule, BasicModuleSerializer, BasicModuleViewSet
from .currency import Currency
from rest_framework import serializers
from django.core.validators import MinValueValidator
......@@ -34,3 +34,14 @@ class Scholarship(BasicModule):
class Meta:
abstract = True
class ScholarshipSerializer(BasicModuleSerializer):
class Meta:
model = Scholarship
fields = '__all__'
class ScholarshipViewSet(BasicModuleViewSet):
serializer_class = ScholarshipSerializer
from django.db import models
from reversion.models import Version
from rest_framework import serializers
class VersionnedModule(models.Model):
def modified_date(self):
try:
v = Version.objects.get_for_object(self)
return v.last().revision.date_created
except AttributeError:
return None
def modified_by(self):
try:
v = Version.objects.get_for_object(self)
user = v.last().revision.user
return {'user_name': user.get_full_name(), 'user_id': user.pk}
except AttributeError:
return None
class Meta:
abstract = True
class VersionnedModuleSerializer(serializers.ModelSerializer):
modified_by = serializers.SerializerMethodField()
modified_date = serializers.SerializerMethodField()
def get_modified_by(self, obj):
return obj.modified_by()
def get_modified_date(self, obj):
return obj.modified_date()
from .myModel import MyModel # noqa: F401
from .myModelSerializer import MyModelSerializer # noqa: F401
from .myModelViewSet import MyModelViewSet # noqa: F401
from .pendingModeration import PendingModeration, PendingModerationSerializer, PendingModerationViewSet # noqa: F401
from .forTestingModeration import ForTestingModeration, ForTestingModerationSerializer, ForTestingModerationViewSet # noqa: F401
from .myModelVersionned import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet # noqa: F401
from .forTestingVersionning import ForTestingVersionning, ForTestingVersionningSerializer, ForTestingVersionningViewSet # noqa: F401
from .myModel import MyModel
from .myModelSerializer import MyModelSerializer
from .myModelViewSet import MyModelViewSet
from django.db import models
class ForTestingModeration(MyModel):
"""
Simple model for testing purposes
"""
aaa = models.CharField(max_length=100)
class ForTestingModerationSerializer(MyModelSerializer):
"""
Same as above
"""
class Meta:
model = ForTestingModeration
fields = '__all__'
class ForTestingModerationViewSet(MyModelViewSet):
"""
Same as above
"""
serializer_class = ForTestingModerationSerializer
queryset = ForTestingModeration.objects.all()
from .myModelVersionned import MyModelVersionned, MyModelVersionnedSerializer, MyModelVersionnedViewSet
from django.db import models
import reversion
@reversion.register()
class ForTestingVersionning(MyModelVersionned):
"""
Simple model for testing purposes
"""
bbb = models.CharField(max_length=100)
class ForTestingVersionningSerializer(MyModelVersionnedSerializer):
"""
Same as above
"""
class Meta:
model = ForTestingVersionning
fields = '__all__'
class ForTestingVersionningViewSet(MyModelVersionnedViewSet):
"""
Same as above
"""
serializer_class = ForTestingVersionningSerializer
queryset = ForTestingVersionning.objects.all()
from django.db import models
from django.contrib.auth.models import User
class MyModel(models.Model):
"""
All models in the app deppend of this one.
It contains the required attributes for managing eventual moderation data.
All the logic behind moderation is done in myModelSerializer
"""
moderated_by = models.ForeignKey(
User, null=True, on_delete=models.SET_NULL, related_name='+')
moderated_on = models.DateTimeField(null=True)
updated_on = models.DateTimeField(null=True)
updated_by = models.ForeignKey(
User, null=True, on_delete=models.SET_NULL, related_name='+')
class Meta:
abstract = True
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