Commit 4bb2ee93 authored by Elger Jonker's avatar Elger Jonker

Add comply_or_explain volunteer


Former-commit-id: 38d6573f
parent 5b541892
......@@ -168,7 +168,47 @@ class UserAdmin(BaseUserAdmin, ImportExportModelAdmin):
inlines = (VolunteerInline, )
list_display = ('username', 'organization', 'first_name', 'last_name',
'email', 'is_staff', 'is_superuser', 'in_groups')
'email', 'is_active', 'is_staff', 'is_superuser', 'in_groups')
actions = []
def add_volunteer(self, request, queryset):
# password is random and non-recoverable. It has to be set explicitly by the admin
import string
from random import choice
alphabet = string.ascii_letters + string.digits
password = ''.join(choice(alphabet) for i in range(42))
# determine number:
volunteer_number = User.objects.all().filter(username__contains="Volunteer").count()
volunteer_number += 1
user = User.objects.create_user(username="Volunteer%s" % volunteer_number,
is_active=False,
is_staff=True,
is_superuser=False,
password=password)
user.save()
# and add the user to the comply or explain group.
user.groups.add(Group.objects.get(name="comply_or_explain"))
user.save()
# add volunteering information
volunteer = Volunteer()
volunteer.organization = "tbd"
volunteer.added_by = "Automatically added"
volunteer.notes = "-"
volunteer.user = user
volunteer.save()
self.message_user(request, "Volunteer added!")
return True
add_volunteer.short_description = '💖 Add Volunteer (select something first)'
actions.append(add_volunteer)
@staticmethod
def in_groups(obj):
......
# Generated by Django 2.0.8 on 2018-10-30 15:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('app', '0007_auto_20181025_1304'),
]
operations = [
migrations.AlterField(
model_name='volunteer',
name='added_by',
field=models.TextField(blank=True, max_length=200, null=True),
),
migrations.AlterField(
model_name='volunteer',
name='notes',
field=models.TextField(blank=True, max_length=2048, null=True),
),
migrations.AlterField(
model_name='volunteer',
name='organization',
field=models.TextField(blank=True, max_length=200, null=True),
),
]
......@@ -117,6 +117,6 @@ def create_verify_job(task_module: str):
class Volunteer(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
organization = models.TextField(max_length=200)
added_by = models.TextField(max_length=200)
notes = models.TextField(max_length=2048)
organization = models.TextField(max_length=200, blank=True, null=True)
added_by = models.TextField(max_length=200, blank=True, null=True)
notes = models.TextField(max_length=2048, blank=True, null=True)
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