Beispiel #1
0
def update(request):
    id = eval("request." + request.method + "['id']")
    if Post.objects(id=id):
        post = Post.objects(id=id)[0]
        if request.method == 'POST':
            template = 'admin/index.html'
            # update field values and save to mongo
            post.title = request.POST['title']
            str_date_published = request.POST['date_published']
            post.date_published = datetime.fromtimestamp(
                mktime(time.strptime(str_date_published, "%b %d %Y")))
            post.publisher = request.POST['publisher']
            post.papertype = request.POST['papertype']
            post.authors = request.POST['authors']
            post.additional_info = request.POST['additional_info']
            post.page_num = request.POST['page_num']
            if request.POST.get('selectedpublication', True):
                post.selectedpublication = True
            post.save()
            params = {'Posts': Post.objects}

        elif request.method == 'GET':
            template = 'admin/update.html'
            params = {'post': post}

    elif Section.objects(id=id):
        section = Section.objects(id=id)[0]
        if request.method == 'POST':
            template = 'admin/index.html'
            # update field values and save to mongo
            section.heading = request.POST['heading']
            section.content = request.POST['content']
            section.save()
            params = {'Sections': Section.objects}

        elif request.method == 'GET':
            template = 'admin/update.html'
            params = {'section': section}

    elif Profile.objects(id=id):
        profile = Profile.objects(id=id)[0]
        if request.method == 'POST':
            template = 'admin/index.html'
            # update field values and save to mongo
            profile.details = request.POST['profile']
            profile.save()
            params = {'Profile': Profile.objects.limit(1)}

        elif request.method == 'GET':
            template = 'admin/update.html'
            params = {'Profile': Profile.objects.limit(1)}

    return render_to_response(template,
                              params,
                              context_instance=RequestContext(request))
Beispiel #2
0
def update(request):
    id = eval("request." + request.method + "['id']")
    if Post.objects(id=id):
        post = Post.objects(id=id)[0]
        if request.method == 'POST':
            template = 'admin/index.html'
            # update field values and save to mongo
            post.title = request.POST['title']
            #str_date_published = request.POST['date_published']
            #post.date_published = datetime.fromtimestamp(mktime(time.strptime(str_date_published, "%b %d %Y")))
            post.publisher = request.POST['publisher']
            post.papertype = request.POST['papertype']
            post.authors = request.POST['authors']
            #post.additional_info = request.POST['additional_info']
            #post.page_num = request.POST['page_num']
            #if request.POST.get('selectedpublication', True):
            #    post.selectedpublication = True;
            post.save()
            params = {'Posts': Post.objects} 

        elif request.method == 'GET':
            template = 'admin/update.html'
            params = {'post':post}
    
    elif Section.objects(id=id):
        section = Section.objects(id=id)[0]
        if request.method == 'POST':
            template = 'admin/index.html'
            # update field values and save to mongo
            section.heading = request.POST['heading']
            section.content = request.POST['content']
            section.save()
            params = {'Sections': Section.objects} 

        elif request.method == 'GET':
            template = 'admin/update.html'
            params = {'section':section}
            
    elif Profile.objects(id=id):
        profile = Profile.objects(id=id)[0]
        if request.method == 'POST':
            template = 'admin/index.html'
            # update field values and save to mongo
            profile.details = request.POST['profile']
            profile.save()
            params = {'Profile': Profile.objects.limit(1)} 

        elif request.method == 'GET':
            template = 'admin/update.html'
            params = {'Profile': Profile.objects.limit(1)}

    return render_to_response(template, params, context_instance=RequestContext(request))
Beispiel #3
0
def delete(request):
    id = eval("request." + request.method + "['id']")

    if request.method == 'POST':
        template = 'admin/index.html'
        if Post.objects(id=id):
            post = Post.objects(id=id)[0]
            post.delete()
            params = {'Posts': Post.objects, 'Sections': Section.objects, 'Profile': Profile.objects.limit(1)} 
        elif Section.objects(id=id):
            section = Section.objects(id=id)[0]
            section.delete()            
            params = {'Sections': Section.objects, 'Posts': Post.objects, 'Profile': Profile.objects.limit(1)} 
        elif Profile.objects(id=id):
            profile = Profile.objects(id=id)[0]
            profile.delete()            
            params = {'Profile': Profile.objects.limit(1), 'Sections': Section.objects, 'Posts': Post.objects} 
    elif request.method == 'GET':
        template = 'admin/delete.html'
        params = { 'id': id } 

    return render_to_response(template, params, context_instance=RequestContext(request))
Beispiel #4
0
def delete(request):
    id = eval("request." + request.method + "['id']")

    if request.method == 'POST':
        template = 'admin/index.html'
        if Post.objects(id=id):
            post = Post.objects(id=id)[0]
            post.delete()
            params = {
                'Posts': Post.objects,
                'Sections': Section.objects,
                'Profile': Profile.objects.limit(1)
            }
        elif Section.objects(id=id):
            section = Section.objects(id=id)[0]
            section.delete()
            params = {
                'Sections': Section.objects,
                'Posts': Post.objects,
                'Profile': Profile.objects.limit(1)
            }
        elif Profile.objects(id=id):
            profile = Profile.objects(id=id)[0]
            profile.delete()
            params = {
                'Profile': Profile.objects.limit(1),
                'Sections': Section.objects,
                'Posts': Post.objects
            }
    elif request.method == 'GET':
        template = 'admin/delete.html'
        params = {'id': id}

    return render_to_response(template,
                              params,
                              context_instance=RequestContext(request))