Example #1
0
    def post(self, request, *args, **kwargs):
        #find parent node
        node_parent = Nodes.objects.get(path=request.POST.get('parent'))
        #add new node
        node_add = Nodes()
        node_add.path = request.POST.get('parent')+"/"+slugify(request.POST.get('title'))
        node_add.description = request.POST.get('title')
        node_add.parent = node_parent
        node_add.is_secure = request.POST.get('is_secure',False)
        node_add.is_active = request.POST.get('is_active',False)
        node_add.domain = Domains.objects.get(pk=request.POST.get('domain'))
        node_add.save()

        page_add = Pages()
        page_add.title = request.POST.get('title')
        page_add.slug = slugify(request.POST.get('title'))
        page_add.node=node_add
        page_add.short_description = request.POST.get('short_description')
        page_add.large_description = request.POST.get('large_description','')
        if not request.POST.get('author',False):
            page_add.author_text = request.POST.get('author_text')
        else:
            page_add.author = Accounts.objects.get(pk=request.POST.get('author'))
        page_add.save()
        messages.success(request,_("Page Added"))
        return redirect('/admin/cms')
Example #2
0
def pag(request, resource):
    if request.method == "GET":
        try:
            pagina = Pages.objects.get(name=resource)
            respuesta = pagina.page + "<br>"
            respuesta += "<br>Contenido de Barrapunto:<br>"
            respuesta += rss_contenido
        except Pages.DoesNotExist:
            respuesta = "La página no existe<p>"
            respuesta += "Rellene el siguiente formulario "
            respuesta += "si desea crearla:<p>"
            respuesta += FORMULARIO
    elif request.method == "POST":
        name = request.POST['nombre']
        page = request.POST['page']
        nueva_pag = Pages(name=name, page=page)
        nueva_pag.save()
        respuesta = "Pagina guardada "
        respuesta += VOLVER
    elif request.method == "PUT":
        try:
            pagina = Pages.objects.get(name=resource)
            respuesta = "La pagina ya está creada. "
            respuesta += VOLVER
        except Pages.DoesNotExist:
            nueva_pag = Pages(name=resource, page=request.body)
            nueva_pag.save()
            respuesta = "Se ha guardado la pagina "
            respuesta += nueva_pag.name + ". " + VOLVER
    else:
        respuesta = "Metodo no permitido"
    return HttpResponse(respuesta)
def content(request, key):

    if request.user.is_authenticated():
        try:
            resource = Pages.objects.get(name=key)
            if request.method == 'PUT':
                updated = Pages(id=resource.id,
                                name=resource.name,
                                page=request.body)
                updated.save()
                resource.page = request.body
            return HttpResponse(resource.page)

        except Pages.DoesNotExist:
            if request.method == 'PUT':
                new = Pages(name=key, page=request.body)
                new.save()
                return HttpResponse(new.page)
            return HttpResponseNotFound(
                '<h1><center>Resource not found</center></h1>')
    else:
        try:
            resource = Pages.objects.get(name=key)
            return HttpResponse(resource.page + '<br><br>Not logged in.' +
                                '<br><a href="/login">Login</a><br><br>')

        except Pages.DoesNotExist:
            return HttpResponse('Resource not found. Not logged in.' +
                                '<br><a href="/login">Login</a><br><br>')
def nuevonombre(request, uno, dos):
    if request.method == "POST":
        uno = request.POST['name']
        dos = request.POST['page']
        pag = Pages(name=uno, page=dos)
        pag.save()
        return HttpResponse("Nombre incluido correctamente")
    elif request.method == "PUT":
        cuerpo = request.body.decode('utf-8')
        uno, dos = cuerpo.split(",")
        pag = Pages(name=uno, page=dos)
        pagina.save()
        return HttpResponse("Nombre incluido correctamente")
    else:
        respuesta = "Operacion no valida"
        return HttpResponse(respuesta)
Example #5
0
 def get_context_data(self, slug, **kwargs):
     context = super(ArticleHomePage, self).get_context_data(**kwargs)
     settings = CmsSettings.all().get()
     article = Pages.all().filter("is_active =", True).filter("slug =", slug).get()
     context['post'] = article
     context['settings'] = settings
     return context
Example #6
0
 def get(self, request, *arg, **kwargs):
     context = self.get_context_data(**kwargs)
     """
     return the post list
     """
     articles = Pages.all().filter("is_active =", True).fetch(None)
     context['articles'] = articles
     return self.render_to_response(context)
def edit(request, key):
	
	if request.user.is_authenticated():
		try:
			resource = Pages.objects.get(name=key)
			
			if request.method == 'POST':
				text = str(request.POST['text'])
				updated = Pages(id=resource.id, name=resource.name, page=text) 
				updated.save()
				resource.page = text
				
			return render_to_response('form.html', {'text': resource.page})
		except Pages.DoesNotExist:
			return HttpResponseNotFound('<h1><center>Resource not found</center></h1>')
	else:
		return HttpResponse('Not logged in.' + '<br><a href="/login">Login</a><br><br>')
Example #8
0
 def get_context_data(self, **kwargs):
     # Call the base implementation first to get a context
     context = super(Admin_Cms_Pages_IndexController, self).get_context_data(**kwargs)
     # Add in a QuerySet of all the books
     q = Pages.all()
     results = q.fetch(None)
     context['pages'] = results
     return context
def get_page(request, req_name):
    try:
        req_page = Pages.objects.get(name=req_name).page
        if request.method == "GET":
            return HttpResponse(req_page)
        else:
            return HttpResponseNotFound("<h1>Page already exist.</h1>")
    except Pages.DoesNotExist:
        if request.method == "PUT":
            Pages(name=req_name, page=request.body).save()
            return HttpResponse("Page submitted.<br><br><a href=/>Home</a>")
        else:
            return HttpResponseNotFound("<h1>Page does not exist.</h1>")
def annotated(request):
    answer = ""
    user = ""
    if request.user.is_authenticated():
        user = request.user.username
        if request.method == "GET" :
            template = get_template('annotated.html')
        elif request.method == "PUT" or request.method == "POST":
            try:
                split_list = request.body.split('&', 2)
                name = split_list[1].split('=')[1]
                content = split_list[2].split('=')[1]
            except IndexError:
                print("eh! ha petado :)")
            if name != "" and content != "":
                database = Pages(name=name, page=content)
                database.save()
            else:
                return HttpResponse("Empty QS")
            template = get_template('annotated.html')
    else:
        template = get_template("unlogged.html")
    context = RequestContext(request, {"user" : user, "answer" : answer})
    return HttpResponse(template.render(context))
Example #11
0
def get_page(request, req_name):
    if request.method == "PUT":
        if request.user.is_authenticated():
            Pages(name=req_name, page=request.body).save()
            return HttpResponse("Page submitted.<br><br><a href=/>Home</a>")
        else:
            return HttpResponseNotFound("<h1>Login to add pages. "
                                        "<a href=/login>login</a></h1>")
    else:
        try:
            req_page = login_view(request)
            req_page += Pages.objects.get(name=req_name).page
            if request.method == "GET":
                return HttpResponse(req_page)
            else:
                return HttpResponseNotAllowed("['GET', 'PUT']",
                                              "<h1>405 Not Allowed</h1>")
        except Pages.DoesNotExist:
            return HttpResponseNotFound("<h1>Page does not exist.</h1>")
Example #12
0
def nuevonombre(request, uno, dos):
    if request.method == "POST":
        uno = request.POST['name']
        dos = request.POST['page']
        pag = Pages(name=uno, page=dos)
        pag.save()
        return HttpResponse("Nombre incluido correctamente")
    elif request.method == "PUT":
        cuerpo = request.body.decode('utf-8')
        uno, dos = cuerpo.split(",")
        pag = Pages(name=uno, page=dos)
        pagina.save()
        return HttpResponse("Nombre incluido correctamente")
    else:
        respuesta = "Operacion no valida"
        return HttpResponse(respuesta)
Example #13
0
 def form_valid(self, form):
     q = Pages(
           author=self.request.user,
           title=form.cleaned_data['title'],
           slug=str(slugify(form.cleaned_data['title'])),
           body=form.cleaned_data['body'],
           is_active=form.cleaned_data['is_active'],
           created=datetime.datetime.now().date())
     q.put()
     if form.cleaned_data['menu']:
         #put the page to the menu
         menu_base = Menu.get_by_id(int(form.cleaned_data['menu']))
         q = MenuItems(
               menu=menu_base,
               title = form.cleaned_data['menu_label'],
               namespc = "cms",
               view = "page",
               parameters = [str(slugify(form.cleaned_data['title']))],
               is_root=True).put()
               
     tags = self.request.POST.get('tags', False)
     if tags:
         splitted_tags = tags.split(",")
         for split in splitted_tags:
             result = Tags.all().filter("tag =", split).get()
             if result is None:
                 result = Tags(tag=split).put()
             PagesTags(tag=result, page=q).put()
     
     #add images
     large_image = self.request.FILES.get('large_image', False)
     
     if large_image:
         q.large_image = Images(content=db.Blob(large_image.read())).put()
         q.put()
     
     return super(Admin_Cms_Pages_AddController, self).form_valid(form)
Example #14
0
def nuevonombre(request, uno, dos):
    pag = Pages(name=uno, page=dos)
    pag.save()
    return HttpResponse("Nombre incluido correctamente")
Example #15
0
 def get(self, request):
     id_post = request.GET.get('id')
     q = Pages.get_by_id(int(id_post))
     db.delete(q)
     return redirect('/admin/app/cms/pages/index')