micro-users 1.3.1__tar.gz → 1.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of micro-users might be problematic. Click here for more details.
- micro_users-1.4.0/PKG-INFO +284 -0
- micro_users-1.4.0/README.md +253 -0
- micro_users-1.4.0/micro_users.egg-info/PKG-INFO +284 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/micro_users.egg-info/SOURCES.txt +2 -1
- {micro_users-1.3.1 → micro_users-1.4.0}/pyproject.toml +1 -1
- {micro_users-1.3.1 → micro_users-1.4.0}/setup.py +1 -1
- {micro_users-1.3.1 → micro_users-1.4.0}/users/forms.py +114 -89
- {micro_users-1.3.1 → micro_users-1.4.0}/users/tables.py +6 -6
- {micro_users-1.3.1 → micro_users-1.4.0}/users/templates/user_activity_log.html +5 -7
- {micro_users-1.3.1 → micro_users-1.4.0}/users/templates/users/manage_users.html +2 -5
- micro_users-1.4.0/users/templates/users/widgets/grouped_permissions.html +210 -0
- micro_users-1.3.1/PKG-INFO +0 -133
- micro_users-1.3.1/README.md +0 -102
- micro_users-1.3.1/micro_users.egg-info/PKG-INFO +0 -133
- {micro_users-1.3.1 → micro_users-1.4.0}/LICENSE +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/MANIFEST.in +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/micro_users.egg-info/dependency_links.txt +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/micro_users.egg-info/requires.txt +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/micro_users.egg-info/top_level.txt +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/setup.cfg +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/__init__.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/admin.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/apps.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/filters.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/migrations/0001_initial.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/migrations/0002_alter_useractivitylog_action.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/migrations/__init__.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/models.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/signals.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/static/css/login.css +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/static/img/default_profile.webp +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/templates/registration/login.html +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/templates/users/profile.html +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/templates/users/profile_edit.html +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/templates/users/user_actions.html +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/templates/users/user_detail.html +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/templates/users/user_form.html +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/urls.py +0 -0
- {micro_users-1.3.1 → micro_users-1.4.0}/users/views.py +0 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: micro_users
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: Arabic Django user management app with abstract user, permissions, and activity logging
|
|
5
|
+
Home-page: https://github.com/debeski/micro-users
|
|
6
|
+
Author: DeBeski
|
|
7
|
+
Author-email: DeBeski <debeski1@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: django,users,permissions,authentication
|
|
10
|
+
Classifier: Framework :: Django
|
|
11
|
+
Classifier: Framework :: Django :: 5
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: Django>=5.1
|
|
26
|
+
Requires-Dist: django-crispy-forms>=2.4
|
|
27
|
+
Requires-Dist: django-tables2>=2.7
|
|
28
|
+
Requires-Dist: django-filter>=24.3
|
|
29
|
+
Requires-Dist: pillow>=11.0
|
|
30
|
+
Requires-Dist: babel>=2.1
|
|
31
|
+
|
|
32
|
+
# Micro Users - Arabic Django User Management App
|
|
33
|
+
|
|
34
|
+
[](https://pypi.org/project/micro-users/)
|
|
35
|
+
|
|
36
|
+
**Arabic** lightweight, reusable Django app providing user management with abstract user, permissions, localization, and activity logging.
|
|
37
|
+
|
|
38
|
+
## Requirements
|
|
39
|
+
- **Must be installed on a fresh database.**
|
|
40
|
+
- Python 3.11+
|
|
41
|
+
- Django 5.1+
|
|
42
|
+
- django-crispy-forms 2.4+
|
|
43
|
+
- django-tables2 2.7+
|
|
44
|
+
- django-filter 24.3+
|
|
45
|
+
- pillow 11.0+
|
|
46
|
+
- babel 2.1+
|
|
47
|
+
|
|
48
|
+
## Features
|
|
49
|
+
- Custom AbstractUser model
|
|
50
|
+
- User permissions system
|
|
51
|
+
- Activity logging (login/logout, CRUD tracking)
|
|
52
|
+
- Specific User detail and log view *new*
|
|
53
|
+
- Localization support
|
|
54
|
+
- Admin interface integration
|
|
55
|
+
- CRUD views and templates
|
|
56
|
+
- Filtering and tabulation
|
|
57
|
+
> *Future updates are planned to support dynamic language switching between RTL and LTR.*
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install git+https://github.com/debeski/micro-users.git
|
|
63
|
+
# OR
|
|
64
|
+
pip install micro-users
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
1. Add to `INSTALLED_APPS`:
|
|
70
|
+
```python
|
|
71
|
+
INSTALLED_APPS = [
|
|
72
|
+
'users', # Preferably on top
|
|
73
|
+
'django.contrib.admin',
|
|
74
|
+
'django.contrib.auth',
|
|
75
|
+
...
|
|
76
|
+
]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
2. Set custom user model in settings.py:
|
|
80
|
+
```python
|
|
81
|
+
AUTH_USER_MODEL = 'users.CustomUser'
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
3. Include URLs in your main project folder `urls.py`:
|
|
85
|
+
```python
|
|
86
|
+
urlpatterns = [
|
|
87
|
+
...
|
|
88
|
+
path('manage/', include('users.urls')),
|
|
89
|
+
]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
4. Run migrations:
|
|
93
|
+
```bash
|
|
94
|
+
python manage.py migrate users
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## How to Use
|
|
98
|
+
|
|
99
|
+
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.
|
|
100
|
+
|
|
101
|
+
### Activity Logging
|
|
102
|
+
|
|
103
|
+
The app automatically logs **LOGIN** and **LOGOUT** actions. For custom logging of other actions in your application, you can use the following helper functions:
|
|
104
|
+
|
|
105
|
+
#### Available Helper Functions
|
|
106
|
+
|
|
107
|
+
1. **Get Client IP** - Extract the user's IP address from request:
|
|
108
|
+
```python
|
|
109
|
+
from users.signals import get_client_ip
|
|
110
|
+
|
|
111
|
+
# Usage in views
|
|
112
|
+
ip_address = get_client_ip(request)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
2. **Log User Action** - Create a reusable logging function:
|
|
116
|
+
```python
|
|
117
|
+
from django.utils import timezone
|
|
118
|
+
from users.models import UserActivityLog
|
|
119
|
+
from users.signals import get_client_ip
|
|
120
|
+
|
|
121
|
+
def log_user_action(request, instance, action, model_name):
|
|
122
|
+
"""
|
|
123
|
+
Logs a user action to the activity log.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
request: HttpRequest object
|
|
127
|
+
instance: The model instance being acted upon
|
|
128
|
+
action: Action type (see ACTION_TYPES below)
|
|
129
|
+
model_name: Name of the model/entity (in Arabic or English)
|
|
130
|
+
"""
|
|
131
|
+
UserActivityLog.objects.create(
|
|
132
|
+
user=request.user,
|
|
133
|
+
action=action,
|
|
134
|
+
model_name=model_name,
|
|
135
|
+
object_id=instance.pk,
|
|
136
|
+
number=instance.number if hasattr(instance, 'number') else '',
|
|
137
|
+
timestamp=timezone.now(),
|
|
138
|
+
ip_address=get_client_ip(request),
|
|
139
|
+
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
140
|
+
)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
#### Action Types Available
|
|
144
|
+
Use these constants when logging actions:
|
|
145
|
+
|
|
146
|
+
| Action Constant | Arabic Display | Description |
|
|
147
|
+
|-----------------|----------------|-------------|
|
|
148
|
+
| `'LOGIN'` | تسجيل دخـول | User login (auto-logged) |
|
|
149
|
+
| `'LOGOUT'` | تسجيل خـروج | User logout (auto-logged) |
|
|
150
|
+
| `'CREATE'` | انشـاء | Object creation |
|
|
151
|
+
| `'UPDATE'` | تعديـل | Object modification |
|
|
152
|
+
| `'DELETE'` | حــذف | Object deletion |
|
|
153
|
+
| `'VIEW'` | عـرض | Object viewing |
|
|
154
|
+
| `'DOWNLOAD'` | تحميل | File download |
|
|
155
|
+
| `'CONFIRM'` | تأكيـد | Action confirmation |
|
|
156
|
+
| `'REJECT'` | رفــض | Action rejection |
|
|
157
|
+
| `'RESET'` | اعادة ضبط | Password/Data reset |
|
|
158
|
+
|
|
159
|
+
#### Usage Examples
|
|
160
|
+
|
|
161
|
+
1. **Logging a CREATE action**:
|
|
162
|
+
```python
|
|
163
|
+
def create_document(request):
|
|
164
|
+
# ... create logic ...
|
|
165
|
+
document = Document.objects.create(...)
|
|
166
|
+
|
|
167
|
+
# Log the action
|
|
168
|
+
from users.models import UserActivityLog
|
|
169
|
+
from users.signals import get_client_ip
|
|
170
|
+
|
|
171
|
+
UserActivityLog.objects.create(
|
|
172
|
+
user=request.user,
|
|
173
|
+
action='CREATE',
|
|
174
|
+
model_name='وثيقة',
|
|
175
|
+
object_id=document.pk,
|
|
176
|
+
number=document.number,
|
|
177
|
+
ip_address=get_client_ip(request),
|
|
178
|
+
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
2. **Using the helper function**:
|
|
183
|
+
```python
|
|
184
|
+
# Create a helper function in your app
|
|
185
|
+
def log_action(request, instance, action, model_name):
|
|
186
|
+
from users.models import UserActivityLog
|
|
187
|
+
from users.signals import get_client_ip
|
|
188
|
+
from django.utils import timezone
|
|
189
|
+
|
|
190
|
+
UserActivityLog.objects.create(
|
|
191
|
+
user=request.user,
|
|
192
|
+
action=action,
|
|
193
|
+
model_name=model_name,
|
|
194
|
+
object_id=instance.pk,
|
|
195
|
+
number=getattr(instance, 'number', ''),
|
|
196
|
+
timestamp=timezone.now(),
|
|
197
|
+
ip_address=get_client_ip(request),
|
|
198
|
+
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
# Usage in views
|
|
202
|
+
def update_order(request, order_id):
|
|
203
|
+
order = get_object_or_404(Order, pk=order_id)
|
|
204
|
+
# ... update logic ...
|
|
205
|
+
log_action(request, order, 'UPDATE', 'طلب')
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
3. **Logging without an instance** (for general actions):
|
|
209
|
+
```python
|
|
210
|
+
def log_general_action(request, action, model_name, description=''):
|
|
211
|
+
from users.models import UserActivityLog
|
|
212
|
+
from users.signals import get_client_ip
|
|
213
|
+
from django.utils import timezone
|
|
214
|
+
|
|
215
|
+
UserActivityLog.objects.create(
|
|
216
|
+
user=request.user,
|
|
217
|
+
action=action,
|
|
218
|
+
model_name=model_name,
|
|
219
|
+
object_id=None,
|
|
220
|
+
number=description,
|
|
221
|
+
timestamp=timezone.now(),
|
|
222
|
+
ip_address=get_client_ip(request),
|
|
223
|
+
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
# Usage
|
|
227
|
+
log_general_action(request, 'CONFIRM', 'نظام', 'تم تأكيد الإعدادات')
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Available URLs
|
|
231
|
+
|
|
232
|
+
All user management URLs are prefixed with `manage/` as configured. Below is the complete list:
|
|
233
|
+
|
|
234
|
+
| URL Pattern | View/Function | Description |
|
|
235
|
+
|-------------|---------------|-------------|
|
|
236
|
+
| `manage/login/` | `auth_views.LoginView.as_view()` | User login |
|
|
237
|
+
| `manage/logout/` | `auth_views.LogoutView.as_view()` | User logout |
|
|
238
|
+
| `manage/users/` | `views.UserListView.as_view()` | List all users |
|
|
239
|
+
| `manage/users/create/` | `views.create_user` | Create new user |
|
|
240
|
+
| `manage/users/edit/<int:pk>/` | `views.edit_user` | Edit existing user |
|
|
241
|
+
| `manage/users/delete/<int:pk>/` | `views.delete_user` | Delete user |
|
|
242
|
+
| `manage/users/<int:pk>/` | `views.UserDetailView.as_view()` | View user details |
|
|
243
|
+
| `manage/profile` | `views.user_profile` | View current user profile |
|
|
244
|
+
| `manage/profile/edit/` | `views.edit_profile` | Edit current profile |
|
|
245
|
+
| `manage/logs/` | `views.UserActivityLogView.as_view()` | View activity logs |
|
|
246
|
+
| `manage/reset_password/<int:pk>/` | `views.reset_password` | Reset user password |
|
|
247
|
+
|
|
248
|
+
## Structure
|
|
249
|
+
```
|
|
250
|
+
users/
|
|
251
|
+
├── views.py # CRUD operations
|
|
252
|
+
├── urls.py # URL routing
|
|
253
|
+
├── tables.py # User and Activity Log tables
|
|
254
|
+
├── signals.py # Logging signals
|
|
255
|
+
├── models.py # User model, permissions, activity logs
|
|
256
|
+
├── forms.py # Creation, edit,. etc.
|
|
257
|
+
├── filter.py # Search filters
|
|
258
|
+
├── apps.py # Permissions Localization
|
|
259
|
+
├── admin.py # Admin UI integration
|
|
260
|
+
├── __init__.py # Python init
|
|
261
|
+
├── templates/ # HTML templates
|
|
262
|
+
├── static/ # CSS classes
|
|
263
|
+
└── migrations/ # Database migrations
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Version History
|
|
267
|
+
|
|
268
|
+
| Version | Changes |
|
|
269
|
+
|----------|---------|
|
|
270
|
+
| v1.0.0 | • Initial release as pip package |
|
|
271
|
+
| v1.0.1 | • Fixed a couple of new issues as a pip package |
|
|
272
|
+
| v1.0.2 | • Fixed the readme and building files |
|
|
273
|
+
| v1.0.3 | • Still getting the hang of this pip publish thing |
|
|
274
|
+
| v1.0.4 | • Honestly still messing with and trying settings and stuff out |
|
|
275
|
+
| v1.1.0 | • OK, finally a working seamless micro-users app |
|
|
276
|
+
| v1.1.1 | • Fixed an expolit where a staff member could disable the ADMIN user |
|
|
277
|
+
| v1.2.0 | • Added User Details view with specific user activity log |
|
|
278
|
+
| v1.2.1 | • Fixed a minor import bug |
|
|
279
|
+
| v1.2.2 | • Separated user detail view from table for consistency<br> • Optimized the new detail + log view for optimal compatibiliyy with users |
|
|
280
|
+
| v1.2.3 | • Fixed a couple of visual inconsistencies |
|
|
281
|
+
| v1.3.0 | • Patched a critical security permission issue<br> • Disabled ADMIN from being viewed/edited from all other members<br> • Fixed a crash when sorting with full_name<br> • Enabled Logging for all actions |
|
|
282
|
+
| v1.3.1 | • Corrected a misplaced code that caused a crash when editing profile |
|
|
283
|
+
| v1.3.2 | • Minor table modifications |
|
|
284
|
+
| v1.4.0 | • Redesigned Permissions UI (Grouped by App/Action) <br> • Added Global Bulk Permission Selectors <br> • Improved Arabic Localization for Permissions <br> • Optimized printing (hidden forms/buttons) <br> • Fixed various bugs and crashes |
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# Micro Users - Arabic Django User Management App
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/micro-users/)
|
|
4
|
+
|
|
5
|
+
**Arabic** lightweight, reusable Django app providing user management with abstract user, permissions, localization, and activity logging.
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
- **Must be installed on a fresh database.**
|
|
9
|
+
- Python 3.11+
|
|
10
|
+
- Django 5.1+
|
|
11
|
+
- django-crispy-forms 2.4+
|
|
12
|
+
- django-tables2 2.7+
|
|
13
|
+
- django-filter 24.3+
|
|
14
|
+
- pillow 11.0+
|
|
15
|
+
- babel 2.1+
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
- Custom AbstractUser model
|
|
19
|
+
- User permissions system
|
|
20
|
+
- Activity logging (login/logout, CRUD tracking)
|
|
21
|
+
- Specific User detail and log view *new*
|
|
22
|
+
- Localization support
|
|
23
|
+
- Admin interface integration
|
|
24
|
+
- CRUD views and templates
|
|
25
|
+
- Filtering and tabulation
|
|
26
|
+
> *Future updates are planned to support dynamic language switching between RTL and LTR.*
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install git+https://github.com/debeski/micro-users.git
|
|
32
|
+
# OR
|
|
33
|
+
pip install micro-users
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Configuration
|
|
37
|
+
|
|
38
|
+
1. Add to `INSTALLED_APPS`:
|
|
39
|
+
```python
|
|
40
|
+
INSTALLED_APPS = [
|
|
41
|
+
'users', # Preferably on top
|
|
42
|
+
'django.contrib.admin',
|
|
43
|
+
'django.contrib.auth',
|
|
44
|
+
...
|
|
45
|
+
]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
2. Set custom user model in settings.py:
|
|
49
|
+
```python
|
|
50
|
+
AUTH_USER_MODEL = 'users.CustomUser'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. Include URLs in your main project folder `urls.py`:
|
|
54
|
+
```python
|
|
55
|
+
urlpatterns = [
|
|
56
|
+
...
|
|
57
|
+
path('manage/', include('users.urls')),
|
|
58
|
+
]
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
4. Run migrations:
|
|
62
|
+
```bash
|
|
63
|
+
python manage.py migrate users
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## How to Use
|
|
67
|
+
|
|
68
|
+
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.
|
|
69
|
+
|
|
70
|
+
### Activity Logging
|
|
71
|
+
|
|
72
|
+
The app automatically logs **LOGIN** and **LOGOUT** actions. For custom logging of other actions in your application, you can use the following helper functions:
|
|
73
|
+
|
|
74
|
+
#### Available Helper Functions
|
|
75
|
+
|
|
76
|
+
1. **Get Client IP** - Extract the user's IP address from request:
|
|
77
|
+
```python
|
|
78
|
+
from users.signals import get_client_ip
|
|
79
|
+
|
|
80
|
+
# Usage in views
|
|
81
|
+
ip_address = get_client_ip(request)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
2. **Log User Action** - Create a reusable logging function:
|
|
85
|
+
```python
|
|
86
|
+
from django.utils import timezone
|
|
87
|
+
from users.models import UserActivityLog
|
|
88
|
+
from users.signals import get_client_ip
|
|
89
|
+
|
|
90
|
+
def log_user_action(request, instance, action, model_name):
|
|
91
|
+
"""
|
|
92
|
+
Logs a user action to the activity log.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
request: HttpRequest object
|
|
96
|
+
instance: The model instance being acted upon
|
|
97
|
+
action: Action type (see ACTION_TYPES below)
|
|
98
|
+
model_name: Name of the model/entity (in Arabic or English)
|
|
99
|
+
"""
|
|
100
|
+
UserActivityLog.objects.create(
|
|
101
|
+
user=request.user,
|
|
102
|
+
action=action,
|
|
103
|
+
model_name=model_name,
|
|
104
|
+
object_id=instance.pk,
|
|
105
|
+
number=instance.number if hasattr(instance, 'number') else '',
|
|
106
|
+
timestamp=timezone.now(),
|
|
107
|
+
ip_address=get_client_ip(request),
|
|
108
|
+
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
109
|
+
)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Action Types Available
|
|
113
|
+
Use these constants when logging actions:
|
|
114
|
+
|
|
115
|
+
| Action Constant | Arabic Display | Description |
|
|
116
|
+
|-----------------|----------------|-------------|
|
|
117
|
+
| `'LOGIN'` | تسجيل دخـول | User login (auto-logged) |
|
|
118
|
+
| `'LOGOUT'` | تسجيل خـروج | User logout (auto-logged) |
|
|
119
|
+
| `'CREATE'` | انشـاء | Object creation |
|
|
120
|
+
| `'UPDATE'` | تعديـل | Object modification |
|
|
121
|
+
| `'DELETE'` | حــذف | Object deletion |
|
|
122
|
+
| `'VIEW'` | عـرض | Object viewing |
|
|
123
|
+
| `'DOWNLOAD'` | تحميل | File download |
|
|
124
|
+
| `'CONFIRM'` | تأكيـد | Action confirmation |
|
|
125
|
+
| `'REJECT'` | رفــض | Action rejection |
|
|
126
|
+
| `'RESET'` | اعادة ضبط | Password/Data reset |
|
|
127
|
+
|
|
128
|
+
#### Usage Examples
|
|
129
|
+
|
|
130
|
+
1. **Logging a CREATE action**:
|
|
131
|
+
```python
|
|
132
|
+
def create_document(request):
|
|
133
|
+
# ... create logic ...
|
|
134
|
+
document = Document.objects.create(...)
|
|
135
|
+
|
|
136
|
+
# Log the action
|
|
137
|
+
from users.models import UserActivityLog
|
|
138
|
+
from users.signals import get_client_ip
|
|
139
|
+
|
|
140
|
+
UserActivityLog.objects.create(
|
|
141
|
+
user=request.user,
|
|
142
|
+
action='CREATE',
|
|
143
|
+
model_name='وثيقة',
|
|
144
|
+
object_id=document.pk,
|
|
145
|
+
number=document.number,
|
|
146
|
+
ip_address=get_client_ip(request),
|
|
147
|
+
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
2. **Using the helper function**:
|
|
152
|
+
```python
|
|
153
|
+
# Create a helper function in your app
|
|
154
|
+
def log_action(request, instance, action, model_name):
|
|
155
|
+
from users.models import UserActivityLog
|
|
156
|
+
from users.signals import get_client_ip
|
|
157
|
+
from django.utils import timezone
|
|
158
|
+
|
|
159
|
+
UserActivityLog.objects.create(
|
|
160
|
+
user=request.user,
|
|
161
|
+
action=action,
|
|
162
|
+
model_name=model_name,
|
|
163
|
+
object_id=instance.pk,
|
|
164
|
+
number=getattr(instance, 'number', ''),
|
|
165
|
+
timestamp=timezone.now(),
|
|
166
|
+
ip_address=get_client_ip(request),
|
|
167
|
+
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
# Usage in views
|
|
171
|
+
def update_order(request, order_id):
|
|
172
|
+
order = get_object_or_404(Order, pk=order_id)
|
|
173
|
+
# ... update logic ...
|
|
174
|
+
log_action(request, order, 'UPDATE', 'طلب')
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
3. **Logging without an instance** (for general actions):
|
|
178
|
+
```python
|
|
179
|
+
def log_general_action(request, action, model_name, description=''):
|
|
180
|
+
from users.models import UserActivityLog
|
|
181
|
+
from users.signals import get_client_ip
|
|
182
|
+
from django.utils import timezone
|
|
183
|
+
|
|
184
|
+
UserActivityLog.objects.create(
|
|
185
|
+
user=request.user,
|
|
186
|
+
action=action,
|
|
187
|
+
model_name=model_name,
|
|
188
|
+
object_id=None,
|
|
189
|
+
number=description,
|
|
190
|
+
timestamp=timezone.now(),
|
|
191
|
+
ip_address=get_client_ip(request),
|
|
192
|
+
user_agent=request.META.get("HTTP_USER_AGENT", ""),
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
# Usage
|
|
196
|
+
log_general_action(request, 'CONFIRM', 'نظام', 'تم تأكيد الإعدادات')
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Available URLs
|
|
200
|
+
|
|
201
|
+
All user management URLs are prefixed with `manage/` as configured. Below is the complete list:
|
|
202
|
+
|
|
203
|
+
| URL Pattern | View/Function | Description |
|
|
204
|
+
|-------------|---------------|-------------|
|
|
205
|
+
| `manage/login/` | `auth_views.LoginView.as_view()` | User login |
|
|
206
|
+
| `manage/logout/` | `auth_views.LogoutView.as_view()` | User logout |
|
|
207
|
+
| `manage/users/` | `views.UserListView.as_view()` | List all users |
|
|
208
|
+
| `manage/users/create/` | `views.create_user` | Create new user |
|
|
209
|
+
| `manage/users/edit/<int:pk>/` | `views.edit_user` | Edit existing user |
|
|
210
|
+
| `manage/users/delete/<int:pk>/` | `views.delete_user` | Delete user |
|
|
211
|
+
| `manage/users/<int:pk>/` | `views.UserDetailView.as_view()` | View user details |
|
|
212
|
+
| `manage/profile` | `views.user_profile` | View current user profile |
|
|
213
|
+
| `manage/profile/edit/` | `views.edit_profile` | Edit current profile |
|
|
214
|
+
| `manage/logs/` | `views.UserActivityLogView.as_view()` | View activity logs |
|
|
215
|
+
| `manage/reset_password/<int:pk>/` | `views.reset_password` | Reset user password |
|
|
216
|
+
|
|
217
|
+
## Structure
|
|
218
|
+
```
|
|
219
|
+
users/
|
|
220
|
+
├── views.py # CRUD operations
|
|
221
|
+
├── urls.py # URL routing
|
|
222
|
+
├── tables.py # User and Activity Log tables
|
|
223
|
+
├── signals.py # Logging signals
|
|
224
|
+
├── models.py # User model, permissions, activity logs
|
|
225
|
+
├── forms.py # Creation, edit,. etc.
|
|
226
|
+
├── filter.py # Search filters
|
|
227
|
+
├── apps.py # Permissions Localization
|
|
228
|
+
├── admin.py # Admin UI integration
|
|
229
|
+
├── __init__.py # Python init
|
|
230
|
+
├── templates/ # HTML templates
|
|
231
|
+
├── static/ # CSS classes
|
|
232
|
+
└── migrations/ # Database migrations
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Version History
|
|
236
|
+
|
|
237
|
+
| Version | Changes |
|
|
238
|
+
|----------|---------|
|
|
239
|
+
| v1.0.0 | • Initial release as pip package |
|
|
240
|
+
| v1.0.1 | • Fixed a couple of new issues as a pip package |
|
|
241
|
+
| v1.0.2 | • Fixed the readme and building files |
|
|
242
|
+
| v1.0.3 | • Still getting the hang of this pip publish thing |
|
|
243
|
+
| v1.0.4 | • Honestly still messing with and trying settings and stuff out |
|
|
244
|
+
| v1.1.0 | • OK, finally a working seamless micro-users app |
|
|
245
|
+
| v1.1.1 | • Fixed an expolit where a staff member could disable the ADMIN user |
|
|
246
|
+
| v1.2.0 | • Added User Details view with specific user activity log |
|
|
247
|
+
| v1.2.1 | • Fixed a minor import bug |
|
|
248
|
+
| v1.2.2 | • Separated user detail view from table for consistency<br> • Optimized the new detail + log view for optimal compatibiliyy with users |
|
|
249
|
+
| v1.2.3 | • Fixed a couple of visual inconsistencies |
|
|
250
|
+
| v1.3.0 | • Patched a critical security permission issue<br> • Disabled ADMIN from being viewed/edited from all other members<br> • Fixed a crash when sorting with full_name<br> • Enabled Logging for all actions |
|
|
251
|
+
| v1.3.1 | • Corrected a misplaced code that caused a crash when editing profile |
|
|
252
|
+
| v1.3.2 | • Minor table modifications |
|
|
253
|
+
| v1.4.0 | • Redesigned Permissions UI (Grouped by App/Action) <br> • Added Global Bulk Permission Selectors <br> • Improved Arabic Localization for Permissions <br> • Optimized printing (hidden forms/buttons) <br> • Fixed various bugs and crashes |
|