Commit 1c37ecc2 authored by Florent Chehab's avatar Florent Chehab
Browse files

Versionning slightly changed

parent 15eb91b0
Pipeline #26519 failed with stages
in 1 minute and 16 seconds
# Generated by Django 2.0.3 on 2018-08-24 08:11
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('backend', '0002_auto_20180824_0910'),
]
operations = [
migrations.AddField(
model_name='campus',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='campus',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='campusaccommodation',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='campusaccommodation',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='campuscultureandstudentlife',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='campuscultureandstudentlife',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='campusotherstuff',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='campusotherstuff',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='campustransport',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='campustransport',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='cityotherstuff',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='cityotherstuff',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='cityphoto',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='cityphoto',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='citytourism',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='citytourism',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='citytransport',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='citytransport',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countryculture',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countryculture',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countrydri',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countrydri',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countryhealthinsurance',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countryhealthinsurance',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countryotherinsurance',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countryotherinsurance',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countryotherstuff',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countryotherstuff',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countryphoto',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countryphoto',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countryscholarship',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countryscholarship',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countrytourism',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countrytourism',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countrytransport',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countrytransport',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='countryvisaadministrative',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='countryvisaadministrative',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='university',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='university',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universitycourses',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universitycourses',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universityculture',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universityculture',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universitydri',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universitydri',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universityinfo',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universityinfo',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universityinsurance',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universityinsurance',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universityotherstuff',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universityotherstuff',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universityphoto',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universityphoto',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universityscholarship',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universityscholarship',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universitysemestersdates',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universitysemestersdates',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='universityspecialoffer',
name='updated_at',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='universityspecialoffer',
name='updated_by',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
]
from django.db import models from django.db import models
from reversion.models import Version
from rest_framework import serializers from rest_framework import serializers
from django.contrib.auth.models import User
class VersionnedModule(models.Model): class VersionnedModule(models.Model):
def modified_date(self): updated_at = models.DateTimeField(auto_now=True)
try: updated_by = models.ForeignKey(
v = Version.objects.get_for_object(self) User, null=True, blank=True, on_delete=models.SET_NULL)
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: class Meta:
abstract = True abstract = True
class VersionnedModuleSerializer(serializers.ModelSerializer): class VersionnedModuleSerializer(serializers.ModelSerializer):
modified_by = serializers.SerializerMethodField() updated_by_username = serializers.SerializerMethodField(read_only=True)
modified_date = serializers.SerializerMethodField()
def get_modified_by(self, obj): def get_updated_by_username(self, obj):
return obj.modified_by() if obj.updated_by:
return obj.updated_by.username
else:
return None
def get_modified_date(self, obj): def save(self, **kwargs):
return obj.modified_date() self.validated_data['updated_by'] = self.context['request'].user
super(VersionnedModuleSerializer, self).save(**kwargs)
...@@ -48,5 +48,5 @@ class CampusSerializer(BasicModuleSerializer): ...@@ -48,5 +48,5 @@ class CampusSerializer(BasicModuleSerializer):
class CampusViewSet(viewsets.ModelViewSet): # TODO switch to dict class CampusViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,) permission_classes = (permissions.DjangoModelPermissions,)
queryset = Campus.objects.all() # pylint: disable=E1101 queryset = Campus.objects.all().prefetch_related('updated_by') # pylint: disable=E1101
serializer_class = CampusSerializer serializer_class = CampusSerializer
...@@ -13,5 +13,5 @@ class UniversitySerializer(serializers.ModelSerializer): ...@@ -13,5 +13,5 @@ class UniversitySerializer(serializers.ModelSerializer):
class UniversityViewSet(viewsets.ModelViewSet): # TODO switch to dict class UniversityViewSet(viewsets.ModelViewSet): # TODO switch to dict
permission_classes = (permissions.DjangoModelPermissions,) permission_classes = (permissions.DjangoModelPermissions,)
queryset = University.objects.all().prefetch_related('univ_campus') # pylint: disable=E1101 queryset = University.objects.all().prefetch_related('univ_campus', 'univ_campus__updated_by') # pylint: disable=E1101
serializer_class = UniversitySerializer serializer_class = UniversitySerializer
...@@ -45,7 +45,7 @@ MIDDLEWARE = [ ...@@ -45,7 +45,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
# 'general.middleware.LoginRequiredMiddleware', 'general.middleware.LoginRequiredMiddleware',
] ]
INTERNAL_IPS = ['127.0.0.1'] INTERNAL_IPS = ['127.0.0.1']
......
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