def cycle_waitlist(): # get the current waitlist waitlist = list(Hacker.objects.filter(waitlist=True).order_by('waitlist_date')) # while the event is not full and there are waitlisted hackers while not Settings.is_full() and len(waitlist) > 0: hacker = waitlist.pop(0) # Hacker can be waitlisted but not in waitlist(e.g late) if hacker.profile.state == 'waitlist': hacker.unwaitlist()
def calc_ticket_expires(): # Calculates the ticket expire time based on the settings now = timezone.now() settings = Settings.get() if settings.ticket_expire != 0: expires_at = now + timedelta(minutes=settings.ticket_expire) else: # if expire is disabled, expire in 1 year expires_at = now + timedelta(weeks=52) return expires_at
def calc_ticket_expires(): # Calculates the ticket expire time based on the settings now = timezone.now() settings = Settings.get() if settings.ticket_expire != 0: expires_at = now + timedelta(minutes=settings.ticket_expire) else: # if expire is disabled, expire in 1 year expires_at = now + timedelta(weeks=52) return expires_at
def hacker_state(self): if self.checked_in: return 'checkedin' if self.confirmed: return "confirmed" if not Settings.can_confirm(self.waitlist): return "late" if self.withdraw: return "withdraw" if self.waitlist: return "waitlist" if self.admitted: return "admitted" if self.declined: return "declined" if hasattr(self, 'application'): return "submitted" if not Settings.registration_is_open(): return "late" return "incomplete"
def change_email(self, email): user = self.user user.email = email user.save() if Settings.get().verify_email: self.verified = False self.new_verification_code() send_verify_email.delay(self.id) else: self.verified = True self.save()
def admit(self, send_email=True): # Admit hacker and send notification email # Also called when a hacker that has withdrowned changes their mind self.admitted = True self.declined = False self.waitlist = False self.withdraw = False self.save() if Settings.is_full(): # If event is full return self.put_on_waitlist(send_email) if send_email: tasks.send_notify_admitted.delay(self.id)
def admit(self, send_email=True): # Admit hacker and send notification email # Also called when a hacker that has withdrowned changes their mind self.admitted = True self.declined = False self.waitlist = False self.withdraw = False self.save() if Settings.is_full(): # If event is full return self.put_on_waitlist(send_email) if send_email: tasks.send_notify_admitted.delay(self.id)
def hacker_state(self): # If the user submitted an application but didn't pay (i.e. asked for a refund or something) if Settings.get().require_payment and not self.payed and hasattr( self, 'application'): return 'unpaid' if self.checked_in: return 'checkedin' if self.confirmed: return "confirmed" if not Settings.can_confirm(self.waitlist): return "late" if self.withdraw: return "withdraw" if self.waitlist: return "waitlist" if self.admitted: return "admitted" if self.declined: return "declined" if hasattr(self, 'application'): return "submitted" if not Settings.registration_is_open(): return "late" return "incomplete"
def save(self, commit=True, hacker=None): data = self.cleaned_data first_name = data['first_name'] last_name = data['last_name'] email = data['email'] user = hacker.profile.user user.first_name = first_name user.last_name = last_name user.save() if email != user.email: user.profile.change_email(email) instance = forms.ModelForm.save(self, False) instance.hacker = hacker if commit: instance.save() if Settings.get().auto_admit_hackers(): hacker.admit(False) return instance
def get_redirect_url(self, *args, **kwargs): sett = Settings.get() if not sett.require_payment: add_message(self.request, ERROR, 'Pagamentos desabilitados') return '/' item = PagSeguroItem( id='1', description=f'Ingresso para {settings.EVENT_NAME}', amount=f'{sett.ticket_price}', quantity=1 ) reference = get_random_string(length=32) api = PagSeguroApi(reference=reference) api.add_item(item) checkout = api.checkout() if checkout['success']: hacker = self.request.user.profile.hacker hacker.transaction_reference = reference hacker.save() return checkout['redirect_url'] else: add_message(self.request, ERROR, 'Erro ao criar pedido de pagamento. Tente novamente mais tarde.') return '/'
def is_full(self): max_team_size = Settings.get().max_team_size return max_team_size != 0 and len(self.members) >= max_team_size
def create_or_update(**kwargs): # Creates or updates a Social instance. Also creates User if email does not exist user = kwargs.pop('user') request = kwargs.pop('request', None) first_name = kwargs.pop('first_name') last_name = kwargs.pop('last_name') social_id = kwargs.pop('social_id') name = f'{first_name} {last_name}' user_created = False social_created = False temp_email = False email = kwargs.pop('email') if not email or email is None: email = Social.unique_email() temp_email = True social = Social.objects.filter(social_id=social_id) if social.exists(): user = social.first().profile.user # If the social email is not temporary and the user is not verified if not temp_email and not user.profile.is_verified: # update the user email and verify them user.email = email user.save() profile = user.profile profile.verified = True profile.save() else: try: if user is None: user = User.objects.get(email=email) except User.DoesNotExist: # Only create users if registration is open if not Settings.registration_is_open(): if request is not None: messages.add_message(request, messages.INFO, 'Período de registro fechado!') return None, user_created, social_created, request user = User( first_name=first_name, last_name=last_name, username=Social.unique_username(name), email=email ) user.save() user_created = True if not temp_email: profile = user.profile profile.verified = True profile.save() # New user created if Settings.default_hacker(): from hacker.models import Hacker Hacker(profile=user.profile).save() if Settings.default_staff(): from staff.models import Staff Staff(profile=user.profile).save() profile = user.profile try: social, social_created = Social.objects.update_or_create( profile=profile, social_id=social_id, provider=kwargs['provider'], defaults=kwargs ) except IntegrityError: messages.add_message(request, messages.ERROR, f"Parece que alguém já tentou se inscrever com esse perfil do {kwargs['provider']}") return None, user_created, social_created, request return social, user_created, social_created, request
def create_or_update(**kwargs): # Creates or updates a Social instance. Also creates User if email does not exist user = kwargs.pop('user') request = kwargs.pop('request', None) first_name = kwargs.pop('first_name') last_name = kwargs.pop('last_name') social_id = kwargs.pop('social_id') name = f'{first_name} {last_name}' user_created = False social_created = False temp_email = False email = kwargs.pop('email') if not email or email is None: email = Social.unique_email() temp_email = True social = Social.objects.filter(social_id=social_id) if social.exists(): user = social.first().profile.user # If the social email is not temporary and the user is not verified if not temp_email and not user.profile.is_verified: # update the user email and verify them user.email = email user.save() profile = user.profile profile.verified = True profile.save() else: try: if user is None: user = User.objects.get(email=email) except User.DoesNotExist: # Only create users if registration is open if not Settings.registration_is_open(): if request is not None: messages.add_message(request, messages.INFO, 'Período de registro fechado!') return None, user_created, social_created, request user = User(first_name=first_name, last_name=last_name, username=Social.unique_username(name), email=email) user.save() user_created = True if not temp_email: profile = user.profile profile.verified = True profile.save() # New user created if Settings.default_hacker(): from hacker.models import Hacker Hacker(profile=user.profile).save() if Settings.default_staff(): from staff.models import Staff Staff(profile=user.profile).save() profile = user.profile try: social, social_created = Social.objects.update_or_create( profile=profile, social_id=social_id, provider=kwargs['provider'], defaults=kwargs) except IntegrityError: messages.add_message( request, messages.ERROR, f"Parece que alguém já tentou se inscrever com esse perfil do {kwargs['provider']}" ) return None, user_created, social_created, request return social, user_created, social_created, request