Esempio n. 1
0
class PostOfficePasswordResetForm(forms.Form):
    email = forms.EmailField(label=u'Email', max_length=254)

    def get_user(self):
        AuthUser = get_user_model()
        email = self.cleaned_data['email']
        userSet = AuthUser.objects.filter(email__iexact=email, is_active=True)
        if not userSet.exists():
            raise forms.ValidationError(
                'User with email {0} does not exist.'.format(email))
        elif userSet.count() != 1:
            raise forms.ValidationError(
                'More than one user has the e-mail {0}. Ideally this would be a db constraint, but django is stupid.'.format(email))
        return userSet[0]

    def clean_email(self):
        return self.get_user().email

    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)
Esempio n. 2
0
 def __init__(self, prizes, *args, **kwargs):
     super(AutomailPrizeContributorsForm, self).__init__(*args, **kwargs)
     self.choices = []
     prizes = filter(lambda prize: prize.handler, prizes)
     event = prizes[0].event if len(prizes) > 0 else None
     for prize in prizes:
         self.choices.append((prize.id, mark_safe(format_html(
             u'<a href="{0}">{1}</a> State: {2} (<a href="mailto:{3}">{3}</a>)', viewutil.admin_url(prize), prize, prize.get_state_display(), prize.handler.email))))
     self.fields['fromaddress'] = forms.EmailField(max_length=256, initial=prizemail.get_event_default_sender_email(
         event), required=True, label='From Address', help_text='Specify the e-mail you would like to identify as the sender')
     self.fields['replyaddress'] = forms.EmailField(
         max_length=256, required=False, label='Reply Address', help_text="If left blank this will be the same as the from address")
     self.fields['emailtemplate'] = forms.ModelChoiceField(queryset=post_office.models.EmailTemplate.objects.all(
     ), empty_label="Pick a template...", required=True, label='Email Template', help_text="Select an email template to use.")
     self.fields['prizes'] = forms.TypedMultipleChoiceField(choices=self.choices, initial=[
                                                            prize.id for prize in prizes], label='Prizes', empty_value='', widget=forms.widgets.CheckboxSelectMultiple)
Esempio n. 3
0
    def __init__(self, prizewinners, *args, **kwargs):
        super(AutomailPrizeShippingNotifyForm, self).__init__(*args, **kwargs)
        event = prizewinners[0].prize.event if len(prizewinners) > 0 else None
        self.fields['fromaddress'] = forms.EmailField(max_length=256, initial=prizemail.get_event_default_sender_email(
            event), required=True, label='From Address', help_text='Specify the e-mail you would like to identify as the sender')
        self.fields['replyaddress'] = forms.EmailField(
            max_length=256, required=False, label='Reply Address', help_text="If left blank this will be the same as the from address")
        self.fields['emailtemplate'] = forms.ModelChoiceField(queryset=post_office.models.EmailTemplate.objects.all(
        ), initial=None, empty_label="Pick a template...", required=True, label='Email Template', help_text="Select an email template to use.")

        self.choices = []
        for prizewinner in prizewinners:
            winner = prizewinner.winner
            prize = prizewinner.prize
            self.choices.append((prizewinner.id,
                                 mark_safe(format_html(u'<a href="{0}">{1}</a>: <a href="{2}">{3}</a>',
                                                       viewutil.admin_url(prize), prize, viewutil.admin_url(winner), winner))))
        self.fields['prizewinners'] = forms.TypedMultipleChoiceField(choices=self.choices, initial=[prizewinner.id for prizewinner in prizewinners], coerce=lambda x: int(
            x), label='Prize Winners', empty_value='', widget=forms.widgets.CheckboxSelectMultiple)
Esempio n. 4
0
 def __init__(self, event=None, *args, **kwargs):
     super(DonationEntryForm, self).__init__(*args, **kwargs)
     minDonationAmount = event.minimumdonation if event != None else Decimal(
         "1.00")
     self.fields['amount'] = forms.DecimalField(decimal_places=2, min_value=minDonationAmount, max_value=Decimal("100000"),  label="Donation Amount (min ${0})".format(
         minDonationAmount), widget=tracker.widgets.NumberInput(attrs={'id': 'iDonationAmount', 'min': str(minDonationAmount), 'step': '0.01'}), required=True)
     self.fields['comment'] = forms.CharField(
         widget=forms.Textarea, required=False)
     self.fields['requestedvisibility'] = forms.ChoiceField(
         initial='ALIAS', choices=models.Donation._meta.get_field('requestedvisibility').choices, label='Name Visibility')
     self.fields['requestedalias'] = forms.CharField(
         max_length=32, label='Preferred Alias', required=False)
     self.fields['requestedemail'] = forms.EmailField(
         max_length=128, label='Preferred Email', required=False)
     self.fields['requestedsolicitemail'] = forms.ChoiceField(
         initial='CURR', choices=models.Donation._meta.get_field('requestedsolicitemail').choices, label='Charity Email Opt In')
Esempio n. 5
0
class RegistrationForm(forms.Form):
    email = forms.EmailField(label=u'Email', max_length=254, required=True)

    def clean_email(self):
        user = self.get_existing_user()
        if user is not None and user.is_active:
            raise forms.ValidationError(
                'This email is already registered. Please log in, (or reset your password if you forgot it).')
        return self.cleaned_data['email']

    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 get_existing_user(self):
        AuthUser = get_user_model()
        email = self.cleaned_data['email']
        userSet = AuthUser.objects.filter(email__iexact=email)
        if userSet.count() > 1:
            raise forms.ValidationError(
                'More than one user has the e-mail {0}. Ideally this would be a db constraint, but django is stupid. Contact SMK to get this sorted out.'.format(email))
        if userSet.exists():
            return userSet[0]
        else:
            return None
Esempio n. 6
0
class DonationCredentialsForm(forms.Form):
    paypalemail = forms.EmailField(min_length=1, label="Paypal Email")
    amount = forms.DecimalField(
        decimal_places=2, min_value=Decimal('0.00'), label="Donation Amount")
    transactionid = forms.CharField(min_length=1, label="Transaction ID")
Esempio n. 7
0
class PrizeSubmissionForm(forms.Form):
    name = forms.CharField(max_length=64, required=True, label="Prize Name",
                           help_text="Please use a name that will uniquely identify your prize throughout the event.")
    description = forms.CharField(max_length=1024, required=True, label="Prize Description", widget=forms.Textarea,
                                  help_text="Briefly describe your prize, as you would like it to appear to the public. All descriptions are subject to editing at our discretion.")
    maxwinners = forms.IntegerField(required=True, initial=1, widget=tracker.widgets.NumberInput({'min': 1, 'max': 10}), label="Number of Copies",
                                    help_text="If you are submitting multiple copies of the same prize (e.g. multiple copies of the same print), specify how many. Otherwise, leave this at 1.")
    startrun = forms.fields.IntegerField(label="Suggested Start Game", required=False, widget=tracker.widgets.MegaFilterWidget(model="run"),
                                         help_text="If you feel your prize would fit with a specific game (or group of games), enter them here. Please specify the games in the order that they will appear in the marathon.")
    endrun = forms.fields.IntegerField(label="Suggested End Game", required=False, widget=tracker.widgets.MegaFilterWidget(model="run"),
                                       help_text="Leaving only one or the other field blank will simply set the prize to only cover the one game")
    extrainfo = forms.CharField(max_length=1024, required=False, label="Extra/Non-Public Information", widget=forms.Textarea,
                                help_text="Enter any additional information you feel the staff should know about your prize. This information will not be made public. ")
    estimatedvalue = forms.DecimalField(decimal_places=2, max_digits=20, required=True, label='Estimated Value', validators=[positive, nonzero],
                                        help_text="Estimate the actual value of the prize. If the prize is handmade, use your best judgement based on time spent creating it. Note that this is not the bid amount.")
    imageurl = forms.URLField(max_length=1024, label='Prize Image', required=True,
                              help_text=mark_safe("Enter the URL of an image of the prize. Please see our notes regarding prize images at the bottom of the form. Images are now required for prize submissions."))
    creatorname = forms.CharField(max_length=64, required=False, label="Prize Creator",
                                  help_text="Name of the creator of the prize. This is for crediting/promoting the people who created this prize (please fill this in even if you are the creator).")
    creatoremail = forms.EmailField(max_length=128, label='Prize Creator Email', required=False,
                                    help_text="Enter an e-mail if the creator of this prize accepts comissions and would like to be promoted through our marathon. Do not enter an e-mail unless they are known to accept comissions, or you have received their explicit consent.")
    creatorwebsite = forms.URLField(max_length=1024, label='Prize Creator Website', required=False,
                                    help_text="Enter the URL of the prize creator's website or online storefront if applicable.")
    agreement = forms.BooleanField(label="Agreement", help_text=mark_safe("""Check if you agree to the following: 
  <ul>
    <li>I am expected to ship the prize myself, and will keep a receipt to be reimbursed for the cost of shipping.</li>
    <li>I currently have the prize in my possesion, or can guarantee that I can obtain it within one week of the start of the marathon.</li>
    <li>I agree to communicate with the staff in a timely manner as neccessary regarding this prize.</li>
    <li>I agree that all contact information is correct has been provided with the consent of the respective parties.</li>
    <li>I agree that if the prize is no longer available, I will contact the staff immediately to withdraw it, and no later than one month of the start date of the marathon.</li>
  </ul>"""))

    def impl_clean_run(self, data):
        if not data:
            return None
        try:
            return models.SpeedRun.objects.get(id=data)
        except:
            raise forms.ValidationError("Invalid Run id.")

    def clean_startrun(self):
        return self.impl_clean_run(self.cleaned_data['startrun'])

    def clean_endrun(self):
        return self.impl_clean_run(self.cleaned_data['endrun'])

    def clean_name(self):
        basename = self.cleaned_data['name']
        prizes = models.Prize.objects.filter(name=basename)
        if not prizes.exists():
            return basename
        name = basename
        count = 1
        while prizes.exists():
            count += 1
            name = basename + ' ' + str(count)
            prizes = models.Prize.objects.filter(name=name)
        raise forms.ValidationError(
            'Prize name taken. Suggestion: "{0}"'.format(name))

    def clean_agreement(self):
        value = self.cleaned_data['agreement']
        if not value:
            raise forms.ValidationError(
                "You must agree with this statement to submit a prize.")
        return value

    def clean(self):
        if not self.cleaned_data['startrun']:
            self.cleaned_data['startrun'] = self.cleaned_data.get(
                'endrun', None)
        if not self.cleaned_data['endrun']:
            self.cleaned_data['endrun'] = self.cleaned_data.get(
                'startrun', None)
        if self.cleaned_data['startrun'] and self.cleaned_data['startrun'].starttime > self.cleaned_data['endrun'].starttime:
            self.errors['startrun'] = "Start run must be before the end run"
            self.errors['endrun'] = "Start run must be before the end run"
            raise forms.ValidationError(
                "Error, Start run must be before the end run")
        return self.cleaned_data

    def save(self, event, handler=None):
        provider = ''
        if handler and handler.username != handler.email:
            provider = handler.username
        prize = models.Prize.objects.create(
            event=event,
            name=self.cleaned_data['name'],
            description=self.cleaned_data['description'],
            maxwinners=self.cleaned_data['maxwinners'],
            extrainfo=self.cleaned_data['extrainfo'],
            estimatedvalue=self.cleaned_data['estimatedvalue'],
            minimumbid=5,
            maximumbid=5,
            image=self.cleaned_data['imageurl'],
            handler=handler,
            provider=provider,
            creator=self.cleaned_data['creatorname'],
            creatoremail=self.cleaned_data['creatoremail'],
            creatorwebsite=self.cleaned_data['creatorwebsite'],
            startrun=self.cleaned_data['startrun'],
            endrun=self.cleaned_data['endrun'])
        prize.save()
        return prize