Skip to content

Commit

Permalink
Merge pull request #212 from Seshat-Global-History-Databank/seshat-ex…
Browse files Browse the repository at this point in the history
…perts-updates

Seshat experts updates stable
  • Loading branch information
MajidBenam authored Dec 19, 2024
2 parents 56fd3ba + 682c181 commit f33a399
Show file tree
Hide file tree
Showing 135 changed files with 5,056 additions and 1,800 deletions.
59 changes: 58 additions & 1 deletion seshat/apps/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from .forms import SeshatExpertAdminForm

from .models import Profile, Seshat_Expert, Seshat_Task
######EMAIL_CONFIRMATION_BRANCH is the keyword that needs to be searched

Expand Down Expand Up @@ -38,8 +40,63 @@ def get_inline_instances(self, request, obj=None):
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
admin.site.register(Profile)
admin.site.register(Seshat_Expert)
#admin.site.unregister(Seshat_Expert)
admin.site.register(Seshat_Task)


class SeshatExpertAdmin(admin.ModelAdmin):
"""
Custom admin for Seshat_Expert model.
"""
form = SeshatExpertAdminForm

list_display = ('id', 'get_full_name', 'role', 'get_username', 'email', 'is_staff', 'is_active', 'last_login', 'date_joined')
list_filter = ('role',) # Add filters for roles
search_fields = ('user__username', 'user__first_name', 'user__last_name', 'user__email') # Enable search by user details

ordering = ('user__last_name', 'user__first_name') # Order by name

@admin.display(description='Full Name')
def get_full_name(self, obj):
"""
Returns the full name of the user.
"""
if obj.user.first_name and obj.user.last_name:
return f"{obj.user.first_name} {obj.user.last_name}"
return "N/A"

@admin.display(description='Username')
def get_username(self, obj):
"""
Returns the username of the user.
"""
return obj.user.username

@admin.display(description='Last login')
def last_login(self, obj):
return obj.user.last_login

@admin.display(description='Joined')
def date_joined(self, obj):
return obj.user.date_joined

@admin.display(description='Email')
def email(self, obj):
"""
Returns the email of the user.
"""
return obj.user.email

@admin.display(description='Active')
def is_active(self, obj):
return obj.user.is_active

@admin.display(description='Staff')
def is_staff(self, obj):
return obj.user.is_staff



admin.site.register(Seshat_Expert, SeshatExpertAdmin)


29 changes: 26 additions & 3 deletions seshat/apps/accounts/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms
from django.db.models.base import Model
from django.forms import ModelForm
from django.forms import ModelForm, ModelChoiceField, Select
from django.forms.widgets import Textarea

from django.core.exceptions import ValidationError
Expand All @@ -13,7 +13,6 @@
from django.contrib.auth.forms import UserCreationForm



class Seshat_TaskForm(forms.ModelForm):
"""
Form for adding or updating a task.
Expand Down Expand Up @@ -108,4 +107,28 @@ def clean_email(self):
username_parts = username.split('.')
if len(username_parts) > 5:
raise ValidationError("Email address contains too many dots in the username part.")
return email
return email


class SeshatExpertAdminForm(ModelForm):
class Meta:
model = Seshat_Expert
fields = '__all__'

# Override the user field
user = ModelChoiceField(
queryset=User.objects.all(),
widget=Select(attrs={'class': 'form-control'}),
label="User",
help_text="Select a user for this expert.",
)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Customize display of user dropdown
self.fields['user'].queryset = User.objects.filter(is_staff=True).order_by('id')
self.fields['user'].label_from_instance = lambda obj: f"{obj.id}: {obj.username} ({obj.first_name} {obj.last_name} - {obj.email})"




18 changes: 18 additions & 0 deletions seshat/apps/accounts/migrations/0014_alter_seshat_expert_role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.0.3 on 2024-12-04 17:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0013_alter_seshat_task_task_url'),
]

operations = [
migrations.AlterField(
model_name='seshat_expert',
name='role',
field=models.CharField(blank=True, choices=[('Seshat Admin', 'Seshat Admin'), ('RA', 'Seshat Researcher'), ('Seshat Expert', 'Seshat Expert')], max_length=60, null=True),
),
]
12 changes: 10 additions & 2 deletions seshat/apps/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ class Seshat_Expert(models.Model):
Model representing a Seshat Expert.
"""
SESHATADMIN = 'Seshat Admin'
RA = 'RA'
RA = 'Researcher'
SESHATEXPERT = 'Seshat Expert'
LR = 'Lead Researcher'
SD = 'Seshat Director'
PM = 'Project Manager'

ROLE_CHOICES = (
(SESHATADMIN, 'Seshat Admin'),
(RA, 'RA'),
(RA, 'Researcher'),
(SESHATEXPERT, 'Seshat Expert'),
(LR, 'Lead Researcher'),
(SD, 'Seshat Director'),
(PM, 'Project Manager'),

)
user = models.ForeignKey(User, on_delete=models.CASCADE)
role = models.CharField(max_length=60,
Expand Down
9 changes: 1 addition & 8 deletions seshat/apps/accounts/templates/account/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@
<div class="container">
<div class="main-body">
<!-- source: https://www.bootdey.com/snippets/view/profile-with-data-and-skills#css -->
<!-- Breadcrumb -->
<nav aria-label="breadcrumb" class="main-breadcrumb mt-2">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'seshat-index' %}">Home</a></li>
<li class="breadcrumb-item active" aria-current="page">User Profile</li>
</ol>
</nav>
<!-- /Breadcrumb -->


<div class="row gutters-sm">
<div class="col-md-3 mb-3">
Expand Down
33 changes: 33 additions & 0 deletions seshat/apps/accounts/templates/account/seshat_expert_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seshat Experts</title>
</head>
<body>
<h1>List of Seshat Experts</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for expert in experts %}
<tr>
<td>{{ expert }}</td> <!-- Adjust fields as needed -->
<td>{{ expert.role }}</td>

</tr>
{% empty %}
<tr>
<td colspan="3">No experts found.</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
Loading

0 comments on commit f33a399

Please sign in to comment.