Beispiel #1
0
def page_create(request, page_id=None):

    if page_id:
        page = get_object_or_404(Page, pk=page_id)
    else:
        page = Page()

    if request.method == 'POST':
        form = PageForm(request.POST, instance=page)
        serial = MakeRndCode()
        serialCd = serial.mkrnd()
        if form.is_valid():
            page = form.save(commit=False)
            page.serialcd = serialCd

            #response = HttpResponse('test')
            response = redirect('cms:member_list')
            response['location'] += '?S=' + serialCd + '&case=1'

            #response.set_cookie('serial_cd', serialCd)

            page.save()
            #return redirect('cms:member_list')
            #return render(request, 'cms/member_list.html')
            return response
    else:
        form = PageForm(instance=page)

    #初回きた時はGetなので、そのままindexを渡す
    #POSTでリクエストがきたら、Saveして、メンバーリストに飛ばす
    #ここからはクッキーでIDを渡す
    #DBにはPageIDを持つ

    return render(request, 'cms/index.html', dict(form=form))
Beispiel #2
0
def page_edit(request, pk):
    page = get_object_or_404(Page, pk=pk)

    if request.POST.get('save'):
        page_form = PageForm(request.POST, instance=page)
        if page_form.is_valid():
            page = page_form.save()

            # Moderation not required for moderators or superusers
            if request.user.profile.is_moderator or request.user.is_superuser:
                page.vised()

            return redirect('cms:menu', pk=page.menu.id)
    else:
        page_form = PageForm(initial={'last_edit_by': request.user},
            instance=page)

    if request.POST.get('upload'):
        attach_form = AttachmentForm(request.POST, request.FILES)
        if attach_form.is_valid():
            attach_form.save()
    else:
        attach_form = AttachmentForm(initial={'page': page})

    return render(request, Page.tmpl_edit(), {
        'page': page,
        'page_form': page_form,
        'attach_form': attach_form,
        # TODO: LANG in template context processor
        'LANG': get_language(),
    })
Beispiel #3
0
def page_edit(request, path):
    
    if not can_edit(request.user):
        raise Http404
    
    try:
        page = Page.published.get(path=path)
    except Page.DoesNotExist:
        page = None
    
    if request.method == "POST":
        form = PageForm(request.POST, instance=page)
        if form.is_valid():
            page = form.save(commit=False)
            page.path = path
            page.save()
            return redirect(page)
        else:
            print form.errors
    else:
        form = PageForm(instance=page, initial={"path": path})
    
    return render(request, "cms/page_edit.html", {
        "path": path,
        "form": form
    })
def new_page_form(request):
	if request.method == 'POST':
		form = PageForm(request.POST)
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('')
	else:
		form = PageForm()
	return render(request, "new_page.html", {'form' : form})
Beispiel #5
0
    def post(self, request, *args, **kwargs):
        if permissions.can_user_create_page(self.request.user):
            form = PageForm(request.POST)

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

                return HttpResponseRedirect(reverse('cms:homepage_url'))
            else:
                return self.render_to_response(self.get_context_data(form=form))
        else:
            return HttpResponseForbidden('You do not have permission to access this page.')
Beispiel #6
0
def page(request,page_id,page_name):
    try:

        menu_item = MenuItem.objects.get(pk=page_id)
        page = menu_item.topic.pages.all()[0]
        page_form = PageForm(instance=page)
        if (request.method == "POST"):
            page_form = PageForm(instance=page, data=request.POST)
            if (page_form.is_valid()):
                page = page_form.save(commit=False)
                page.save()
                print("page saved")
                messages.add_message(request, messages.INFO, _('This page was successfully saved.'))

        return render_to_response('cms/page.html', {'page': page, 'form': page_form, 'menu_item': menu_item},
                                  context_instance=RequestContext(request))
    except Exception as e:
        print(e)
        raise Http404
Beispiel #7
0
def page_add(request, menu_pk):
    menu = get_object_or_404(Menu, pk=menu_pk)
    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            page = form.save()

            # Moderation not required for moderators or superusers
            if request.user.profile.is_moderator or request.user.is_superuser:
                page.publish()
                page.vised()

            return redirect('cms:menu', pk=menu.id)
    else:
        form = PageForm(initial={
            'menu': menu, 'region': get_region(), 'last_edit_by': request.user
        })
    return render(request, Page.tmpl_add(), {
        'menu': menu,
        'form': form,
        # TODO: LANG in template context processor
        'LANG': get_language(),
    })
Beispiel #8
0
    def page_add_edit(self, request, id=None):
        model = self.model
        opts = model._meta

        if id:
            page = get_object_or_404(Page, pk=id)
            form = PageForm(request, instance=page)
            add = False
        else:
            page = None
            form = PageForm(request)
            add = True

        page_contents = not add and page.pagecontent_set.all()

        pagecontent_data = None

        if request.method == 'POST':
            if not add:
                pagecontent_forms = PageContentForm.get_forms(request)
                pagecontent_data = [pagecontent_form.render_js('from_template') for pagecontent_form in pagecontent_forms]


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

                if not add:
                    # Save the PageContents
                    for pagecontent_form in pagecontent_forms:
                        if pagecontent_form.id:
                            try:
                                page_content = PageContent.objects.get(pk=pagecontent_form.id)
                            except PageContent.DoesNotExist:
                                page_content = PageContent() # Is this ok?
                        else:
                            page_content = PageContent()
                        set_values(page_content, PAGECONTENT_FIELDS, pagecontent_form.cleaned_data)
                        page_content.page = page
                        page_content.save()

                # Inform the user
                if add:
                    request.user.message_set.create(message=_('The page was added successfully. Now you can create your content.'))
                else:
                    request.user.message_set.create(message=_('The page was updated successfully. You may edit it again below.'))

                return HttpResponseRedirect('../%d/' % page.id)

        else: # get
            if not add:
                pagecontent_data = []
                for page_content in page_contents:
                    content_form = PageContentForm(
                        initial=get_values(page_content, PAGECONTENT_FIELDS),
                        id=page_content.id)
                    pagecontent_data.append(content_form.render_js('from_template'))

        media = self.media
        if USE_TINYMCE:
            media.add_js(self.tinymce_js)
        media.add_js((
            "cms/js/dynamicforms.js",
            "cms/js/page_add.js",
        ))

        return render_to_response('cms/page_add.html', {
                'title': u'%s %s' % (add and _('Add') or _('Edit'), _('page')),
                'page': page,
                'form': form,
                'add':add,
                'page_contents': page_contents,
                'page_addons': PAGE_ADDONS,
                'pagecontent_template': PageContentForm().render_js('from_template'),
                'pagecontent_data': pagecontent_data,
                'use_tinymce': USE_TINYMCE,
                'root_path': self.admin_site.root_path,
                'media': mark_safe(media),
                'opts': opts,
            }, context_instance=RequestContext(request))
    def page_add_edit(self, request, id=None):
        model = self.model
        opts = model._meta

        if id:
            page = get_object_or_404(Page, pk=id)
            form = PageForm(request, instance=page)
            add = False
        else:
            page = None
            form = PageForm(request)
            add = True

        page_contents = not add and page.pagecontent_set.all()

        pagecontent_data = None

        if request.method == 'POST':
            if not add:
                pagecontent_forms = PageContentForm.get_forms(request)
                pagecontent_data = [pagecontent_form.render_js('from_template') for pagecontent_form in pagecontent_forms]
            if form.is_valid() and (add or pagecontent_forms.are_valid()):
                page = form.save()

                if not add:
                    # Save the PageContents
                    for pagecontent_form in pagecontent_forms:
                        if pagecontent_form.id:
                            try:
                                page_content = PageContent.objects.get(pk=pagecontent_form.id)
                            except PageContent.DoesNotExist:
                                page_content = PageContent() # Is this ok?
                        else:
                            page_content = PageContent()
                        set_values(page_content, PAGECONTENT_FIELDS, pagecontent_form.cleaned_data)
                        page_content.page = page
                        page_content.save()

                # Inform the user
                if add:
                    request.user.message_set.create(message=_('The page was added successfully. Now you can create your content.'))
                else:
                    request.user.message_set.create(message=_('The page was updated successfully. You may edit it again below.'))

                return HttpResponseRedirect('../%d/' % page.id)

        else: # get
            if not add:
                pagecontent_data = [PageContentForm(
                        initial=get_values(page_content, PAGECONTENT_FIELDS),
                        id=page_content.id
                    ).render_js('from_template') for page_content in page_contents]

        media = self.media
        if USE_TINYMCE:
            try:
                from tinymce import settings as tinymce_settings
            except ImportError:
                try:
                    from tinymce import widgets as tinymce_settings
                except ImportError:
                    raise ImportError, _('tinymce app not found in sys.path. Is tinymce app installed?')
            except NoReverseMatch:
                raise NoReverseMatch, _('Can not find tinymce helper script or app is misonfigured. Is tinymce app installed?')
            helper_script_url = reverse("tinymce-js", kwargs={'name': "cms",})
            media.add_js((
                tinymce_settings.JS_URL,
                helper_script_url,
            ))
        media.add_js((
            "cms/js/dynamicforms.js",
            "cms/js/page_add.js",
        ))

        return render_to_response('cms/page_add.html', {
                'title': u'%s %s' % (add and _('Add') or _('Edit'), _('page')),
                'page':page,
                'form':form,
                'add':add,
                'page_contents':page_contents,
                'page_addons': PAGE_ADDONS,
                'use_tinymce': unicode(USE_TINYMCE),
                'pagecontent_template':PageContentForm().render_js('from_template'),
                'pagecontent_data':pagecontent_data,
                'use_tinymce': USE_TINYMCE,
                'root_path': self.admin_site.root_path,
                'media': mark_safe(media),
                'opts': opts,
            }, context_instance=RequestContext(request))