From 734cf64cbbfd24ebe39f09298869038ed7ed1a4b Mon Sep 17 00:00:00 2001
From: Ernesto Rico Schmidt <ernesto@helsinki.at>
Date: Tue, 11 Oct 2022 18:05:42 -0400
Subject: [PATCH] Integrate Profile as UserProfile model

---
 profile/__init__.py                           |   0
 profile/admin.py                              |  69 ---------
 profile/migrations/0001_initial.py            | 122 ---------------
 profile/migrations/0001_squashed.py           |  69 ---------
 profile/migrations/0002_auto_20171129_1828.py | 146 ------------------
 profile/migrations/0002_auto_20220117_1721.py |  27 ----
 profile/migrations/0003_auto_20171213_1737.py |  67 --------
 profile/migrations/0003_auto_20220728_1807.py |  39 -----
 profile/migrations/0004_auto_20221011_2217.py |  23 ---
 profile/migrations/__init__.py                |   0
 profile/models.py                             |  40 -----
 profile/serializers.py                        |  42 -----
 program/models.py                             |  11 ++
 13 files changed, 11 insertions(+), 644 deletions(-)
 delete mode 100644 profile/__init__.py
 delete mode 100644 profile/admin.py
 delete mode 100644 profile/migrations/0001_initial.py
 delete mode 100644 profile/migrations/0001_squashed.py
 delete mode 100644 profile/migrations/0002_auto_20171129_1828.py
 delete mode 100644 profile/migrations/0002_auto_20220117_1721.py
 delete mode 100644 profile/migrations/0003_auto_20171213_1737.py
 delete mode 100644 profile/migrations/0003_auto_20220728_1807.py
 delete mode 100644 profile/migrations/0004_auto_20221011_2217.py
 delete mode 100644 profile/migrations/__init__.py
 delete mode 100644 profile/models.py
 delete mode 100644 profile/serializers.py

diff --git a/profile/__init__.py b/profile/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/profile/admin.py b/profile/admin.py
deleted file mode 100644
index 9efa339d..00000000
--- a/profile/admin.py
+++ /dev/null
@@ -1,69 +0,0 @@
-#
-# steering, Programme/schedule management for AURA
-#
-# Copyright (C) 2017-2018, Ingo Leindecker
-#
-# This program is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the Free
-# Software Foundation, either version 3 of the License, or (at your option) any
-# later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-from django.contrib import admin
-from django.contrib.auth.admin import UserAdmin
-from django.contrib.auth.models import User
-
-from .models import Profile
-
-
-class ProfileInline(admin.StackedInline):
-    model = Profile
-    fields = ("cba_username", "cba_user_token")
-    can_delete = False
-    verbose_name_plural = "Profile"
-    fk_name = "user"
-
-
-class ProfileUserAdmin(UserAdmin):
-    inlines = (ProfileInline,)
-
-    def get_queryset(self, request):
-        """Let common users only edit their own profile"""
-        if not request.user.is_superuser:
-            return super(UserAdmin, self).get_queryset(request).filter(pk=request.user.id)
-
-        return super(UserAdmin, self).get_queryset(request)
-
-    def get_readonly_fields(self, request, obj=None):
-        """Limit field access for common users"""
-        if not request.user.is_superuser:
-            return (
-                "username",
-                "is_staff",
-                "is_superuser",
-                "is_active",
-                "date_joined",
-                "last_login",
-                "groups",
-                "user_permissions",
-            )
-        return list()
-
-    def get_inline_instances(self, request, obj=None):
-        """Append profile fields to UserAdmin"""
-        if not obj:
-            return list()
-
-        return super(ProfileUserAdmin, self).get_inline_instances(request, obj)
-
-
-admin.site.unregister(User)
-admin.site.register(User, ProfileUserAdmin)
diff --git a/profile/migrations/0001_initial.py b/profile/migrations/0001_initial.py
deleted file mode 100644
index ad7c45b8..00000000
--- a/profile/migrations/0001_initial.py
+++ /dev/null
@@ -1,122 +0,0 @@
-# -*- coding: utf-8 -*-
-# Generated by Django 1.11.3 on 2017-11-09 18:42
-from __future__ import unicode_literals
-
-import versatileimagefield.fields
-
-import django.db.models.deletion
-from django.conf import settings
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    initial = True
-
-    dependencies = [
-        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name="Profile",
-            fields=[
-                (
-                    "id",
-                    models.AutoField(
-                        auto_created=True,
-                        primary_key=True,
-                        serialize=False,
-                        verbose_name="ID",
-                    ),
-                ),
-                (
-                    "biography",
-                    models.TextField(blank=True, null=True, verbose_name="Biography"),
-                ),
-                ("website", models.URLField(blank=True, verbose_name="Website")),
-                (
-                    "googleplus_url",
-                    models.URLField(blank=True, verbose_name="Google+ URL"),
-                ),
-                (
-                    "facebook_url",
-                    models.URLField(blank=True, verbose_name="Facebook URL"),
-                ),
-                (
-                    "twitter_url",
-                    models.URLField(blank=True, verbose_name="Twitter URL"),
-                ),
-                (
-                    "linkedin_url",
-                    models.URLField(blank=True, verbose_name="LinkedIn URL"),
-                ),
-                (
-                    "youtube_url",
-                    models.URLField(blank=True, verbose_name="Youtube URL"),
-                ),
-                ("dorftv_url", models.URLField(blank=True, verbose_name="DorfTV URL")),
-                ("cba_url", models.URLField(blank=True, verbose_name="CBA URL")),
-                (
-                    "cba_username",
-                    models.CharField(
-                        blank=True, max_length=60, verbose_name="CBA Username"
-                    ),
-                ),
-                (
-                    "cba_user_token",
-                    models.CharField(
-                        blank=True, max_length=255, verbose_name="CBA Token"
-                    ),
-                ),
-                (
-                    "ppoi",
-                    versatileimagefield.fields.PPOIField(
-                        default="0.5x0.5",
-                        editable=False,
-                        max_length=20,
-                        verbose_name="Image PPOI",
-                    ),
-                ),
-                (
-                    "height",
-                    models.PositiveIntegerField(
-                        blank=True,
-                        editable=False,
-                        null=True,
-                        verbose_name="Image Height",
-                    ),
-                ),
-                (
-                    "width",
-                    models.PositiveIntegerField(
-                        blank=True,
-                        editable=False,
-                        null=True,
-                        verbose_name="Image Width",
-                    ),
-                ),
-                (
-                    "image",
-                    versatileimagefield.fields.VersatileImageField(
-                        blank=True,
-                        height_field="height",
-                        null=True,
-                        upload_to="user_images",
-                        verbose_name="Profile picture",
-                        width_field="width",
-                    ),
-                ),
-                (
-                    "user",
-                    models.OneToOneField(
-                        on_delete=django.db.models.deletion.CASCADE,
-                        to=settings.AUTH_USER_MODEL,
-                    ),
-                ),
-            ],
-            options={
-                "db_table": "profile",
-            },
-        ),
-    ]
diff --git a/profile/migrations/0001_squashed.py b/profile/migrations/0001_squashed.py
deleted file mode 100644
index 1313caa1..00000000
--- a/profile/migrations/0001_squashed.py
+++ /dev/null
@@ -1,69 +0,0 @@
-# Generated by Django 2.2.12 on 2020-11-21 01:34
-
-import django.db.models.deletion
-from django.conf import settings
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    replaces = [
-        ("profile", "0001_initial"),
-        ("profile", "0002_auto_20171129_1828"),
-        ("profile", "0003_auto_20171213_1737"),
-    ]
-
-    initial = True
-
-    dependencies = [
-        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name="Profile",
-            fields=[
-                (
-                    "id",
-                    models.AutoField(
-                        auto_created=True,
-                        primary_key=True,
-                        serialize=False,
-                        verbose_name="ID",
-                    ),
-                ),
-                (
-                    "cba_username",
-                    models.CharField(
-                        blank=True,
-                        help_text="Your username in CBA. This is necessary for uploading files to"
-                        " your account.",
-                        max_length=60,
-                        verbose_name="CBA Username",
-                    ),
-                ),
-                (
-                    "cba_user_token",
-                    models.CharField(
-                        blank=True,
-                        help_text="The CBA upload token for your account. This is NOT your"
-                        " password which you use to log into CBA!",
-                        max_length=255,
-                        verbose_name="CBA Token",
-                    ),
-                ),
-                (
-                    "user",
-                    models.OneToOneField(
-                        editable=False,
-                        on_delete=django.db.models.deletion.CASCADE,
-                        related_name="profile",
-                        to=settings.AUTH_USER_MODEL,
-                    ),
-                ),
-            ],
-            options={
-                "db_table": "profile",
-            },
-        ),
-    ]
diff --git a/profile/migrations/0002_auto_20171129_1828.py b/profile/migrations/0002_auto_20171129_1828.py
deleted file mode 100644
index 38955424..00000000
--- a/profile/migrations/0002_auto_20171129_1828.py
+++ /dev/null
@@ -1,146 +0,0 @@
-# -*- coding: utf-8 -*-
-# Generated by Django 1.11.3 on 2017-11-29 18:28
-from __future__ import unicode_literals
-
-import versatileimagefield.fields
-
-import django.db.models.deletion
-from django.conf import settings
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ("profile", "0001_initial"),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name="profile",
-            name="biography",
-            field=models.TextField(
-                blank=True,
-                help_text="Describe yourself and your fields of interest in a few sentences.",
-                null=True,
-                verbose_name="Biography",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="cba_url",
-            field=models.URLField(
-                blank=True, help_text="URL to your CBA profile.", verbose_name="CBA URL"
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="cba_user_token",
-            field=models.CharField(
-                blank=True,
-                help_text="The CBA upload token for your account. This is NOT your password which"
-                " you use to log into CBA!",
-                max_length=255,
-                verbose_name="CBA Token",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="cba_username",
-            field=models.CharField(
-                blank=True,
-                help_text="Your username in CBA. This is necessary for uploading files to your"
-                " account.",
-                max_length=60,
-                verbose_name="CBA Username",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="dorftv_url",
-            field=models.URLField(
-                blank=True,
-                help_text="URL to your dorfTV channel.",
-                verbose_name="DorfTV URL",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="facebook_url",
-            field=models.URLField(
-                blank=True,
-                help_text="URL to your Facebook profile.",
-                verbose_name="Facebook URL",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="googleplus_url",
-            field=models.URLField(
-                blank=True,
-                help_text="URL to your Google+ profile.",
-                verbose_name="Google+ URL",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="image",
-            field=versatileimagefield.fields.VersatileImageField(
-                blank=True,
-                height_field="height",
-                help_text="Upload a picture of yourself. Images are automatically cropped around"
-                " the 'Primary Point of Interest'. Click in the image to change it and"
-                " press Save.",
-                null=True,
-                upload_to="user_images",
-                verbose_name="Profile picture",
-                width_field="width",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="linkedin_url",
-            field=models.URLField(
-                blank=True,
-                help_text="URL to your LinkedIn profile.",
-                verbose_name="LinkedIn URL",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="twitter_url",
-            field=models.URLField(
-                blank=True,
-                help_text="URL to your Twitter profile.",
-                verbose_name="Twitter URL",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="user",
-            field=models.OneToOneField(
-                editable=False,
-                on_delete=django.db.models.deletion.CASCADE,
-                related_name="profile",
-                to=settings.AUTH_USER_MODEL,
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="website",
-            field=models.URLField(
-                blank=True,
-                help_text="URL to your personal website.",
-                verbose_name="Website",
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="youtube_url",
-            field=models.URLField(
-                blank=True,
-                help_text="URL to your Youtube channel.",
-                verbose_name="Youtube URL",
-            ),
-        ),
-    ]
diff --git a/profile/migrations/0002_auto_20220117_1721.py b/profile/migrations/0002_auto_20220117_1721.py
deleted file mode 100644
index e209efde..00000000
--- a/profile/migrations/0002_auto_20220117_1721.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Generated by Django 2.2.25 on 2022-01-17 16:21
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ("profile", "0001_squashed"),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name="profile",
-            name="cba_user_token",
-            field=models.CharField(
-                blank=True, max_length=255, verbose_name="CBA Token"
-            ),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="cba_username",
-            field=models.CharField(
-                blank=True, max_length=60, verbose_name="CBA Username"
-            ),
-        ),
-    ]
diff --git a/profile/migrations/0003_auto_20171213_1737.py b/profile/migrations/0003_auto_20171213_1737.py
deleted file mode 100644
index 8a4b1103..00000000
--- a/profile/migrations/0003_auto_20171213_1737.py
+++ /dev/null
@@ -1,67 +0,0 @@
-# -*- coding: utf-8 -*-
-# Generated by Django 1.11.3 on 2017-12-13 17:37
-from __future__ import unicode_literals
-
-from django.db import migrations
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ("profile", "0002_auto_20171129_1828"),
-    ]
-
-    operations = [
-        migrations.RemoveField(
-            model_name="profile",
-            name="biography",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="cba_url",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="dorftv_url",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="facebook_url",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="googleplus_url",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="height",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="image",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="linkedin_url",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="ppoi",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="twitter_url",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="website",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="width",
-        ),
-        migrations.RemoveField(
-            model_name="profile",
-            name="youtube_url",
-        ),
-    ]
diff --git a/profile/migrations/0003_auto_20220728_1807.py b/profile/migrations/0003_auto_20220728_1807.py
deleted file mode 100644
index 78009bea..00000000
--- a/profile/migrations/0003_auto_20220728_1807.py
+++ /dev/null
@@ -1,39 +0,0 @@
-# Generated by Django 3.2.14 on 2022-07-28 16:07
-
-import django.utils.timezone
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ("profile", "0002_auto_20220117_1721"),
-    ]
-
-    operations = [
-        migrations.AddField(
-            model_name="profile",
-            name="created_at",
-            field=models.DateTimeField(
-                auto_now_add=True, default=django.utils.timezone.now
-            ),
-            preserve_default=False,
-        ),
-        migrations.AddField(
-            model_name="profile",
-            name="created_by",
-            field=models.CharField(default="root", max_length=150),
-            preserve_default=False,
-        ),
-        migrations.AddField(
-            model_name="profile",
-            name="updated_at",
-            field=models.DateTimeField(auto_now=True),
-        ),
-        migrations.AddField(
-            model_name="profile",
-            name="updated_by",
-            field=models.CharField(default="root", max_length=150),
-            preserve_default=False,
-        ),
-    ]
diff --git a/profile/migrations/0004_auto_20221011_2217.py b/profile/migrations/0004_auto_20221011_2217.py
deleted file mode 100644
index b3d6d05b..00000000
--- a/profile/migrations/0004_auto_20221011_2217.py
+++ /dev/null
@@ -1,23 +0,0 @@
-# Generated by Django 3.2.16 on 2022-10-11 20:17
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ("profile", "0003_auto_20220728_1807"),
-    ]
-
-    operations = [
-        migrations.AlterField(
-            model_name="profile",
-            name="updated_at",
-            field=models.DateTimeField(auto_now=True, null=True),
-        ),
-        migrations.AlterField(
-            model_name="profile",
-            name="updated_by",
-            field=models.CharField(blank=True, max_length=150, null=True),
-        ),
-    ]
diff --git a/profile/migrations/__init__.py b/profile/migrations/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/profile/models.py b/profile/models.py
deleted file mode 100644
index 2faa9788..00000000
--- a/profile/models.py
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# steering, Programme/schedule management for AURA
-#
-# Copyright (C) 2017-2018, Ingo Leindecker
-#
-# This program is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the Free
-# Software Foundation, either version 3 of the License, or (at your option) any
-# later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-from django.contrib.auth.models import User
-from django.db import models
-from django.utils.translation import gettext_lazy as _
-from program.models import ModelWithCreatedUpdatedFields
-
-
-class Profile(ModelWithCreatedUpdatedFields, models.Model):
-    user = models.OneToOneField(
-        User, on_delete=models.CASCADE, related_name="profile", editable=False
-    )
-    cba_username = models.CharField(_("CBA Username"), blank=True, max_length=60)
-    cba_user_token = models.CharField(_("CBA Token"), blank=True, max_length=255)
-
-    def __str__(self):
-        return self.user.username
-
-    class Meta:
-        db_table = "profile"
-
-    def save(self, *args, **kwargs):
-        super(Profile, self).save(*args, **kwargs)
diff --git a/profile/serializers.py b/profile/serializers.py
deleted file mode 100644
index 4d4d6ade..00000000
--- a/profile/serializers.py
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# steering, Programme/schedule management for AURA
-#
-# Copyright (C) 2017-2018, Ingo Leindecker
-#
-# This program is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the Free
-# Software Foundation, either version 3 of the License, or (at your option) any
-# later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-from profile.models import Profile
-
-from rest_framework import serializers
-
-
-class ProfileSerializer(serializers.ModelSerializer):
-    class Meta:
-        model = Profile
-        fields = (
-            "user",
-            "cba_username",
-            "cba_user_token",
-            "created_at",
-            "created_by",
-            "updated_at",
-            "updated_by",
-        )
-        read_only_fields = (
-            "created_at",
-            "created_by",
-            "updated_at",
-            "updated_by",
-        )
diff --git a/program/models.py b/program/models.py
index 08146fbb..e7a76ded 100644
--- a/program/models.py
+++ b/program/models.py
@@ -1168,3 +1168,14 @@ class Note(ModelWithImageFields, ModelWithCreatedUpdatedFields):
 
 class NoteLink(Link):
     note = models.ForeignKey(Note, on_delete=models.CASCADE, related_name="links")
+
+
+class UserProfile(ModelWithCreatedUpdatedFields, models.Model):
+    user = models.OneToOneField(
+        User, on_delete=models.CASCADE, related_name="profile", editable=False
+    )
+    cba_username = models.CharField("CBA Username", blank=True, max_length=60)
+    cba_user_token = models.CharField("CBA Token", blank=True, max_length=255)
+
+    def __str__(self):
+        return self.user.username
-- 
GitLab