Re: Textarea taking htnml tags

2015-03-29 Thread Akash Patni
*Hi,*
*This my template*
{% block content %}



  

View Notes
See your notes details.
  
  

{% for i in result %}

Note Title
{{i.note_title}}



Note
 *{{i.note}}*





Beneficiaries

{% if all_nominees %}
{% for nominee in all_nominees %}
{% if nominee.1 %}
{{nominee.0.first_name}} {% if nominee.last_name
%}{{nominee.last_name}}{% endif %} {% if nominee.0.is_charity %}(charity){%
else %}(individual){% endif %}

{% endif %}
{% endfor %}
{% else %}
No beneficiaries at the moment.
{% endif %}





Action

Edit
Delete



  {% endfor %}

{% endblock %}


On Fri, Mar 27, 2015 at 11:30 PM, aRkadeFR  wrote:

>  Hey,
>
> He doubled post. A thread already exists about this called:
> "textarea showing image instead of code"
>
>
>
> On 03/27/2015 03:54 PM, Filipe Ximenes wrote:
>
> Can you send us the code of the view and the template of this form?
>
> On Fri, Mar 27, 2015 at 3:27 AM,  wrote:
>
>> Hie to all,
>> In one of my template i am using text area. The issue is that when i
>> write html tags with some image link using img tag, when i am saving this i
>> am getting image on the desription field.
>>
>> Actual-Image is comming
>>
>> Expected-I want HTML code to be displayed in the discription.
>>
>> Please suggest
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/32bb3e0a-1eb1-46d1-94fe-4135c7c916df%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
>  --
>
>
> *Filipe Ximenes *+55 (81) 8245-9204
>
> *Vinta Software Studio *http://www.vinta.com.br
>   --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAA-QWB3OPdmK11XzPFf--2MBT6evTDu-RuRrPArem1PbZT2FmA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/cpx4qG6daPU/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/55159AA1.9070605%40arkade.info
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Best Regards,*
Akash Patni
Software Engineer




*[image: ranosys]   [image: facebook]
[image: twitter]
[image: linkedin]
[image:
googleplus]  Head Office: Oxley Bizhub,
#06-48 | 73 Ubi Road 1 | Singapore - 408733Tel: +65 66331556  |  HP: +65
98573420Global Offices:San Francisco, USA | Jaipur, India | Bikaner, India*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANSMZiQo%3DM0RaBbawUNrsvO%2BLZpTQD%3DHtXCZsJDjnUE8zCFjRw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple Django projects using the same database

2015-03-29 Thread Russell Keith-Magee
On Mon, Mar 30, 2015 at 10:20 AM, Ien C.  wrote:

> Thanks Russ!
>
> Good point about the validation logic. Will definitely keep that in mind.
> And yes, my basic approach here is the same code base working on different
> subsets of data by default, with the ability for data to be optionally
> "seen" by both sites as needed.
>
> One more question: there's no need to keep settings.SECRET_KEY the same
> across the sites, is there? In the context of this question, someone told
> me that SECRET_KEY is used for hashing db reads/writes, but that doesn't
> sound right to me and I don't see anything about that in the docs. The two
> sites can (and should) have different SECRET_KEY values, right?
>

Depends on what your "secret" sharing policy is between the two sites. If
you want a truly shared login (as in - log into site A, login is recognised
on size B), or shared session payloads, you would need to have a shared
SECRET_KEY (along with some other cookie domain tweaks). However, if
they're independent sites, and you explicitly *want* someone to log into
site A and site B separately, then different SECRET_KEYs are advisable.

I don't know what your "someone" meant about hashing db read/writes -
unless they were referring to the session table. It certainly isn't
something that is applied to *all* DB read/writes, or would prevent data
written with one site from being read by the second.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq849buUK-ESY0PTaSNjTvOFjgRqN3mDg2R0OBM6Y%3DzET7sA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multiple Django projects using the same database

2015-03-29 Thread Ien C.
Thanks Russ!

Good point about the validation logic. Will definitely keep that in mind. 
And yes, my basic approach here is the same code base working on different 
subsets of data by default, with the ability for data to be optionally 
"seen" by both sites as needed. 

One more question: there's no need to keep settings.SECRET_KEY the same 
across the sites, is there? In the context of this question, someone told 
me that SECRET_KEY is used for hashing db reads/writes, but that doesn't 
sound right to me and I don't see anything about that in the docs. The two 
sites can (and should) have different SECRET_KEY values, right?

All the best, Ien

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6472a75d-cebe-43ec-85fe-cbfd5a2bde95%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Upgrade to django 1.7- ImproperlyConfigured -Tastypie label duplicate? help

2015-03-29 Thread amarshall
Hi,

 So I updated my django project from django 1.6 to 1.7.7 and when I run 
"python manage.py migrate" I get this error stating that I have a duplicate 
label. 

Here's the traceback

  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying tastypie.0001_initial...Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_from_command_line(sys.argv)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 385, in execute_from_command_line
utility.execute()
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", 
line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", 
line 288, in run_from_argv
self.execute(*args, **options.__dict__)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", 
line 338, in execute
output = self.handle(*args, **options)
  File 
"/usr/local/lib/python2.7/dist-packages/django/core/management/commands/migrate.py"
, line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", 
line 68, in migrate
self.apply_migration(migration, fake=fake)
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", 
line 96, in apply_migration
if self.detect_soft_applied(migration):
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", 
line 140, in detect_soft_applied
apps = project_state.render()
  File 
"/usr/local/lib/python2.7/dist-packages/django/db/migrations/state.py", 
line 57, in render
self.apps = Apps([AppConfigStub(label) for label in sorted(self.real_apps 
+ list(app_labels))])
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", 
line 56, in __init__
self.populate(installed_apps)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", 
line 89, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't 
unique, duplicates: tastypie


Not sure what to do here. I remove tastypie from the list of INSTALLED_APPS 
in my settings and everything works fine. but I do need it. Any suggestions 
?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7e4cfbf8-d3e0-4e0e-a38c-b83930ffa3b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to prevent save/delete in the Admin

2015-03-29 Thread Mike Dewhirst

On 30/03/2015 3:11 AM, Melvyn Sopacua wrote:

On Sunday 29 March 2015 22:04:23 Mike Dewhirst wrote:

On 29/03/2015 7:28 PM, Julo wrote:

Maybe you can add an interface for the models that are importants
and hook to the save/delete signal a interfaced function called
CanSave() And you check the premisson he has, if not allowed rais
an exception, and don't save.

Julo

I like that. I'll dig a bit deper. It would be best to do it in the
model but I'm not sure how I can get request.user from there.


It's convenient to have all information in one place, but...permission
validation is a view and by extension form action. Data correctness and
integrity validation belongs in the model.


I agree and that's where I always put it.



That said, maybe I'm not getting your workflow correctly, but to me it
seems that if request.user is not owner, some fields should be readonly.
And this is what ModelAdmin.get_readonly_fields() is for.


Working on this as we speak!



If this doesn't work for you, can you explain why?


I think it will work!

More later.

Thank you Melvyn

Mike





--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/55188F4E.50402%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: sidebar menu appears with every click on the main menu item before it disappears

2015-03-29 Thread Behee Trimble
Thanks very much for your reply. You are right - it is much easier if I had 
to write the code myself.

I am kind of doing the same and I see the repetition but when I try to 
eliminate the duplicates the program breaks!!

Thanks again
Beheen

On Sunday, March 29, 2015 at 6:16:04 PM UTC-4, Mike Dewhirst wrote:
>
> On 30/03/2015 2:13 AM, Behee Trimble wrote: 
> > Any body out there to give me a clue about my problem? Please? 
> > 
> > 
> > On Saturday, March 28, 2015 at 7:08:23 PM UTC-4, Behee Trimble wrote: 
> > 
> > Please help me to detect this problem: sidebar menu appears with 
> > every click on the main menu item. 
> > 
> > I inherited a Django app and I am trying to learn it. However, since 
> > this is a real app and in use I do not have much time to investigate 
> > in details. I really appreciate your help. I include only the few 
> > templates and I am hoping some one is experienced enough to see the 
> > problem by looking at these few templates. 
>
> I am not experienced enough to help but I can feel your sense of 
> frustration. Trying to learn Django by inspecting an existing project is 
> a daunting task. This is what I think you should do: 
>
> a. Copy the entire project to your local dev machine [1] 
>
> b. Chop out parts and put them back until you identify the sidebar menu. 
>
> c. Search for the code involved and try to see why it is being called 
> multiple times. 
>
>
> [1] Install the same version of Django on your local machine. To get 
> that info: on the production machine get a console and launch python. 
> Then at the prompt ... 
>
>  >>>import django 
>  >>>django.get_version() 
>
> Getting the project across, ought to be easy. Work through (at least) 
> the installation parts of the documentation/tutorial. 
> https://docs.djangoproject.com/en/1.7/ (use the same version as in 
> production rather than 1.7) 
>
> Using the Django developer's webserver, you can insert print statements 
> wherever you like in the code and see the results. It also identifies 
> syntax errors immediately and displays error tracebacks. 
>
> Enjoy 
>
> Mike 
>
> > 
> > All the other templates are including the base.html, see below 
> please: 
> > 
> > base.html 
> >  
> >  
> > {% load add_utility %} 
> > 
> >  
> > 
> >   
> >   
> >   
> >   
> >  Quo - {% block title %}{% endblock %} 
> >   > href="/static/Quo3/css/foundation.css" /> 
> >   
> >   > href="/static/Quo3/css/font-awesome.css" /> 
> >   /> 
> >   
> >   
> >   
> >   
> >   
> >   
> > 
> > 
> > 
> >   > href="/static/Quo3/img/quo_favicon.png" /> 
> > 
> > 
> >   
> > 
> > 
> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
>
> >  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new 
> > Date();a=s.createElement(o), 
> > 
> > 
> m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
>  
>
> > 
> > })(window,document,'script','//www.google-analytics.com/analytics.js 
> > <http://www.google-analytics.com/analytics.js>','ga'); 
> > 
> >  ga('create', 'UA-55718101-1', 'auto'); 
> >  ga('send', 'pageview'); 
> >   
> >   
> >   
> >   
> >   
> >   
> >   
> >   
> >   > src="/static/Quo3/img/quo_logo_white.png"/> 
> >   
> > 
> >   > href="#">Menu 
> >   
> >   
> >  
> >   
> >   
> > MENU 
> >   
> >   
> >   
> >   
> >   
> >   
> >   
> >  
> > 
> >   
> >   
> >   
> >  Followed Topics 
> >   
> >   
> >   
> >   > id="searchform"> 
> >   
> >   > placeholder="Search" class="no-border" name="q"> 
> >   
> >   
> >   > class="button fa searchbutton" value=""> 
> >  {% csrf_token %} 
> >   

Re: Multiple Django projects using the same database

2015-03-29 Thread Russell Keith-Magee
On Mon, Mar 30, 2015 at 12:14 AM, Ien C.  wrote:

> Hi everyone,
>
> I'm hoping to confirm my understanding on how to deploy multiple Django
> websites using the same database, using postgres and gunicorn/nginx.
>
> Doing this seems to me as simple as:
> 1. Creating a copy of the Django project in its own directory, with its
> own settings.py etc.
> 2. Keep the same settings.DATABASES the same, i.e. pointing to the same
> postgres server.
> 3. Deploy the new site as if were a standalone site, e.g. separate
> /etc/nginx/sites-available/new-site-name.conf etc.
>
> Of course doing the above wouldn't be very useful unless the two sites did
> something different. For instance, to have them by default work on
> different subsets of the data, I could use the Django sites framework,
> where the CurrentSiteManager restricts queries to data associated with the
> specific site baed on settings.SITE_ID. The two sites could still access
> all data using standard model managers, and there would be no problem
> having models associated with one site link to models from another site via
> related fields as normal, as long as the model's default manager could see
> all data.
>
> Core Django tables like User and Permissions would be shared between the
> two sites, so if a user has access to one site, they will have access to
> the other site.
>
> As for race conditions, there are no particular new issues raised by two
> sites sharing the same database, i.e. race conditions could happen but it's
> no different than with multiple requests on a single site.
>
> Have I got all that right? Anything I'm missing? Is it really as simple as
> just having two Django sites point to the same database via
> settings.DATABASES?
>
> Thanks,
> Ien
>
> Hi Ien,

You've got it right - it's exactly that simple.

Remember, even if you've only deployed a single website, you're still going
to have multiple threads/processes accessing that site - your web server is
inherently multithreaded. All you're doing by deploying 2 sites is
introducing a way by which half of those threads/processes will be using a
different chunk of code to evaluate requests.

The only caveats you didn't cover that I can think of relate to
inconsistencies in the two different sites interacting with the data in
different ways. If you've got site logic that imposes validation conditions
or something like that, and the two sites have different validation logic,
there's no inherent guarantee that an object created on one site will meet
the validation requirements of another. However if you make sure all the
validation logic is common between the two sites, and the only thing that
is different is the subset of data available, or the presentation style of
that information, then you shouldn't hit this sort of problem.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq84-AhQ5HONF_tL56LD67_43KNuA2E-Aavx5f_-NmLNZmJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: sidebar menu appears with every click on the main menu item before it disappears

2015-03-29 Thread Mike Dewhirst

On 30/03/2015 2:13 AM, Behee Trimble wrote:

Any body out there to give me a clue about my problem? Please?


On Saturday, March 28, 2015 at 7:08:23 PM UTC-4, Behee Trimble wrote:

Please help me to detect this problem: sidebar menu appears with
every click on the main menu item.

I inherited a Django app and I am trying to learn it. However, since
this is a real app and in use I do not have much time to investigate
in details. I really appreciate your help. I include only the few
templates and I am hoping some one is experienced enough to see the
problem by looking at these few templates.


I am not experienced enough to help but I can feel your sense of 
frustration. Trying to learn Django by inspecting an existing project is 
a daunting task. This is what I think you should do:


a. Copy the entire project to your local dev machine [1]

b. Chop out parts and put them back until you identify the sidebar menu.

c. Search for the code involved and try to see why it is being called 
multiple times.



[1] Install the same version of Django on your local machine. To get 
that info: on the production machine get a console and launch python. 
Then at the prompt ...


>>>import django
>>>django.get_version()

Getting the project across, ought to be easy. Work through (at least) 
the installation parts of the documentation/tutorial. 
https://docs.djangoproject.com/en/1.7/ (use the same version as in 
production rather than 1.7)


Using the Django developer's webserver, you can insert print statements 
wherever you like in the code and see the results. It also identifies 
syntax errors immediately and displays error tracebacks.


Enjoy

Mike



All the other templates are including the base.html, see below please:

base.html


{% load add_utility %}



 
 
 
 
 Quo - {% block title %}{% endblock %}
 
 
 
 
 
 
 
 
 
 



 


 

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new
Date();a=s.createElement(o),


m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

})(window,document,'script','//www.google-analytics.com/analytics.js
<http://www.google-analytics.com/analytics.js>','ga');

 ga('create', 'UA-55718101-1', 'auto');
 ga('send', 'pageview');
 
 
 
 
 
 
 
 
 
 

 Menu
 
 

 
 
MENU
 
 
 
 
 
 
 


 
 
 
 Followed Topics
 
 
 
 
 
 
 
 
 
 {% csrf_token %}
 
 
 
 

 
 
 
 
 
 

 
 
 


 
 
 


 
 
 {% block quicknav %}{% endblock %}
 
 {% get_visible_departments user as deps %}
 {% for dep in deps %}
  {{dep}} >
 {% endfor %}
 


 
 {% block addstuff %}{% endblock %}
 
 Logout
 
 
 

 {% block content %}{% endblock %}


 
 
 
 
 $(document).ready(function() {
 $('.menu-link').bigSlide();
 });
 
 
 
 
 
   

Re: How to prevent save/delete in the Admin

2015-03-29 Thread Mike Dewhirst

On 30/03/2015 2:06 AM, Ezequiel wrote:

On Sunday, March 29, 2015 at 5:08:06 AM UTC-3, Mike Dewhirst wrote:

A perhaps better solution would be to disable the Save and Delete
widgets/actions in particular circumstances.

How can I do something like this?



The quick way I did this was:


Ezequiel

Lots of clues there ...

Thanks

Mike



In settings.py create a tuple indicating read-only users:

ADMIN_READONLY_USERS = (5826, 6074, )


In the custom UserProfile model I added:

@property
def is_admin_readonly(self):
 return self.id in settings. ADMIN_READONLY_USERS


And them override /admin/change_form.html file template and change
submit_buttons_bottom block:

{% block submit_buttons_bottom %}
 {% if request.user.is_admin_readonly is False %}
 {% submit_row %}
 {% endif %}
{% endblock %}
As you said in your last post you should also include some check in the
view to prevent malicious users to POST form in other ways like using
firebug.

Ezequiel.
http://flickrock.com/mikelpierre

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/5efe4687-3aef-4f76-988d-789f98f8ae59%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/551872DE.6050208%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: Jinja2 with Django 1.8c1 & cannot import name 'Environment'

2015-03-29 Thread Simon Charette
Hi Rolf,

Django 1.8+ adds built-in support but doesn't ship with Jinja2, the same 
way it has built-in support for PostgreSQL but doesn't ship the psycopg2 
package.

You must install it in your environment just like you did with the Django 
package.

Simon
 
Le dimanche 29 mars 2015 16:40:33 UTC-4, Rolf Brudeseth a écrit :
>
> Hello Simon,
>  
>
>> Did you install jinja2  in 
>> your python environment (I assumed /www/pbs-venv was a virtualenv)?
>>
>
> No, Jinja2 is integrated into Django 1.8c1.
>
> https://docs.djangoproject.com/en/dev/releases/1.8/ 
> 
>
> - I am using pyvenv which is integrated into Python, not the virtualenv 
> pypi package.
> pbs-venv was created this way:
> ./Python-3.4.3/python ./Python-3.4.3/Tools/scripts/pyvenv pbs-venv
>  
>
>>
>> What does /www/pbs-venv/bin/pip --freeze outputs?
>>
>
> www$ pip --freeze
> Usage:   
>   pip  [options]
> no such option: --freeze
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0fe3f13c-fb6a-482b-bba8-79a2d2b3a868%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jinja2 with Django 1.8c1 & cannot import name 'Environment'

2015-03-29 Thread Rolf Brudeseth
Hello Simon,
 

> Did you install jinja2  in 
> your python environment (I assumed /www/pbs-venv was a virtualenv)?
>

No, Jinja2 is integrated into Django 1.8c1.

https://docs.djangoproject.com/en/dev/releases/1.8/

- I am using pyvenv which is integrated into Python, not the virtualenv 
pypi package.
pbs-venv was created this way:
./Python-3.4.3/python ./Python-3.4.3/Tools/scripts/pyvenv pbs-venv
 

>
> What does /www/pbs-venv/bin/pip --freeze outputs?
>

www$ pip --freeze
Usage:   
  pip  [options]
no such option: --freeze

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b837928f-7d7e-475a-8e6e-fd13efe63df2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jinja2 with Django 1.8c1 & cannot import name 'Environment'

2015-03-29 Thread Simon Charette
Hi Rolf,

Did you install jinja2  in your 
python environment (I assumed /www/pbs-venv was a virtualenv)?

What does /www/pbs-venv/bin/pip --freeze outputs?

Simon

Le dimanche 29 mars 2015 14:53:49 UTC-4, Rolf Brudeseth a écrit :
>
>
>> Rename your jinja2.py file something else and things should be working.
>>
>>  
> I am having some problems wrapping my head around how to implement this.
>
> When I rename the file I created to something arbitrary I get:
>
> Exception Value: 
>
> No module named 'jinja2'
>
>  Exception Location: 
> /www/pbs-venv/lib/python3.4/site-packages/django/template/backends/jinja2.py 
> in , line 6
> Not sure why the file above has this statement on line 6 if it is not to 
> reference the file I created:
> import jinja2
>
> Furthermore, this file does not have an 'Environment' class so I am not 
> sure how the following statement will work in the file I am supposed to 
> create:
> from jinja2 import Environment
>
> Finally, I am not sure how to reference the file I need to create. Is that 
> specified in settings.py?
>
> Thanks
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/62d0327a-b639-4a9c-b202-7f367bcd01d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Jinja2 with Django 1.8c1 & cannot import name 'Environment'

2015-03-29 Thread Rolf Brudeseth

>
>
> Rename your jinja2.py file something else and things should be working.
>
>  
I am having some problems wrapping my head around how to implement this.

When I rename the file I created to something arbitrary I get:

Exception Value: 

No module named 'jinja2'

 Exception Location: 
/www/pbs-venv/lib/python3.4/site-packages/django/template/backends/jinja2.py 
in , line 6
Not sure why the file above has this statement on line 6 if it is not to 
reference the file I created:
import jinja2

Furthermore, this file does not have an 'Environment' class so I am not 
sure how the following statement will work in the file I am supposed to 
create:
from jinja2 import Environment

Finally, I am not sure how to reference the file I need to create. Is that 
specified in settings.py?

Thanks
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/61f74405-0cd8-4d1e-a436-ff00cee7e7c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to mock a model backend

2015-03-29 Thread Alejandro Varas G.
Hi Sven,

You can mock the call to the external service like this.


  @mock.patch.object(MyModelBackend, 'authenticate')  # First the
class of your model backend. Then the method you want to mock.

  def test_something_that_uses_login(self, mock_authenticate):  # The
mock object is passed to your test method

  mock_authenticate.return_value = # whatever your authenticate
method to returns

  # the rest of your code


More about mock library

http://www.voidspace.org.uk/python/mock/

Best





On Thu, Mar 26, 2015 at 11:18 AM Sven Mäurer  wrote:

> In my model backend I usually call an external service which returns me an
> user that is saved and returned. When I don't have credentials I want to
> mock the backend for some test cases. In the setup of each test case I am
> calling the login method where CRED contains the real credentials or mock
> credentials. This can be determined by are_credentials_given.
>
> def are_credentials_given():
> return not os.path.isfile(os.path.join(BASE_DIR, 'settings/credentials'))
>
>
> def login(self):
> u = User.objects.create(id=CRED['ID'], is_staff=True)
> u.save()
> token, c = Token.objects.get_or_create(user=u)
> if c:
> token.save()
> self.client = APIClient()
> self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key)
> self.client.login(username=CRED['USERNAME'], password=CRED['PASSWORD'])
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/894d8e22-b448-41fc-bd1b-a82a2a35db8a%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL60nj%2BS4aLkdt7E7ALoTmK4uFC%3DrH5NXSdUZ8P4R_B8KZWVeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Multiple Django projects using the same database

2015-03-29 Thread Ien C.
Hi everyone,

I'm hoping to confirm my understanding on how to deploy multiple Django 
websites using the same database, using postgres and gunicorn/nginx. 

Doing this seems to me as simple as:
1. Creating a copy of the Django project in its own directory, with its own 
settings.py etc.
2. Keep the same settings.DATABASES the same, i.e. pointing to the same 
postgres server.
3. Deploy the new site as if were a standalone site, e.g. separate 
/etc/nginx/sites-available/new-site-name.conf etc.

Of course doing the above wouldn't be very useful unless the two sites did 
something different. For instance, to have them by default work on 
different subsets of the data, I could use the Django sites framework, 
where the CurrentSiteManager restricts queries to data associated with the 
specific site baed on settings.SITE_ID. The two sites could still access 
all data using standard model managers, and there would be no problem 
having models associated with one site link to models from another site via 
related fields as normal, as long as the model's default manager could see 
all data.

Core Django tables like User and Permissions would be shared between the 
two sites, so if a user has access to one site, they will have access to 
the other site.

As for race conditions, there are no particular new issues raised by two 
sites sharing the same database, i.e. race conditions could happen but it's 
no different than with multiple requests on a single site.

Have I got all that right? Anything I'm missing? Is it really as simple as 
just having two Django sites point to the same database via 
settings.DATABASES?

Thanks,
Ien  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1845301e-bca7-43ea-8101-d3fe860ba202%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django system check gives error when storing method in variable

2015-03-29 Thread Wouter Miltenburg
Hi Markus,

That explains it :), will change the code.

Not really sure why that line is there to be honest. The original version 
of that code was developed by someone else and this is just the version 
that is compatible with Python 3. Don't really see dependencies in the code 
itself that uses the 'check' method, so it shouldn't be a real problem to 
remove that line. However, as I am not the original author of that code I 
am not aware of the user-base that might have dependencies with this method.

Thank you for your quick response.

Cheers,
Wouter.

Op zondag 29 maart 2015 18:06:10 UTC+2 schreef Markus Holtermann:
>
> Hey Wouter,
>
> since Django 1.7 Model.check() is a reserved method that is used by the 
> system checks framework (
> https://docs.djangoproject.com/en/1.7/topics/checks/#field-model-and-manager-checks).
>  
> The cleanest way is to remove that line (check = is_paid). Why do you have 
> that in the first place?
>
> /Markus
>
> On Sunday, March 29, 2015 at 6:01:04 PM UTC+2, Wouter Miltenburg wrote:
>>
>> Hi all, 
>>
>> Haven't used Django 1.7.7 till today, but whenever I want to launch my 
>> project I get the following error: 
>> ERRORS: 
>> gopro.MyPayment: (models.E020) The 'MyPayment.check()' class method is 
>> currently overridden by > 0x7f0716731b90>. 
>>
>> I use another django app 
>> (https://github.com/wmiltenburg/django-mollie-ideal) inside the app that 
>> I am currently writing. The problem seems to be relating to line 75 in 
>> models.py 
>> (
>> https://github.com/wmiltenburg/django-mollie-ideal/blob/master/mollie/ideal/models.py,
>>  
>>
>> check = is_paid), where is_paid is a method. If I comment it out it 
>> works fine. However, this used to work in previous Django releases (1.6) 
>> and it is valid Python code. In Django 1.7 it shows the following error: 
>> TypeError: is_paid() missing 1 required positional argument: 'self'. 
>>
>> The error shows up when Django performs the system checks. My guess is 
>> that the "system check" from Django 1.7 doesn't handle function 
>> referencing in Python well (which used to be in Django 1.6). However, I 
>> am wondering if this is a more of a general problem in Django itself and 
>> if other users experience the same problem. 
>>
>> Cheers, 
>> Wouter. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b3db366f-b960-419c-9e33-c3268531459f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Inserting literal % sign in QuerySet.extra()

2015-03-29 Thread Tim Graham
No, it won't. See 
https://docs.djangoproject.com/en/dev/internals/release-process/#supported-versions
 
for the guidelines on which changes are backported.

On Saturday, March 28, 2015 at 2:49:21 AM UTC-4, Gergely Polonkai wrote:
>
> Great, thank you!
>
> Although I'm more than willing to upgrade, I still wonder if this fix will 
> be backported to 1.7…
> On 28 Mar 2015 02:15, "Tim Graham"  
> wrote:
>
>> This is fixed in Django 1.8. See the fifth item in 
>> https://docs.djangoproject.com/en/dev/releases/1.8/#models.
>>
>> On Friday, March 27, 2015 at 5:38:15 PM UTC-4, Gergely Polonkai wrote:
>>>
>>> Hello,
>>>
>>> I’d like to execute the following code:
>>>
>>> Booking.objects.filter(start_ts__isnull = False, end_ts__isnull = 
>>> False).extra(select = {'amount': "strftime('%s', end_ts) - strftime('%s', 
>>> start_ts)"})
>>>
>>> However, in the shell, I get the following error:
>>>
>>> Traceback (most recent call last): File "", line 1, in  
>>> File "/home/polesz/Projects/duckbook/venv/lib/python3.4/
>>> site-packages/django/db/models/query.py", line 835, in extra 
>>> clone.query.add_extra(select, select_params, where, params, tables, 
>>> order_by) File "/home/polesz/Projects/duckbook/venv/lib/python3.4/
>>> site-packages/django/db/models/sql/query.py", line 1744, in add_extra 
>>> entry_params.append(next(param_iter)) StopIteration
>>>
>>> I have tried doubling the percent signs (%%s) and escaping them with a 
>>> backslash (\%s), but neither helped. I also looked at this answer 
>>> [1], but that solution 
>>> doesn’t work with QuerySet.extra() (or I just miss the point).
>>>
>>> What is the correct way to solve this?
>>>
>>> I also tried to use select_params like this:
>>>
>>> Booking.objects.filter(start_ts__isnull = False, end_ts__isnull = 
>>> False).extra(select = {'amount': "strftime('%s', end_ts) - strftime(%s, 
>>> start_ts)"}, select_params = ['%s', '%s'])
>>>
>>> but regardless the usage of quote signs, the resulting query has \'%s\', 
>>> which gives an SQL error, of course.
>>>
>>> Best,
>>> Gergely
>>>
>>> [1] http://stackoverflow.com/a/18143147/1305139
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/fa509ee1-6bb2-43c8-a1a1-e12ad70a123f%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/585b40a1-081a-495b-9651-1e34233992f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to prevent save/delete in the Admin

2015-03-29 Thread Melvyn Sopacua
On Sunday 29 March 2015 22:04:23 Mike Dewhirst wrote:
> On 29/03/2015 7:28 PM, Julo wrote:
> > Maybe you can add an interface for the models that are importants
> > and hook to the save/delete signal a interfaced function called
> > CanSave() And you check the premisson he has, if not allowed rais
> > an exception, and don't save.
> Julo
> 
> I like that. I'll dig a bit deper. It would be best to do it in the
> model but I'm not sure how I can get request.user from there.

It's convenient to have all information in one place, but...permission 
validation is a view and by extension form action. Data correctness and 
integrity validation belongs in the model.

That said, maybe I'm not getting your workflow correctly, but to me it 
seems that if request.user is not owner, some fields should be readonly. 
And this is what ModelAdmin.get_readonly_fields() is for.

If this doesn't work for you, can you explain why?
-- 
Melvyn Sopacua

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4084934.niUPzQKpei%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Django system check gives error when storing method in variable

2015-03-29 Thread Markus Holtermann
Hey Wouter,

since Django 1.7 Model.check() is a reserved method that is used by the 
system checks framework 
(https://docs.djangoproject.com/en/1.7/topics/checks/#field-model-and-manager-checks).
 
The cleanest way is to remove that line (check = is_paid). Why do you have 
that in the first place?

/Markus

On Sunday, March 29, 2015 at 6:01:04 PM UTC+2, Wouter Miltenburg wrote:
>
> Hi all, 
>
> Haven't used Django 1.7.7 till today, but whenever I want to launch my 
> project I get the following error: 
> ERRORS: 
> gopro.MyPayment: (models.E020) The 'MyPayment.check()' class method is 
> currently overridden by  0x7f0716731b90>. 
>
> I use another django app 
> (https://github.com/wmiltenburg/django-mollie-ideal) inside the app that 
> I am currently writing. The problem seems to be relating to line 75 in 
> models.py 
> (
> https://github.com/wmiltenburg/django-mollie-ideal/blob/master/mollie/ideal/models.py,
>  
>
> check = is_paid), where is_paid is a method. If I comment it out it 
> works fine. However, this used to work in previous Django releases (1.6) 
> and it is valid Python code. In Django 1.7 it shows the following error: 
> TypeError: is_paid() missing 1 required positional argument: 'self'. 
>
> The error shows up when Django performs the system checks. My guess is 
> that the "system check" from Django 1.7 doesn't handle function 
> referencing in Python well (which used to be in Django 1.6). However, I 
> am wondering if this is a more of a general problem in Django itself and 
> if other users experience the same problem. 
>
> Cheers, 
> Wouter. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/591911f5-9f54-4099-82f5-8a9e15b1fa7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django system check gives error when storing method in variable

2015-03-29 Thread Wouter Miltenburg
Hi all,

Haven't used Django 1.7.7 till today, but whenever I want to launch my
project I get the following error:
ERRORS:
gopro.MyPayment: (models.E020) The 'MyPayment.check()' class method is
currently overridden by .

I use another django app
(https://github.com/wmiltenburg/django-mollie-ideal) inside the app that
I am currently writing. The problem seems to be relating to line 75 in
models.py
(https://github.com/wmiltenburg/django-mollie-ideal/blob/master/mollie/ideal/models.py,
check = is_paid), where is_paid is a method. If I comment it out it
works fine. However, this used to work in previous Django releases (1.6)
and it is valid Python code. In Django 1.7 it shows the following error:
TypeError: is_paid() missing 1 required positional argument: 'self'.

The error shows up when Django performs the system checks. My guess is
that the "system check" from Django 1.7 doesn't handle function
referencing in Python well (which used to be in Django 1.6). However, I
am wondering if this is a more of a general problem in Django itself and
if other users experience the same problem.

Cheers,
Wouter.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5518207A.2080308%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: sidebar menu appears with every click on the main menu item before it disappears

2015-03-29 Thread Behee Trimble
Any body out there to give me a clue about my problem? Please?


On Saturday, March 28, 2015 at 7:08:23 PM UTC-4, Behee Trimble wrote:
>
> Please help me to detect this problem: sidebar menu appears with every 
> click on the main menu item.
>
> I inherited a Django app and I am trying to learn it. However, since this 
> is a real app and in use I do not have much time to investigate in details. 
> I really appreciate your help. I include only the few templates and I am 
> hoping some one is experienced enough to see the problem by looking at 
> these few templates.
>
> All the other templates are including the base.html, see below please:
>
> base.html
> 
> 
> {% load add_utility %}
>
> 
>
> 
> 
> 
> 
> Quo - {% block title %}{% endblock %}
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>
>
>
>  href="/static/Quo3/img/quo_favicon.png" />
>
>
> 
> 
> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
> (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new 
> Date();a=s.createElement(o),
> 
> m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
> })(window,document,'script','//
> www.google-analytics.com/analytics.js','ga');
>
> ga('create', 'UA-55718101-1', 'auto');
> ga('send', 'pageview');
> 
> 
> 
> 
> 
> 
> 
> 
>  src="/static/Quo3/img/quo_logo_white.png"/>
> 
>
>  href="#">Menu
> 
> 
> 
> 
> 
> MENU class="fa fa-navicon fa-15x">
> 
> 
> 
> 
> 
> 
> 
> 
>
> 
> 
> 
> Followed Topics
> 
> 
> 
>  id="searchform">
> 
>  placeholder="Search" class="no-border" name="q">
> 
> 
>  class="button fa searchbutton" value="">
> {% csrf_token %}
> 
> 
> 
> 
>
> 
> 
> 
>  href="/L2/PMO%20and%20QA/L3/Quo%20Documents/L4/Quo%20Basic%20Training"> class="fa fa-question-circle fa-15x">
> 
> 
>
> 
> 
> 
>
>
> 
> 
> 
>
>
> 
> 
> {% block quicknav %}{% endblock %}
>  class="offnav-list">
> {% get_visible_departments user as deps %}
> {% for dep in deps %}
>  {{dep}} >
> {% endfor %}
> 
>
>
> 
> {% block addstuff %}{% endblock %}
> 
> Logout
> 
> 
> 
>
> {% block content %}{% endblock %}
>
>
> 
>  src="/static/Quo3/js/foundation/foundation.topbar.js">
> 
> 
> $(document).ready(function() {
> $('.menu-link').bigSlide();
> });
> 
>  src="/static/Quo3/js/foundation/foundation.equalizer.js">
>  src="/static/Quo3/js/foundation/foundation.reveal.js">
>  src="/static/Quo3/js/foundation/foundation.accordion.js">
>  src="/static/Quo3/js/foundation/foundation.tooltip.js">
> 
> $(document).foundation();
> 
> 
> 
>
>
> index_zero.html
> 
> {% extends "base.html" %}
>
> {% block title %}
> Home
> {% endblock %}
>
> {% block quicknav %}
> 
> Quick Nav
> 
> Home >
> 
> 
> 
> {% endblock %}
>
> {% block content %}
>
> 
> 
> 
> {% for obj in objects %}
> 
>  class="fa">{{ obj.title }}
>  id="panelimage"/>
> 
> 
> {% endfor %}
> 
> 
> 
> {% endblock %}
>
> =
> I myself am trying to cache the images to make sure is not the bad 
> performance involved. Other than that I am suspicious to the ajax calls but 
> it is hard for me to touch it without breaking the app!!
>
> 

Re: How to prevent save/delete in the Admin

2015-03-29 Thread Ezequiel
On Sunday, March 29, 2015 at 5:08:06 AM UTC-3, Mike Dewhirst wrote:
>
> A perhaps better solution would be to disable the Save and Delete 
> widgets/actions in particular circumstances. 
>
> How can I do something like this?



The quick way I did this was:

In settings.py create a tuple indicating read-only users: 

ADMIN_READONLY_USERS = (5826, 6074, )


In the custom UserProfile model I added: 

@property
def is_admin_readonly(self):
return self.id in settings. ADMIN_READONLY_USERS


And them override /admin/change_form.html file template and change 
submit_buttons_bottom block:

{% block submit_buttons_bottom %}
{% if request.user.is_admin_readonly is False %}
{% submit_row %}
{% endif %}
{% endblock %}
 
As you said in your last post you should also include some check in the 
view to prevent malicious users to POST form in other ways like using 
firebug.

Ezequiel.
http://flickrock.com/mikelpierre

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5efe4687-3aef-4f76-988d-789f98f8ae59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to prevent save/delete in the Admin

2015-03-29 Thread Mike Dewhirst

On 29/03/2015 9:22 PM, Gabriel - Iulian Dumbrava wrote:

In case you hide/not display the save/delete button you must also double
check in the delete view if the current user has the right permissions
to delete the item. It's pretty easy to add a post button in firebug, or
even trigger the post using a different method.


You are correct. That was a bad idea!

Thanks

Mike




duminică, 29 martie 2015, 11:08:06 UTC+3, Mike Dewhirst a scris:

At the moment "has_change_permission" in the Admin works by returning
403 Forbidden if it gets a False.

That doesn't suit my needs but it is probably not advisable to
adjust it.

Users without change permission need to be able to see the data and
perhaps raise an exception (in this case BusinessRuleViolation
subclassed from ValidationError) if they try to save. In other words,
maybe use the existing form clean() mechanism.

However, I recognise that this subverts the Admin by preventing [Save]
and therefore may not be appropriate.

A perhaps better solution would be to disable the Save and Delete
widgets/actions in particular circumstances.

How can I do something like this?

TL;DR

All the business rule decision logic is calculated using the object
instance and request.user.

The application displays a substance record with a few 1:1, 1:n, n:1
and
n:m related records. The substance has a status field which can be made
"public domain".

The business rule is that a user can see and edit all their own
substances but can see nothing owned by anyone else - unless they have
been put in the public domain (and which then must be readonly to the
"public")

Thanks for any ideas

Mike

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/5245622d-04a2-435d-9efb-cd61f824953b%40googlegroups.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5517EC30.9080905%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: How to prevent save/delete in the Admin

2015-03-29 Thread Mike Dewhirst

On 29/03/2015 7:09 PM, Avraham Serour wrote:

maybe overwrite the view in your own modeladmin class?


I need to keep using the Admin and haven't done anything like that 
previously. I'll have to do the research.


Thanks

Mike



On Sun, Mar 29, 2015 at 11:07 AM, Mike Dewhirst > wrote:

At the moment "has_change_permission" in the Admin works by returning
403 Forbidden if it gets a False.

That doesn't suit my needs but it is probably not advisable to
adjust it.

Users without change permission need to be able to see the data and
perhaps raise an exception (in this case BusinessRuleViolation
subclassed from ValidationError) if they try to save. In other words,
maybe use the existing form clean() mechanism.

However, I recognise that this subverts the Admin by preventing [Save]
and therefore may not be appropriate.

A perhaps better solution would be to disable the Save and Delete
widgets/actions in particular circumstances.

How can I do something like this?

TL;DR

All the business rule decision logic is calculated using the object
instance and request.user.

The application displays a substance record with a few 1:1, 1:n, n:1 and
n:m related records. The substance has a status field which can be made
"public domain".

The business rule is that a user can see and edit all their own
substances but can see nothing owned by anyone else - unless they have
been put in the public domain (and which then must be readonly to the
"public")

Thanks for any ideas

Mike

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users+unsubscribe@__googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at http://groups.google.com/__group/django-users
.
To view this discussion on the web visit

https://groups.google.com/d/__msgid/django-users/5517B2B5.__7020805%40dewhirst.com.au

.
For more options, visit https://groups.google.com/d/__optout
.


--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to django-users+unsubscr...@googlegroups.com
.
To post to this group, send email to django-users@googlegroups.com
.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAFWa6tJu_uVd5c%3DvWsVEpa84CGWh-K0WS_xQnHrGs33iEMoZHQ%40mail.gmail.com
.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5517EBE7.3050908%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: How to prevent save/delete in the Admin

2015-03-29 Thread Mike Dewhirst

On 29/03/2015 7:28 PM, Julo wrote:

Maybe you can add an interface for the models that are importants and hook to 
the save/delete signal a interfaced function called CanSave()
And you check the premisson he has, if not allowed rais an exception, and don't 
save.


Julo

I like that. I'll dig a bit deper. It would be best to do it in the 
model but I'm not sure how I can get request.user from there.


Thank you

Mike


Sorry for the bad english.
Saludos,
Julian
-Original Message-
From: Mike Dewhirst 
Sender: django-users@googlegroups.com
Date: Sun, 29 Mar 2015 19:07:17
To: 
Reply-To: django-users@googlegroups.com
Subject: How to prevent save/delete in the Admin

At the moment "has_change_permission" in the Admin works by returning
403 Forbidden if it gets a False.

That doesn't suit my needs but it is probably not advisable to adjust it.

Users without change permission need to be able to see the data and
perhaps raise an exception (in this case BusinessRuleViolation
subclassed from ValidationError) if they try to save. In other words,
maybe use the existing form clean() mechanism.

However, I recognise that this subverts the Admin by preventing [Save]
and therefore may not be appropriate.

A perhaps better solution would be to disable the Save and Delete
widgets/actions in particular circumstances.

How can I do something like this?

TL;DR

All the business rule decision logic is calculated using the object
instance and request.user.

The application displays a substance record with a few 1:1, 1:n, n:1 and
n:m related records. The substance has a status field which can be made
"public domain".

The business rule is that a user can see and edit all their own
substances but can see nothing owned by anyone else - unless they have
been put in the public domain (and which then must be readonly to the
"public")

Thanks for any ideas

Mike



--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5517DC37.8040607%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: How to prevent save/delete in the Admin

2015-03-29 Thread Gabriel - Iulian Dumbrava
In case you hide/not display the save/delete button you must also double 
check in the delete view if the current user has the right permissions to 
delete the item. It's pretty easy to add a post button in firebug, or even 
trigger the post using a different method.

duminică, 29 martie 2015, 11:08:06 UTC+3, Mike Dewhirst a scris:
>
> At the moment "has_change_permission" in the Admin works by returning 
> 403 Forbidden if it gets a False. 
>
> That doesn't suit my needs but it is probably not advisable to adjust it. 
>
> Users without change permission need to be able to see the data and 
> perhaps raise an exception (in this case BusinessRuleViolation 
> subclassed from ValidationError) if they try to save. In other words, 
> maybe use the existing form clean() mechanism. 
>
> However, I recognise that this subverts the Admin by preventing [Save] 
> and therefore may not be appropriate. 
>
> A perhaps better solution would be to disable the Save and Delete 
> widgets/actions in particular circumstances. 
>
> How can I do something like this? 
>
> TL;DR 
>
> All the business rule decision logic is calculated using the object 
> instance and request.user. 
>
> The application displays a substance record with a few 1:1, 1:n, n:1 and 
> n:m related records. The substance has a status field which can be made 
> "public domain". 
>
> The business rule is that a user can see and edit all their own 
> substances but can see nothing owned by anyone else - unless they have 
> been put in the public domain (and which then must be readonly to the 
> "public") 
>
> Thanks for any ideas 
>
> Mike 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5245622d-04a2-435d-9efb-cd61f824953b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to prevent save/delete in the Admin

2015-03-29 Thread Julo
Maybe you can add an interface for the models that are importants and hook to 
the save/delete signal a interfaced function called CanSave()
And you check the premisson he has, if not allowed rais an exception, and don't 
save.
Sorry for the bad english.
Saludos,
Julian 
-Original Message-
From: Mike Dewhirst 
Sender: django-users@googlegroups.com
Date: Sun, 29 Mar 2015 19:07:17 
To: 
Reply-To: django-users@googlegroups.com
Subject: How to prevent save/delete in the Admin

At the moment "has_change_permission" in the Admin works by returning
403 Forbidden if it gets a False.

That doesn't suit my needs but it is probably not advisable to adjust it.

Users without change permission need to be able to see the data and
perhaps raise an exception (in this case BusinessRuleViolation
subclassed from ValidationError) if they try to save. In other words,
maybe use the existing form clean() mechanism.

However, I recognise that this subverts the Admin by preventing [Save]
and therefore may not be appropriate.

A perhaps better solution would be to disable the Save and Delete
widgets/actions in particular circumstances.

How can I do something like this?

TL;DR

All the business rule decision logic is calculated using the object
instance and request.user.

The application displays a substance record with a few 1:1, 1:n, n:1 and
n:m related records. The substance has a status field which can be made
"public domain".

The business rule is that a user can see and edit all their own
substances but can see nothing owned by anyone else - unless they have
been put in the public domain (and which then must be readonly to the
"public")

Thanks for any ideas

Mike

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5517B2B5.7020805%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/545655854-1427617702-cardhu_decombobulator_blackberry.rim.net-1563162238-%40b1.c1.bise6.blackberry.
For more options, visit https://groups.google.com/d/optout.


Re: How to prevent save/delete in the Admin

2015-03-29 Thread Avraham Serour
maybe overwrite the view in your own modeladmin class?

On Sun, Mar 29, 2015 at 11:07 AM, Mike Dewhirst 
wrote:

> At the moment "has_change_permission" in the Admin works by returning
> 403 Forbidden if it gets a False.
>
> That doesn't suit my needs but it is probably not advisable to adjust it.
>
> Users without change permission need to be able to see the data and
> perhaps raise an exception (in this case BusinessRuleViolation
> subclassed from ValidationError) if they try to save. In other words,
> maybe use the existing form clean() mechanism.
>
> However, I recognise that this subverts the Admin by preventing [Save]
> and therefore may not be appropriate.
>
> A perhaps better solution would be to disable the Save and Delete
> widgets/actions in particular circumstances.
>
> How can I do something like this?
>
> TL;DR
>
> All the business rule decision logic is calculated using the object
> instance and request.user.
>
> The application displays a substance record with a few 1:1, 1:n, n:1 and
> n:m related records. The substance has a status field which can be made
> "public domain".
>
> The business rule is that a user can see and edit all their own
> substances but can see nothing owned by anyone else - unless they have
> been put in the public domain (and which then must be readonly to the
> "public")
>
> Thanks for any ideas
>
> Mike
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/5517B2B5.7020805%40dewhirst.com.au.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFWa6tJu_uVd5c%3DvWsVEpa84CGWh-K0WS_xQnHrGs33iEMoZHQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to prevent save/delete in the Admin

2015-03-29 Thread Mike Dewhirst

At the moment "has_change_permission" in the Admin works by returning
403 Forbidden if it gets a False.

That doesn't suit my needs but it is probably not advisable to adjust it.

Users without change permission need to be able to see the data and
perhaps raise an exception (in this case BusinessRuleViolation
subclassed from ValidationError) if they try to save. In other words,
maybe use the existing form clean() mechanism.

However, I recognise that this subverts the Admin by preventing [Save]
and therefore may not be appropriate.

A perhaps better solution would be to disable the Save and Delete
widgets/actions in particular circumstances.

How can I do something like this?

TL;DR

All the business rule decision logic is calculated using the object
instance and request.user.

The application displays a substance record with a few 1:1, 1:n, n:1 and
n:m related records. The substance has a status field which can be made
"public domain".

The business rule is that a user can see and edit all their own
substances but can see nothing owned by anyone else - unless they have
been put in the public domain (and which then must be readonly to the
"public")

Thanks for any ideas

Mike

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5517B2B5.7020805%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.