Пример #1
0
    def generate(self, configuration, generate_data=True):
        random_gen = RandomWeighted()
        random_gen.seed(configuration.seed)
        regions = configuration.regiondata_set.all()
        for i in range(configuration.n_informers):
            # Create an informer for a given region
            region = random_gen.weighted_choice([(r, r.percentage) for r in regions])
            informer = NeutronInformer(name='{} {}'.format(configuration.name, i))
            informer.region = region.region
            informer.save()
            # Create auxiliary class
            instance = self.model(configuration=configuration, informer=informer)
            instance.seed = random_gen.randint(1, 10000)
            if region.random:
                instance.randomness = random_gen.beta_ppf(region.beta_a, region.beta_b)
            instance.n_use_data = random_gen.randint(region.min_use_data, region.max_use_data)
            instance.n_coarse_data = random_gen.randint(region.min_coarse_data, region.max_coarse_data)
            instance.save()

            if generate_data:
                instance.generate()  # TODO: Send to worker pool
Пример #2
0
    def form_valid(self, form):
        if self.request.user.is_authenticated():
            log.error("User {!r} is already authenticated".format(
                self.request.user))
        else:
            # Create user and log him in
            new_user = form.save()
            new_user = authenticate(username=form.cleaned_data['username'],
                                    password=form.cleaned_data['password1'])
            auth_login(self.request, new_user)

            # Grab data from previous step to create the informer
            join_data = self.request.session.pop('join_data', None)
            if join_data:
                # Extra data for user
                new_user.first_name = join_data['name']
                new_user.email = join_data['email']
                new_user.save()

                # Create informer data
                informer = Informer(user=new_user)
                informer.name = join_data['name']
                informer.region = Region.objects.get(pk=join_data['region'])
                informer.is_native_speaker = join_data['is_native_speaker']
                informer.is_living_region = join_data['is_living_region']
                informer.is_no_abroad = join_data['is_no_abroad']
                informer.known_us = join_data['known_us']
                informer.education = join_data['education']
                informer.honor_code = form.cleaned_data['honor_code']
                informer.save()

            if not form.cleaned_data['honor_code']:
                return HttpResponseRedirect(reverse('neutron:honor_code'))

        # Redirection
        next = self.request.POST.get('next', None)
        if not next or len(next.strip()) == 0:
            next = reverse('faq')
        return HttpResponseRedirect(next)
Пример #3
0
    def form_valid(self, form):
        if self.request.user.is_authenticated():
           log.error("User {!r} is already authenticated".format(self.request.user))
        else:
            # Create user and log him in
            new_user = form.save()
            new_user = authenticate(username=form.cleaned_data['username'],
                                    password=form.cleaned_data['password1'])
            auth_login(self.request, new_user)

            # Grab data from previous step to create the informer
            join_data = self.request.session.pop('join_data', None)
            if join_data:
                # Extra data for user
                new_user.first_name = join_data['name']
                new_user.email = join_data['email']
                new_user.save()

                # Create informer data
                informer = Informer(user=new_user)
                informer.name = join_data['name']
                informer.region = Region.objects.get(pk=join_data['region'])
                informer.is_native_speaker = join_data['is_native_speaker']
                informer.is_living_region = join_data['is_living_region']
                informer.is_no_abroad = join_data['is_no_abroad']
                informer.known_us = join_data['known_us']
                informer.education = join_data['education']
                informer.honor_code = form.cleaned_data['honor_code']
                informer.save()

            if not form.cleaned_data['honor_code']:
                return HttpResponseRedirect(reverse('neutron:honor_code'))

        # Redirection
        next = self.request.POST.get('next', None)
        if not next or len(next.strip()) == 0:
             next = reverse('faq')
        return HttpResponseRedirect(next)