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 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 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 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 is_full(self): max_team_size = Settings.get().max_team_size return max_team_size != 0 and len(self.members) >= max_team_size