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
Related
I have an icon on a navigation bar which serves as a link to a admin route, I'd like this icon to change when I'm on that specific route, for this I can just replace the mdi-settings-outline class with mdi-settings, which will show a filled version of the same icon.
<li class="nav-item">
<a routerLink="/admin" routerLinkActive="mdi-settings" class="nav-link mdi mdi-settings-outline"></a>
</li>
However the regular routerLinkActive directive will only add the mdi-settings class to the link, which won't have the desired result. Can the routerLinkActive directive somehow replace the class instead of just adding it?
The routerLinkActive exports some properties that you can use in the template. You access the API by assigning the directive to a template variable. This is done by adding #link="routerLinkActive" where "link" is the name of the variable.
You can then use the properties of the directive, which are defined here in the API documentation.
https://angular.io/api/router/RouterLinkActive#properties
<li class="nav-item">
<a routerLink="/admin"
routerLinkActive="mdi-settings"
#link="routerLinkActive"
class="nav-link mdi"
[class.mdi-settings-outline]="!link.isActive"
></a>
</li>
Need to make the variable unique for each link
<a mat-list-item
[routerLinkActive]="['']"
[routerLinkActiveOptions]="{ exact: true }"
#reportsLink="routerLinkActive"
[ngClass]="reportsLink.isActive ? 'route-active': 'route-inactive'"
[routerLink]="['/reports']"
title="Reports">
</a>
<a mat-list-item
[routerLinkActive]="['']"
[routerLinkActiveOptions]="{ exact: true }"
#notificationsLink="routerLinkActive"
[ngClass]="notificationsLink.isActive ? 'route-active': 'route-inactive'"
[routerLink]="['/notifications']"
title="Notifications">
</a>
I want to send GET, POST request to server to get a response. how to do that in Wordpress?
Here it is:
<a href="<?php echo admin_url('post-new.php?post_type=page');?>">
Create new page</a>
You can place this code whereever you want in your theme. To give the link button UI, you can use any CSS button class of your theme.
F.e.
<a class="btn btn-info" href="<?php echo admin_url('post-new.php?post_type=page');?>">
Create new page</a>
I would like to find a complete solution to Thymeleaf pagination using Spring PagingAndSortingRepository DAO. I got a partial solution working, but I can not get the final one. I think it would be interesting for everyone else as a code snipet, so I will ask for the whole thing. I could not find a solution on the web which is kind of strange for me (since I think it could be a quite common problem).
The final solution should behave like Google's pagination: with arrows on both sides only if it makes sense; with a maximun of 10 numbers (for example), and it should move from 1..10 --> 11..20 and so on, when you click the right arrow; and move to 5..15 when you click on 10. Just like google, you know. The size controls the number of items in each page, not the number of blocks or links in the pagination bar.
I have a DAO repository in Spring that extends PagingAndSortingRepository ...
package music.bolo.domain.repository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
import music.bolo.domain.entity.Announcement;
#Repository public interface AnnouncementDao extends
PagingAndSortingRepository {
Announcement findFirstByOrderByDateDesc(); }
So my service can make a request and each page will get the totalPageNumbers (http://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/domain/Page.html)...
private final static int PAGESIZE = 2;
.. .. #Autowired annotations...
public Page<Announcement> readAnnouncementPage (int pageNumber){
PageRequest request = new PageRequest(pageNumber-1, PAGESIZE, Sort.Direction.DESC, "date");
return announcementDao.findAll(request); }
My Controller uses the data to send all the information to Thymeleaf
#RequestMapping(value = "/viewannouncements", method = RequestMethod.GET)
ModelAndView viewAnnouncements(ModelAndView modelAndView, #RequestParam(name = "p", defaultValue = "1") int pageNumber) {
Page<Announcement> page = announcementService.readAnnouncementPage(pageNumber);
modelAndView.getModel().put("page2th", page);
modelAndView.setViewName("viewannouncements");
return modelAndView; }
My solution is partial, it shows all the pages all the time, no arrow control (actually useless) and without any other funcionality, but it is the most I could make it work without bugs.
<div class="tag-box tag-box-v7 text-justify">
<!-- <h2>Pagination Centered</h2>-->
<div class="text-center">
<ul class="pagination">
<li>«</li>
<!--<li>«</li>-->
<li th:each="i : ${#numbers.sequence( 1, page2th.TotalPages)}">
<a th:href="#{'/viewannouncements?p='}+${ i }" th:text="${ i }">1</a></li>
<!--<li>»</li>-->
<li>»</li>
</ul>
</div>
</div>
This is an example of pagination with SpringBoot and Thymeleaf templates, you can try it.
It is self-explanatory.
Following you can find link to GitHub repo -
https://github.com/karelp90/control_asp
<div class="tag-box tag-box-v7 text-justify">
<div class="text-center">
<ul class="pagination" th:with="elementsperpage=2, blocksize=10, pages=${page2th.Number}/${elementsperpage}, wholepages=${format.format(pages)},
whole=(${page2th.Number}/${blocksize})+1, wholex=${format.format(whole)}, startnlockpage=${wholepages}*${blocksize+1}, endblockpage=${wholepages}*${blocksize+1},
startpage=${wholex-1}*${blocksize}, endpage=(${wholex}*${blocksize})+1">
<li>
<a th:if="${startpage gt 0}" th:href="#{${'/viewannouncements?p='}+${startpage}}"><<</a>
<a th:if="${startpage eq 0}" href="javascript:void(0);"><<</a>
</li>
<li th:each="pageNo : ${#numbers.sequence(endpage-11, (endpage lt page2th.TotalPages)? endpage-2 : page2th.TotalPages-1)}"
th:class="${page2th.Number eq pageNo}? 'active' : ''">
<a th:if="${page2th.Number eq pageNo}" href="javascript:void(0);">
<span th:text="${pageNo + 1}"></span>
</a>
<a th:if="${not (page2th.Number eq pageNo)}" th:href="#{${'/viewannouncements?p='}+${pageNo+1}}">
<span th:text="${pageNo + 1}"></span>
</a>
</li>
<li>
<a th:if="${(endpage*elementsperpage) le (page2th.TotalElements)}" th:href="#{${'/viewannouncements?p='}+${endpage}}">>></a>
<a th:if="${(endpage*elementsperpage) le (page2th.TotalElements)}" href="javascript:void(0);"></a>
</li>
</ul>
</div>
</div>
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
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)