Ejemplo n.º 1
0
def edit_post_comment_ajax(request, id, post_id):
    context = {'success': False, 'comment': {}}

    if request.user.is_authenticated() or request.user_site.is_authenticated():
        ip = get_client_ip(request)

        if request.user.is_authenticated():
            autor = request.user
        else:
            autor = request.user_site

        model = ContentType.objects.get_for_model(autor)

        comment = get_object_or_404(Comments,
                                    pk=int(id),
                                    content_type=model.model_class(),
                                    autor_object_id=model.id,
                                    target__id=int(post_id))
        if request.method == "POST":
            x = request.POST
            form = CommentsModelForm(data=x, ip=ip, instance=comment)
            if form.is_valid():
                m = form.save()
                context['success'] = True
                context['comment'] = {
                    'logo': autor.get_logo(64, 64),
                    'message': m.comment,
                    'publish_date': m.created.strftime("%Y-%m-%d %H:%M:%S"),
                    'modify_date': m.modified.strftime("%Y-%m-%d %H:%M:%S"),
                }

    return HttpResponse(json.dumps(context), content_type="application/json")
Ejemplo n.º 2
0
def post_comment_ajax(request, id, parent=None):
    context = {'success': False, 'comment': {}}
    post = get_object_or_404(PostItem, pk=int(id))
    if request.user.is_authenticated() or request.user_site.is_authenticated():
        ip = get_client_ip(request)
        if request.user.is_authenticated():
            autor = request.user
        else:
            autor = request.user_site
        if request.method == "POST":
            x = request.POST
            form = CommentsModelForm(autor=autor,
                                     ip=ip,
                                     parent=parent,
                                     target=post,
                                     data=x)
            if form.is_valid():
                m = form.save()
                context['success'] = True
                context['comment'] = {
                    'logo': autor.get_logo(64, 64),
                    'message': m.comment,
                    'publish_date': m.created.strftime("%Y-%m-%d %H:%M:%S"),
                    'modify_date': m.modified.strftime("%Y-%m-%d %H:%M:%S"),
                }
            else:
                messages.add_message(request, messages.WARNING,
                                     _('AN_ERROR_OCURRED_LABEL'))

    return HttpResponse(json.dumps(context), content_type="application/json")
Ejemplo n.º 3
0
def edit_post_comment(request, id, post_id):
    redirect_to = request.REQUEST.get('next', '')

    if request.user.is_authenticated() or request.user_site.is_authenticated():
        ip = get_client_ip(request)
        if request.user.is_authenticated():
            autor = request.user
        else:
            autor = request.user_site

        model = ContentType.objects.get_for_model(autor)

        comment = get_object_or_404(Comments,
                                    pk=int(id),
                                    content_type=model.model_class(),
                                    autor_object_id=model.id,
                                    target__id=int(post_id))
        if request.method == "POST":
            x = request.POST
            form = CommentsModelForm(data=x, ip=ip, instance=comment)
            if form.is_valid():
                m = form.save()

        if request.method == "POST":

            if form.is_valid():
                m = form.save()

    return HttpResponseRedirect(redirect_to)
Ejemplo n.º 4
0
def post_comment(request, id, parent=None):
    redirect_to = request.REQUEST.get('next', '')
    post = get_object_or_404(PostItem, pk=int(id))
    if request.user.is_authenticated() or request.user_site.is_authenticated():
        ip = get_client_ip(request)
        if request.user.is_authenticated():
            autor = request.user
        else:
            autor = request.user_site
        if request.method == "POST":
            x = request.POST
            form = CommentsModelForm(autor=autor,
                                     ip=ip,
                                     parent=parent,
                                     target=post,
                                     data=x)

            if form.is_valid():
                m = form.save()
            else:
                messages.add_message(request, messages.WARNING,
                                     _('AN_ERROR_OCURRED_LABEL'))

    return HttpResponseRedirect(redirect_to)
Ejemplo n.º 5
0
def rate_game(request, slug=None):
    gameinfo = None
    context2 = {'success': False}
    if request.method == "POST":
        x = request.POST
        form = RateForm(data=x)

        if form.is_valid():
            rating = form.cleaned_data.get('rating')
            ip = get_client_ip(request)

            headers = {
                "User-Agent": "Gamajuegos Browser",
                "Accept-Encoding": "gzip, deflate",
                "Accept": "application/json; charset=utf-8",
                "Accept-Language": "es-MX,es;q=0.8",
                "Connection": "keep-alive",
                'Content-type': 'application/json; charset=utf-8'
            }

            r = requests.post(settings.GET_GAME,
                              data=json.dumps({'slug': slug}),
                              headers=headers)
            r.encoding = 'utf-8'
            if r.status_code == 204:
                context2['success'] = False

            if r.status_code == 200:
                try:
                    gameinfo = json.loads(r.text.encode('utf-8'))
                    headers = {
                        "User-Agent": "Gamajuegos Browser",
                        "Accept-Encoding": "gzip, deflate",
                        "Accept": "application/json; charset=utf-8",
                        "Accept-Language": "es-MX,es;q=0.8",
                        "Connection": "keep-alive",
                        'Content-type': 'application/json; charset=utf-8'
                    }

                    r = requests.post(settings.GAMES_RATE,
                                      data=json.dumps({
                                          'parent_id':
                                          int(gameinfo.get('id')),
                                          'ip':
                                          ip,
                                          'ratting':
                                          rating
                                      }),
                                      headers=headers)
                    r.encoding = 'utf-8'

                    if r.status_code == 200:
                        context2['success'] = True
                    if r.status_code > 400:
                        context2['success'] = False
                except ValueError:
                    context2['success'] = False
            else:
                raise Http404

    return HttpResponse(json.dumps(context2))