Arabic Django user management app with abstract user, permissions, and activity logging
Project description
Micro Users - Arabic Django User Management App
Arabic lightweight, reusable Django app providing user management with abstract user, permissions, localization, and activity logging.
Requirements
- Must be installed on a fresh database.
- Python 3.11+
- Django 5.1+
- django-crispy-forms 2.4+
- django-tables2 2.7+
- django-filter 24.3+
- pillow 11.0+
- babel 2.1+
Features
- Custom AbstractUser model
- User permissions system
- Activity logging (login/logout, CRUD tracking)
- Specific User detail and log view new
- Localization support
- Admin interface integration
- CRUD views and templates
- Filtering and tabulation
Future updates are planned to support dynamic language switching between RTL and LTR.
Installation
pip install git+https://github.com/debeski/micro-users.git
# OR
pip install micro-users
Configuration
- Add to
INSTALLED_APPS:
INSTALLED_APPS = [
'users', # Preferably on top
'django.contrib.admin',
'django.contrib.auth',
...
]
- Set custom user model in settings.py:
AUTH_USER_MODEL = 'users.CustomUser'
- Include URLs in your main project folder
urls.py:
urlpatterns = [
...
path('manage/', include('users.urls')),
]
- Run migrations:
python manage.py migrate users
How to Use
Once configured, the app automatically handles user management and activity logging. Ensure your project has a base.html template in the root templates directory, as all user management templates extend it.
Activity Logging
The app automatically logs LOGIN and LOGOUT actions. For custom logging of other actions in your application, you can use the following helper functions:
Available Helper Functions
- Get Client IP - Extract the user's IP address from request:
from users.signals import get_client_ip
# Usage in views
ip_address = get_client_ip(request)
- Log User Action - Create a reusable logging function:
from django.utils import timezone
from users.models import UserActivityLog
from users.signals import get_client_ip
def log_user_action(request, instance, action, model_name):
"""
Logs a user action to the activity log.
Args:
request: HttpRequest object
instance: The model instance being acted upon
action: Action type (see ACTION_TYPES below)
model_name: Name of the model/entity (in Arabic or English)
"""
UserActivityLog.objects.create(
user=request.user,
action=action,
model_name=model_name,
object_id=instance.pk,
number=instance.number if hasattr(instance, 'number') else '',
timestamp=timezone.now(),
ip_address=get_client_ip(request),
user_agent=request.META.get("HTTP_USER_AGENT", ""),
)
Action Types Available
Use these constants when logging actions:
| Action Constant | Arabic Display | Description |
|---|---|---|
'LOGIN' |
تسجيل دخـول | User login (auto-logged) |
'LOGOUT' |
تسجيل خـروج | User logout (auto-logged) |
'CREATE' |
انشـاء | Object creation |
'UPDATE' |
تعديـل | Object modification |
'DELETE' |
حــذف | Object deletion |
'VIEW' |
عـرض | Object viewing |
'DOWNLOAD' |
تحميل | File download |
'CONFIRM' |
تأكيـد | Action confirmation |
'REJECT' |
رفــض | Action rejection |
'RESET' |
اعادة ضبط | Password/Data reset |
Usage Examples
- Logging a CREATE action:
def create_document(request):
# ... create logic ...
document = Document.objects.create(...)
# Log the action
from users.models import UserActivityLog
from users.signals import get_client_ip
UserActivityLog.objects.create(
user=request.user,
action='CREATE',
model_name='وثيقة',
object_id=document.pk,
number=document.number,
ip_address=get_client_ip(request),
user_agent=request.META.get("HTTP_USER_AGENT", ""),
)
- Using the helper function:
# Create a helper function in your app
def log_action(request, instance, action, model_name):
from users.models import UserActivityLog
from users.signals import get_client_ip
from django.utils import timezone
UserActivityLog.objects.create(
user=request.user,
action=action,
model_name=model_name,
object_id=instance.pk,
number=getattr(instance, 'number', ''),
timestamp=timezone.now(),
ip_address=get_client_ip(request),
user_agent=request.META.get("HTTP_USER_AGENT", ""),
)
# Usage in views
def update_order(request, order_id):
order = get_object_or_404(Order, pk=order_id)
# ... update logic ...
log_action(request, order, 'UPDATE', 'طلب')
- Logging without an instance (for general actions):
def log_general_action(request, action, model_name, description=''):
from users.models import UserActivityLog
from users.signals import get_client_ip
from django.utils import timezone
UserActivityLog.objects.create(
user=request.user,
action=action,
model_name=model_name,
object_id=None,
number=description,
timestamp=timezone.now(),
ip_address=get_client_ip(request),
user_agent=request.META.get("HTTP_USER_AGENT", ""),
)
# Usage
log_general_action(request, 'CONFIRM', 'نظام', 'تم تأكيد الإعدادات')
Available URLs
All user management URLs are prefixed with manage/ as configured. Below is the complete list:
| URL Pattern | View/Function | Description |
|---|---|---|
manage/login/ |
auth_views.LoginView.as_view() |
User login |
manage/logout/ |
auth_views.LogoutView.as_view() |
User logout |
manage/users/ |
views.UserListView.as_view() |
List all users |
manage/users/create/ |
views.create_user |
Create new user |
manage/users/edit/<int:pk>/ |
views.edit_user |
Edit existing user |
manage/users/delete/<int:pk>/ |
views.delete_user |
Delete user |
manage/users/<int:pk>/ |
views.UserDetailView.as_view() |
View user details |
manage/profile |
views.user_profile |
View current user profile |
manage/profile/edit/ |
views.edit_profile |
Edit current profile |
manage/logs/ |
views.UserActivityLogView.as_view() |
View activity logs |
manage/reset_password/<int:pk>/ |
views.reset_password |
Reset user password |
Structure
users/
├── views.py # CRUD operations
├── urls.py # URL routing
├── tables.py # User and Activity Log tables
├── signals.py # Logging signals
├── models.py # User model, permissions, activity logs
├── forms.py # Creation, edit,. etc.
├── filter.py # Search filters
├── apps.py # Permissions Localization
├── admin.py # Admin UI integration
├── __init__.py # Python init
├── templates/ # HTML templates
├── static/ # CSS classes
└── migrations/ # Database migrations
Version History
| Version | Changes |
|---|---|
| v1.0.0 | • Initial release as pip package |
| v1.0.1 | • Fixed a couple of new issues as a pip package |
| v1.0.2 | • Fixed the readme and building files |
| v1.0.3 | • Still getting the hang of this pip publish thing |
| v1.0.4 | • Honestly still messing with and trying settings and stuff out |
| v1.1.0 | • OK, finally a working seamless micro-users app |
| v1.1.1 | • Fixed an expolit where a staff member could disable the ADMIN user |
| v1.2.0 | • Added User Details view with specific user activity log |
| v1.2.1 | • Fixed a minor import bug |
| v1.2.2 | • Separated user detail view from table for consistency • Optimized the new detail + log view for optimal compatibiliyy with users |
| v1.2.3 | • Fixed a couple of visual inconsistencies |
| v1.3.0 | • Patched a critical security permission issue • Disabled ADMIN from being viewed/edited from all other members • Fixed a crash when sorting with full_name • Enabled Logging for all actions |
| v1.3.1 | • Corrected a misplaced code that caused a crash when editing profile |
| v1.3.2 | • Minor table modifications |
| v1.4.0 | • Redesigned Permissions UI (Grouped by App/Action) • Added Global Bulk Permission Selectors • Improved Arabic Localization for Permissions • Optimized printing (hidden forms/buttons) • Fixed various bugs and crashes |
| v1.4.1 | • Changed "Administrative User" translation to "Responsible User" (مستخدم مسؤول) • Enforced custom sorting order for Permissions (View -> Add -> Change -> Other) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file micro_users-1.4.1.tar.gz.
File metadata
- Download URL: micro_users-1.4.1.tar.gz
- Upload date:
- Size: 28.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62fe244c4f4d5c9d8d25d37467487bd630ad75dd213db3706109ce3bb0bb1b12
|
|
| MD5 |
a508942bb8c8157fd690e82c43b62594
|
|
| BLAKE2b-256 |
a66899e948d759ea48c0c4dcecc592f4fc418685d0bcc83b2fcbab1c103201b7
|
File details
Details for the file micro_users-1.4.1-py3-none-any.whl.
File metadata
- Download URL: micro_users-1.4.1-py3-none-any.whl
- Upload date:
- Size: 34.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
061dd7dd924c8d9a4f3b34465a45879c0ba396bdbdaaa574e075a8ff81fd8a2a
|
|
| MD5 |
00c76ad0b03a5027b221d861d2f9568c
|
|
| BLAKE2b-256 |
c79f4ccbe68e71ac19b87d5285dceec386238457e1bc6173572929ef17272dd9
|