예제 #1
0
def new_blog_entry(request):
    """
    TODO: Use Ajax in preview
    """
#    user_profile = request.user.get_profile()
    # All accessible sites from the current user:
#    user_site_ids = user_profile.sites.values_list("id", "name")
#    m2m_limit = {"sites": user_site_ids} # Limit the site choice field with LimitManyToManyFields

    context = {
        "title": _("Create a new blog entry"),
        "form_url": request.path,
        "tag_cloud": BlogEntry.objects.get_tag_cloud(request),
        "add_tag_filter_link": False, # Don't add filters in tag cloud
    }

    if request.method == "POST":
        form = BlogEntryForm(request.POST)
        if form.is_valid():
            instance = form.save()
            messages.success(request, _("New blog entry '%s' saved.") % instance.headline)
            return http.HttpResponseRedirect(instance.get_absolute_url())
    else:
        # Get preferences
        pref_form = BlogPrefForm()

        initial = {
            "sites": get_site_preselection(pref_form, request), # preselect sites field
            "language": request.PYLUCID.current_language.pk, # preselect current language
        }
        form = BlogEntryForm(initial=initial)

    context["form"] = form
    return context
예제 #2
0
def new_entry(request):
    """ create a new lexicon entry """
    context = {
        "title": _("Create a new lexicon entry"),
        "form_url": request.path,
        "abort_url": "/",
    }

    context = _extend_form_url(request, context)

    if request.method == "POST":
        form = LexiconEntryForm(request.POST)
        if form.is_valid():
            instance = form.save()
            messages.info(request, _("Lexicon entry '%s' saved.") % instance.term)
            return http.HttpResponseRedirect(instance.get_absolute_url())
    else:
        # Get preferences
        pref_form = LexiconPrefForm()

        initial = {
            "sites": get_site_preselection(pref_form, request), # preselect sites field
            "language": request.PYLUCID.current_language.pk, # preselect current language
        }
        form = LexiconEntryForm(initial=initial)

    context["form"] = form
    return context
예제 #3
0
def new_blog_entry(request):
    """
    TODO: Use Ajax in preview
    """
    #    user_profile = request.user.get_profile()
    # All accessible sites from the current user:
    #    user_site_ids = user_profile.sites.values_list("id", "name")
    #    m2m_limit = {"sites": user_site_ids} # Limit the site choice field with LimitManyToManyFields

    try:
        plugin_page = PluginPage.objects.filter(app_label__endswith="blog")[0]
    except IndexError:
        messages.error(
            request,
            _("There exist no blog plugin page, yet. Please create one, first."
              ))
        return http.HttpResponseRedirect("/")

    context = {
        "title": _("Create a new blog entry"),
        "form_url": request.path,
        "tag_cloud": BlogEntryContent.objects.get_tag_cloud(request),
        "add_tag_filter_link": False,  # Don't add filters in tag cloud
    }

    if request.method == "POST":
        if "cancel" in request.POST:
            messages.info(request, _("Create new blog entry aborted, ok."))
            url = plugin_page.get_absolute_url()
            return http.HttpResponseRedirect(url)

        form = BlogForm(request.POST)
        if form.is_valid():
            new_entry = BlogEntry.objects.create()
            new_entry.sites = form.cleaned_data["sites"]
            new_entry.save()

            blog_content = form.save(commit=False)
            blog_content.entry = new_entry
            blog_content.save()

            messages.success(
                request,
                _("New blog entry '%s' saved.") % blog_content.headline)
            return http.HttpResponseRedirect(blog_content.get_absolute_url())
    else:
        # Get preferences
        pref_form = BlogPrefForm()

        initial = {
            "sites": get_site_preselection(pref_form,
                                           request),  # preselect sites field
            "language":
            request.PYLUCID.current_language.pk,  # preselect current language
        }
        form = BlogForm(initial=initial)

    context["form"] = form
    return context
예제 #4
0
def new_blog_entry(request):
    """
    TODO: Use Ajax in preview
    """
#    user_profile = request.user.get_profile()
    # All accessible sites from the current user:
#    user_site_ids = user_profile.sites.values_list("id", "name")
#    m2m_limit = {"sites": user_site_ids} # Limit the site choice field with LimitManyToManyFields

    try:
        plugin_page = PluginPage.objects.filter(app_label__endswith="blog")[0]
    except IndexError:
        messages.error(request, _("There exist no blog plugin page, yet. Please create one, first."))
        return http.HttpResponseRedirect("/")

    context = {
        "title": _("Create a new blog entry"),
        "form_url": request.path,
        "tag_cloud": BlogEntryContent.objects.get_tag_cloud(request),
        "add_tag_filter_link": False, # Don't add filters in tag cloud
    }

    if request.method == "POST":
        if "cancel" in request.POST:
            messages.info(request, _("Create new blog entry aborted, ok."))
            url = plugin_page.get_absolute_url()
            return http.HttpResponseRedirect(url)

        form = BlogForm(request.POST)
        if form.is_valid():
            new_entry = BlogEntry.objects.create()
            new_entry.sites = form.cleaned_data["sites"]
            new_entry.save()

            blog_content = form.save(commit=False)
            blog_content.entry = new_entry
            blog_content.save()

            messages.success(request, _("New blog entry '%s' saved.") % blog_content.headline)
            return http.HttpResponseRedirect(blog_content.get_absolute_url())
    else:
        # Get preferences
        pref_form = BlogPrefForm()

        initial = {
            "sites": get_site_preselection(pref_form, request), # preselect sites field
            "language": request.PYLUCID.current_language.pk, # preselect current language
        }
        form = BlogForm(initial=initial)

    context["form"] = form
    return context
예제 #5
0
def new_entry(request):
    """ create a new lexicon entry """
    context = {
        "title": _("Create a new lexicon entry"),
        "form_url": request.path,
    }

    context = _extend_form_url(request, context)

    if request.method == "POST":
        if "cancel" in request.POST:
            messages.info(request, _("Create new lexicon entry aborted, ok."))
            try:
                url = PluginPage.objects.reverse("lexicon",
                                                 viewname="Lexicon-summary")
            except urlresolvers.NoReverseMatch:
                messages.warning(
                    request,
                    _("Lexicon plugin page doesn't exists, yet. Please create."
                      ))
                url = "/"
            return http.HttpResponseRedirect(url)

        form = LexiconEntryForm(request.POST)
        if form.is_valid():
            instance = form.save()
            messages.info(request,
                          _("Lexicon entry '%s' saved.") % instance.term)
            return http.HttpResponseRedirect(instance.get_absolute_url())
    else:
        # Get preferences
        pref_form = LexiconPrefForm()

        initial = {
            "sites": get_site_preselection(pref_form,
                                           request),  # preselect sites field
            "language":
            request.PYLUCID.current_language.pk,  # preselect current language
        }
        form = LexiconEntryForm(initial=initial)

    context["form"] = form
    return context
예제 #6
0
def new_entry(request):
    """ create a new lexicon entry """
    context = {
        "title": _("Create a new lexicon entry"),
        "form_url": request.path,
    }

    context = _extend_form_url(request, context)

    if request.method == "POST":
        if "cancel" in request.POST:
            messages.info(request, _("Create new lexicon entry aborted, ok."))
            try:
                url = PluginPage.objects.reverse("lexicon", viewname="Lexicon-summary")
            except urlresolvers.NoReverseMatch:
                messages.warning(request, _("Lexicon plugin page doesn't exists, yet. Please create."))
                url = "/"
            return http.HttpResponseRedirect(url)

        form = LexiconEntryForm(request.POST)
        if form.is_valid():
            instance = form.save()
            messages.info(request, _("Lexicon entry '%s' saved.") % instance.term)
            return http.HttpResponseRedirect(instance.get_absolute_url())
    else:
        # Get preferences
        pref_form = LexiconPrefForm()

        initial = {
            "sites": get_site_preselection(pref_form, request), # preselect sites field
            "language": request.PYLUCID.current_language.pk, # preselect current language
        }
        form = LexiconEntryForm(initial=initial)

    context["form"] = form
    return context