Skip to content

Commit

Permalink
Merge pull request #34 from davidslusser/new_fields
Browse files Browse the repository at this point in the history
adding timezone and help_text to user preferences
  • Loading branch information
davidslusser committed Aug 8, 2022
2 parents 1374fb9 + 0b0910b commit ea2d46b
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/source/about.rst
Expand Up @@ -4,7 +4,7 @@
About
=====
django-userextensions is a reusable django application that extends the user model to provide profile settings, tracking
of user favorites and recently viewed urls and other user-based functionality.
of user favorites and recently viewed urls and other user-based functionality and service account management.

See details on django-extensions features on the :ref:`Features <features>` page

Expand Down
7 changes: 5 additions & 2 deletions docs/source/version_history.rst
Expand Up @@ -5,13 +5,16 @@ Version History
===============


Pre-Release
-----------

.. csv-table::
:header: "Release", "Details"
:widths: 20, 100

"0.1.4", "adding timezone and help text options to user preferences"
"0.1.3', "updating service account form"
"0.1.2", "allowing custom service account names"
"0.1.1", "updating version tag"
"0.1.0", "requiring django 3.2.x or above"
"0.0.10", "added service account management"
"0.0.6", "added documentation via sphinx"
"0.0.5", "fixed base_tempalte in recents/favorites views"
Expand Down
2 changes: 1 addition & 1 deletion userextensions/__init__.py
Expand Up @@ -7,7 +7,7 @@
"""

__title__ = 'django-userextensions'
__version__ = '0.1.3'
__version__ = '0.1.4'
__author__ = 'David Slusser'
__email__ = 'dbslusser@gmail.com'
__license__ = 'GPL-3.0'
Expand Down
3 changes: 2 additions & 1 deletion userextensions/admin.py
Expand Up @@ -11,8 +11,9 @@ class ThemeAdmin(admin.ModelAdmin):


class UserPreferenceAdmin(admin.ModelAdmin):
list_display = ("id", "user", "theme", "recents_count", "page_refresh_time", "start_page", "updated_at")
list_display = ("id", "user", "theme", "recents_count", "page_refresh_time", "timezone", "help_text_enable", "start_page", "updated_at")
search_fields = ["host", "user__username"]
list_filter = ['help_text_enable']


class UserRecentAdmin(admin.ModelAdmin):
Expand Down
10 changes: 10 additions & 0 deletions userextensions/forms.py
@@ -1,3 +1,5 @@
from pytz import common_timezones

from django import forms

# import models
Expand All @@ -6,13 +8,21 @@

class UserPreferenceForm(forms.ModelForm):
""" Form class used to add/edit UserPreference objects """
timezone = forms.ChoiceField(choices=[(i, i) for i in common_timezones],
widget=forms.Select(attrs={'class': 'form-control'}),
required=False,
label='Timezone')

class Meta:
model = UserPreference
exclude = ['created_at', 'updated_at', 'user']
widgets = {
'recents_count': forms.NumberInput(attrs={'class': 'form-control'}),
'page_refresh_time': forms.NumberInput(attrs={'class': 'form-control'}),
'theme': forms.Select(attrs={'class': 'form-control'}),
# 'timezone': forms.ChoiceField(choices=[(i, i) for i in common_timezones],
# attrs={'class': 'form-control'}),
'help_text_enabled': forms.CheckboxInput(attrs={'class': 'form-control'}),
'start_page': forms.TextInput(attrs={'class': 'form-control'}),
}

Expand Down
53 changes: 53 additions & 0 deletions userextensions/migrations/0007_auto_20220807_2104.py
@@ -0,0 +1,53 @@
# Generated by Django 3.2.13 on 2022-08-07 21:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('userextensions', '0006_auto_20210507_1831'),
]

operations = [
migrations.AddField(
model_name='userpreference',
name='help_text_enable',
field=models.BooleanField(default=True, help_text='enable help text and tooltips'),
),
migrations.AddField(
model_name='userpreference',
name='timezone',
field=models.CharField(blank=True, help_text='timezone to use when displaying time and datetime values', max_length=32, null=True),
),
migrations.AlterField(
model_name='serviceaccount',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='serviceaccounttokenhistory',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='theme',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='userfavorite',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='userpreference',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
migrations.AlterField(
model_name='userrecent',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]
4 changes: 4 additions & 0 deletions userextensions/models.py
Expand Up @@ -33,6 +33,10 @@ class UserPreference(HandyHelperBaseModel):
page_refresh_time = models.IntegerField(default=5, blank=True, null=True,
help_text='time, in minutes, to auto-refresh a page (where applicable')
start_page = models.CharField(max_length=255, blank=True, null=True, help_text='url to redirect to after login')
help_text_enable = models.BooleanField(default=True, help_text='enable help text and tooltips')
timezone = models.CharField(max_length=32, blank=True, null=True, default='UTC',
help_text='timezone to use when displaying time and datetime values')
"""https://stackoverflow.com/questions/48383549/how-to-show-local-time-in-template"""

def __str__(self):
return self.user.username
Expand Down
19 changes: 19 additions & 0 deletions userextensions/templates/userextensions/detail/detail_user.html
Expand Up @@ -17,6 +17,7 @@ <h1 class="text-primary"><b>User Profile: </b><span class="text-secondary"><smal
<div class="row mb-5 animated fadeIn" style="animation-delay: .15s;">
<div class="col-sm-12 col-md-3 col-lg-2 mb-3 pl-0">
<i class="far fa-address-card fa-6x text-primary"></i><br/>
<span class="text-primary font-weight-bold">Identity</span>
</div>

<div class="col-sm-12 col-md-9 col-lg-10">
Expand Down Expand Up @@ -77,6 +78,7 @@ <h1 class="text-primary"><b>User Profile: </b><span class="text-secondary"><smal
<div class="row mb-5 animated fadeIn" style="animation-delay: .3s;">
<div class="col-sm-12 col-md-3 col-lg-2 mb-3 pl-0">
<i class="fas fa-cogs fa-6x text-primary"></i><br/>
<span class="text-primary text-center font-weight-bold">Settings</span>
</div>

<div class="col-sm-12 col-md-9 col-lg-10">
Expand All @@ -85,6 +87,22 @@ <h1 class="text-primary"><b>User Profile: </b><span class="text-secondary"><smal
<div class="col-sm-9">{{ user.preference.theme }}</div>
</div>

<div class="row border-bottom border-secondary p-2">
<div class="col-sm-3 font-weight-bold text-primary">Timezone: </div>
<div class="col-sm-9">{{ user.preference.timezone }}</div>
</div>

<div class="row border-bottom border-secondary p-2">
<div class="col-sm-3 font-weight-bold text-primary">Help Enabled: </div>
<div class="col-sm-9">
{% if user.preference.help_text_enable %}
<span class="badge badge-pill badge-primary"><i class="fa fa-check fa-fw"></i></span>
{% else %}
<span class="badge badge-pill badge-danger"><i class="fa fa-times fa-fw"></i></span>
{% endif %}
</div>
</div>

<div class="row border-bottom border-secondary p-2">
<div class="col-sm-3 font-weight-bold text-primary">Recents Count: </div>
<div class="col-sm-9">{{ user.preference.recents_count }}</div>
Expand Down Expand Up @@ -116,6 +134,7 @@ <h1 class="text-primary"><b>User Profile: </b><span class="text-secondary"><smal
<div class="row mb-5 animated fadeIn" style="animation-delay: .45s;">
<div class="col-sm-12 col-md-3 col-lg-2 mb-3 pl-0">
<i class="fas fa-users fa-6x text-primary"></i><br/>
<span class="text-primary text-center font-weight-bold">Groups</span>
</div>

<div class="col-sm-12 col-md-9 col-lg-10">
Expand Down

0 comments on commit ea2d46b

Please sign in to comment.