Ejemplo n.º 1
0
def register(request, campaign_id):
    try:
        should_redirect = False
        campaign = None
        template = 'petition/register_form.html'

        try:
            campaign = Campaign.objects.get(pk=campaign_id)
        except Campaign.DoesNotExist:
            messages.error(request, _('Campaign you tried to register for, doesn\'t exist.'))

        if campaign and request.method == 'POST':
            form = CampaignRegistrationForm(request.POST)

            if not campaign.is_active:
                messages.warning(request, _('The chosen campaign is not currently open for new signatures'))
                return HttpResponseRedirect(request.META.get('HTTP_REFERER', reverse('campaign_list')))

            if form.is_valid():
                users_email = form.cleaned_data['email']
                users_name = form.cleaned_data['name']

                if not users_email:
                    messages.error(request, _('Empty email address submited, please submit a valid one'))
                else:
                    if not campaign.is_valid_domain(users_email):
                        messages.error(request, _('Your email is not listed amongst the domains that are allowed to participate in this campaign!'))
                    elif not campaign.is_registered(users_email):
                        try:
                            signature_request = Signature()
                            signature_request.email = users_email
                            signature_request.name = users_name
                            signature_request.campaign = campaign
                            signature_request.save()

                            # some kind of try / catch around this one?
                            # transaction? yawn.
                            signature_request.send_verify_email()
                            messages.warning(request,
                                             _('Your signature is receieved. You MUST click on the link sent to you by email in order for your signature to be approved.'))
                            #template = 'petition/details.html'
                        except Exception, e:
                            messages.error(request, _('Ooops, something went wrong ..'))
                            messages.error(request, e)
                            signature_request.delete()
                            print(str(e))
                    else:
                        messages.error(request, _('You are already registered to this campaign!'))

                    should_redirect = True
            else:
Ejemplo n.º 2
0
    def handle(self, *args, **options):

        petition_count = 100
        signatures_min = 20
        signatures_max = 30

        user, newly_created = User.objects.get_or_create(
            username='******', first_name='Test User')

        petitions = Petition.objects.all().order_by(
            '-date_created')[:petition_count]
        for petition in petitions:

            signatures_count = randrange(signatures_min, signatures_max + 1)

            stdout.write("Generating %d signatures for petition '%s'" %
                         (signatures_count, petition.name))
            stdout.flush()

            for i in range(0, signatures_count):
                random_number = 0  # Just for formality's sake, really.
                user = None
                while user is None:
                    random_number = randrange(100000, 999999)
                    random_username = '******' % random_number
                    random_name = 'Tester nr. %d' % random_number
                    if User.objects.filter(
                            username=random_username).count() == 0:
                        user = User.objects.create(username=random_username)
                        user.first_name = random_name
                        user.save()

                # Generate a test authentication
                auth = UserAuthentication()
                auth.user = user
                auth.method = 'test'
                auth.token = 'test_%d' % random_number
                auth.save()

                # Generate a test signature
                sig = Signature()
                sig.user = user
                sig.petition = petition
                sig.authentication = auth
                sig.show_public = True
                sig.stance = 'oppose' if randrange(
                    0, 2) == 1 else 'endorse'  # Coin toss
                sig.save()

                stdout.write(".")
                stdout.flush()

            stdout.write(" done\n")
            stdout.flush()
Ejemplo n.º 3
0
def register(request, campaign_id):
    try:
        should_redirect = False
        campaign = None
        template = 'petition/register_form.html'

        try:
            campaign = Campaign.objects.get(pk=campaign_id)
        except Campaign.DoesNotExist:
            messages.error(request, 'Campaign you tried to register for, doesn\'t exist.')

        if campaign and request.method == 'POST':
            form = CampaignRegistrationForm(request.POST)

            if form.is_valid():
                users_email = form.cleaned_data['email']

                if not users_email:
                    messages.error(request, 'Empty email address submited, please submit a valid one')
                else:
                    if not campaign.is_valid_domain(users_email):
                        messages.error(request, 'Your email is not listed in the alloweded domains that are allowed to participate in this campaign!')
                    elif not campaign.is_registered(users_email):
                        try:
                            signature_request = Signature()
                            signature_request.email = users_email
                            signature_request.campaign = campaign
                            signature_request.save()

                            # some kind of try / catch around this one?
                            # transaction? yawn.
                            signature_request.send_verify_email()
                            messages.success(request,
                                             'Registrering mottatt, vennligst bekreft registrering via lenken som kommer pr. epost!')
                            #template = 'petition/details.html'
                        except Exception, e:
                            messages.error(request, 'Ooops, something went wrong ..')
                            signature_request.delete()
                            print(str(e))
                    else:
                        messages.error(request, 'You are already registered to this campaign!')

                    should_redirect = True
            else:
Ejemplo n.º 4
0
    def handle(self, *args, **options):

        petition_count = 100
        signatures_min = 20
        signatures_max = 30

        user, newly_created = User.objects.get_or_create(username='******', first_name='Test User')

        petitions = Petition.objects.all().order_by('-date_created')[:petition_count]
        for petition in petitions:

            signatures_count = randrange(signatures_min, signatures_max + 1)

            stdout.write("Generating %d signatures for petition '%s'" % (signatures_count, petition.name))
            stdout.flush()

            for i in range(0, signatures_count):
                random_number = 0 # Just for formality's sake, really.
                user = None
                while user is None:
                    random_number = randrange(100000, 999999)
                    random_username = '******' % random_number
                    random_name = 'Tester nr. %d' % random_number
                    if User.objects.filter(username=random_username).count() == 0:
                        user = User.objects.create(username=random_username)
                        user.first_name = random_name
                        user.save()

                # Generate a test authentication
                auth = UserAuthentication()
                auth.user = user
                auth.method = 'test'
                auth.token = 'test_%d' % random_number
                auth.save()

                # Generate a test signature
                sig = Signature()
                sig.user = user
                sig.petition = petition
                sig.authentication = auth
                sig.show_public = True
                sig.stance = 'oppose' if randrange(0, 2) == 1 else 'endorse' # Coin toss
                sig.save()

                stdout.write(".")
                stdout.flush()

            stdout.write(" done\n")
            stdout.flush()