Beispiel #1
0
    def handle(self, *args, **options):

        fake = (not options["send"])
        queryset = ResultSemifinal.objects.select_related("contestant").filter(
            contestant__contest_year=contest_year(), qualified=True)

        for result in queryset:
            lang = result.contestant.language

            if lang == LANG_FR:
                activate("fr")
                title = "beOI - Finale"
                tpl = "emails/fr/final-reminder.txt"
            if lang == LANG_NL:
                activate("nl")
                title = "beOI - Finale"
                tpl = "emails/nl/final-reminder.txt"

            mail_template = get_template(tpl)
            context = Context({})

            if fake: email = dict(settings.ADMINS).values()[0]
            else: email = result.contestant.email

            send_mail(title,
                      mail_template.render(context),
                      "*****@*****.**", [email],
                      fail_silently=True)
            self.stdout.write("Mail (template:%s) sent to %s\n" %
                              (tpl, result.contestant.email))
            time.sleep(1)
Beispiel #2
0
def referrals(request, template="", confirm=None):

	if "token" in request.GET:

		full_token_computed = full_token_from_stat_token(request.GET["token"])
		try:
			contestant = Contestant.objects.get(token=full_token_computed)
			godchildren=[]
			for godchild in Contestant.objects.filter(contest_year=contest_year()):
				if full_token(full_token_computed, godchild.registering_time) == godchild.token:
					godchildren.append(godchild)
			invalid = False
			points = len(godchildren)
			if full_token("",contestant.registering_time) != contestant.token: points += 1

			return 	render_to_response(template, 
			{
				"correcttoken" : True,
				"godchildren":godchildren,
				"points": points,
				"sharinglink": "%s?token=%s" % (reverse("home", args=[request.LANGUAGE_CODE]),full_token_computed)
			 }, 
			context_instance=RequestContext(request))

		except ObjectDoesNotExist:
			return 	render_to_response(template, {"correcttoken": False}, context_instance=RequestContext(request))

	else: 
		return 	render_to_response(template, {"correcttoken": False}, context_instance=RequestContext(request))
Beispiel #3
0
def stats(request, template):
	from django.conf import settings
	from datetime import datetime 
	
	remaining = settings.REGISTRATION_DEADLINE - datetime.now()
	allcontestant = Contestant.objects.filter(contest_year=contest_year()).select_related("semifinal_center")
	allcenters = set( map(lambda c:c.semifinal_center, allcontestant) )
	
	return render_to_response(template, {
			'total': len(allcontestant),
			'registration_open': registration_open(),
			'remaining_days': remaining.days,
			'remaining_hours': remaining.seconds / 3600,
			'dutch': len(filter(lambda c:c.language==LANG_NL, allcontestant)),
			'french': len(filter(lambda c:c.language==LANG_FR, allcontestant)),
			'centers': [ {
				'name': center.name,
				'fr': len(filter(lambda c:c.language==LANG_FR and c.semifinal_center == center, allcontestant)),
				'nl': len(filter(lambda c:c.language==LANG_NL and c.semifinal_center == center, allcontestant))
			} for center in allcenters ],
			'years': [ {
				'year': year,
				'nb': len(filter(lambda c:c.year_study==year, allcontestant)),
			} for year in xrange(1,8) ],
		}, context_instance=RequestContext(request)
	)
    def handle(self, *args, **options):

        fake = (not options["send"])
        queryset = ResultSemifinal.objects.select_related("contestant").filter(
            contestant__contest_year=contest_year())

        for result in queryset:
            lang = result.contestant.language
            qualified = result.qualified

            if lang == LANG_FR:
                activate("fr")
                if qualified: tpl = "emails/fr/semifinal-result-qualified.txt"
                else: tpl = "emails/fr/semifinal-result-notqualified.txt"
            if lang == LANG_NL:
                activate("nl")
                if qualified: tpl = "emails/nl/semifinal-result-qualified.txt"
                else: tpl = "emails/nl/semifinal-result-notqualified.txt"

            title = _("beOI - Semifinal results")

            score = result.score
            position = 1 + ResultSemifinal.objects.filter(
                contestant__contest_year=contest_year(),
                score__gt=score).count()

            mail_template = get_template(tpl)
            context = Context({"SCORE": score, "POSITION": position})

            if fake: email = dict(settings.ADMINS).values()[0]
            else: email = result.contestant.email

            send_mail(title,
                      mail_template.render(context),
                      "*****@*****.**", [email],
                      fail_silently=True)
            self.stdout.write("Mail (template:%s) sent to %s\n" %
                              (tpl, result.contestant.email))
            time.sleep(1)
Beispiel #5
0
def stats(request, template):
    from django.conf import settings
    from datetime import datetime

    remaining = settings.REGISTRATION_DEADLINE - datetime.now()
    allcontestant = Contestant.objects.filter(
        contest_year=contest_year()).select_related("semifinal_center")
    allcenters = set(map(lambda c: c.semifinal_center, allcontestant))

    return render_to_response(template, {
        'total':
        len(allcontestant),
        'registration_open':
        registration_open(),
        'remaining_days':
        remaining.days,
        'remaining_hours':
        remaining.seconds / 3600,
        'dutch':
        len(filter(lambda c: c.language == LANG_NL, allcontestant)),
        'french':
        len(filter(lambda c: c.language == LANG_FR, allcontestant)),
        'centers': [{
            'name':
            center.name,
            'fr':
            len(
                filter(
                    lambda c: c.language == LANG_FR and c.semifinal_center ==
                    center, allcontestant)),
            'nl':
            len(
                filter(
                    lambda c: c.language == LANG_NL and c.semifinal_center ==
                    center, allcontestant))
        } for center in allcenters],
        'years': [{
            'year':
            year,
            'nb':
            len(filter(lambda c: c.year_study == year, allcontestant)),
        } for year in xrange(1, 8)],
    },
                              context_instance=RequestContext(request))
Beispiel #6
0
def referrals(request, template="", confirm=None):

    if "token" in request.GET:

        full_token_computed = full_token_from_stat_token(request.GET["token"])
        try:
            contestant = Contestant.objects.get(token=full_token_computed)
            godchildren = []
            for godchild in Contestant.objects.filter(
                    contest_year=contest_year()):
                if full_token(full_token_computed,
                              godchild.registering_time) == godchild.token:
                    godchildren.append(godchild)
            invalid = False
            points = len(godchildren)
            if full_token("", contestant.registering_time) != contestant.token:
                points += 1

            return render_to_response(template, {
                "correcttoken":
                True,
                "godchildren":
                godchildren,
                "points":
                points,
                "sharinglink":
                "%s?token=%s" % (reverse("home", args=[request.LANGUAGE_CODE
                                                       ]), full_token_computed)
            },
                                      context_instance=RequestContext(request))

        except ObjectDoesNotExist:
            return render_to_response(template, {"correcttoken": False},
                                      context_instance=RequestContext(request))

    else:
        return render_to_response(template, {"correcttoken": False},
                                  context_instance=RequestContext(request))
	def handle(self, *args, **options):
		
		fake = (not options["send"])
		queryset = ResultSemifinal.objects.select_related("contestant").filter(contestant__contest_year=contest_year())
		
		for result in queryset:
			lang = result.contestant.language
			qualified = result.qualified
			
			if lang == LANG_FR :
				activate("fr")
				if qualified: tpl = "emails/fr/semifinal-result-qualified.txt"
				else:  tpl = "emails/fr/semifinal-result-notqualified.txt"
			if lang == LANG_NL:
				activate("nl")
				if qualified: tpl = "emails/nl/semifinal-result-qualified.txt"
				else: tpl = "emails/nl/semifinal-result-notqualified.txt"
			
			title = _("beOI - Semifinal results")
			
			score = result.score
			position = 1 + ResultSemifinal.objects.filter(
				contestant__contest_year=contest_year(), 
				score__gt=score
				).count()

			mail_template = get_template(tpl)
			context = Context({
				"SCORE": score,
				"POSITION": position
			})
			
			if fake: email = dict(settings.ADMINS).values()[0]
			else: email = result.contestant.email
			
			send_mail(title, mail_template.render(context), "*****@*****.**", [email], fail_silently=True)
			self.stdout.write( "Mail (template:%s) sent to %s\n" %  (tpl, result.contestant.email) )
			time.sleep(1)
Beispiel #8
0
 url(r'^press$',
     TemplateView.as_view(template_name='press.html'),
     name="press"),
 url(r'^semifinal/places$',
     ListView.as_view(template_name='semifinal_places.html',
                      queryset=SemifinalCenter.objects.filter(active=True)),
     name="semifinal-places"),
 url(r'^final/results$',
     ListView.as_view(
         template_name='final_results.html',
         queryset=ResultFinal.objects.select_related(
             'contestant', 'contestant__school').extra(select={
                 "total":
                 "score_written+score_computer"
             }).filter(
                 contestant__contest_year=contest_year()).order_by("rank")),
     name="final-results"),
 url(r'^semifinal/results$',
     ListView.as_view(
         template_name='semifinal_results.html',
         queryset=ResultSemifinal.objects.select_related(
             'contestant', 'contestant__school').filter(
                 qualified=True,
                 contestant__contest_year=contest_year()).order_by(
                     "contestant__surname", "contestant__firstname")),
     name="semifinal-results"),
 url(r'^training$',
     TemplateView.as_view(template_name='training.html'),
     name="training"),
 url(r'^preparing$',
     TemplateView.as_view(template_name='preparing.html'),
Beispiel #9
0
	url(r'^registration/confirm/(?P<object_id>\d+)$', ListView.as_view(
		template_name='registration_confirm.html',
		queryset=SemifinalCenter.objects.filter(active=True)
		), name="registration-confirm"),

	url(r'^sponsors$', TemplateView.as_view(template_name='sponsors.html'), name="sponsors"),
	url(r'^membership$', TemplateView.as_view(template_name='membership.html'), name="membership"),
	url(r'^press$', TemplateView.as_view(template_name='press.html'), name="press"),
	
	url(r'^semifinal/places$', ListView.as_view(template_name='semifinal_places.html',
		queryset=SemifinalCenter.objects.filter(active=True)), name="semifinal-places"),

	url(r'^final/results$', ListView.as_view(template_name='final_results.html',
		queryset=ResultFinal.objects.select_related('contestant', 'contestant__school')
		.extra(select={"total":"score_written+score_computer"})
		.filter(contestant__contest_year=contest_year())
		.order_by("rank")), name="final-results"),

	url(r'^semifinal/results$', ListView.as_view(template_name='semifinal_results.html',
		queryset=ResultSemifinal.objects.select_related('contestant', 'contestant__school')
		.filter(qualified=True,contestant__contest_year=contest_year())
		.order_by("contestant__surname","contestant__firstname")), name="semifinal-results"),

	url(r'^training$', TemplateView.as_view(template_name='training.html'), name="training"),
	url(r'^preparing$', TemplateView.as_view(template_name='preparing.html'), name="preparing"),
	url(r'^learn-programming$', TemplateView.as_view(template_name='learn_programming.html'), name="learn-programming"),
	
	url(r'^archives/1992$', TemplateView.as_view(template_name='1992.html'), name="archives-1992"),		
	url(r'^archives/2010$', TemplateView.as_view(template_name='2010.html'), name="archives-2010"),
	url(r'^archives/2011$', TemplateView.as_view(template_name='2011.html'), name="archives-2011"),
	url(r'^archives/2012$', TemplateView.as_view(template_name='2012.html'), name="archives-2012"),
Beispiel #10
0
def registration(request, template):

    if not semifinal_started():
        return render_to_response(request.LANGUAGE_CODE +
                                  "/registration_closed.html",
                                  context_instance=RequestContext(request))

    if request.method == 'POST':
        form = RegisteringForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data

            # retrieve the school
            if cd["school_exists"] == SCHOOL_NOT_EXIST:  # if a new one

                school, created = School.objects.get_or_create(  # if already exists, does not create a new one
                    name=cd["new_school_name"],
                    city=cd["new_school_city"],
                    postal_code=cd["new_school_postal_code"],
                    ##category = cd["contest_category"]
                )
                # should never raise a IntegrityError, right?

            else:  # if school selected in the list
                school = cd["school"]

            # create the contestant
            contestant = Contestant(
                surname=cd["surname"],
                firstname=cd["firstname"],
                gender=cd["gender"],
                email=cd["email"],
                address=cd["address"],
                city=cd["city"],
                postal_code=cd["postal_code"],
                dob=cd["dob"],
                #contest_category 	= cd["contest_category"],
                school=school,
                year_study=cd["year_study"],
                language=cd["language"],
                semifinal_center=cd["semifinal_center"],
                token="",
                contest_year=contest_year())
            try:
                # if using postgres >=8.2, should use database-level autocommit instead
                sid = transaction.savepoint()
                contestant.save()
                transaction.savepoint_commit(sid)

            except IntegrityError:  # triggered by db or model validation
                transaction.savepoint_rollback(sid)
                test = Contestant.objects.count()

                return HttpResponseRedirect(reverse("registration-error"))

            # if not cd["token"]: cd["token"] = ""
            # contestant.token = full_token(cd["token"], contestant.registering_time)
            contestant.save()

            # get the full url for mail data
            if Site._meta.installed: current_site = Site.objects.get_current()
            else: current_site = RequestSite(request)

            # mail sending
            context = Context({
                "NAME": cd["firstname"] + " " + cd["surname"],
                "CENTER_NAME": cd["semifinal_center"],
                # "GODCHILDTOKEN": contestant.token,
                # "URLTOSHARE":  add_domain(current_site.domain,"%s?t=%s" % (reverse("home", args=[request.LANGUAGE_CODE]),contestant.token)),
                # "URLSTAT": add_domain(current_site.domain,"%s?token=%s" % (reverse("referrals", args=[request.LANGUAGE_CODE]),stat_token(cd["token"], contestant.registering_time)))
            })
            mail_template = get_template("emails/" + request.LANGUAGE_CODE +
                                         "/registration.txt")
            context["CENTER_DETAILS"] = add_domain(current_site.domain,
                                                   reverse("semifinal-places"))
            send_mail(_("Registering to Belgian Olympiads in Informatics"),
                      mail_template.render(context),
                      "*****@*****.**", [cd["email"]],
                      fail_silently=True)
            # redirect to confirmation page
            return HttpResponseRedirect(
                reverse("registration-confirm",
                        args=[cd["semifinal_center"].id]))

    else:
        if request.LANGUAGE_CODE == "fr":
            initial_lang = LANG_FR
        else:
            initial_lang = LANG_NL

        if "registration_token" in request.session:
            token = request.session["registration_token"]
        else:
            token = ""

        form = RegisteringForm(initial={
            "language": initial_lang,
            "token": token
        })

    return render_to_response(template, {
        'form': form,
        "global_errors": form.non_field_errors(),
    },
                              context_instance=RequestContext(request))
Beispiel #11
0
def registration(request, template):

    if not registration_open():
        return render_to_response(
            request.LANGUAGE_CODE + "/closed_registration.html", context_instance=RequestContext(request)
        )

    if request.method == "POST":
        form = RegisteringForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data

            # retrieve the school
            if cd["school_exists"] == SCHOOL_NOT_EXIST:  # if a new one

                school, created = School.objects.get_or_create(  # if already exists, does not create a new one
                    name=cd["new_school_name"],
                    city=cd["new_school_city"],
                    postal_code=cd["new_school_postal_code"],
                    ##category = cd["contest_category"]
                )
                # should never raise a IntegrityError, right?

            else:  # if school selected in the list
                school = cd["school"]

                # create the contestant
            token = _gen_token()
            contestant = Contestant(
                surname=cd["surname"],
                firstname=cd["firstname"],
                gender=cd["gender"],
                email=cd["email"],
                address=cd["address"],
                city=cd["city"],
                postal_code=cd["postal_code"],
                dob=cd["dob"],
                # contest_category 	= cd["contest_category"],
                school=school,
                year_study=cd["year_study"],
                language=cd["language"],
                semifinal_center=cd["semifinal_center"],
                token=token,
                contest_year=contest_year(),
            )
            try:
                # if using postgres >=8.2, should use database-level autocommit instead
                sid = transaction.savepoint()
                contestant.save()
                transaction.savepoint_commit(sid)

            except IntegrityError:  # triggered by db or model validation
                transaction.savepoint_rollback(sid)
                test = Contestant.objects.count()

                return HttpResponseRedirect(reverse("registration-error", args=[request.LANGUAGE_CODE]))

                # get the full url for mail data
            if Site._meta.installed:
                current_site = Site.objects.get_current()
            else:
                current_site = RequestSite(request)

            # mail sending
            context = Context(
                {
                    "NAME": cd["firstname"] + " " + cd["surname"],
                    # "CONTEST": dict(CONTEST_CHOICES)[cd["contest_category"]],
                    "CENTER_NAME": cd["semifinal_center"],
                }
            )
            mail_template = get_template("emails/" + request.LANGUAGE_CODE + "/registration.txt")
            context["CENTER_DETAILS"] = add_domain(
                current_site.domain, reverse("semifinal-places", args=[request.LANGUAGE_CODE])
            )
            send_mail(
                _("Registering to Belgian Olympiads in Informatics"),
                mail_template.render(context),
                "*****@*****.**",
                [cd["email"]],
                fail_silently=True,
            )

            # redirect to confirmation page
            return HttpResponseRedirect(
                reverse("registration-confirm", args=[request.LANGUAGE_CODE, cd["semifinal_center"].id])
            )

    else:
        if request.LANGUAGE_CODE == "fr":
            initial_lang = LANG_FR
        else:
            initial_lang = LANG_NL
        form = RegisteringForm(initial={"language": initial_lang})

    return render_to_response(
        template, {"form": form, "global_errors": form.non_field_errors()}, context_instance=RequestContext(request)
    )
	def handle(self, *args, **options):
		
		fake = (not options["send"])
		queryset = ResultFinal.objects.select_related("contestant").filter(contestant__contest_year=contest_year(),rank__lte=20)
		
		for result in queryset:
			lang = result.contestant.language
			
			if lang == LANG_FR :
				activate("fr")
				title = "beOI - Proclamation"
				tpl = "emails/fr/proclamation-prize.txt"
			if lang == LANG_NL:
				activate("nl")
				title = "beOI -Proclamatie"
				tpl = "emails/nl/proclamation-prize.txt"
						
			mail_template = get_template(tpl)
			context = Context({})
			
			if fake: email = dict(settings.ADMINS).values()[0]
			else: email = result.contestant.email
			
			send_mail(title, mail_template.render(context), "*****@*****.**", [email], fail_silently=True)
			self.stdout.write( "Mail (template:%s) sent to %s\n" %  (tpl, result.contestant.email) )
			time.sleep(1)