Skip to content
Snippets Groups Projects
Commit 734cf64c authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

Integrate Profile as UserProfile model

parent 349c4ca4
No related branches found
No related tags found
No related merge requests found
#
# 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)
# -*- 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",
},
),
]
# 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",
},
),
]
# -*- 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",
),
),
]
# 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"
),
),
]
# -*- 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",
),
]
# 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,
),
]
# 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),
),
]
#
# 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)
#
# 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",
)
...@@ -1168,3 +1168,14 @@ class Note(ModelWithImageFields, ModelWithCreatedUpdatedFields): ...@@ -1168,3 +1168,14 @@ class Note(ModelWithImageFields, ModelWithCreatedUpdatedFields):
class NoteLink(Link): class NoteLink(Link):
note = models.ForeignKey(Note, on_delete=models.CASCADE, related_name="links") 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment