示例#1
0
def subcomment_list(request, comment_id):
    comment = get_object_or_404(IdeaComment, pk=comment_id)
    rendered_list = render_to_string(
        'idea/partials/comments/subcomment_list.html', {
            'list': comment.comments.all(),
        }
    )
    return json_response({'list': rendered_list})
示例#2
0
def vote_btns(request, idea_id):
    idea = get_object_or_404(Idea, pk=idea_id)
    return json_response({
        'yes_btn_html': render_to_string('idea/partials/yes_btn.html', {
            'idea': idea
        }),
        'no_btn_html': render_to_string('idea/partials/no_btn.html', {
            'idea': idea
        }),
    })
示例#3
0
def mobile_form_handler(request):
    success_response = {
        'success': True,
        'msg': 'Uspješno ste predali broj mobitela. Hvala!'
    }
    fail_response = {'success': False, 'msg': 'Neispravan broj.'}

    try:
        data = json.loads(request.body)
    except:
        return json_response(fail_response)

    mobile = re.sub('[^0-9]', '', data['mobile'])
    if len(mobile) not in [9, 10]:
        return json_response(fail_response)

    MobilePhone.objects.get_or_create(number=mobile)

    return json_response(success_response)
示例#4
0
def unflag_comment(request, comment_id):
    comment = get_object_or_404(IdeaComment, id=comment_id)
    comment.flagged_by.remove(request.user)
    return json_response({
        'message': 'Komentar nije SPAM.',
        'html': render_to_string('idea/partials/comments/inner.html',
            {
                'comment': comment,
                'flagged_comments_ids': request.user.get_profile().flagged_comments_ids
            })
    })
示例#5
0
def flag_comment(request, comment_id):
    comment = get_object_or_404(IdeaComment, id=comment_id)
    comment.flagged_by.add(request.user)
    return json_response({
        'message': 'Komentar je označen kao spam. Razmotriti ćemo tvoj prijedlog.',
        'html': render_to_string('idea/partials/comments/inner.html',
            {
                'comment': comment,
                'flagged_comments_ids': request.user.get_profile().flagged_comments_ids
            })
    })
示例#6
0
def comment_list(request, idea_id, state):
    idea = get_object_or_404(Idea, pk=idea_id)
    if request.user.is_authenticated():
        flagged_comments_ids = request.user.get_profile().flagged_comments_ids
    else:
        flagged_comments_ids = []
    comment_list = idea.comments.valid().select_related('user', 'user__profile').filter(state=state)
    rendered_list = render_to_string('idea/partials/comments/list.html', {
        'list': comment_list,
        'flagged_comments_ids': flagged_comments_ids
    })
    return json_response({'list': rendered_list})
示例#7
0
def member_list_ajax(request):
    try:
        offset = int(request.GET.get('offset', 0))
    except ValueError:
        raise Http404

    qs = UserProfile.objects.exclude(user__emailaddress__verified=False)\
        .filter(points__gt=0).distinct()

    html_list = MemberPresenter.qs_to_list(
        qs, request.GET.get('template', 'partials/small_item.html'), offset)

    return json_response(html_list)
示例#8
0
def blog_comment_add(request, blog_entry_id):
    blog_entry = get_object_or_404(BlogEntry, id=blog_entry_id)

    try:
        data = json.loads(request.body)
    except (ValueError, TypeError):
        data = None

    form = BlogEntryCommentForm(
        data,
        instance=BlogEntryComment(blog_entry=blog_entry, author=request.user))

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

    return json_response({})
示例#9
0
def idea_list(request):
    """ returns list of render idea cards """
    # offset
    try:
        offset = int(request.GET.get('offset', 0))
    except ValueError:
        raise Http404

    # initial queryset
    qs = Idea.objects.filter(approved=True)

    if request.subdomain == 'holdingjenas':
        qs = qs.filter(category__name="Holding je naš")

    # filter by user
    filter_user_id = request.GET.get('filter_user_id')
    if filter_user_id:
        qs = qs.filter(user_id=filter_user_id)

    # filter by district
    filter_district_id = request.GET.get('filter_district_id')
    if filter_district_id and filter_district_id != 'all':
        qs = qs.filter(district_id=filter_district_id)

    # filter by category
    filter_category_id = request.GET.get('filter_category_id')
    if filter_category_id and filter_category_id != 'all':
        qs = qs.filter(category_id=filter_category_id)

    # ordering
    order = request.GET.get('order')
    if order == 'latest':
        qs = qs.order_by('-created')
    elif order == 'top':
        qs = qs.order_by('-vote_diff', '-vote_yes_count')

    # render list of idea items (html)
    html_list = SmallBoxPresenter.qs_to_list(qs, request.GET.get(
        'template', 'idea/item.html'), offset)

    # if load_create_link in GET prepend html to html_list
    load_create_link = request.GET.get('load_create_link')
    if load_create_link:
        html_list.insert(0, render_to_string('idea/create_link.html',
            {'STATIC_URL': settings.STATIC_URL}))

    return json_response(html_list)
示例#10
0
def create_comment(request, idea_id, state):
    idea = get_object_or_404(Idea, pk=idea_id)
    data = None
    if request.raw_post_data:
        data = json.loads(request.raw_post_data)
    instance = IdeaComment(user=request.user, idea=idea, state=state)
    form = IdeaCommentForm(data, instance=instance)
    form_valid = False
    if form.is_valid():
        form.save()
        form = IdeaCommentForm()
        form_valid = True
    rendered_form = render_to_string(
        'idea/partials/comments/form.html', {'form': form}
    )
    return json_response({'form': rendered_form, 'form_valid': form_valid,
        'state': state})
示例#11
0
def vote(request, idea_id, state):
    idea = get_object_or_404(Idea, pk=idea_id)
    if state == 'yes':
        action = idea.vote_yes(request.user)
        if action == 'delete':
            message = 'Obrisan glas ZA prijedlog "%s". ' % idea.title
        else:
            message = 'Dodan glas ZA prijedlog "%s". ' % idea.title
    elif state == 'no':
        action = idea.vote_no(request.user)
        if action == 'delete':
            message = 'Obrisan glas PROTIV prijedloga "%s". ' % idea.title
        else:
            message = 'Dodan glas PROTIV prijedloga "%s". ' % idea.title

    message += "<br>Tvoji bodovi: %d" % request.user.get_profile().points
    return json_response({
        'action': action,
        'yes_count': idea.vote_yes_count,
        'no_count': idea.vote_no_count,
        'message': message
    })
示例#12
0
def blog_comment_delete(request, id):
    blog_entry_comment = get_object_or_404(BlogEntryComment, id=id)
    if request.user == blog_entry_comment.author:
        blog_entry_comment.delete()
    return json_response({})
示例#13
0
def blog_comment_list(request, blog_entry_id):
    blog_entry = get_object_or_404(BlogEntry, id=blog_entry_id)
    html = render_to_string('blog/comments/list.html',
                            RequestContext(request, {'entry': blog_entry}))
    return json_response({'html': html})
示例#14
0
def blog_sidebar(request, slug):
    return json_response([
        BlogSidebarPresenter(el, 'type_two').html
        for el in BlogHolder.objects.filter(slug__iexact=slug)
    ])
示例#15
0
def unban_comment(request, comment_id):
    comment = get_object_or_404(IdeaComment, id=comment_id)
    comment.banned = False
    comment.save()
    return json_response({})
示例#16
0
def disapprove_idea(request, idea_id):
    data = json.loads(request.raw_post_data)
    idea = get_object_or_404(Idea, pk=idea_id)
    idea.disapprove(data['reason'])
    return json_response({})
示例#17
0
def district_options(request):
    rendered_options = render_to_string('idea/partials/_district_options.html',
        {'districts': District.get_choices()})
    return json_response({'html': rendered_options})
示例#18
0
def test_login(request):
    return json_response({'result': request.user.is_authenticated()})
示例#19
0
def category_options(request):
    rendered_options = render_to_string('idea/partials/_category_options.html',
        {'categories': [(el.id, el.name.lower()) for el in IdeaCategory.objects.all()]})
    return json_response({'html': rendered_options})
示例#20
0
    fields = request.GET.get('fields', '')

    try:
      query = json.loads(query)
      fields = json.loads(fields)
    except Exception, err:
      logger.info(err)
      return http_400()

    engine = QueryGetEngine()
    try:
      info = engine.execute(ip, app_name, query, fields)
    except Exception:
      return http_403()

    return json_response(info)

class UserEventsView(View):
  def get(self, request, *args, **kwargs):
    ip = request.META['REMOTE_ADDR']
    uid = request.GET.get('uid', '')
    from_datetime = request.GET.get('from_datetime', '')
    to_datetime = request.GET.get('to_datetime', '')

    engine = UserEventsEngine()
    try:
      info = engine.execute(ip, uid, from_datetime, to_datetime)
    except Exception, err:
      logger.info(err)
      return http_403()
示例#21
0
def approve_idea(request, idea_id):
    idea = get_object_or_404(Idea, pk=idea_id)
    idea.approve()
    return json_response({})