Exemplo n.º 1
0
    def wrapper(*args):
        request = get_request(*args)
        if need_redirect_to_home(request):
            return Redirect('/')

        elif not_need_login_redirect(request):
            return get_response(*args)
        return Redirect(login_page_url(next_page=request.path))
Exemplo n.º 2
0
 def on_logged_in(self, request, openid, openid_response):
     # Do we recognise their OpenID?
     matches = self.lookup_openid(request, openid)
     # Are they logged in already?
     if request.user.is_authenticated():
         # Did we find their account already? If so, ignore login
         if request.user.id in [u.id for u in matches]:
             response = self.redirect_if_valid_next(request)
             if not response:
                 response = Redirect(self.after_login_redirect_url)
             return response
         else:
             # Offer to associate this OpenID with their account
             return self.show_associate(request, openid)
     if matches:
         # If there's only one match, log them in as that user
         if len(matches) == 1:
             user = matches[0]
             if self.user_can_login(request, user):
                 self.log_in_user(request, user)
                 return self.on_login_complete(request, user, openid)
             else:
                 # User is not allowed to log in for some other reason -
                 # for example, they have not yet validated their e-mail
                 # or they have been banned from the site.
                 return self.show_you_cannot_login(request, user, openid)
         # Otherwise, let them to pick which account they want to log in as
         else:
             return self.show_pick_account(request, openid)
     else:
         # We don't know anything about this openid
         return self.show_unknown_openid(request, openid)
Exemplo n.º 3
0
def create_task(request):
    context = {}
    if 'text' in request.POST:
        f = TaskForm(request.POST)
        f.save()
        context["result"] = "Task created"
        return Redirect(reverse("tasks:all"))
    context["form"] = TaskForm()
    return render(request, "task_manager/create.html", context)
Exemplo n.º 4
0
def create_company(request):
    if request.method == 'POST':
        form = AddCompanyForm(request.POST)
        if form.is_valid():
            form.save()
            return Redirect('/create/investment')
    else:
        form = AddCompanyForm()
        return render(request, 'add_company.html', {'form': form})
Exemplo n.º 5
0
def tools(request):
    if request.POST.get('purge_all'):
        cf = CloudFlare.CloudFlare(email=settings.CLOUDFLARE_EMAIL,
                                   token=settings.CLOUDFLARE_TOKEN)
        cf.zones.purge_cache.delete(settings.CLOUDFLARE_ZONE_ID,
                                    data={'purge_everything': True})
        return Redirect(request.path + '?msg=Cache+purged')
    return render(
        request, 'tools.html', {
            'msg': request.GET.get('msg'),
            'deployed_hash': os.environ.get('HEROKU_SLUG_COMMIT'),
        })
Exemplo n.º 6
0
def archive_day(request, year, month, day):
    if day.startswith("0"):
        day = day.lstrip("0")
        return Redirect("/%s/%s/%s/" % (year, month, day))
    context = {}
    context["date"] = datetime.date(int(year), MONTHS_3_REV[month.lower()],
                                    int(day))
    items = []  # Array of {'type': , 'obj': }
    count = 0
    for name, model in (
        ("blogmark", Blogmark),
        ("entry", Entry),
        ("quotation", Quotation),
        ("photo", Photo),
    ):
        filt = model.objects.filter(
            created__year=int(year),
            created__month=MONTHS_3_REV[month.lower()],
            created__day=int(day),
        ).order_by("created")
        if name == "photo":
            filt = filt[:25]
        context[name] = list(filt)
        count += len(context[name])
        items.extend([{"type": name, "obj": obj} for obj in context[name]])
    # Now do photosets separately because they have no created field
    context["photoset"] = list(
        Photoset.objects.filter(
            primary__created__year=int(year),
            primary__created__month=MONTHS_3_REV[month.lower()],
            primary__created__day=int(day),
        ))
    for photoset in context["photoset"]:
        photoset.created = photoset.primary.created
    count += len(context["photoset"])
    items.extend([{
        "type": "photoset",
        "obj": ps
    } for ps in context["photoset"]])
    if count == 0:
        raise Http404("No photosets/photos/entries/quotes/links for that day")
    items.sort(key=lambda x: x["obj"].created, reverse=True)
    context["items"] = items
    photos = Photo.objects.filter(
        created__year=context["date"].year,
        created__month=context["date"].month,
        created__day=context["date"].day,
    )
    context["photos"] = photos[:25]
    # Should we show more_photos ?
    if photos.count() > 25:
        context["more_photos"] = photos.count()
    return render(request, "archive_day.html", context)
Exemplo n.º 7
0
def edit_task(request, task_id):
    if request.method == "POST":
        task = Task.objects.get(id=task_id)
        f = EditTaskForm(request.POST, instance=task)
        f.save()
        return Redirect(reverse("tasks:all"))

    elif request.method == "GET":
        task = Task.objects.get(id=task_id)
        f = EditTaskForm(instance=task)
        return render(request, "task_manager/edit.html", {"form": f})
    else:
        return HttpResponse("Method is not supported")
Exemplo n.º 8
0
def archive_day(request, year, month, day):
    if day.startswith('0'):
        day = day.lstrip('0')
        return Redirect('/%s/%s/%s/' % (year, month, day))
    context = {}
    context['date'] = datetime.date(
        int(year), MONTHS_3_REV[month.lower()], int(day)
    )
    items = [] # Array of {'type': , 'obj': }
    count = 0
    for name, model in (
        ('blogmark', Blogmark), ('entry', Entry),
        ('quotation', Quotation), ('photo', Photo)
    ):
        filt = model.objects.filter(
            created__year=int(year),
            created__month=MONTHS_3_REV[month.lower()],
            created__day=int(day)
        ).order_by('created')
        if (name == 'photo'):
            filt = filt[:25]
        context[name] = list(filt)
        count += len(context[name])
        items.extend([{'type': name, 'obj': obj} for obj in context[name]])
    # Now do photosets separately because they have no created field
    context['photoset'] = list(Photoset.objects.filter(
        primary__created__year=int(year),
        primary__created__month=MONTHS_3_REV[month.lower()],
        primary__created__day=int(day)
    ))
    for photoset in context['photoset']:
        photoset.created = photoset.primary.created
    count += len(context['photoset'])
    items.extend([{'type': 'photoset', 'obj': ps}
        for ps in context['photoset']])
    if count == 0:
        raise Http404("No photosets/photos/entries/quotes/links for that day")
    items.sort(lambda x, y: cmp(x['obj'].created, y['obj'].created))
    context['items'] = items
    photos = Photo.objects.filter(
        created__year=context['date'].year,
        created__month=context['date'].month,
        created__day=context['date'].day
    )
    context['photos'] = photos[:25]
    # Should we show more_photos ?
    if photos.count() > 25:
        context['more_photos'] = photos.count()
    return render(request, 'archive_day.html', context)
Exemplo n.º 9
0
def add(request):
    if request.method == 'POST':
        form = NewTaskForm(request.POST)
        if form.is_valid():
            task = form.cleaned_data['task']
            request.session['tasks'] += [task]
            return Redirect(reverse('tasks:index'))
        else:
            return render(request, 'tasks/add.html', {
                'form': form
            })

    return render(request, 'tasks/add.html', {
        'form': NewTaskForm()
    })
Exemplo n.º 10
0
def tools(request):
    if request.POST.get("purge_all"):
        cf = CloudFlare.CloudFlare(email=settings.CLOUDFLARE_EMAIL,
                                   token=settings.CLOUDFLARE_TOKEN)
        cf.zones.purge_cache.delete(settings.CLOUDFLARE_ZONE_ID,
                                    data={"purge_everything": True})
        return Redirect(request.path + "?msg=Cache+purged")
    return render(
        request,
        "tools.html",
        {
            "msg": request.GET.get("msg"),
            "deployed_hash": os.environ.get("HEROKU_SLUG_COMMIT"),
        },
    )
Exemplo n.º 11
0
def archive_item(request, year, month, day, slug):
    if day.startswith("0"):
        day = day.lstrip("0")
        return Redirect("/%s/%s/%s/%s/" % (year, month, day, slug))

    # This could be a quote OR link OR entry
    for content_type, model in (
        ("blogmark", Blogmark),
        ("entry", Entry),
        ("quotation", Quotation),
    ):
        try:
            obj = get_object_or_404(
                model,
                created__year=int(year),
                created__month=MONTHS_3_REV[month.lower()],
                created__day=int(day),
                slug=slug,
            )
        except Http404:
            continue

        # If item is entry posted before Dec 1 2006, add "previously hosted"
        if content_type == "entry" and obj.created < datetime.datetime(
                2006, 12, 1, 1, 1, 1, tzinfo=utc):
            previously_hosted = ("http://simon.incutio.com/archive/" +
                                 obj.created.strftime("%Y/%m/%d/") + obj.slug)
        else:
            previously_hosted = None

        return render(
            request,
            "%s.html" % content_type,
            {
                content_type: obj,
                "content_type": content_type,
                "object_id": obj.id,
                "previously_hosted": previously_hosted,
                "item": obj,
            },
        )

    # If we get here, non of the views matched
    raise Http404
Exemplo n.º 12
0
def votar(peticion, pregunta_id):
    pregunta = findOrFail(Pregunta, pk=pregunta_id)

    try:
        opcion = pregunta.opcion_set.get(pk=peticion.POST['opcion'])
    except (KeyError, Opcion.DoesNotExist):
        # Redisplay the question voting form.
        return render(peticion, 'encuestas/detalles.html', {
            'pregunta': pregunta,
            'error_message': "Seleccione una opcion",
        })

    else:
        opcion.votos += 1
        opcion.save()
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return Redirect( reverse('encuestas:resultados', args=(pregunta.id,)) )
Exemplo n.º 13
0
def archive_item(request, year, month, day, slug):
    if day.startswith('0'):
        day = day.lstrip('0')
        return Redirect('/%s/%s/%s/%s/' % (year, month, day, slug))

    # This could be a quote OR link OR entry
    for content_type, model in (
        ('blogmark', Blogmark),
        ('entry', Entry),
        ('quotation', Quotation)
    ):
        try:
            obj = get_object_or_404(model,
                created__year=int(year),
                created__month=MONTHS_3_REV[month.lower()],
                created__day=int(day),
                slug=slug
            )
        except Http404:
            continue

        # If item is entry posted before Dec 1 2006, add "previously hosted"
        if content_type == 'entry' and obj.created < datetime.datetime(
            2006, 12, 1, 1, 1, 1, tzinfo=utc
        ):
            previously_hosted = 'http://simon.incutio.com/archive/' + \
                obj.created.strftime("%Y/%m/%d/") + obj.slug
        else:
            previously_hosted = None

        return render(request, '%s.html' % content_type, {
            content_type: obj,
            'content_type': content_type,
            'object_id': obj.id,
            'previously_hosted': previously_hosted,
            'item': obj,
        })

    # If we get here, non of the views matched
    raise Http404
Exemplo n.º 14
0
 def on_login_complete(self, request, user, openid=None):
     response = self.redirect_if_valid_next(request)
     if not response:
         response = Redirect(self.after_login_redirect_url)
     return response
Exemplo n.º 15
0
def archive_item_redirect(request, yyyy, mm, dd, slug):
    return Redirect('/%s/%s/%d/%s' %
                    (yyyy, MONTHS_3_REV_REV[int(mm)].title(), int(dd), slug))
Exemplo n.º 16
0
def archive_day_redirect(request, yyyy, mm, dd):
    return Redirect('/%s/%s/%d/' %
                    (yyyy, MONTHS_3_REV_REV[int(mm)].title(), int(dd)))
Exemplo n.º 17
0
 def already_logged_in(self, request, openid):
     response = self.redirect_if_valid_next(request)
     if not response:
         response = Redirect(self.after_login_redirect_url)
     return response