Example #1
0
def google_news(depute):
    depute = get_object_or_404(Depute, {"slug": depute})
    quoted_query = quote_plus("%s %s" % (depute["prenom"].encode("Utf-8"), depute["nom_de_famille"].encode("Utf-8")))
    return render_template(
        "rss_to_html.haml",
        entries=prepare_rss("http://news.google.fr/news?q=%s&hl=fr&ie=UTF-8&output=rss" % quoted_query),
    )
Example #2
0
def note_details(note_id):
    """
    Note details api endpoint. Returns a note instance
    """

    note = shortcuts.get_object_or_404(models.Note, note_id)

    return jsonify(note.to_data())
Example #3
0
def note_delete(note_id):
    """
    Note delete api endpoint. Delete a note
    """

    note = shortcuts.get_object_or_404(models.Note, note_id)
    note.key.delete()

    return jsonify({})
Example #4
0
def avatar_crop(request, id=None):
    """
    Avatar management, creates a new avatar and makes it default
    """
    if id:
        avatar = get_object_or_404(Avatar, id=id, user=request.user)
    else:
        avatar = get_object_or_404(Avatar, identity=request.user)

    if (avatar.original_image.width <= avatar.original_image.height):
        result = "width"
    else:
        result = "height"

    if not request.method == "POST":
        form = AvatarCropForm()
    else:
        try:
            orig = avatar.original_image.storage.open(
                avatar.original_image.name, 'rb').read()
            image = Image.open(StringIO(orig))
        except IOError:
            return
        form = AvatarCropForm(image, request.POST)

        if form.is_valid():
            avatar.cropped_image.delete()

            left = int(form.cleaned_data.get('left'))
            top = int(form.cleaned_data.get('top'))
            right = int(form.cleaned_data.get('right'))
            bottom = int(form.cleaned_data.get('bottom'))

            avatar.box = '%s,%s,%s,%s' % (left, top, right, bottom)
            avatar.cropped_image.generate(lazy=False)
            avatar.save()

    return render_to_response("avatar_crop/crop.html", {
        'AVATAR_CROP_MAX_SIZE': AVATAR_CROP_MAX_SIZE,
        'dim': result,
        'avatar': avatar,
        'form': form
    },
                              context_instance=RequestContext(request))
Example #5
0
def google_news(depute):
    depute = get_object_or_404(Depute, {"slug": depute})
    quoted_query = quote_plus("%s %s" %
                              (depute["prenom"].encode("Utf-8"),
                               depute["nom_de_famille"].encode("Utf-8")))
    return render_template(
        "rss_to_html.haml",
        entries=prepare_rss(
            "http://news.google.fr/news?q=%s&hl=fr&ie=UTF-8&output=rss" %
            quoted_query))
def avatar_crop(request, id=None):
    """
    Avatar management, creates a new avatar and makes it default
    """
    if id:
        avatar = get_object_or_404(Avatar, id=id, user=request.user)
    else:
        avatar = get_object_or_404(Avatar, identity=request.user)

    if (avatar.original_image.width<=avatar.original_image.height):
        result = "width"
    else:
        result = "height"

    if not request.method == "POST":
        form = AvatarCropForm()
    else:
        try:
            orig = avatar.original_image.storage.open(avatar.original_image.name, 'rb').read()
            image = Image.open(StringIO(orig))
        except IOError:
            return
        form = AvatarCropForm(image, request.POST)

        if form.is_valid():
            avatar.cropped_image.delete()

            left = int(form.cleaned_data.get('left'))
            top = int(form.cleaned_data.get('top'))
            right = int(form.cleaned_data.get('right'))
            bottom = int(form.cleaned_data.get('bottom'))

            avatar.box = '%s,%s,%s,%s' % (left, top, right, bottom)
            avatar.cropped_image.generate(lazy=False)
            avatar.save()

    return render_to_response("avatar_crop/crop.html", {
        'AVATAR_CROP_MAX_SIZE': AVATAR_CROP_MAX_SIZE,
        'dim': result,
        'avatar': avatar,
        'form': form
    }, context_instance=RequestContext(request))
Example #7
0
def note_update(note_id):
    """
    Note update api endpoint. Update a note
    """

    note = shortcuts.get_object_or_404(models.Note, note_id)
    form = forms.NoteForm(request.form, note)

    if form.validate():
        form.populate_obj(note)
        note.put()

        return jsonify(note.to_data())

    return jsonify(errors=form.errors)
Example #8
0
def nosdeputes_rss(depute):
    depute = get_object_or_404(Depute, {"slug": depute})
    return render_template("rss_to_html.haml", entries=prepare_rss("http://www.nosdeputes.fr/%s/rss" % depute["slug"]))
Example #9
0
def depute(depute):
    return render_template("depute.haml", depute=get_object_or_404(Depute, {"slug": depute}))
Example #10
0
def nosdeputes_rss(depute):
    depute = get_object_or_404(Depute, {"slug": depute})
    return render_template(
        "rss_to_html.haml",
        entries=prepare_rss("http://www.nosdeputes.fr/%s/rss" %
                            depute["slug"]))
Example #11
0
def depute(depute):
    return render_template("depute.haml",
                           depute=get_object_or_404(Depute, {"slug": depute}))