Skip to content

Commit

Permalink
Add profile image. Bump to v1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
MaistrenkoAnton committed Jul 6, 2019
1 parent b4e07cf commit 5c6481a
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/demo/profile/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = 'demo.profile.apps.ProfileConfig'
23 changes: 23 additions & 0 deletions app/demo/profile/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.contrib import admin

from demo.profile.model import UserProfile
from material.admin import MaterialUserAdmin
from material.decorators import register
from material.sites import site

from django.contrib.auth.models import User


site.unregister(User)


class UserPictureInline(admin.TabularInline):
model = UserProfile
extra = 0


@register(User)
class MaterialUserPictureAdmin(MaterialUserAdmin):
"""Register User model with material styles"""
inlines = [UserPictureInline]

6 changes: 6 additions & 0 deletions app/demo/profile/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ProfileConfig(AppConfig):
name = 'demo.profile'
icon_name = 'layers'
30 changes: 30 additions & 0 deletions app/demo/profile/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 2.2.3 on 2019-07-06 12:03

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('picture', models.FileField(blank=True, null=True, upload_to='', verbose_name='User Picture')),
('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Picture',
'verbose_name_plural': 'Picture',
'db_table': 'user_pictures',
},
),
]
Empty file.
23 changes: 23 additions & 0 deletions app/demo/profile/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _


class UserProfile(models.Model):
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='profile',
null=True,
blank=True
)
picture = models.FileField(
_('User Picture'),
null=True,
blank=True
)

class Meta:
verbose_name = _('Picture')
verbose_name_plural = _('Picture')
db_table = 'user_pictures'
1 change: 1 addition & 0 deletions app/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'django.contrib.staticfiles',
'django.contrib.sites',

'demo.profile',
'demo.countries',
'demo.documents',
'demo.relations',
Expand Down
4 changes: 3 additions & 1 deletion material/templates/material/side_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<li>
<div class="card">
<div class="card-image">
{% if user.picture %}
{% if user.profile.picture %}
<img class="login-logo" src="{{ user.profile.picture.url }}">
{% elif user.picture %}
<img class="login-logo" src="{{ user.picture.url }}">
{% else %}
<img class="login-logo" src="{% static 'material/images/login-logo.png' %}">
Expand Down
2 changes: 0 additions & 2 deletions package/material/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
},
models.TimeField: {'widget': widgets.MaterialAdminTimeWidget},
models.TextField: {'widget': widgets.MaterialAdminTextareaWidget},
models.ImageField: {'widget': widgets.MaterialAdminFileWidget},
models.FileField: {'widget': widgets.MaterialAdminFileWidget},
}


Expand Down
4 changes: 3 additions & 1 deletion package/material/templates/material/side_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<li>
<div class="card">
<div class="card-image">
{% if user.picture %}
{% if user.profile.picture %}
<img class="login-logo" src="{{ user.profile.picture.url }}">
{% elif user.picture %}
<img class="login-logo" src="{{ user.picture.url }}">
{% else %}
<img class="login-logo" src="{% static 'material/images/login-logo.png' %}">
Expand Down
5 changes: 0 additions & 5 deletions package/material/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ class MaterialAdminTimeWidget(forms.TimeInput):
template_name = 'material/widgets/time.html'


class MaterialAdminFileWidget(widgets.AdminFileWidget):
"""File input with material css styles"""
template_name = 'material/widgets/clearable_file_input.html'


class MaterialAdminTextareaWidget(widgets.AdminTextareaWidget):
"""Textarea with material css styles"""

Expand Down
2 changes: 1 addition & 1 deletion package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="django-material-admin",
version="1.1.3",
version="1.1.4",
packages=find_packages(),
author="Anton Maistrenko",
include_package_data=True,
Expand Down

0 comments on commit 5c6481a

Please sign in to comment.