I want to have multiple site trees and, dependent of the role, display the corresponding menu.
For instance; this is my menu:
Site
Home
Products
Contact
User
Start
Admin
Now i can display my menu for a User like this:
{% show_menu_below_id "User" 0 1 0 1 %}
That will look like this: Start | Admin
The problem is that i want to have it start on "User/Start" and not on "User".
The url: /user/ should actualy by /user/start/
"User" should act like a tree node and i just need it to have an id to display the right tree, but that is about is, i do need it to start at... "Start".
I find it hard to find all ins en outs of Django CMS3 and i am sure/hope this is possible, but can not figure out how? I am not even sure where to look.
I found: add CMS_REDIRECTS = True to the settings.
then you can hardcode a url in the extra fields in the CMS.
Would be nice if it was not hardcoded, but i can continue now.
Related
The website has these pages - Home, Product1, Product2 and the Home page has a banner.
When user's journey is - Home > Product1 > Home, the banner should show image1.
When user's journey is - Home > Product2 > Home, the banner should show image2.
When user visits - Home > Product2 > Product1 > Home, the banner should show image1.
..which means, I want to show the image based on the last visited page before Home.
In the rule set editor, I set the 3 rules:
1. where the specific page during the visit is "product1" , then the image will be image1.
2. where the specific page during the visit is "product2" , then the image will be image2.
3. Default - hide banner
This is not working as desired. If user visits product1 first, then its always image1 in the banner. I understand it's working according the rule, as rule 1 will always become true here.
But, how can I achieve what I need.
You'll have to create a custom condition for that. There are lots of blogposts around how to do that part, so I won't focus on that.
Your condition could be something like where previous page is specific page
Then in your condition, you'll pass in an ID (where it says specific page). You can then do something like this in the condition:
var pagesVisited = Sitecore.Analytics.Tracker.Current.Interaction.GetPages().ToList();
return pagesVisited.Last().Item.Id == Guid.Parse(id); // id is the item you've selected in the Rule Editor
(Note that I haven't tested the code, but it should be similar to this. You might also want to run a bit of a performance test on it of course).
Right now. I have a search function in my page to search for item id. When I click search, I will render the same page with the result items and show item. And in other pages where I also display the item id, I want to add a link to the id to go to the same page where I search for that id.
Example: id: 123, I want the same page when:
1. search '123' in my search page(my search only accept exact match)
2. In other pages, click '123', go to the search page with results
How should I achieve this, I have tried many ways which don't wok.
You need to make use of the GET method that HTML forms provide. When you perform a search from the first page, you must make sure that you are doing so using the GET method in the form. This will append the form data into the URL.
E.g. If you have a 'name' field in your form which has 'John' inputted. The submission of this form will compose a URL like so:
http://someurl.com/?name=John
This can then be accessed using the Django request object:
name = request.GET['name']
You've probably done something similar already for displaying your search results. So, all you need to do is create a link in your second page that redirects to the search page with GET request variables appended.
E.g.
<a href="{% url 'search_page' %}?searchterm=232> Item 232 </a>
EDIT: If you are going to give a downvote, at least explain why -.-
Also, read comments if my post is still unclear. I tried to explain it a bit more in the comments but if it is still unclear about what I'm saying, let me know and I will take printscreens and explain using images.
I have created a model like so
class Post(models.Model):
title_of_post = models.CharField(max_length=100)
actual_post = models.TextField()
and I put this model in the admin interface and enabled the admin interface. Now, when I go to 127.0.0.1/admin/ and sign in, I can add this model. The posts created in the Post model can be seen on the homepage (127.0.0.1) so say my "title_of_post" is "title" and my "actual_post" is "the actual post", if I go to 127.0.0.1 I can see both the title and actual post on the homepage. The problem is, when I am in the admin interface and in the actual_post text box / TextField section, suppose I write this.
Something.
else
It would not recognize that I pushed the enter key after the period. I tried
Something. <br>
else
but that also didn't work. It does not go on a new line after the period. Is there any way to go to the next line when inputting information from the text box / TextField in the django admin interface? Is there any way to put headers from the admin interface, not from the template? Essentially, I want to be able to create this html from the admin interface.
<h1>Something.</h1> <br>
else
in order to show html inside a property, you need to place like this in your template:
{{ post.actual_post|safe }}
the safe template filter its good for not escaping html tags inside your template.
And this will print as:
Something
else
intead of:
Something <br /> else
I am using django-registration and would like to have a different page for failed logins. The initial login screen is loaded via jQuery, so doesn't need to extend the base page:
{% extends 'base.htm' %}
but the "fail" page does need to extend it. I cannot "if" an extends tag because it needs to be the first tag on the page.
So! I thought to load a different login-fail page, but I haven't the foggiest how to do that - how do I specify a different login-fail page?
sigh.
So the login page needs to be changed - i suppose i could extend and override it in a child class - maybe i will so i don't lose all my logic!
Yeah, i cut and paste it into my own views.py file
Ok, so all i done was add an "else" after the form.is_valid check that sets a variable (failed) to true.
And then, at the end of the method, when i render_to_response, i run a check to see if failed is True - and if so, just render to a different login page (failedLogin.html) ~ where this one does extend base.htm.
yay!
I am new to django and I really like its modular construction so I decided to take advantage of it and put all the separated functionalities each in different app.
Now I need a way to switch on and off this apps by both user and admin.
The user options panel would look like this:
[ ] blog
---------------------
[ ] tagging [BUY]
After checking "blog" option user would get the blog in his profile and after buying and checking "tagging" he would get tagging for the blog.
The admin panel would have an ability to show or hide an app from user panel.
I wonder if:
there is an app which would help me switch on and off an app for specyfic user
and if not -
what would be a proper "architecture" for such django app?
Can it be done dynamically in middleware or should it be done during login (check available apps from database, switch them on, redirect to user home page)?
Any advices for such a task?
Thanks,
Robert
I haven't heard of any such app… But I don't expect it would be too hard to build.
If I were doing it, I would put a permissions check in the entry points to each app. For example:
check_app_permission = lambda request: permissions.check_app_permission("blog", request)
def view_blog(request, …):
check_app_permission(request)
…
(it might even be possible to do some magic and inject this check at the urls.py level…)
Additionally, I would create a has_app_permission template tag:
<div id="sidebar">
{% if has_app_permission "blog" %}
{% include "blog/sidebar_recent_posts.html" %}
{% endif %}
</div>
Or similar.
Finally, there are approximately a million ways you could implement the permission system… And without more information I wouldn't be able to comment. The simplest, though, would be something like this:
class App(Model):
name = CharField(…)
class AppPermission(object):
app = ForeignKey(App)
user = ForiegnKey(User)
def user_has_permission(user, app_name):
return AppPermission.objects.filter(app__name=app_name, user=user).exists()
I would avoid trying to do this with middleware, because if I understand the problem correctly, I expect you will (or, at least, I expect I would) end up spending a bunch of time building a generic framework which, in the end, would just have checks similar to those above.
Does that help? Is there something I can clarify?