How to Paginate with Django Postman - django

I'm kinda new to Django, I'm working on a project that requires user to user messaging, so I decided to use Django postman. I was able to install in my project folder but the problem I'm facing has to do with pagination. The inbox should paginate after 20 messages but does not.
base_folder.html
<p>
<div id="postman">
<h1>{% block pm_folder_title %}{% endblock %}</h1>
{% autopaginate pm_messages %}
{% if invalid_page %}
<p>{% trans "Sorry, this page number is invalid." %}</p>
{% else %}
{% if pm_messages %}
{% b
lock pm_by_modes %}<div id="pm_byModes">
</p>
Really need help guys

According to FAQ in django-postman docs:
I installed django-pagination, and still I don’t see any pagination widgets
Is there really more messages than one page capacity (default is 20)?
Check that pagination is declared before postman in the INSTALLED_APPS setting.
See if it’s better by disabling postman/templatetags/pagination_tags.py and .pyc (rename or move the files).

Related

Django template fragment caching not working the way it is supposed to

Referring to following documentation, I am trying this
https://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching
{% cache 500 sidebar request.user.username %}
{% if user.is_authenticated %}
{{ user.first_name}}
{% endif %}
{% endcache %}
The problem is my authenticated Name and picture is getting cached and seen by other users, and those of other users by some other user. Essentially anyone coming in hits the cache of previous chap visiting the web site.
Apart from this no user access or any other security issue is not there.
Can you advise why this is so and what is the solution to the problem.

Django-cms, children variable in template, page navigation doesn't show in newer version

I'm trying to run project using Django-cms 3.6.0. It was created using Django-cms 2.3.8, I'm trying to use the old code. In this new version the menu with subpages links doesn't appear. children variable in template doesn't seem to contain anything.
I expect it to show links to 4 subpages of a page. I've added pages manually in admin UI in new version of django-cms.
subbase.html:
{% extends "base.html" %}
{% load i18n %}
{% load menu_tags cms_tags %}
...
{% block left_menu %}
<nav id="lMenu">
{% show_menu 1 1 0 1 "menu/sub_menu.html" %}
{% block left_content %}{% endblock left_content %}
</nav>
{% endblock left_menu %}
sub_menu.html:
{% load menu_tags %}
<ul class="subMenu">
{% for child in children %}
<li>{{ child.get_menu_title }}</li>
{% endfor %}
</ul>
I've checked in database, using manage.py shell, that those pages has child pages:
from cms.models.pagemodel import Page
pages = Page.object.all()
children = pages[2].get_descendant_pages()
And now, e.g., calling pages[2].get_menu_title(), children[0].get_menu_title() returns expected proper names of the pages, as added through UI.
I haven't found much about this children variable in docs. Should this still work this way in 3.6? What is the proper way to refer to child pages in template?
I've found, that I had something wrong with language settings. Menu with subpages links started to appear after I:
used i18n_patterns in main project urls.py file
added CMS_LANGUAGES in settings.py according to docs http://docs.django-cms.org/en/latest/reference/configuration.html#cms-languages
added pages in both languages through cms admin page. Before I had page in only one language.
Can't remember exactly which one fixed issue with submenu.
Also maybe something were wrong with urls handling, I used django apps urls from urls.py instead of cms.urls.

Django lockdown authentication - Login form not working

I've been investigating methods of locking down an entire page. A colleague drew my attention to django-lockdown. I've installed and and my code looks like this:
INSTALLED_APPS += ('lockdown',)
MIDDLEWARE_CLASSES += ('lockdown.middleware.LockdownMiddleware',)
LOCKDOWN_PASSWORD = 'letmein'
I'm using the supplied template code that comes with bit bucket that looks like this:
{% extends "lockdown/base.html" %}
{% block title %}Coming soon...{% endblock %}
{% block content %}
<div id="lockdown">
<h2>Coming soon...</h2>
<p>This is not yet available to the public.</p>
{% if form %}
<form action="" method="post">
{{ form.as_p }}
<p><input type="submit" value="Preview"></p>
</form>
{% endif %}
</div>
{% endblock %}
When I run a server locally I get no errors however the form itself does not appear on the screen. There is no place to type in a password which leads me to believe {% if form %} probably isn't true.
There isn't a lot of documentation available online so I'm struggling to fix this error.
Your lockdown password should be a tuple. Something like LOCKDOWN_PASSWORDS = ('letmein', 'beta').
Also you should not be writing a template to get it working. Django-lockdown is batteries included. Just out of the box (this and only this):
pip install django-lockdown,
add 'lockdown', (with trailing comma) to APPS,
add 'lockdown.middleware.LockdownMiddleware', (with trailing comma) to the middleware,
add LOCKDOWN_PASSWORDS = ('letmein', 'beta')
[all these things in settings]
Quote from documentation:
To enable admin preview of locked-down sites or views with passwords, set the LOCKDOWN_PASSWORDS setting to a tuple of one or more plain-text passwords.
So you should have this in setting:
LOCKDOWN_PASSWORDS = ('let me in', )

Django Tutorial: Templates and Views

I'm in the process of completing the official Django tutorial and I'm stuck on part 3. Since templates are also used in the last part of part2, I will describe what I did:
Part 2 told me to "copy the template admin/base_site.html from within the default Django admin template directory in the source code of Django itself (django/contrib/admin/templates) into an admin subdirectory of whichever directory you're using in TEMPLATE_DIRS."
So I created a new directory "admin" that has the following relative path (note that where Django uses the directory name 'mysite', I use 'django_test' : /django_test/polls/templates/admin. I copied the base_site.html file into this directory.
When I render the file in my local browser, it says: {% extends "admin/base.html" %} {% load i18n %} {% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %} {% block branding %}{% trans 'Django administration' %}{% endblock %} {% block nav-global %}{% endblock %}
Part 3 has me create an index.html file in a new subdirectory polls/index.html. But when I load this file in my web browser (using localhost server), I simply see the html code instead of a bulleted list (see below).
Note that I also edited TEMPLATE_DIRS in my settings.py file to tell Django that it can find index.html under /Users/myname/Sites/django_test/django_test/templates
Below I will paste the code that my local server renders (instead of the bulleted list, which is what I want). Do you know why this code is being rendered, instead of the bulleted list?
<html>
<head><title>Test</title></head>
<body>
{% if latest_poll_list %}
<ul>
{% for poll in latest_poll_list %}
<li>{{ poll.question }}</li>
{% endfor %}
</ul>
{% else %}
<p>No polls are available.</p>
{% endif %}
</body>
</html>
I don't know whether I'm making a mistake in how I'm organizing the files. Might someone have an idea about what I'm doing wrong?
As you say in your comment, you're putting the file path into your browser. Naturally, then, you're going to see the text of the template, because you are bypassing Django completely and getting the browser to load the unrendered template from disk.
As the tutorial describes, you need to ask Django to serve the template and render it, via its normal URL mechanism. In the earlier part of that section, you went to localhost:8000/admin/ to see the admin site - this hasn't changed just because you've replaced a template. Go back to that address and you'll see your updated - and rendered - template.
The django admin site is easy once you get the hang of it.
The steps to take are:
-Uncomment the django admin site in your urls.py
-Make the css available to the admin site by either copying the admin folder (inside django package) into the folder specified in STATIC_ROOT in your settings.py or making the diectory available on your PYTHONPATH
In other words, you dont need to create a template for the admin site. You will, however, need to create templates to access the views that you create in your project

How to integrate a django-disqus app into a blog

Hi my client is desperate to integrate django disqus into the blog we have built for them. I stumbled upon https://github.com/arthurk/django-disqus django disqus app and couldnt believe my luck, i had this up and running in no time, everything appears to be working ok, im posting comments etc however it dosent seem to be identifying properly as a comment posted with object.id for one blog post appears for all posts through out the blog.
in the index template that lists all the blog posts out i have
{% for entry in entries %}
{% set_disqus_identifier entry.id %}
{% set_disqus_url entry.get_absolute_url %}
{% set_disqus_developer 1 %}
{% blog stuff goes here %}
{%endfor%}
in the article template i have
{% set_disqus_identifier entry.id %}
{% set_disqus_url entry.get_absolute_url %}
{% set_disqus_developer 1 %}
<section id="comments">
View Comments
<h1>{% disqus_num_replies %}</h1>
<article class="comment">
{% disqus_dev %}
{% disqus_show_comments entry.get_absolute_url %}
the problem as i mentioned before is that if i post one comment disqus is applying that to all the blog posts. I guess im doing something wrong with the identifiers, but when i view source the javascript is getting the right id for each blog post
I really need this to work so will be eternally grateful for any help or advice that has got this working
in your index template, you don't need to do all this set_* stuff. So just load the dev tag to enable local development:
{% disqus_dev %}
{% for entry in entries %}
{% blog stuff goes here %}
{% endfor %}
In your article template just do this to display the comments. The disqus javascript will use the current URL as the identifier, so there's no need to set it manually:
{% disqus_show_comments %}
Don't forget to set the settings to the correct values as described in the documentation: http://django-disqus.readthedocs.org/en/latest/installation.html#configuring-your-django-installation And also change the url of your Site object to your actual domain.
I think you should not set the identifier and other values in index template. Because of the for loop its overriding the previous values. Rather, you should set the values in template related to particular post. That way, you would be setting disqus parameters for that particular post.
Note: django-disqus has newer version now, with django 1.7 support.