示例#1
0
def get_object_or_404(*args, **kwargs):
    try:
        return goo404(*args, **kwargs)
    except Http404:
        # Hack for old version of Django for saved datetimes in DB.
        # Migration is not safity, so I can't create it.
        timezone.activate(timezone.utc)
        obj = goo404(*args, **kwargs)
        timezone.deactivate()
        return obj
示例#2
0
文件: utils.py 项目: adw0rd/marcus
def get_object_or_404(*args, **kwargs):
    try:
        return goo404(*args, **kwargs)
    except Http404:
        # Hack for old version of Django for saved datetimes in DB.
        # Migration is not safity, so I can't create it.
        timezone.activate(timezone.utc)
        obj = goo404(*args, **kwargs)
        timezone.deactivate()
        return obj
示例#3
0
文件: views.py 项目: zoyron/CodeShare
def code_by_filename(request, file_name,format=None):   
    if request.method == 'GET':
        code_share = goo404(CodeShare,file_name=file_name)
        serialized_code=Codeserializer(code_share)
        return Response(serialized_code.data)        
    if request.method == 'POST':     
        code_obj = goo404(CodeShare,file_name=file_name)
        serializer=Codeserializer(code_obj,data=request.data)
        if  serializer.is_valid():
                serializer.validated_data["file_name"]=code_obj.file_name
                serializer.save()
                return Response(serializer.data)
        return Response("error occured")
示例#4
0
def view_by_hash(request, hash_id):
    if request.method == 'GET':
        code_obj = goo404(bugshare, hash_value=hash_id)
        return render(request, 'shareapp/home.html', {
            "modelcode": code_obj,
            "filename": "yes"
        })
    if request.method == 'POST':
        code = request.POST.get('code_snippet')
        code_obj = goo404(bugshare, hash_value=hash_id)
        code_obj.code = code
        code_obj.save()
        return redirect("shareapp:view_by_hash", hash_id=hash_id)
示例#5
0
def code_by_filename(request, file_name, format=None):
    if request.method == 'GET':
        code_share = goo404(CodeShare, file_name=file_name)
        serialized_code = Codeserializer(code_share)
        return Response(serialized_code.data)
    if request.method == 'POST':
        code_share = request.POST.get('code_snippet')
        code_obj = goo404(CodeShare, file_name=file_name)
        serializer = Codeserializer(code_obj, data=request.data)
        if serializer.is_valid():
            obj = serializer.save()
            obj.code = code_share
            obj.save()
            return Response(serializer.data)
        return Response("error occured")
示例#6
0
def view_by_hash(request, hash_id):
    """
    retrives the code snippet associated with the unique Hash anda handles the editing

    :param hash_id: unique ID of the code snippet

    GET:
        query database for code snippet

        :returns code snippet

    POST:
        handles updation in the content

        :param code_snippet: updated code snippet

        :returns redirects to this view again to render the new results
        
    """

    if request.method == 'GET':
        code_share = CodeShare.objects.get(hash_value=hash_id)
        return render(request, 'app_code_share/homepage.html', {
            'code_share': code_share,
            "filename": "yes"
        })

    if request.method == 'POST':
        code_share = request.POST.get('code_snippet')
        code_obj = goo404(CodeShare, hash_value=hash_id)
        code_obj.code = code_share
        code_obj.save()

        return redirect('code_share:view_by_hash', hash_id=hash_id)
示例#7
0
def code_by_hash(request, hash_id, format=None):
    if request.method == 'GET':
        code_share = goo404(CodeShare, hash_value=hash_id)
        serialized_code = Codeserializer(code_share)
        return Response(serialized_code.data)
    if request.method == 'POST':
        code_share = request.POST.get('code_snippet')
        code_obj = goo404(CodeShare, hash_value=hash_id)
        serializer = Codeserializer(code_obj, data=request.data)
        if serializer.is_valid():
            obj = serializer.save()
            obj.code = code_share
            obj.save()
            return Response(serializer.data)
        else:
            return JsonResponse("error occured")
示例#8
0
def view_by_name(request,name):
    if request.method=='GET':
        code = request.objects.get(name=name)
        return render(request,'shareapp/homepage.html',{'code':code})
    if request.method=='POST':
        code = request.POST.get('code')
        code_object = goo404(bugshare,name=name)
        code_object = code
        code_object.save()
        return render('shareapp:view_by_name',name=name)
示例#9
0
def view_by_hash(request,hash_id):
    if request.method=='GET':
        code = Bugshare.objects.get(hash_value=hash_id)
        return render(request,'shareapp/homepage.html',{'code':code})
    if request.method=='POST':
        code = request.POST.get('code')
        code_object = goo404(bugshare,hash_value=hash_id)
        code_object = code
        code_object.save()
        return render('shareapp:view_by_hash',hash_id=hash_id)