Skip to content

Commit

Permalink
Merge pull request #531 from MetaPhase-Consulting/update/extend-hands…
Browse files Browse the repository at this point in the history
…hake-model

Update/extend handshake model
  • Loading branch information
scott062 authored May 25, 2021
2 parents af36a0e + 5d6ea26 commit 3cd12bb
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 8 deletions.
38 changes: 38 additions & 0 deletions talentmap_api/bidding/migrations/0004_auto_20210519_1439.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 2.2.18 on 2021-05-19 14:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('bidding', '0003_bidhandshake_owner'),
]

operations = [
migrations.AddField(
model_name='bidhandshake',
name='bidder_status',
field=models.CharField(choices=[('A', 'Handshake accepted'), ('D', 'Handshake declined')], max_length=2, null=True),
),
migrations.AddField(
model_name='bidhandshake',
name='date_accepted',
field=models.DateTimeField(null=True),
),
migrations.AddField(
model_name='bidhandshake',
name='date_declined',
field=models.DateTimeField(null=True),
),
migrations.AddField(
model_name='bidhandshake',
name='date_offered',
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name='bidhandshake',
name='date_revoked',
field=models.DateTimeField(null=True),
),
]
16 changes: 16 additions & 0 deletions talentmap_api/bidding/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,36 @@ class BidHandshake(models.Model):
('D', 'Handshake declined'),
]

BIDDER_STATUS_CHOICES = [
('A', 'Handshake accepted'),
('D', 'Handshake declined'),
]

bidder_perdet = models.CharField(max_length=255, null=False, help_text="The bidder being offered a handshake")
cp_id = models.CharField(max_length=255, null=False, help_text="The cycle position ID")
status = models.CharField(
max_length=2,
choices=STATUS_CHOICES,
default='O',
)
bidder_status = models.CharField(
max_length=2,
choices=BIDDER_STATUS_CHOICES,
null=True,
)
date_created = models.DateTimeField(auto_now_add=True)
update_date = models.DateTimeField(auto_now_add=True)
is_cdo_update = models.BooleanField(default=False)
owner = models.ForeignKey('user_profile.UserProfile', related_name='owner', null=False, on_delete=models.DO_NOTHING, help_text="The first to initiate the HS")
last_editing_user = models.ForeignKey('user_profile.UserProfile', related_name='bureau_user', null=False, on_delete=models.DO_NOTHING, help_text="The last offerer user to edit")
last_editing_bidder = models.ForeignKey('user_profile.UserProfile', related_name='bidder', null=True, on_delete=models.DO_NOTHING, help_text="The last acceptee/cdo to edit")

# Track dates of actions
date_offered = models.DateTimeField(auto_now_add=True, null=True)
date_revoked = models.DateTimeField(auto_now_add=False, null=True)
date_accepted = models.DateTimeField(auto_now_add=False, null=True)
date_declined = models.DateTimeField(auto_now_add=False, null=True)

class Meta:
managed = True
unique_together = ('cp_id', 'bidder_perdet',)
24 changes: 16 additions & 8 deletions talentmap_api/bidding/views/bidhandshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ def put(self, serializer, pk, cp_id, **ars):

# Revoke any previously offered handshakes for this cp_id
hsToArchive = BidHandshake.objects.exclude(bidder_perdet=pk).filter(cp_id=cp_id)
hsToArchive.update(last_editing_user=user, status='R', update_date=datetime.now())
hsToArchive.update(last_editing_user=user, status='R', update_date=datetime.now(), date_revoked=datetime.now())

if hs.exists():
hs.update(last_editing_user=user, status='O', update_date=datetime.now())
# If the handshake is re-offered, clear the bidder_status
hs.update(last_editing_user=user, status='O', bidder_status=None, update_date=datetime.now(),
date_offered=datetime.now())
bureauHandshakeNotification(pk, cp_id, True)
return Response(status=status.HTTP_204_NO_CONTENT)
else:
BidHandshake.objects.create(last_editing_user=user, owner=user, bidder_perdet=pk, cp_id=cp_id, status='O')
BidHandshake.objects.create(last_editing_user=user, owner=user, bidder_perdet=pk, cp_id=cp_id,
status='O', date_offered=datetime.now())
bureauHandshakeNotification(pk, cp_id, True)
return Response(status=status.HTTP_204_NO_CONTENT)

Expand All @@ -83,7 +86,8 @@ def delete(self, request, pk, cp_id, format=None):
return Response(status=status.HTTP_404_NOT_FOUND)
else:
user = UserProfile.objects.get(user=self.request.user)
hs.update(last_editing_user=user, bidder_perdet=pk, cp_id=cp_id, status='R', update_date=datetime.now())
hs.update(last_editing_user=user, bidder_perdet=pk, cp_id=cp_id, status='R',
update_date=datetime.now(), date_revoked=datetime.now())
bureauHandshakeNotification(pk, cp_id, False)
return Response(status=status.HTTP_204_NO_CONTENT)

Expand All @@ -108,7 +112,8 @@ def put(self, serializer, pk, cp_id, **ars):
if not BidHandshake.objects.filter(bidder_perdet=pk, cp_id=cp_id, status__in=['O', 'A', 'D']).exists():
return Response(status=status.HTTP_404_NOT_FOUND)
else:
hs.update(last_editing_bidder=user, status='A', is_cdo_update=True, update_date=datetime.now())
hs.update(last_editing_bidder=user, status='A', bidder_status='A', is_cdo_update=True,
update_date=datetime.now(), date_accepted=datetime.now())
cdoHandshakeNotification(pk, cp_id, True)
return Response(status=status.HTTP_204_NO_CONTENT)

Expand All @@ -122,7 +127,8 @@ def delete(self, request, pk, cp_id, format=None):
if not BidHandshake.objects.filter(bidder_perdet=pk, cp_id=cp_id, status__in=['O', 'A', 'D']).exists():
return Response(status=status.HTTP_404_NOT_FOUND)
else:
hs.update(last_editing_bidder=user, status='D', is_cdo_update=True, update_date=datetime.now())
hs.update(last_editing_bidder=user, status='D', bidder_status='D', is_cdo_update=True,
update_date=datetime.now(), date_declined=datetime.now())
cdoHandshakeNotification(pk, cp_id, False)
return Response(status=status.HTTP_204_NO_CONTENT)

Expand All @@ -148,7 +154,8 @@ def put(self, serializer, cp_id, **ars):
if not BidHandshake.objects.filter(bidder_perdet=user.emp_id, cp_id=cp_id, status__in=['O', 'A', 'D']).exists():
return Response(status=status.HTTP_404_NOT_FOUND)
else:
hs.update(last_editing_bidder=user, status='A', is_cdo_update=False, update_date=datetime.now())
hs.update(last_editing_bidder=user, status='A', bidder_status='A', is_cdo_update=False,
update_date=datetime.now(), date_accepted=datetime.now())
bidderHandshakeNotification(hs.first().owner, cp_id, user.emp_id, jwt, True)
return Response(status=status.HTTP_204_NO_CONTENT)

Expand All @@ -163,6 +170,7 @@ def delete(self, request, cp_id, format=None):
if not BidHandshake.objects.filter(bidder_perdet=user.emp_id, cp_id=cp_id, status__in=['O', 'A', 'D']).exists():
return Response(status=status.HTTP_404_NOT_FOUND)
else:
hs.update(last_editing_bidder=user, status='D', is_cdo_update=False, update_date=datetime.now())
hs.update(last_editing_bidder=user, status='D', bidder_status='D', is_cdo_update=False,
update_date=datetime.now(), date_declined=datetime.now())
bidderHandshakeNotification(hs.first().owner, cp_id, user.emp_id, jwt, False)
return Response(status=status.HTTP_204_NO_CONTENT)

0 comments on commit 3cd12bb

Please sign in to comment.