Browse Source

Check for shadowcalls on user registration, copy data if necessary

Sebastian Lohff 3 years ago
parent
commit
8018706715
2 changed files with 21 additions and 1 deletions
  1. 3
    1
      contest/models.py
  2. 18
    0
      contest/signals.py

+ 3
- 1
contest/models.py View File

@@ -5,9 +5,10 @@ import datetime
5 5
 from django.db import models
6 6
 from django.contrib.auth.models import AbstractUser
7 7
 from django.core.validators import RegexValidator
8
-from django.db.models import Q
8
+from django.db.models import Q, signals
9 9
 
10 10
 from .validators import CallUsernameValidator
11
+from .signals import checkForShadowCall
11 12
 
12 13
 class Contest(models.Model):
13 14
 	name = models.CharField(max_length=20)
@@ -63,6 +64,7 @@ class User(AbstractUser):
63 64
 
64 65
 	def getCfmdRefCount(self):
65 66
 		return len(set(map(lambda _x: _x["refStr"], self.qso_set.filter(ref__isnull=False).values("ref", "refStr"))))
67
+signals.post_save.connect(checkForShadowCall, sender=User)
66 68
 
67 69
 class Band(models.Model):
68 70
 	name = models.CharField(max_length=10)

+ 18
- 0
contest/signals.py View File

@@ -0,0 +1,18 @@
1
+
2
+def checkForShadowCall(sender, instance, created, raw, **kwargs):
3
+	""" Check for existing shadow call. If present copy it's data and delete it. """
4
+	if created:
5
+		# to prevent circular imports we import ShadowCall here
6
+		from .models import ShadowCall
7
+
8
+		try:
9
+			shadow = ShadowCall.objects.get(username=instance.username)
10
+			instance.ref = shadow.ref
11
+			instance.location = shadow.location
12
+			instance.opName = shadow.opName
13
+			instance.regTime = shadow.regTime
14
+
15
+			instance.save()
16
+			shadow.delete()
17
+		except ShadowCall.DoesNotExist:
18
+			pass

Loading…
Cancel
Save