예제 #1
0
def jsonify(raw, wrap=None):
  expr = raw

  if wrap:
    expr = json.success(raw) if wrap.lower()[0] == 's' else json.error(raw)
  
  return mark_safe(serialize_json(expr))
예제 #2
0
def abandon(request):
    if request.method == "POST":
        abandon_form = AbandonForm(request, data=request.POST)
        if abandon_form.is_valid():
            abandon_form.save()
            return json.success({ 'sidebar': render_sidebar(request.user) })

        return json.error(abandon_form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #3
0
def settings_notice(request):
    if request.method == "POST":
        notice_form = NoticeForm(request, data=request.POST)
        if notice_form.is_valid():
            notice_form.save()
            return json.success()

        return json.error(notice_form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #4
0
def transfer(request):
    if request.method == "POST":
        transfer_form = TransferForm(request, data=request.POST)
        if transfer_form.is_valid():
            transfer_form.save()
            return json.success({ 'sidebar': render_sidebar(request.user) })

        return json.error(transfer_form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #5
0
def markup(request):
    if request.method == "POST":
        markup_form = MarkupForm(request, data=request.POST)
        if markup_form.is_valid():
            markup_form.save()
            return json.success({ 'sidebar': render_sidebar(request.user) })

        return json.error(markup_form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #6
0
def guide(request):
    if request.method == "POST":
        guide_form = GuideForm(request, data=request.POST)
        if guide_form.is_valid():
            guide_form.save()
            return json.success({ 'sidebar': render_sidebar(request.user) })

        return json.error(guide_form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #7
0
def invite(request):
    if request.method == "POST":
        invite_form = InviteForm(request, data=request.POST)
        if invite_form.is_valid():
            invite_form.save()
            return json.success()

        return json.error(invite_form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #8
0
def resign(request):
    if request.method == "POST":
        form = LeadResignForm(request, data=request.POST)

        if form.is_valid():
            form.save()
            return json.success({})

        return json.error(form.errors)
    return HttpResponseNotAllowed(["POST"])
예제 #9
0
def invite(request):
    if request.method == 'POST':
        form = InviteForm(request, data=request.POST)

        if form.is_valid():
            code = form.save()
            return json.success({ "code": code })

        return json.error(form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #10
0
def invite(request):
    if request.method == 'POST':
        form = NewInvitation(data=request.POST)

        if form.is_valid():
            form.save()
            return json.success()

    return json.error(form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #11
0
def follow_bulletin(request):
    if request.method == 'POST':
        form = FollowForm(request, data=request.POST)

        if form.is_valid():
            followed = form.save()
            return json.success({'followed': followed, 'id': request.user.pk, 'username': request.user.username, 'url': render_to_string('account/gravatar_img.jade', {'user': request.user})})

        return json.error(form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #12
0
def promote_bulletin(request):
    if request.method == 'POST':
        form = PromoteForm(request, data=request.POST)

        if form.is_valid():
            form.save()
            return json.success()

        return json.error(form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #13
0
def add_comment(request):
    if request.method == 'POST':
        form = CommentForm(request, data=request.POST)

        if form.is_valid():
            form.save()
            comments = request.bulletin.comment_set.all().order_by('-created_at')
            return json.success({'feed': render_to_string('comment/comments.jade', {'comments': comments, 'current_user': request.user, 'current_chapter': request.chapter})})

        return json.error(form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #14
0
  def wrap(request, *args, **kwargs):
    response = None
    
    # Handle jsonp remote requests appropriately
    jsonp = (
      'callback' in request.REQUEST,
      request.REQUEST.get('callback', None)
    )

    try:
      response = func(request, *args, **kwargs)
      
      if not isinstance(response, dict):
        return response

    except Exception, e:
      if settings.DEBUG:
        import traceback
        response = json.error(traceback.format_exc())
      else:
        response = json.error("An error has occurred")
예제 #15
0
def add_pending(request):
    if request.method == 'POST' and request.user.get_profile().chapter:
        form = PendingForm(request, data=request.POST)

        if form.is_valid():
            form.save()
            pending = Pending.objects.filter(chapter=request.chapter).order_by('-created')
            contextDict = {'pendings': pending}
            context = Context(contextDict)

            template = get_template('pending/pendings.jade')
            return json.success({'feed': template.render(context)})

        return json.error(form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #16
0
def edit_talk(request):
    if request.method == 'POST':
        form = TalkForm(request, data=request.POST)

        if form.is_valid():
            form.save(request.bulletin)
            talks = Talk.objects.filter(chapter=request.chapter).order_by('-created')
            contextDict = {'talks': talks, 'current_user': request.user}
            context = Context(contextDict)

            template = get_template('talk/talks.jade')
            return json.success({'feed': template.render(context)})

        return json.error(form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #17
0
def add_intro(request):
    if request.method == 'POST':
        form = IntroductionForm(request, data=request.POST)

        if form.is_valid():
            form.save()
            intros = Introduction.objects.filter(chapter=request.chapter).order_by('-created')
            contextDict = {'intros': intros, 'current_user': request.user}
            context = Context(contextDict)

            template = get_template('introduction/intros.jade')
            return json.success({'feed': template.render(context)})

        return json.error(form.errors)
    return HttpResponseNotAllowed(['POST'])
예제 #18
0
    def _inner(request):
        if request.method == "POST":
            form = formcls(request, data=request.POST)

            if form.is_valid():
                form.save()
                contextDict = {"current_user": request.user}
                mentees = request.user.get_profile().get_mentees() if request.is_insider else []

                if request.user.get_profile().is_leader:
                    pending_requests = []
                else:
                    pending_requests = Leadership.objects.filter(
                        owner=request.user, response=Leadership.PENDING
                    ).order_by("-created")

                mentee_chunks = []

                if mentees:
                    mentee_chunks = chunks(mentees, 3)

                count = 0
                for chunk in mentee_chunks:
                    count += 3
                    for i in range(0, 3 - len(chunk)):
                        chunk.append({"mentee": None})

                for i in range(0, (settings.MAX_MENTEES - count) / 3):
                    mentee_chunks.append([{"mentee": None} for j in range(0, 3)])

                my_mentee_string = ",".join([mentee.user.username for mentee in mentees])
                contextDict["mentee_chunks"] = mentee_chunks
                contextDict["my_mentee_string"] = my_mentee_string
                contextDict["pending_requests"] = pending_requests
                contextDict["current_chapter"] = request.chapter
                context = Context(contextDict)

                template = get_template("chapter/sidebar.jade")
                return json.success({"sidebar": template.render(context)})

            return json.error(form.errors)
        return HttpResponseNotAllowed(["POST"])