import re

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from user import tokens
from user.models import User

REGEX_PATTERN = getattr(settings, 'REGEX_HACKATHON_ORGANIZER_EMAIL', None)


# MAke user organizer if fits regex
@receiver(post_save, sender=User)
def user_organizer(sender, instance, created, *args, **kwargs):
    if not REGEX_PATTERN or not created:
        return None
    if re.match(REGEX_PATTERN, instance.email):
        instance.is_organizer = True
        instance.save()


# Send user verification
@receiver(post_save, sender=User)
def user_verify_email(sender, instance, created, *args, **kwargs):
    if created and not instance.email_verified:
        msg = tokens.generate_verify_email(instance)
        msg.send()

import re

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from user import tokens
from user.models import User

REGEX_PATTERN = getattr(settings, 'REGEX_HACKATHON_ORGANIZER_EMAIL', None)
DEV_EMAILS = getattr(settings, 'HACKATHON_DEV_EMAILS', None)


# Make user organizer or admin if fits regex
@receiver(post_save, sender=User)
def user_organizer(sender, instance, created, *args, **kwargs):
    if not created:
        return None

    if REGEX_PATTERN and re.match(REGEX_PATTERN, instance.email):
        instance.is_organizer = True
        instance.save()

    if DEV_EMAILS and instance.email in DEV_EMAILS:
        instance.is_admin = True
        instance.save()


# Send user verification
@receiver(post_save, sender=User)
def user_verify_email(sender, instance, created, *args, **kwargs):
    if created and not instance.email_verified:
        msg = tokens.generate_verify_email(instance)
        msg.send()

Make developers an admin on registration
Make developers an admin on registration

  import re
  
  from django.conf import settings
  from django.db.models.signals import post_save
  from django.dispatch import receiver
  
  from user import tokens
  from user.models import User
  
  REGEX_PATTERN = getattr(settings, 'REGEX_HACKATHON_ORGANIZER_EMAIL', None)
+ DEV_EMAILS = getattr(settings, 'HACKATHON_DEV_EMAILS', None)
  
  
- # MAke user organizer if fits regex
+ # Make user organizer or admin if fits regex
  @receiver(post_save, sender=User)
  def user_organizer(sender, instance, created, *args, **kwargs):
-     if not REGEX_PATTERN or not created:
+     if not created:
          return None
+ 
-     if re.match(REGEX_PATTERN, instance.email):
+     if REGEX_PATTERN and re.match(REGEX_PATTERN, instance.email):
          instance.is_organizer = True
+         instance.save()
+ 
+     if DEV_EMAILS and instance.email in DEV_EMAILS:
+         instance.is_admin = True
          instance.save()
  
  
  # Send user verification
  @receiver(post_save, sender=User)
  def user_verify_email(sender, instance, created, *args, **kwargs):
      if created and not instance.email_verified:
          msg = tokens.generate_verify_email(instance)
          msg.send()
  
Make developers an admin on registration
## Code Before:
import re

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from user import tokens
from user.models import User

REGEX_PATTERN = getattr(settings, 'REGEX_HACKATHON_ORGANIZER_EMAIL', None)


# MAke user organizer if fits regex
@receiver(post_save, sender=User)
def user_organizer(sender, instance, created, *args, **kwargs):
    if not REGEX_PATTERN or not created:
        return None
    if re.match(REGEX_PATTERN, instance.email):
        instance.is_organizer = True
        instance.save()


# Send user verification
@receiver(post_save, sender=User)
def user_verify_email(sender, instance, created, *args, **kwargs):
    if created and not instance.email_verified:
        msg = tokens.generate_verify_email(instance)
        msg.send()

## Instruction:
Make developers an admin on registration
## Code After:
import re

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

from user import tokens
from user.models import User

REGEX_PATTERN = getattr(settings, 'REGEX_HACKATHON_ORGANIZER_EMAIL', None)
DEV_EMAILS = getattr(settings, 'HACKATHON_DEV_EMAILS', None)


# Make user organizer or admin if fits regex
@receiver(post_save, sender=User)
def user_organizer(sender, instance, created, *args, **kwargs):
    if not created:
        return None

    if REGEX_PATTERN and re.match(REGEX_PATTERN, instance.email):
        instance.is_organizer = True
        instance.save()

    if DEV_EMAILS and instance.email in DEV_EMAILS:
        instance.is_admin = True
        instance.save()


# Send user verification
@receiver(post_save, sender=User)
def user_verify_email(sender, instance, created, *args, **kwargs):
    if created and not instance.email_verified:
        msg = tokens.generate_verify_email(instance)
        msg.send()
