I am following this solution to show whether a user is online or not.
But when I try to add:
'userprofile.middleware.ActiveUserMiddleware',
to MIDDLEWARE_CLASSES, I get a 502 error.
{{ profile.online }} returns false.
Thank you for any help.
UPDATE
It seems to work now without the middleware.
{% if object.profile.is_online %}
Online
{% else %}
Offline
{% endif %}
I have a list of users called "recommended".
{% recommended request user %}
Can I check within the template if these users are online?
{% recommended request user.is_online %}
does not work.
Thank you for any help / resource on this topic
I found a solution.
Django-online-users works perfectly fine.
Related
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.
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).
I am pretty new to Flask/Flask-Admin.
I have followed the tutorial on flask admin and managed to get the admin panel working but slightly lost on how to get the below things implemented.
https://github.com/flask-admin/flask-admin/tree/master/examples/auth
When logged in as a normal user I can only see "home" page.
How can I expose other views to "normal user" and restrict actions such as read only etc.
I have created a "baseview" which is not associated with any other models as below:
class SitesView(MyBaseView):
#expose('/')
def index(self):
return self.render('views/testviews.html')
admin.add_view(SitesView(name='Test views', endpoint='test views'))
and html as below:
{% extends 'admin/master.html' %}
{% block body %}
{{ super() }}
{% if current_user.has_role('view1') %}
Site1
{% endif %}
{% if current_user.has_role('view2') %}
<a>Site2</a>
{% endif %}
{% if current_user.has_role('view3') %}
<a>Site3</a>
{% endif %}
{% if current_user.has_role('view4') %}
<a>Site4</a>
{% endif %}
{% endblock %}
This gives me a new tab with different views with works as expected.
What I am trying to achieve here is when user click the Site1 link they go to Site1 page within flask-admin interface but I am not sure how to do that. I could create a new route for this but the problem is I can't(don't know how to) extend flask admin template.
For example this works but it redirect the page outside flask-admin template:
#app.route('/views/')
def views():
return render_template('views/views1.html')
and modified the templates>admin>index.html page with below:
<ul class="lead text-center list-group">
{% if current_user.has_role('view1') %}
<li class="list-group-item">View1</li>
{% endif %}
{% if current_user.has_role('view2') %}
<li class="list-group-item">View2</li>
{% endif %}
{% if current_user.has_role('view3') %}
<li class="list-group-item">View3</li>
{% endif %}
{% if current_user.has_role('view4') %}
<li class="list-group-item">View4</li>
{% endif %}
</ul
I want to build the whole web site using flask admin so that I can keep user experience consistence. Am I doing this the wrong way?
Thanks for your time.
Please do let me know if you want me to provide more information on this issue.
Kind Regards.
So after going through documentations and tutorials I have found the solution to my issue.
For my first question:
When logged in as a normal user I can only see "home" page. How can I
expose other views to "normal user" and restrict actions such as read
only etc.
We can do this by overwriting our view functions is_accessible method as below:
def is_accessible(self):
if not current_user.is_active or not current_user.is_authenticated:
return False
if current_user.has_role('superuser') or current_user.has_role('user') or current_user.has_role('view1'):
return True
return False
For my second question we just need to give the endpoint as for our BaseView as below:
class MyView(BaseView):
#expose('/')
def index(self):
return self.render('views.html')
admin.add_view(MyView(name='Custom Views', endpoint='customviews'))
And then in your jinja template you need to call it:
href="{{ url_for('customviews.index') }}
Just one thing to note, doing this:
current_user.has_role('superuser') or current_user.has_role('user') or current_user.has_role('view1')
could get quite messy if we have so many roles, not sure how we would approach this but hoping this will help someone.
Thanks all.
I know this is an old question, but for the following code
current_user.has_role('superuser') or current_user.has_role('user') or current_user.has_role('view1')
What I like to do is having a hybrid_property (available on both Peewee and SQLAlchemy) inside my User class that consolidates these properties. So it'd look something like this:
#hybrid_property
def user_has_administrative_rights(self):
return self.has_role('superuser') or self.has_role('user')
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.
I use the obvious powerful registration 0.8 alpha version. I do have to questions.
1.) I want to add the checkbox RegistrationTermsOfService at the registration form html file. I just don't know how to do it. Please don't give me an link on uebernstorm docs. Just tell me please how to do it. I have read and tried a lot and it actually doesn't work. I am dispairing!
2.) The activation email is send with the activation key. When I click on activation the account is getting activated in the database but the template says something different. It says:"Sorry, it didn't work. Either..."
I use the standard activate.html below:
{% extends "base.html" %}
{% block title %}Account activated{% endblock %}
{% block content %}
Account activated
{% load humanize %}
{% if account %}
Thanks for signing up! Now you can "href"
{% else %}
Sorry, it didn't work. Either your activation link was incorrect, or
the activation key for your account has expired; activation keys are
only valid for {{ expiration_days|apnumber }} days after
registration.
{% endif %}
{% endblock %}
PLEASE, PLEASE help me!!! I am dispairing!!!
Craphunter
For 1) you need to use a different form. Look in registration.forms for the one you need and pass it as an additional argument in the backend's urls.py
For 2) we'll need more info - is the URL correct? Is there a RegistrationProfile object created for the user account in question? What is the value of the key?