-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/user request (#72) Add userRequest model and update related f…
…iles This pull request adds a new Django model called userRequest.py, creates corresponding migrations, updates the admin site, and adds various improvements. The new model includes a userBitmap Celery task, a new reviewer field in datasetBitmapPosition, and a new notes field for the user. Changes: Added userRequest.py Added migrations for userRequest.py Updated admin.py Updated __init__.py Added userBitmap celery task Created 0045_datasetbitmapposition_reviewer.py with a new reviewer field Added update_user_bitmap_task Updated datasetBitmapPosition.py Updated admin.py Added profile__uid to user search in alignment with errors Renamed subscriber field to user Added notes field and appended latest note to changelog on save --------
- Loading branch information
1 parent
d7157e0
commit 2d0dd7b
Showing
11 changed files
with
226 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 5.0.8 on 2024-10-14 14:33 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('impresso', '0042_alter_userbitmap_subscriptions'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='UserRequest', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('date_created', models.DateTimeField(auto_now_add=True)), | ||
('date_last_modified', models.DateTimeField(auto_now=True)), | ||
('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected')], default='pending', max_length=10)), | ||
('change_logs', models.JSONField(blank=True, default=list, null=True)), | ||
('reviewer', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='review', to=settings.AUTH_USER_MODEL)), | ||
('subscriber', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='request', to=settings.AUTH_USER_MODEL)), | ||
('subscription', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='impresso.datasetbitmapposition')), | ||
], | ||
options={ | ||
'verbose_name': 'User Subscription Request', | ||
'verbose_name_plural': 'User Subscription Requests', | ||
'unique_together': {('subscriber', 'subscription')}, | ||
}, | ||
), | ||
] |
26 changes: 26 additions & 0 deletions
26
impresso/migrations/0044_rename_change_logs_userrequest_changelog_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 5.0.8 on 2024-10-14 14:40 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('impresso', '0043_userrequest'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='userrequest', | ||
old_name='change_logs', | ||
new_name='changelog', | ||
), | ||
migrations.AlterField( | ||
model_name='userrequest', | ||
name='reviewer', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='review', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
21 changes: 21 additions & 0 deletions
21
impresso/migrations/0045_datasetbitmapposition_reviewer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 5.0.8 on 2024-10-15 14:07 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('impresso', '0044_rename_change_logs_userrequest_changelog_and_more'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='datasetbitmapposition', | ||
name='reviewer', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='reviewed_datasets', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
24 changes: 24 additions & 0 deletions
24
impresso/migrations/0046_rename_subscriber_userrequest_user_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 5.0.8 on 2024-10-16 09:24 | ||
|
||
from django.conf import settings | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('impresso', '0045_datasetbitmapposition_reviewer'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='userrequest', | ||
old_name='subscriber', | ||
new_name='user', | ||
), | ||
migrations.AlterUniqueTogether( | ||
name='userrequest', | ||
unique_together={('user', 'subscription')}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.8 on 2024-10-16 09:59 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('impresso', '0046_rename_subscriber_userrequest_user_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='userrequest', | ||
name='notes', | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from django.db import models | ||
from django.contrib.auth.models import User | ||
from .datasetBitmapPosition import DatasetBitmapPosition | ||
|
||
|
||
class UserRequest(models.Model): | ||
STATUS_PENDING = "pending" | ||
STATUS_APPROVED = "approved" | ||
STATUS_REJECTED = "rejected" | ||
|
||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="request") | ||
reviewer = models.ForeignKey( | ||
User, on_delete=models.SET_NULL, related_name="review", null=True, blank=True | ||
) | ||
subscription = models.ForeignKey( | ||
DatasetBitmapPosition, on_delete=models.SET_NULL, null=True | ||
) | ||
date_created = models.DateTimeField(auto_now_add=True) | ||
date_last_modified = models.DateTimeField(auto_now=True) | ||
status = models.CharField( | ||
max_length=10, | ||
default=STATUS_PENDING, | ||
choices=( | ||
(STATUS_PENDING, "Pending"), | ||
(STATUS_APPROVED, "Approved"), | ||
(STATUS_REJECTED, "Rejected"), | ||
), | ||
) | ||
changelog = models.JSONField(null=True, blank=True, default=list) | ||
notes = models.TextField(null=True, blank=True) | ||
|
||
def __str__(self): | ||
return f"{self.user.username} Request for {self.subscription.name if self.subscription else '[deleted subscription]'}" | ||
|
||
class Meta: | ||
unique_together = ("user", "subscription") | ||
verbose_name = "User Subscription Request" | ||
verbose_name_plural = "User Subscription Requests" | ||
|
||
def save(self, *args, **kwargs): | ||
if self.pk: | ||
# Prepare the new changelog entry | ||
changelog_entry = { | ||
"status": self.status, | ||
"subscription": self.subscription.name if self.subscription else None, | ||
"date": self.date_last_modified.isoformat(), | ||
"reviewer": self.reviewer.username if self.reviewer else None, | ||
"notes": self.notes if self.notes else "", | ||
} | ||
|
||
# Append the new entry to the changelog list | ||
self.changelog.append(changelog_entry) | ||
|
||
super().save(*args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from ...models import UserBitmap | ||
|
||
|
||
def update_user_bitmap(user_id): | ||
user_bitmap = UserBitmap.objects.get(user_id=user_id) | ||
bitmap = user_bitmap.get_up_to_date_bitmap() | ||
bitmap_bytes = bitmap.to_bytes((user_bitmap.bit_length() + 7) // 8, byteorder="big") | ||
user_bitmap.bitmap = bitmap_bytes | ||
user_bitmap.save() |