How to hide a navigation portlet after logging out? What I exactly want is, if a logged-in admin visits a site, the navigation portlet should appear and be visible to him until he logs out from the plone site. But if a normal user visits the plone site, the portlet should not appear.
A nice feature of Plone is the option to assign portlets not only to locations, but also to contenttypes and groups. To solve your request, simply assign the portlet to the group 'Administrators'.
To do that, go to your Plonesite's controlpanel, click 'Users and Groups', click on green tab 'Groups', click on 'Administrators', click on the tab 'Group portlets', add a portlet.
To reproduce this programtically, use Genericsetup (export portlets.xml of the site and include the relevant parts in your product).
For completeness: Similiar for assigning portlets to a contenttype, you go to the controlpanel, click 'Types', choose the wanted type (f.e. 'Event') of the dropdownlist and click on 'Manage portlets assigned to this content type', assign portlet. Progragramtically reproducable via exporting 'Types' and including it to your products.
Thank you all, for all the response towards my question. Unfortunately the solution you all provided doesn't work for me. So I myself Did like this to hide a navigation portlet when logged out.
Step 1: In overrides.zcml
<plone:portlet
name="navigation_bar"
interface="plone.app.portlets.portlets.navigation.INavigationPortlet"
assignment="plone.app.portlets.portlets.navigation.Assignment"
renderer=".browser.navi_portlet.navigation_portlet"
addview="plone.app.portlets.portlets.navigation.AddForm"
editview="plone.app.portlets.portlets.navigation.EditForm"
/>
<plone:portletRenderer
portlet="plone.app.portlets.portlets.navigation.INavigationPortlet"
class=".browser.navi_portlet.navigation_portlet"
layer=".interfaces.IThemeSpecific"
/>
renderer=".browser.navi_portlet.navigation_portlet" here browser is my folder which contains a file called navi_portlet with a method navigation_portlet.
step 2: navi_portlet.py:
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.CMFPlone import PloneMessageFactory as _
from plone.app.portlets.portlets.navigation import Renderer
from plone.app.layout.viewlets.common import PersonalBarViewlet
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from plone.app.layout.globals.interfaces import IViewView
class navigation_portlet(Renderer,PersonalBarViewlet):
_template= ViewPageTemplateFile('templates/nav_portlet.pt')
def nav_up(self):
mytal = PersonalBarViewlet.update(self)
what i did in navi_portlet.py is i just inherited the PersonalBarViewlet from viewlets(eggs folder) and Renderer from portlets(eggs folder). To override the default behavior to hide it when logged out.
step 3: nav_portlet.pt
<dl class="actionMenu deactivated" id="portlet portletNavigationTree"
tal:define="user_actions python:view.nav_up();root view/navigation_root"
tal:condition="python:view.user_actions and not view.anonymous">
<tal:block condition="not: view/anonymous">
<dt class="portletHeader"
tal:attributes="class python:view.hasName() and 'portletHeader' or 'portletHeader hiddenStructure'">
<span class="portletTopLeft"></span>
<a href="#"
class="tile"
tal:attributes="href string:${view/heading_link_target}"
tal:content="view/title"
i18n:translate="">Navigation</a>
<span class="portletTopRight"></span>
</dt>
<dd class="portletItem lastItem">
<ul class="navTree navTreeLevel0">
<li tal:define="selectedClass view/root_item_class;
li_class python:selectedClass and ' navTreeCurrentNode' or '';
normalizeString nocall:context/plone_utils/normalizeString;
section_title root/Title;
section python:normalizeString(section_title);"
tal:condition="view/include_top"
tal:attributes="class string:navTreeItem navTreeTopNode${li_class} section-${section}">
<div tal:define="rootIsPortal view/root_is_portal;
root_icon view/root_icon;
root_type root/portal_type;
root_type_class python:'contenttype-' + normalizeString(root_type);
root_class python:rootIsPortal and 'contenttype-plone-site' or root_type_class;">
<a tal:attributes="href root/absolute_url;
title root/Description;
class python:' '.join([root_class, selectedClass]).strip();">
<img tal:replace="structure root_icon/html_tag" tal:condition="not:rootIsPortal" />
<span tal:omit-tag=""
tal:condition="rootIsPortal"
i18n:translate="tabs_home">Home</span>
<span tal:condition="not:rootIsPortal"
tal:replace="root/Title">Root item title</span>
</a>
</div>
</li>
<li tal:replace="structure view/createNavTree">
SUBTREE
</li>
</ul>
<span class="portletBottomLeft"></span>
<span class="portletBottomRight"></span>
</dd>
What i tried to do in nav_portlet.pt is to merge both portlets(Navigation Portlet using Render(class)) and viewlets(PersonalBarViewlet). so that i used the user_action method from the PersonalBarViewlet Class (i.etal:condition="python:view.user_actions and not view.anonymous">) to hide the Navigation Portlet when logged out.
Hope You all get my points and what i did.
Thanks
Related
Sooo what am trying to do is a link on CONTACT to redirect to HOME and scroll down to some content, but dont know how to pass # in urls in django. Any help appreciated. The scroll is fine on home but cant get it to work from contact.
URL
path('/#products', HomeView.as_view(), name='products'),
CONTACT.html
<a class="nav-link" href="{% url 'core:products' %}">Products</a>
HOME.html
this is in navbar
<a class="nav-link" style="cursor: pointer" href='#products'>Products</a>
this is where i want it scrolled
<a class="anchor" id="products"></a>
RedirectView for this:
views.py
from django.views.generic import RedirectView
from django.urls import reverse
class ViewpostRedirectView(RedirectView):
def get_redirect_url(*args, **kwargs):
hash_part = "add_data_Modal" # the data you want to add to the hash part
return reverse("createpost") + "#{0}".format(hash_part)
urls.py
path('viewpost/', views.createpost, name='createpost'),
path('viewpost/modal/', views.ViewpostRedirectView.as_view(), name='createpost_modal')
More info : https://www.kite.com/python/docs/django.views.generic.RedirectView
Hi I hope someone can help with this. I'm building a wordpress plugin. I just have basic knowledge of php and i managed to build the whole plugin except pagination. I have tried so many code using javascript but none is working for me. Here is the image. I want to divide the items with pagination
Thank you in advance!
A good approach will be to think about the pages like tabs. Then the page link will behave like buttons that show/hide based on the page link clicked.
Here's an example using jQuery
// Add an event listener for when the page link is clicked
$('.page-link').on('click', function(){
// Save the page number that was clicked
var pageNum = $(this).data('page-id')
// Hide any open 'pages'
$('.page-content').hide();
// Find and show the selected page
$('[data-page=' + pageNum + ']'').show();
});
For this to work, you'd need a HTML structure a bit like this
<!-- The Page Link -->
<div>
<ul>
<li class="page-link" data-page-id="1">Page 1</li>
<li class="page-link" data-page-id="2">Page 2</li>
<li class="page-link" data-page-id="3">Page 3</li>
</ul>
<!-- The Page Content -->
<div class="page-content" data-page="1" style="display: none;">
Page 1 content
</div>
<div class="page-content" data-page="2" style="display: none;">
Page 2 content
</div>
<div class="page-content" data-page="3" style="display: none;">
Page 3 content
</div>
</div>
Here is a super basic jsfiddle
I'm trying to show the full name for each news item in a list. For the moment I have only the user id (nickname).
Is there a simple way (in existing .pt file) to show the full name of creator or owner instead of a nickname?
The page must work for anonymous users, too. I mean - the page must be public.
Some details:
<div class="container-fluid news-list-container"
tal:define="news_items python:context.getFolderContents(contentFilter={'portal_type':['News Item'], 'sort_on': 'Date', 'sort_order': 'descending',});
Batch python:modules['Products.CMFPlone'].Batch;
b_size python:4;
b_start python:0;
b_start request/b_start | b_start;
batch python:Batch(news_items, b_size, int(b_start), orphan=0);"
tal:condition="news_items">
<div class="news-list-items">
<tal:items tal:repeat="news_item batch">
<!-- News item -->
<div class="row news-item"
tal:define="news_object python:news_item.getObject();
news_date python:news_object.getField('modification_date').getAccessor(news_object)();
news_title python:news_object.getField('title').getAccessor(news_object)();
news_description python:news_object.getField('description').getAccessor(news_object)();
news_image python:news_object.getField('image').getAccessor(news_object)();
news_url python:news_object.absolute_url();
news_creators python:news_object.getField('creators').getAccessor(news_object)(); .... ...
<tal:fullname define="membership context/portal_membership;
info python:membership.getMemberInfo(user.getId());
fullname info/fullname">
You are are <span class="name" tal:content="fullname" />
</tal:fullname>
This example is taken from the plone documentation
You can get inspired a lot by this code:
https://github.com/collective/Products.Scrawl/blob/1021047c4ef6c2655d104e8b345a24140da9e4aa/Products/Scrawl/browser/blogentry_view.pt#L32
<tal:name tal:condition="item_creator"
tal:define="author python:context.portal_membership.getMemberInfo(item_creator)">
<span i18n:translate="label_by_author">Posted by
<a href="#"
title="Read more posts by this author"
tal:attributes="href string:${context/portal_url}/author/${item_creator}"
tal:content="python:author and author['fullname'] or item_creator"
tal:omit-tag="not:author"
i18n:domain="scrawl"
i18n:name="author"
i18n:attributes="title author_title">
Bob Dobalina
</a>
</span>
</tal:name>
Mind the possible performance issues.
A cached view method may work a lot better, e.g.:
#memoize
def userid2fullname(self, userid):
pm = api.portal.get_tool('portal_membership')
memberinfo = pm.getMemberInfo(userid)
return memberinfo and memberinfo['fullname'] or userid
I need to display the shopping cart outside of the the HeaderLinks partial which takes the cart items out of the model passed by the CommonController.HeaderLinks action. By creating a new controller with an action that passes the cart info I was able to get the custom ui element from our template working. Right now the controller is inside a custom plugin I got going for some other stuff. The way I see it I have two options:
Leave the controller in the plugin project and live with the fact that if the plugin for some reason is not installed (i.e. a fresh checkout from a new dev.) the theme is going to break, possibly redirecting the user to the error view.
Put the controller in the Controllers folder at Nop.Web with the downside that this would add an extra step to the process of upgrading NopCommerce. If similar issues arise this could get ugly pretty quick.
So my question is: where is the best place to put the controller? Or is there a simpler way to do this thing with the shopping cart?
Regards,
Jose
i will show you a shortcut way to solve it. First create a partial (razor) view e.g _CustomPartialView and then add these usings at the top inside the partial view
#using Nop.Core;
#using Nop.Core.Infrastructure;
#using Nop.Services.Orders;
then next is to query the shopping cart which is easy becuase nopCommerce has already static way of accessing depency resolver method i.e EngineContext.Current.Resolve<T>(). In your case (for shopping cart) it could be the following;
#{
var shoppingCartEnabled = EngineContext.Current.Resolve<Nop.Services.Security.IPermissionService>()
.Authorize(Nop.Services.Security.StandardPermissionProvider.EnableShoppingCart);
var customer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
int shoppingCartItems = 0;
if (customer.HasShoppingCartItems)
{
shoppingCartItems = customer.ShoppingCartItems
.Where(sci => sci.ShoppingCartType == Nop.Core.Domain.Orders.ShoppingCartType.ShoppingCart)
.LimitPerStore(EngineContext.Current.Resolve<IStoreContext>().CurrentStore.Id)
.ToList()
.GetTotalProducts();
}
if (shoppingCartEnabled)
{
<div class="header-right pull-right wrap-cart hidden-xs ">
<div class="cart-top pull-right">
<div id="cart">
<span class="icon fa fa-shopping-cart"></span>
<div class="heading">
<a href="#Url.RouteUrl("ShoppingCart")" class="ico-cart dropdown-toggle visible-md visible-lg" data-toggle="dropdown" data-hover="dropdown">
<h4 class="cart-label">
#T("ShoppingCart")
<span>#T("ShoppingCart.HeaderQuantity", shoppingCartItems)</span>
</h4>
</a>
</div>
<div class="content">
#if (!String.IsNullOrWhiteSpace(Html.Action("FlyoutShoppingCart", "ShoppingCart").ToString()))
{
<li>#Html.Action("FlyoutShoppingCart", "ShoppingCart")</li>
}
</div>
</div>
</div>
</div>
}
}
Let me know if you need more help :)
I have a custom Dexterity type that utilizes plone.formwidget.multifile.MultiFileFieldWidget:
class ITestimony(form.Schema):
...
form.widget(files=MultiFileFieldWidget)
files = schema.List(
title=_(u"Files"),
value_type=NamedFile()
)
Everything goes well as expected when editing the item:
Here is the relevant view template, that I try borrow from https://developer.plone.org/reference_manuals/external/plone.app.dexterity/advanced/files-and-images.html:
<fieldset tal:condition="context/files">
<legend>Attached Files</legend>
<ul>
<tal:files repeat="item context/files">
<li><a href=""
tal:attributes="href string:${context/absolute_url}/##download/files/${item/filename};"
tal:content="item/filename">Attached File</a></li>
</tal:files>
</ul>
</fieldset>
I want the attached files can be downloaded by clicking on the links. But I get error with my current template:
AttributeError: 'list' object has no attribute 'getSize'
How can I download my uploaded files?
Actually the answer is from http://josh.postach.io/multiple-file-upload-custom-dexterity-content-types-plone-5-02a
The following snippet works for me:
<fieldset tal:condition="context/files">
<legend>Attached Files</legend>
<ul>
<tal:files repeat="item context/files">
<li><a href=""
tal:attributes="href string:${context/absolute_url}/##edit/++widget++form.widgets.files/##download/${repeat/item/index}"
tal:content="item/filename">Attached File</a></li>
</tal:files>
</ul>
</fieldset>
Although using ##edit is wired here, hopefully we will have better version of plone.formwidget.multifile or related packages soon.
Some notes about how files are handled with Dexterity are here:
http://developer.plone.org/forms/files.html
Specifically, constructing download URLs:
http://developer.plone.org/forms/files.html#connstring-download-urls
(##download helper view)