Example #1
0
 def save(self, email_template=None, use_https=False, token_generator=default_token_generator, from_email=None, request=None, domain=None, **kwargs):
     if not email_template:
         email_template = auth.default_registration_template()
     user = self.get_existing_user()
     if user is None:
         email = self.cleaned_data['email']
         username = email
         if len(username) > 30:
             username = email[:30]
         AuthUser = get_user_model()
         tries = 0
         while user is None and tries < 5:
             try:
                 user = AuthUser.objects.create(
                     username=username, email=email, is_active=False)
             except django.db.utils.IntegrityError as e:
                 tries += 1
                 username = tracker.util.random_num_replace(
                     username, 8, max_length=30)
         if tries >= 5:
             raise forms.ValidationError(
                 'Something horrible happened, please try again')
     if domain is None:
         domain = viewutil.get_request_server_url(request)
     return auth.send_registration_mail(domain, user, template=email_template, sender=from_email, token_generator=token_generator)
 def save(self, email_template_name=None, use_https=False, token_generator=default_token_generator, from_email=None, request=None, email_template=None, **kwargs):
     if not email_template:
         email_template = email_template_name
     if not email_template:
         email_template = auth.default_password_reset_template()
     user = self.get_user()
     domain = viewutil.get_request_server_url(request)
     return auth.send_password_reset_mail(domain, user, email_template, sender=from_email, token_generator=token_generator)
Example #3
0
 def save(self, email_template_name=None, use_https=False, token_generator=default_token_generator, from_email=None, request=None, email_template=None, **kwargs):
     if not email_template:
         email_template = email_template_name
     if not email_template:
         email_template = auth.default_password_reset_template()
     user = self.get_user()
     domain = viewutil.get_request_server_url(request)
     return auth.send_password_reset_mail(domain, user, email_template, sender=from_email, token_generator=token_generator)
 def save(self, email_template=None, use_https=False, token_generator=default_token_generator, from_email=None, request=None, **kwargs):
     if not email_template:
         email_template = auth.default_registration_template()
     user = self.get_existing_user()
     email = self.cleaned_data['email']
     if user is None:
         AuthUser = get_user_model()
         user = AuthUser.objects.create(username=email,email=email,is_active=False)
     domain = viewutil.get_request_server_url(request)
     return auth.send_registration_mail(domain, user, template=email_template, sender=from_email, token_generator=token_generator)
Example #5
0
 def save(self,
          email_template=None,
          use_https=False,
          token_generator=default_token_generator,
          from_email=None,
          request=None,
          **kwargs):
     if not email_template:
         email_template = auth.default_registration_template()
     user = self.get_existing_user()
     email = self.cleaned_data['email']
     if user is None:
         AuthUser = get_user_model()
         user = AuthUser.objects.create(username=email,
                                        email=email,
                                        is_active=False)
     domain = viewutil.get_request_server_url(request)
     return auth.send_registration_mail(domain,
                                        user,
                                        template=email_template,
                                        sender=from_email,
                                        token_generator=token_generator)
Example #6
0
 def save(self,
          email_template=None,
          use_https=False,
          token_generator=default_token_generator,
          from_email=None,
          request=None,
          domain=None,
          **kwargs):
     if not email_template:
         email_template = auth.default_registration_template()
     user = self.get_existing_user()
     if user is None:
         email = self.cleaned_data['email']
         username = email
         if len(username) > 30:
             username = email[:30]
         AuthUser = get_user_model()
         tries = 0
         while user is None and tries < 5:
             try:
                 user = AuthUser.objects.create(username=username,
                                                email=email,
                                                is_active=False)
             except django.db.utils.IntegrityError as e:
                 tries += 1
                 username = tracker.util.random_num_replace(username,
                                                            8,
                                                            max_length=30)
         if tries >= 5:
             raise forms.ValidationError(
                 'Something horrible happened, please try again')
     if domain is None:
         domain = viewutil.get_request_server_url(request)
     return auth.send_registration_mail(domain,
                                        user,
                                        template=email_template,
                                        sender=from_email,
                                        token_generator=token_generator)
Example #7
0
def donate(request, event):
  event = viewutil.get_event(event)
  if event.locked:
    raise Http404
  bidsFormPrefix = "bidsform"
  prizeFormPrefix = "prizeForm"
  if request.method == 'POST':
    commentform = DonationEntryForm(data=request.POST)
    if commentform.is_valid():
      prizesform = PrizeTicketFormSet(amount=commentform.cleaned_data['amount'], data=request.POST, prefix=prizeFormPrefix)
      bidsform = DonationBidFormSet(amount=commentform.cleaned_data['amount'], data=request.POST, prefix=bidsFormPrefix)
      if bidsform.is_valid() and prizesform.is_valid():
        try:
          donation = Donation(amount=commentform.cleaned_data['amount'], timereceived=pytz.utc.localize(datetime.datetime.utcnow()), domain='PAYPAL', domainId=str(random.getrandbits(128)), event=event, testdonation=event.usepaypalsandbox)
          if commentform.cleaned_data['comment']:
            donation.comment = commentform.cleaned_data['comment']
            donation.commentstate = "PENDING"
          donation.requestedvisibility = commentform.cleaned_data['requestedvisibility']
          donation.requestedalias = commentform.cleaned_data['requestedalias']
          donation.requestedemail = commentform.cleaned_data['requestedemail']
          donation.currency = event.paypalcurrency
          donation.save()
          for bidform in bidsform:
            if 'bid' in bidform.cleaned_data and bidform.cleaned_data['bid']:
              bid = bidform.cleaned_data['bid']
              if bid.allowuseroptions:
                # unfortunately, you can't use get_or_create when using a non-atomic transaction
                # this does technically introduce a race condition, I'm just going to hope that two people don't
                # suggest the same option at the exact same time
                # also, I want to do case-insensitive comparison on the name
                try:
                  bid = Bid.objects.get(event=bid.event, speedrun=bid.speedrun, name__iexact=bidform.cleaned_data['customoptionname'], parent=bid)
                except Bid.DoesNotExist:
                  bid = Bid.objects.create(event=bid.event, speedrun=bid.speedrun, name=bidform.cleaned_data['customoptionname'], parent=bid, state='PENDING', istarget=True)
              donation.bids.add(DonationBid(bid=bid, amount=Decimal(bidform.cleaned_data['amount'])))
          for prizeform in prizesform:
            if 'prize' in prizeform.cleaned_data and prizeform.cleaned_data['prize']:
              prize = prizeform.cleaned_data['prize']
              donation.tickets.add(PrizeTicket(prize=prize, amount=Decimal(prizeform.cleaned_data['amount'])))
          donation.full_clean()
          donation.save()
        except Exception as e:
          transaction.rollback()
          raise e

        serverURL = viewutil.get_request_server_url(request)

        paypal_dict = {
          "amount": str(donation.amount),
          "cmd": "_donations",
          "business": donation.event.paypalemail,
          "item_name": donation.event.receivername,
          "notify_url": serverURL + reverse('tracker.views.ipn'),
          "return_url": serverURL + reverse('tracker.views.paypal_return'),
          "cancel_return": serverURL + reverse('tracker.views.paypal_cancel'),
          "custom": str(donation.id) + ":" + donation.domainId,
          "currency_code": donation.event.paypalcurrency,
        }
        # Create the form instance
        form = PayPalPaymentsForm(button_type="donate", sandbox=donation.event.usepaypalsandbox, initial=paypal_dict)
        context = {"event": donation.event, "form": form }
        return tracker_response(request, "tracker/paypal_redirect.html", context)
    else:
      bidsform = DonationBidFormSet(amount=Decimal('0.00'), data=request.POST, prefix=bidsFormPrefix)
      prizesform = PrizeTicketFormSet(amount=Decimal('0.00'), data=request.POST, prefix=prizeFormPrefix)
  else:
    commentform = DonationEntryForm()
    bidsform = DonationBidFormSet(amount=Decimal('0.00'), prefix=bidsFormPrefix)
    prizesform = PrizeTicketFormSet(amount=Decimal('0.00'), prefix=prizeFormPrefix)

  def bid_parent_info(bid):
    if bid != None:
      return {'name': bid.name, 'description': bid.description, 'parent': bid_parent_info(bid.parent) }
    else:
      return None

  def bid_info(bid):
    result = {
      'id': bid.id,
      'name': bid.name,
      'description': bid.description,
      'label': bid.full_label(not bid.allowuseroptions),
      'count': bid.count,
      'amount': bid.total,
      'goal': Decimal(bid.goal or '0.00'),
      'parent': bid_parent_info(bid.parent)
    }
    if bid.speedrun:
      result['runname'] = bid.speedrun.name
    if bid.suggestions.exists():
      result['suggested'] = list(map(lambda x: x.name, bid.suggestions.all()))
    if bid.allowuseroptions:
      result['custom'] = ['custom']
      result['label'] += ' (select and add a name next to "New Option Name")'
    return result

  bids = filters.run_model_query('bidtarget', {'state':'OPENED', 'event':event.id }, user=request.user).distinct().select_related('parent').prefetch_related('suggestions')

  allPrizes = filters.run_model_query('prize', {'feed': 'current', 'event': event.id })

  prizes = allPrizes.filter(ticketdraw=False)

  dumpArray = [bid_info(o) for o in bids]
  bidsJson = json.dumps(dumpArray)

  ticketPrizes = allPrizes.filter(ticketdraw=True)

  def prize_info(prize):
    result = {'id': prize.id, 'name': prize.name, 'description': prize.description, 'minimumbid': prize.minimumbid, 'maximumbid': prize.maximumbid}
    return result

  dumpArray = [prize_info(o) for o in ticketPrizes.all()]
  ticketPrizesJson = json.dumps(dumpArray)

  return tracker_response(request, "tracker/donate.html", { 'event': event, 'bidsform': bidsform, 'prizesform': prizesform, 'commentform': commentform, 'hasBids': bids.count() > 0, 'bidsJson': bidsJson, 'hasTicketPrizes': ticketPrizes.count() > 0, 'ticketPrizesJson': ticketPrizesJson, 'prizes': prizes})
Example #8
0
def donate(request, event):
    event = viewutil.get_event(event)
    if event.locked:
        raise Http404
    bidsFormPrefix = "bidsform"
    prizeFormPrefix = "prizeForm"
    if request.method == 'POST':
        commentform = forms.DonationEntryForm(event=event, data=request.POST)
        if commentform.is_valid():
            prizesform = forms.PrizeTicketFormSet(
                amount=commentform.cleaned_data['amount'],
                data=request.POST,
                prefix=prizeFormPrefix)
            bidsform = forms.DonationBidFormSet(
                amount=commentform.cleaned_data['amount'],
                data=request.POST,
                prefix=bidsFormPrefix)
            if bidsform.is_valid() and prizesform.is_valid():
                with transaction.atomic():
                    donation = models.Donation(
                        amount=commentform.cleaned_data['amount'],
                        timereceived=pytz.utc.localize(
                            datetime.datetime.utcnow()),
                        domain='PAYPAL',
                        domainId=str(random.getrandbits(128)),
                        event=event,
                        testdonation=event.usepaypalsandbox)
                    if commentform.cleaned_data['comment']:
                        donation.comment = commentform.cleaned_data['comment']
                        donation.commentstate = "PENDING"
                    donation.requestedvisibility = commentform.cleaned_data[
                        'requestedvisibility']
                    donation.requestedalias = commentform.cleaned_data[
                        'requestedalias']
                    donation.requestedemail = commentform.cleaned_data[
                        'requestedemail']
                    donation.requestedsolicitemail = commentform.cleaned_data[
                        'requestedsolicitemail']
                    donation.currency = event.paypalcurrency
                    donation.save()
                    for bidform in bidsform:
                        if 'bid' in bidform.cleaned_data and bidform.cleaned_data[
                                'bid']:
                            bid = bidform.cleaned_data['bid']
                            if bid.allowuseroptions:
                                # unfortunately, you can't use get_or_create when using a non-atomic transaction
                                # this does technically introduce a race condition, I'm just going to hope that two people don't
                                # suggest the same option at the exact same time
                                # also, I want to do case-insensitive comparison on the name
                                try:
                                    bid = models.Bid.objects.get(
                                        event=bid.event,
                                        speedrun=bid.speedrun,
                                        name__iexact=bidform.
                                        cleaned_data['customoptionname'],
                                        parent=bid)
                                except models.Bid.DoesNotExist:
                                    bid = models.Bid.objects.create(
                                        event=bid.event,
                                        speedrun=bid.speedrun,
                                        name=bidform.
                                        cleaned_data['customoptionname'],
                                        parent=bid,
                                        state='PENDING',
                                        istarget=True)
                            donation.bids.add(
                                models.DonationBid(
                                    bid=bid,
                                    amount=Decimal(
                                        bidform.cleaned_data['amount'])))
                    for prizeform in prizesform:
                        if 'prize' in prizeform.cleaned_data and prizeform.cleaned_data[
                                'prize']:
                            prize = prizeform.cleaned_data['prize']
                            donation.tickets.add(
                                models.PrizeTicket(
                                    prize=prize,
                                    amount=Decimal(
                                        prizeform.cleaned_data['amount'])))
                    donation.full_clean()
                    donation.save()

                serverURL = viewutil.get_request_server_url(request)

                paypal_dict = {
                    "amount":
                    str(donation.amount),
                    "cmd":
                    "_donations",
                    "business":
                    donation.event.paypalemail,
                    "item_name":
                    donation.event.receivername,
                    "notify_url":
                    serverURL + reverse('tracker.views.ipn'),
                    "return_url":
                    serverURL + reverse('tracker.views.paypal_return'),
                    "cancel_return":
                    serverURL + reverse('tracker.views.paypal_cancel'),
                    "custom":
                    str(donation.id) + ":" + donation.domainId,
                    "currency_code":
                    donation.event.paypalcurrency,
                    "no_shipping":
                    0,
                }
                # Create the form instance
                form = PayPalPaymentsForm(
                    button_type="donate",
                    sandbox=donation.event.usepaypalsandbox,
                    initial=paypal_dict)
                context = {"event": donation.event, "form": form}
                return views_common.tracker_response(
                    request, "tracker/paypal_redirect.html", context)
        else:
            bidsform = forms.DonationBidFormSet(amount=Decimal('0.00'),
                                                data=request.POST,
                                                prefix=bidsFormPrefix)
            prizesform = forms.PrizeTicketFormSet(amount=Decimal('0.00'),
                                                  data=request.POST,
                                                  prefix=prizeFormPrefix)
    else:
        commentform = forms.DonationEntryForm(event=event)
        bidsform = forms.DonationBidFormSet(amount=Decimal('0.00'),
                                            prefix=bidsFormPrefix)
        prizesform = forms.PrizeTicketFormSet(amount=Decimal('0.00'),
                                              prefix=prizeFormPrefix)

    def bid_parent_info(bid):
        if bid != None:
            return {
                'name': bid.name,
                'description': bid.description,
                'parent': bid_parent_info(bid.parent)
            }
        else:
            return None

    def bid_info(bid):
        result = {
            'id': bid.id,
            'name': bid.name,
            'description': bid.description,
            'label': bid.full_label(not bid.allowuseroptions),
            'count': bid.count,
            'amount': bid.total,
            'goal': Decimal(bid.goal or '0.00'),
            'parent': bid_parent_info(bid.parent)
        }
        if bid.speedrun:
            result['runname'] = bid.speedrun.name
        if bid.suggestions.exists():
            result['suggested'] = list(
                map(lambda x: x.name, bid.suggestions.all()))
        if bid.allowuseroptions:
            result['custom'] = ['custom']
            result[
                'label'] += ' (select and add a name next to "New Option Name")'
        return result

    bids = filters.run_model_query(
        'bidtarget', {
            'state': 'OPENED',
            'event': event.id
        }, user=request.user).distinct().select_related(
            'parent').prefetch_related('suggestions')

    allPrizes = filters.run_model_query('prize', {
        'feed': 'current',
        'event': event.id
    })

    prizes = allPrizes.filter(ticketdraw=False)

    dumpArray = [bid_info(o) for o in bids]

    bidsJson = json.dumps(dumpArray,
                          ensure_ascii=False,
                          cls=serializers.json.DjangoJSONEncoder)

    ticketPrizes = allPrizes.filter(ticketdraw=True)

    def prize_info(prize):
        result = {
            'id': prize.id,
            'name': prize.name,
            'description': prize.description,
            'minimumbid': prize.minimumbid,
            'maximumbid': prize.maximumbid,
            'sumdonations': prize.sumdonations
        }
        return result

    dumpArray = [prize_info(o) for o in ticketPrizes.all()]
    ticketPrizesJson = json.dumps(dumpArray,
                                  ensure_ascii=False,
                                  cls=serializers.json.DjangoJSONEncoder)

    return views_common.tracker_response(
        request, "tracker/donate.html", {
            'event': event,
            'bidsform': bidsform,
            'prizesform': prizesform,
            'commentform': commentform,
            'hasBids': bids.count() > 0,
            'bidsJson': bidsJson,
            'hasTicketPrizes': ticketPrizes.count() > 0,
            'ticketPrizesJson': ticketPrizesJson,
            'prizes': prizes
        })
def donate(request, event):
  event = viewutil.get_event(event)
  if event.locked:
    raise Http404
  bidsFormPrefix = "bidsform"
  prizeFormPrefix = "prizeForm"
  if request.method == 'POST':
    commentform = forms.DonationEntryForm(event=event,data=request.POST)
    if commentform.is_valid():
      prizesform = forms.PrizeTicketFormSet(amount=commentform.cleaned_data['amount'], data=request.POST, prefix=prizeFormPrefix)
      bidsform = forms.DonationBidFormSet(amount=commentform.cleaned_data['amount'], data=request.POST, prefix=bidsFormPrefix)
      if bidsform.is_valid() and prizesform.is_valid():
        with transaction.atomic():
          donation = models.Donation(amount=commentform.cleaned_data['amount'], timereceived=pytz.utc.localize(datetime.datetime.utcnow()), domain='PAYPAL', domainId=str(random.getrandbits(128)), event=event, testdonation=event.usepaypalsandbox)
          if commentform.cleaned_data['comment']:
            donation.comment = commentform.cleaned_data['comment']
            donation.commentstate = "PENDING"
          donation.requestedvisibility = commentform.cleaned_data['requestedvisibility']
          donation.requestedalias = commentform.cleaned_data['requestedalias']
          donation.requestedemail = commentform.cleaned_data['requestedemail']
          donation.requestedsolicitemail = commentform.cleaned_data['requestedsolicitemail']
          donation.currency = event.paypalcurrency
          donation.save()
          for bidform in bidsform:
            if 'bid' in bidform.cleaned_data and bidform.cleaned_data['bid']:
              bid = bidform.cleaned_data['bid']
              if bid.allowuseroptions:
                # unfortunately, you can't use get_or_create when using a non-atomic transaction
                # this does technically introduce a race condition, I'm just going to hope that two people don't
                # suggest the same option at the exact same time
                # also, I want to do case-insensitive comparison on the name
                try:
                  bid = models.Bid.objects.get(event=bid.event, speedrun=bid.speedrun, name__iexact=bidform.cleaned_data['customoptionname'], parent=bid)
                except models.Bid.DoesNotExist:
                  bid = models.Bid.objects.create(event=bid.event, speedrun=bid.speedrun, name=bidform.cleaned_data['customoptionname'], parent=bid, state='PENDING', istarget=True)
              donation.bids.add(models.DonationBid(bid=bid, amount=Decimal(bidform.cleaned_data['amount'])), bulk=False)
          for prizeform in prizesform:
            if 'prize' in prizeform.cleaned_data and prizeform.cleaned_data['prize']:
              prize = prizeform.cleaned_data['prize']
              donation.tickets.add(models.PrizeTicket(prize=prize, amount=Decimal(prizeform.cleaned_data['amount'])), bulk=False)
          donation.full_clean()
          donation.save()

        serverURL = viewutil.get_request_server_url(request)

		print(serverURL + reverse('tracker:ipn'))

        paypal_dict = {
          "amount": str(donation.amount),
          "cmd": "_donations",
          "business": donation.event.paypalemail,
          "item_name": donation.event.receivername,
          "notify_url": serverURL + reverse('tracker:ipn'),
          "return_url": serverURL + reverse('tracker:paypal_return'),
          "cancel_return": serverURL + reverse('tracker:paypal_cancel'),
          "custom": str(donation.id) + ":" + donation.domainId,
          "currency_code": donation.event.paypalcurrency,
          "no_shipping": 0,
        }
        # Create the form instance
        form = PayPalPaymentsForm(button_type="donate", sandbox=donation.event.usepaypalsandbox, initial=paypal_dict)
        context = {"event": donation.event, "form": form }
        return views_common.tracker_response(request, "tracker/paypal_redirect.html", context)
    else:
      bidsform = forms.DonationBidFormSet(amount=Decimal('0.00'), data=request.POST, prefix=bidsFormPrefix)
      prizesform = forms.PrizeTicketFormSet(amount=Decimal('0.00'), data=request.POST, prefix=prizeFormPrefix)