Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
new model Hub Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
arojas1 committed Aug 18, 2023
1 parent 3d21de5 commit 57121e0
Show file tree
Hide file tree
Showing 21 changed files with 634 additions and 5 deletions.
11 changes: 10 additions & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from researchers.models import Researcher
from bclabels.models import BCLabel
from tklabels.models import TKLabel
from helpers.models import Notice, OpenToCollaborateNoticeURL
from helpers.models import Notice, OpenToCollaborateNoticeURL, HubActivity
from notifications.models import UserNotification
from projects.models import Project, ProjectCreator

Expand Down Expand Up @@ -80,6 +80,10 @@ def register(request):
invite.delete()

send_activation_email(request, user)
HubActivity.objects.create(
action_user_id=user.id,
action_type="New User"
)
return redirect('verify')
else:
messages.error(request, 'Invalid reCAPTCHA. Please try again.')
Expand Down Expand Up @@ -324,6 +328,11 @@ def invite_user(request):
send_invite_user_email(request, data)
# Save invitation instance
data.save()
HubActivity.objects.create(
action_user_id=data.sender.id,
action_type="Sign-Up Invitation",
recipient_email=data.email
)
return redirect('invite')
return render(request, 'accounts/invite.html', {'invite_form': invite_form})

Expand Down
36 changes: 36 additions & 0 deletions communities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def create_community(request):
affiliation = UserAffiliation.objects.prefetch_related('communities').get(user=request.user)
affiliation.communities.add(data)
affiliation.save()

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="New Community",
community_id=data.id,
action_account_type='community'
)
return redirect('confirm-community', data.id)
return render(request, 'communities/create-community.html', {'form': form})

Expand Down Expand Up @@ -861,6 +869,15 @@ def create_project(request, pk, source_proj_uuid=None, related=None):
# Create Activity
ProjectActivity.objects.create(project=data, activity=f'Project was created by {creator_name} | {community.community_name}')

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="Project Created",
project_id=data.id,
action_account_type = 'community',
community_id=community.id
)

# Add project to community projects
creator = ProjectCreator.objects.select_related('community').get(project=data)
creator.community = community
Expand Down Expand Up @@ -917,6 +934,15 @@ def edit_project(request, community_id, project_uuid):
editor_name = get_users_name(request.user)
ProjectActivity.objects.create(project=data, activity=f'Edits to Project were made by {editor_name}')

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="Project Edited",
project_id=data.id,
action_account_type = 'community',
community_id=community_id
)

instances = formset.save(commit=False)
for instance in instances:
if not instance.name or not instance.email:
Expand Down Expand Up @@ -1165,6 +1191,16 @@ def apply_labels(request, pk, project_uuid):
# send email to project creator
send_email_labels_applied(request, project, community)
messages.add_message(request, messages.SUCCESS, "Labels applied!")

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="Label(s) Applied",
community_id=community.id,
action_account_type='community',
project_id=project.id
)

return redirect('apply-labels', community.id, project.unique_id)

context = {
Expand Down
38 changes: 38 additions & 0 deletions helpers/migrations/0055_auto_20230815_1216.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 3.1.13 on 2023-08-15 16:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('helpers', '0054_auto_20230727_2152'),
]

operations = [
migrations.CreateModel(
name='HubActivity',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('action_user_id', models.IntegerField(blank=True, null=True)),
('action_account_type', models.CharField(blank=True, max_length=250, null=True)),
('recipient_id', models.IntegerField(blank=True, null=True)),
('recipient_email', models.EmailField(blank=True, max_length=254, null=True)),
('researcher_id', models.IntegerField(blank=True, null=True)),
('community_id', models.IntegerField(blank=True, null=True)),
('institution_id', models.IntegerField(blank=True, null=True)),
('project_id', models.IntegerField(blank=True, null=True)),
('project_link', models.URLField(blank=True, null=True)),
('action_type', models.CharField(choices=[('New Member Added', 'New Member Added'), ('Sign-Up Invitation', 'Sign-Up Invitation'), ('New User', 'New User'), ('New Researcher', 'New Researcher'), ('New Community', 'New Community'), ('New Institution', 'New Institution'), ('Project Edited', 'Project Edited'), ('Project Created', 'Project Created'), ('Contributor Added', 'Contributor Added'), ('Community Notified', 'Community Notified'), ('Label(s) Applied', 'Label(s) Applied'), ('Disclosure Notice(s) Added', 'Disclosure Notice(s) Added'), ('Engagement Notice Added', 'Engagement Notice Added')], max_length=30, null=True)),
('date', models.DateTimeField(auto_now_add=True, null=True)),
],
options={
'verbose_name': 'Hub Activity',
'verbose_name_plural': 'Hub Activity',
},
),
migrations.AlterModelOptions(
name='noticetranslation',
options={'verbose_name': 'Notice Translation', 'verbose_name_plural': 'Notice Translations'},
),
]
18 changes: 18 additions & 0 deletions helpers/migrations/0056_auto_20230816_1640.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.13 on 2023-08-16 20:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('helpers', '0055_auto_20230815_1216'),
]

operations = [
migrations.AlterField(
model_name='hubactivity',
name='action_type',
field=models.CharField(choices=[('New Member Added', 'New Member Added'), ('New User', 'New User'), ('New Researcher', 'New Researcher'), ('New Community', 'New Community'), ('New Institution', 'New Institution'), ('Project Edited', 'Project Edited'), ('Project Created', 'Project Created'), ('Community Notified', 'Community Notified'), ('Label(s) Applied', 'Label(s) Applied'), ('Disclosure Notice(s) Added', 'Disclosure Notice(s) Added'), ('Engagement Notice Added', 'Engagement Notice Added')], max_length=30, null=True),
),
]
21 changes: 21 additions & 0 deletions helpers/migrations/0057_auto_20230817_1235.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.1.13 on 2023-08-17 16:35

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('helpers', '0056_auto_20230816_1640'),
]

operations = [
migrations.RemoveField(
model_name='hubactivity',
name='recipient_email',
),
migrations.RemoveField(
model_name='hubactivity',
name='recipient_id',
),
]
17 changes: 17 additions & 0 deletions helpers/migrations/0058_remove_hubactivity_project_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.1.13 on 2023-08-17 16:36

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('helpers', '0057_auto_20230817_1235'),
]

operations = [
migrations.RemoveField(
model_name='hubactivity',
name='project_link',
),
]
17 changes: 17 additions & 0 deletions helpers/migrations/0059_remove_hubactivity_researcher_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.1.13 on 2023-08-17 16:39

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('helpers', '0058_remove_hubactivity_project_link'),
]

operations = [
migrations.RemoveField(
model_name='hubactivity',
name='researcher_id',
),
]
27 changes: 27 additions & 0 deletions helpers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,30 @@ def __str__(self):
class Meta:
verbose_name = 'Collections Care Notice Policy'
verbose_name_plural = 'Collections Care Notice Policy'

class HubActivity(models.Model):
TYPES = (
('New Member Added', 'New Member Added'),
('New User', 'New User'),
('New Researcher', 'New Researcher'),
('New Community', 'New Community'),
('New Institution', 'New Institution'),
('Project Edited', 'Project Edited'),
('Project Created', 'Project Created'),
('Community Notified', 'Community Notified'),
('Label(s) Applied', 'Label(s) Applied'),
('Disclosure Notice(s) Added', 'Disclosure Notice(s) Added'),
('Engagement Notice Added', 'Engagement Notice Added'),
)

action_user_id = models.IntegerField(null=True, blank=True)
action_account_type = models.CharField(max_length=250, null=True, blank=True)
community_id = models.IntegerField(null=True, blank=True)
institution_id = models.IntegerField(null=True, blank=True)
project_id = models.IntegerField(null=True, blank=True)
action_type = models.CharField(max_length=30, null=True, choices=TYPES)
date = models.DateTimeField(auto_now_add=True, null=True)

class Meta:
verbose_name = 'Hub Activity'
verbose_name_plural = 'Hub Activity'
60 changes: 60 additions & 0 deletions institutions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def create_institution(request):
# Add to user affiliations
affiliation.institutions.add(data)
affiliation.save()

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="New Institution",
institution_id=data.id,
action_account_type='institution'
)
return redirect('confirm-institution', data.id)
else:
form = CreateInstitutionForm()
Expand All @@ -117,6 +125,14 @@ def create_custom_institution(request):
# Add to user affiliations
affiliation.institutions.add(data)
affiliation.save()

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="New Institution",
institution_id=data.id,
action_account_type='institution'
)
return redirect('confirm-institution', data.id)
return render(request, 'institutions/create-custom-institution.html', {'noror_form': noror_form,})

Expand Down Expand Up @@ -291,6 +307,14 @@ def institution_notices(request, pk):
data = form.save(commit=False)
data.institution = institution
data.save()
# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="Engagement Notice Added",
project_id=data.id,
action_account_type = 'institution',
institution_id=institution.id
)
return redirect('institution-notices', institution.id)

context = {
Expand Down Expand Up @@ -610,6 +634,23 @@ def create_project(request, pk, source_proj_uuid=None, related=None):
# Create activity
ProjectActivity.objects.create(project=data, activity=f'Project was created by {name} | {institution.institution_name}')

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="Project Created",
project_id=data.id,
action_account_type = 'institution',
institution_id=institution.id
)

HubActivity.objects.create(
action_user_id=request.user.id,
action_type="Disclosure Notice(s) Added",
project_id=data.id,
action_account_type = 'institution',
institution_id=institution.id
)

# Add project to institution projects
creator = ProjectCreator.objects.select_related('institution').get(project=data)
creator.institution = institution
Expand Down Expand Up @@ -679,6 +720,15 @@ def edit_project(request, institution_id, project_uuid):
editor_name = get_users_name(request.user)
ProjectActivity.objects.create(project=data, activity=f'Edits to Project were made by {editor_name}')

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="Project Edited",
project_id=data.id,
action_account_type = 'institution',
institution_id=institution_id
)

instances = formset.save(commit=False)
for instance in instances:
if not instance.name or not instance.email:
Expand Down Expand Up @@ -795,6 +845,16 @@ def project_actions(request, pk, project_uuid):
# Add activity
ProjectActivity.objects.create(project=project, activity=f'{community.community_name} was notified by {name}')

# Adds activity to Hub Activity
HubActivity.objects.create(
action_user_id=request.user.id,
action_type="Community Notified",
community_id=community.id,
institution_id=institution.id,
action_account_type='institution',
project_id=project.id
)

# Create project status, first comment and notification
ProjectStatus.objects.create(project=project, community=community, seen=False) # Creates a project status for each community
ActionNotification.objects.create(community=community, notification_type='Projects', reference_id=str(project.unique_id), sender=request.user, title=title)
Expand Down
Loading

0 comments on commit 57121e0

Please sign in to comment.