Re: import problem

2012-02-16 Thread DrBloodmoney
On Thu, Feb 16, 2012 at 9:20 AM, Scott Macri <scottma...@gmail.com> wrote:
> DrBloodmoney I not sure what you mean by circular imports.  datetime
> is the only import I have in this file.

Here are examples of circular import problems [1][2]

I am forever getting bitten by them, so it's become one of the first
things that I think about when weird things/bugs happen in Python.

[1] http://effbot.org/zone/import-confusion.htm#circular-imports
[2] 
http://stackoverflow.com/questions/1556387/circular-import-dependency-in-python

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import problem

2012-02-15 Thread DrBloodmoney
On Wed, Feb 15, 2012 at 10:48 PM, Scott  wrote:
> Hello,
> I'm having a strange issue and have already spent an hour trying to
> figure it out.
>
> I created a python app called mn.  Then I setup all my models and
> stuff to work under mn.hcp.  Everything has been working fine until I
> tried to use date time in a py file in the hcp directory.
>
> I've imported datetime, with import date time at the top of my py
> file.  Then within the file I have a class with an internal method
> trying to use some date functions.
>
> datetime.date(2003,11,11)
>
> For some reason I am getting a NameError on the datetime object.  I
> don't understand why this is happening after I've imported datetime.
> Any help would be appreciated.  Thanks.

You probably have some sort of namespace collision. Look for circular
imports or import modules with the same name etc.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Checkboxes for a list of items like in Django admin interface

2012-01-04 Thread DrBloodmoney
On Wed, Jan 4, 2012 at 5:33 AM, Martin Tiršel  wrote:
> Hello,
>
> I have a list of items (from a model) I want to display with checkboxes (for
> deleting multiple objects at once). The same behaviour like in django admin
> (change list). I can do such thing in templates:
>
> {% for item in item_list %}
> 
> 
> {{ item }}
> 
> {% endfor %}
>
> and in a view loop through somename list I get from POST and delete items.
> Is there a better Django way I should do it or this approach I wrote is
> correct? Is there a way I could use Django forms for processing the POST
> data and delete items in a form's method (so I can use it from multiple
> views)?
>

I do it in a form, because I like to keep all of the heavy logic out
of views and keep it in the models or the forms. Here is a relatively
complete example form from my codebase:

class DivisionRemovalForm(forms.Form):
class MultipleDivisionField(forms.ModelMultipleChoiceField):
def label_from_instance(self, obj):
url = reverse('organizer_division_view', kwargs={'div_pk': obj.pk})
label = '%s' % (url, obj.__unicode__())
return mark_safe(label)

divisions = MultipleDivisionField(queryset=[],
widget=forms.CheckboxSelectMultiple())

def __init__(self, competition, *args, **kwargs):
self.competition = competition
super(DivisionRemovalForm, self).__init__(*args, **kwargs)
self.fields['divisions'].queryset = self.competition.divisions.all()

def save(self):
for div in self.cleaned_data['divisions']:
units = div.units.all()
if units:
for unit in units:
unit.in_division = False
unit.save()
divisions = self.cleaned_data['divisions']
divisions.delete()

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: auth.login function not working as expected

2011-12-19 Thread DrBloodmoney
On Sun, Dec 18, 2011 at 4:25 PM, Abraham Yusuf  wrote:
> Hi all,
> I'm trying to login a user using django's authentication backend with the 
> following:
> user=auth.authenticate(userid,pass)
> if user:
>   if user.is_active:
>      auth.login(request,user)
> I am getting TypeError login() takes exactly 1 argument (2 given). I've 
> checked the docs and i can't find any problem there. Pls any help will be 
> appreciated. Am using django 1.3.1, python 2.7 on ubuntu 11.04.

It sounds like you have solved your problem. In case you haven't, in
the auth.login() call above you have request  user instead of
request  user. That would also give you the same error.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: add project directory path to python path permanently

2011-12-01 Thread DrBloodmoney
On Thu, Dec 1, 2011 at 5:59 AM, Nikhil Verma  wrote:
>
> Hi all,
>
> I want to add my django project directory path to PYTHONPATH. I am a newbie
> in ubuntu 11.10
> Please tell me step by step. When i do
import sys
sys.path.append(''project_directory path")
> It does append but not permanently. I want it like whenever i do sys.path it
> should show me Project Directory path in PYTHONPATH

The easiest way is to find out where your site-packages is on your
python installation. Then just symlink your django project directory
there.

Or just use a separate virtualenv for every django project (hint: this
is what you should be doing anyways). Then just symlink into your
virtualenv site-packages

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Using request.POST.copy() to get hidden field in html template

2011-11-30 Thread DrBloodmoney
On Wed, Nov 30, 2011 at 7:43 PM, jim  wrote:
> I'm trying to use request.POST.copy() to get a hidden field in an html
> template.  The hidden field looks like:
>
> 
>
> I also tried:
>
> 
>
> In my view.py I have:
>
>      postdata = request.POST.copy()
>       url = str(postdata.get('url'))
>
> The value of url is None.  Is there an additional trick to this?

1. Make sure that the hidden field is inside of the  tags.

2. You shouldn't need to copy the QueryDict to get the value:

url = request.POST.get('url', 'default') # or request.POST['url']

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Process management with Supervisord

2011-11-30 Thread DrBloodmoney
On Wed, Nov 30, 2011 at 9:35 AM, Andre Lopes  wrote:
> Hi,
>
> I'm serving to production a Django website with Nginx + Gunicorn with
> virtualenv.
>
> My dumb question is: I must to install supervisord in my virtualenv or
> outside my virtualenv?

You should just install supervisord to your system python install
(easy_install). I run it as root manage it with upstart on Ubuntu so
it'll restart/start properly (run nginx workers and gunicorn as
non-root (servers) - this example is for uwsgi but it'll be very
similar for gunicorn):

# supervisord.conf
# put this directive at the bottom of your /etc/supervisord.conf

[program:uwsgi_example]
command=/usr/local/sbin/uwsgi
  --pythonpath "/home/servers/www/example.com/app/example"
  --virtualenv "/home/servers/virtualenvs/example"
  --socket 127.0.0.1:9000
  --module example.django_wsgi
user=servers
autostart=true
autorestart=true
stdout_logfile=/home/servers/www/example.com/logs/uwsgi.log
redirect_stderr=true



# Upstart init
# copy or symlink to /etc/init/supervisord.conf
# /etc/init/supervisord.conf

# supervisord script for upstart

description"Supervisor"

start on runlevel [2345]
stop on runlevel [!2345]

# --nodaemon: Run supervisord in the foreground
exec /usr/local/bin/supervisord --nodaemon

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: A view associated with a lot of urls

2011-11-29 Thread DrBloodmoney
On Tue, Nov 29, 2011 at 3:37 PM, Nolhian  wrote:
> Thanks !
>
> So you'll not check if the category/item exists ( if a user enter a
> bad url ), you'll just hit the database to check if it does in fact
> exists ?

No I don't know what your business logic for the view/model would be.
I was just showing an example of how you could take keywords from your
request url and map them to your models to display results to the user
without having to hard-code them in your urls or settings or whatever.


> However with that, there is no way for example to make a difference
> between "there is no items in this category" and "this category
> doesn't exist" !
>
> Well that could be a solution but only 1 collection for a lot of
> different unrelated categories seems really odd to me, why not a model
> per category ?

Again it's however you want to model your data. For the sake of
normalization (and typing/database size/etc) I'd probably have one
model for categories:

class Category(models.Model):
...

class Item(models.Model):
category = models.ForeignKey(Category, related_name='items')
...

and so forth.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Nginx - How to configure the virtual.conf to serve a Django application

2011-11-29 Thread DrBloodmoney
On Tue, Nov 29, 2011 at 3:05 PM, Andre Lopes  wrote:
> I'm trying to serve a Django application to production. I have
> installed Gunicorn and now I need to setup a Nginx Virtual Host. I'm
> kind of lost on how to configure the "virtual.conf" from Nginx. I just
> want to use Nginx as proxy, I don't want to configure deplyment
> scripts for now.
>
> I have this layout taken from 
> here(http://senko.net/en/django-nginx-gunicorn/):
>
> [code]
>        server {
>            listen   80;
>            server_name example.com;
>            # no security problem here, since / is alway passed to upstream
>            root /path/to/test/hello;
>            # serve directly - analogous for static/staticfiles
>            location /media/ {
>                # if asset versioning is used
>                if ($query_string) {
>                    expires max;
>                }
>            }
>            location /admin/media/ {
>                # this changes depending on your python version
>                root /path/to/test/lib/python2.6/site-packages/django/contrib;
>            }
>            location / {
>                proxy_pass_header Server;
>                proxy_set_header Host $http_host;
>                proxy_redirect off;
>                proxy_set_header X-Real-IP $remote_addr;
>                proxy_set_header X-Scheme $scheme;
>                proxy_connect_timeout 10;
>                proxy_read_timeout 10;
>                proxy_pass http://localhost:8000/;
>            }
>            # what to serve if upstream is not available or crashes
>            error_page 500 502 503 504 /media/50x.html;
>        }
> [/code]
>
> To put things working I should replace:
>
> [code]
>    root /path/to/test/hello;
> [/code]
>
> For the path where I have my Django Project?
>
> I have Django and all other Python scripts installed in a virtualenv.
>
> Can someone give me some gidelines to get Django working with Gunicorn
> with Nginx as proxy?
>
> Best Regards,


I use uwsgi but the process is the same. Basically gunicorn will be
serving your application up on localhost:PORT (in the example
http://localhost:8000). So first you need to configure gunicorn to do
that. They have a 'deploy' section on their site that has a sample
nginx config. I would base my files off that. But the basic scenario
is gunicorn serving your django app (Nginx knows nothing about django)
+ supervisord (to make sure gunicorn stays running) + Nginx who is
listening for requests with your django url ('/' in your example file)
to proxy that request back to gunicorn. All of the django-specific
stuff is going to be handled by gunicorn (ie. completely different
than serving php out of Apache via mod_php).

Basically install gunicorn (pip install gunicorn). Copy the
gunicorn_django script out of the install path for gunicorn and plop
it into your django project's root (ie. where your settings.py file)
is and run that script (./gunicorn_django -b localhost:8000 for your
example). Once you confirm that it is working and serving requests
proxied back from nginx then you can worry about getting supervisord
to monitor your process and restart it if it stops.

Gunicorn is probably slightly easier than getting uwsgi going so I'd
stay with that before you switch.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: A view associated with a lot of urls

2011-11-29 Thread DrBloodmoney
On Tue, Nov 29, 2011 at 2:19 PM, Nolhian  wrote:
> Thanks you for your answer, yes I plan on using different models for
> the lookups. But I'm confused, is that a yes to my question, Lists/
> dicts are the way to go here ?

I would not do it that way. Seems incredibly brittle and you are
mixing up you model with your view (so to speak).

I would do it like so:

url(r'^(?P\w+)/(?P\w+)/?(?P\w+)/', view,
name='complicated_view')

and then in the view:

def view(request, category, item, subitem=None):
  MyModel.objects.get(category=category, item=item)

or whatever.

Then you could have urls that look like /computer/keyboard/ or
/animal/dog/Fido, etc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django : CSRF and variable handling in a view

2011-11-23 Thread DrBloodmoney
> If I don't check anywhere in the view if a user is authenticated, he
> can still use the form to post data and my goal is that if a user is
> authenticated he can't ( in the template if a user is authenticated it
> doesn't display the form ).
> I'm aware that it kind of defy the DRY principle because I have to
> check both in the view and in the template if a user is authenticated
> but I haven't found another way :(


This seems all sorts of wrong to me. Why couldn't the user just log
out and then post? Seems like an odd workflow, but I don't know your
business-case here.

You could always control what is shown to the user in the template (to
limit their ability to use your form to post to the view) with

{% if not user.is_authenticated %}
SHOW FORM
{% else %}
you're logged in so you can't post
{% endif %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Perhaps more of a general Python question, but..

2011-11-23 Thread DrBloodmoney
On Wed, Nov 23, 2011 at 2:01 PM, Jeff Heard  wrote:
> I have several django apps. all of which are in separate packages and can be
> installed seperately.  I would like them all to be sub-packages of a master
> package named "ga" So:
> ga.datacube
> ga.pyramid
> ga.sensorcollection
>  and so on.  The problem is that when I install them the packages never seem
> to show up.  My project structure looks like this:
> GA pyramid project:
> /home/jeff/ga/ga_pyramid/
> ga/
>   __init__.py        # contains "import pyramid"
>   pyramid/
 __init__.py # needs init
>       models.py
>       views.py
>       tasks.py
>       tests.py
>       urls.py
>       static/
>       templates/
>
> GA datacube project:
> /home/jeff/ga/ga_datacube/
> ga/
>   __init__.py        # contains "import datacube"
>   datacube/
 __init__.py # needs init and here
>       models.py
>       views.py
>       tasks.py
>       tests.py
>       urls.py
>       static/
>       templates/

Make sure you add the __init__.py s to magically transform it into a module

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django : CSRF and variable handling in a view

2011-11-22 Thread DrBloodmoney
On Tue, Nov 22, 2011 at 6:54 PM, Nolhian  wrote:
> Hello,
>
> I've got a subscription form and this view :
>
> def index(request):
>        c = RequestContext(request)
>        if request.user.is_authenticated():
>                return render_to_response('index.html', {'has_account': True})
>        if request.method == 'POST':
>                form = SignupForm(request.POST,error_class=DivErrorList)
>                if form.is_valid():
>                        return HttpResponseRedirect('/thanks/')
>        else:
>                form = SignupForm()
>        return render_to_response('index.html', {'form': form, 'has_account':
> False}, c)
>
> 1) In Index.html I have a form with a {% csrf_token %}. If I don't put
> c = RequestContext(request) and add the c into every
> render_to_response I've got a csrf error. Is my view above the right
> way to handle csrf ?
>
> 2) I noticed that instead putting
> c = RequestContext(request) *at the beginning of my view*
> and :
> return render_to_response('index.html', {'form': form, 'has_account':
> False}, c) *at the end of my view*
>
>  I could just put this at the end of my view :
>
> c = RequestContext(request, {'has_account': False,'form': form})
> return render_to_response('index.html', c)
>
> Which one it the best approach ?
>
> 3) I also noticed that if i don't pass 'has_account': False to my
> template, nothing changes, it still evaluate it as false in {% if
> has_account %}. Is it best to pass it to the template anyway ?
>
> Thanks in advance,
>
> Nolhian
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

Just use the render [1] shortcut. It'll put the RequestContext in for you.

[1] https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/#render

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: browser detection in django

2011-11-18 Thread DrBloodmoney
Well if it is IE then you can do conditional commenting for IE to detect itself:


css


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Extend user model multiple times

2011-11-18 Thread DrBloodmoney
Personally I think get_profile() is an anti-pattern, just access it
like any other OneToOneField (and that's what you want... not
unique=True on a ForeignKey). Just set up a models.OneToOneField(User,
related_name=XXX), then you can access the profile as user.XXX. The
User model and all of its associated limitations are my least favorite
thing about django. Hopefully, we'll get some kind of lazy loading
User model that we can easily override and extend (and will still play
nice with the django ecosystem) in the future.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Programming logic in Classed Based FormView or in the Form Itself?

2011-09-22 Thread DrBloodmoney
On Thu, Sep 22, 2011 at 11:14 AM, Kurtis  wrote:
> Hey,
>
> I'm trying to figure out the best way to do this. I have a FormView
> and an associated Form. In my Form, I take care of all of the
> validation and cleaning as far as the input goes.
>
> However, I need to put in some more logic such as saving the user,
> logging in a user, and whatever else the future holds. I can do this
> in my Class Based View just fine within the is_valid() method.
>
> The problem comes when I need to raise an exception. I'm not sure what
> kind of an exception to raise or how to present it back to the user.
> For example, if a user tries to create an account and the email
> address is already in use, I want to be able to display that message
> to them with the form.
>
> I know that authentication is a bad example on this since most of this
> really could be done from the Form. But I have a feeling that in the
> future there will be places I need to actually do this stuff from the
> View itself.
>
> Are there any suggestions on a good, or conventional, way to do this?
> Basically it boils down to this -- with Class Based FormViews, should
> the logic for *everything* be pushed into the Form itself? Or should
> it be split up between the Form (validation) and the View (everything
> else) like I am trying to do?
>
> Any examples would also be very helpful!
>
> Thanks


I keep all but the most simple of logic (actually I try to not have
*any* logic in views or templates). It doesn't belong there. I don't
think that django's docs make a strong statement about where it should
go, but I think it should go into models (for model instance specific
logic), a model manager (for whole-table related logic) and in the
forms (for CRUD-type logic). A basic example is that I will add a
save() method to every forms.Form that I write (to mimic the
forms.ModelForm api):

class TestForm(forms.Form):
field
field2
field3

def __init__(self, dependency, *args, **kwargs):
self.dependency = dependency
super(TestForm, self).__init__(*args, **kwargs)

def clean_field(self):  
def clean(self): 

def save(self):
self.cleaned_data['field']
do some fancy logic

# in view:
... boilerplate
if request.POST:
 form = TestForm(dependency, data=request.POST)
 if form.is_valid():
form.save()
return redirect()
 # failed validation
 return render(request, template, {'form': form})

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dealing with misc parts of a project

2011-09-22 Thread DrBloodmoney
On Thu, Sep 22, 2011 at 12:30 PM, Micky Hulse  wrote:
> On Thu, Sep 22, 2011 at 8:54 AM, Simon Connah  
> wrote:
>> So do you just tend to create a new misc app to hold all these little bits 
>> and pieces or is there a convention for such things?

>
> For a few projects at work, we use a "global" app that contains code
> for use in other apps.
>

Very similar. I think that a lot of people use a 'core' app. It's what
I use and where I dump a lot of models and utilities/forms that cannot
be separated from the project itself. It's where I'll put profiles and
account routing, about pages, etc.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: request.method not working as expected

2011-09-20 Thread DrBloodmoney
On Tue, Sep 20, 2011 at 11:46 AM, Fabio Natali  wrote:
> Hi everybody!
>
> I have a very simple view which is supposed to print out GET or POST,
> depending which has been used to send data. The problem is I always get
> "GET" even when sending data via POST.
>
> ### views.py:
> def method(request):
>    return HttpResponse(request.method)
>
> ### urls.py:
> (r'^method/$', method)
>
> ### php script to send data to the Django page:
> http://192.168.0.2:8000/method/;>
>  
>  
> 
>
> I am running Django version 1.2.5, development server.
>
> Am I missing something? Any hint?
>
> Thanks, Fabio.
>
> --
> Fabio Natali FNstudio

I'm not 100% sure, but since you aren't including the
csrfmiddlewaretoken in the post data, I would expect it to 403 if you
aren't exempting the view from CSRF protection [1].

[1] https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Virtualenv and Django in Production

2011-09-20 Thread DrBloodmoney
On Tue, Sep 20, 2011 at 1:55 AM, adrian s  wrote:
> Hi all, I've been using virtualenv as recommended in my development
> environments.
> I am now migrating a project which was not using virtualenv, to another
> server and now
> have the opportunity to use it in production.
> I've spent a while googling this subject and I'm not sure what the best
> practice is.
> Is it common to run a production django deployment with apache behind
> virtualenv? If so,
> could anyone steer me in the proper direction for getting this setup with
> the wsgi file...
> Or, is virtualenv best for just testing isolated environments, and running
> production
> with the existing global space (I feel naive typing this out, so I must be
> wrong (: )
>  as is (isn't there more overhead with virtualenv anyhow?)
> I hope I made sense.
> If anyone has any relevant docs that clarify this (maybe my searches stink)
> I'd love to read
> over what there is so I may make an appropriate call.
> Adrian

I run a VPS with several django apps isolated into different
virtualenvs. They are served by either uwsgi or gunicorn and reverse
proxied by nginx. There are several good guides if you google for some
of those keywords.

It is a pretty easy set-up. If you were only serving one django app,
it may be slight overkill, but it may be worth the effort to get it
set up this way so you can easily add more django applications and
have them be completely isolated from each other.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Removing SECRET_KEY from settings.py

2011-09-17 Thread DrBloodmoney
On Fri, Sep 16, 2011 at 8:54 PM, Tim Chase
 wrote:
> Just returning to some Django work after a time away, I (re)started an old
> project in 1.3 and hit an early issue.  I'd like to keep my settings.py
> under revision-control that is somewhat publicly accessible, but don't want
> my SECRET_KEY exposed.  The solution I've opted for is the following excerpt
> of my settings.py on which I'm hoping for feedback:
>
>  SECRET_FILE = "secret.txt"
>  if os.path.exists(SECRET_FILE):
>    SECRET_KEY = file(SECRET_FILE).read()
>  else:
>    from random import choice
>    SECRET_KEY = ''.join([
>      choice(
>      'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
>      ) for i in range(50)])
>    f = file(SECRET_FILE, 'w')
>    f.write(SECRET_KEY)
>    f.close()
>
> (key generation ripped directly from
> core/management/commands/startproject.py )
>
> As best I can tell, this should allow me to place secret.txt on machines I
> control, while allowing others to freely download the code and deploy on
> their end with minimal trouble.
>
> Any input would be greatly appreciated,
>
> -tkc


settings.py/
|- __init__.py
|- base.py
|- development.py
|- production.py
|- secret.py # <== not in version control

then in __init__.py:

from base import *
from secret import *

if DEBUG:
from development import *
else:
from production import *

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: intercept calls to reverse(..) in tests

2011-09-17 Thread DrBloodmoney
On Sat, Sep 17, 2011 at 7:47 AM, Reikje  wrote:
> Okay I am having some troubles getting this to work. In my application
> I am using WebTest and django-webtest to do template testing. In order
> to monkeypatch the django.core.urlresolvers.reverse function, I have
> created a new Test base that looks like this:
>
> class FacebookWebTest(WebTest):
>
>    def __init__(self, methodName='runTest'):
>        super(FacebookWebTest, self).__init__(methodName)
>        import django.core.urlresolvers
>        django.core.urlresolvers.reverse = self.reverse
>
>    def reverse(*args, **kwargs):
>        return "foo"
>
>
> Then hier is a test:
>
> from django.core.urlresolvers import reverse
>
> class HomepageViewTestCase(FacebookWebTest):
>
>    def testPopulateFieldsInitially(self):
>        url = reverse('webapp_home')
>        form = self.app.get(url).form
>        ...
>
> Within the HomepageViewTestCase it is still calling the original
> reverse method in django.core.urlresolvers even though it is calling
> the FacebookWebTest constructor before. Any suggestions :)

I usually monkey patch like so:

# myviews.py

from django.core.urlresolvers import reverse

def view(request):
 blah blah
 x = reverse('whaterrr')
 return HttpResponse('monkey-patch')

# tests.py

import myviews

def patch_reverse(name):
 return whatever_you_want

class MyViewTests(TestCase):

def setUp(self):
self.old_reverse = getattr(myviews, 'reverse')
myviews.reverse = patch_reverse

def tearDown(self):
myviews.reverse = self.old_reverse

Gets the job done

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django-registration + csrf token

2011-09-11 Thread DrBloodmoney
On Fri, Sep 9, 2011 at 12:02 PM, Brett Hutley  wrote:
> You need to add it to the registration_form.html as well.
>
> Make sure you have  'django.middleware.csrf.CsrfViewMiddleware', in the 
> MIDDLEWARE_CLASSES tuple in the settings.py file.
>
> Cheers, Brett
>
> On 9 Sep 2011, at 16:47, nicolas HERSOG wrote:
>
>> Hi All !
>>
>> Do any of you use this app 
>> https://bitbucket.org/ubernostrum/django-registration/overview with the csrf 
>> middleware ?
>>
>> Instead of re-write myself the registar, check via email, lost password, 
>> login and co i tried to use this app, but it don't work and i have this 
>> message :
>> Forbidden (403)
>> CSRF verification failed. Request aborted.
>>
>> I added to the login form {{ csrf_token }} but it's seems that it is not 
>> implemented,
>>
>> any ideas ?
>>
>> Thanks for all :)

Instead of:
{{ csrf_token }}

try:
{% csrf_token %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Best approach to handling different types of Users

2011-08-19 Thread DrBloodmoney
On Fri, Aug 19, 2011 at 9:27 AM, Andre Terra  wrote:
> Alright, do what you will. Whatever floats your boat..
>
> On Fri, Aug 19, 2011 at 5:12 AM, Matt Schinckel  wrote:
>>
>> On Friday, August 19, 2011 12:07:44 PM UTC+9:30, Andre Terra (airstrike)
>> wrote:
>>>
>>> Until you install some third party app that accesses
>>> User.objects.all() and then suddenly nothing works as it's supposed
>>> to.
>>
>> Why wouldn't it? The User subclasses will still appear in the
>> User.objects.all() queryset.
>>>
>>> You can access the User object from its related UserProfile instance
>>> and do everything you say from there instead of breaking the
>>> convention. Nobody's stopping you from writing an abstract
>>> BaseUserProfile model with an FK to User and custom UserProfile
>>> subclasses. I just don't see any advantages in going down that path.
>>
>>  As I said, 'at this stage', it all seems to be working out okay. I have
>> plenty of 3rd party apps, and even some of my own, that access User, and
>> they still work with sub-classes.
>>>
>>> Because how will you access every user if you ever need to? What if
>>> someone gets promoted? How will you separate view from model logic?
>>> Are you going to rewrite forms for every user class? That's probably
>>> going to be hard to maintain.
>>
>>  You can still access User.objects.all(). I even have a way to access the
>> sub-classes (downcasting) when fetching all users.
>>>
>>> FWIW, profiles are the canonical solution. They are also the only
>>> elegant solution, at least until the app loading branch lands on
>>> trunk, which should then allow you to register a different class as
>>> User. But that won't happen any time soon..
>>
>> See, I don't see them as an elegant solution. Having to do:
>>     user.get_profile().date_of_birth
>> instead of:
>>     user.date_of_birth
>> irks me every time I write the code. UserProfile has always felt to me
>> that it was a patchy way of extending User.
>> Matt.
>>

Not being able to define your own User model is easily my least
favorite thing about django. User.get_profile() is an antipattern.

I hope we get the ability to define our own User model makes it into
contrib.auth at some point (lazy loaded)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How control access to static pages that are *not* part of a Django app?

2011-08-01 Thread DrBloodmoney
On Mon, Aug 1, 2011 at 3:51 PM, Chris Seberino <cseber...@gmail.com> wrote:
>
>
> On Aug 1, 7:11 am, DrBloodmoney <drbloodmo...@gmail.com> wrote:
>> You can look into protecting them with mod_xsendfile for Apache
>
> Thanks.  I'll look into that.  Is there no way to have a view hand off
> a page to Apache?

Like Javier mentioned, this is exactly what mod_xsendfiledoes. Check
out this answer[1] on StackOverflow.

[1] 
http://stackoverflow.com/questions/1156246/having-django-serve-downloadable-files/1158750#1158750

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How control access to static pages that are *not* part of a Django app?

2011-08-01 Thread DrBloodmoney
On Mon, Aug 1, 2011 at 1:12 AM, Chris Seberino  wrote:
> My Django app only allows someone to access a /books page, that is
> part of the Django app, if they are signed in.
>
> The pages below that URL are just static directory listings of PDFs
> all handled by Apache.
> For example /books/book_1, /books/book_2, etc.
>
> Because these directory listings aren't handled by Django, they don't
> enjoy Django's access controls.  They don't even have a view since
> they are just static pages handled by Apache.
>
> Is there any way to somehow prevent access to them unless someone is
> signed into my Django app?
>
> chris
>


You can look into protecting them with mod_xsendfile for Apache
(X-accel-redirect for nginx). Basically you restrict access to the
directory from Apache so someone cannot naively navigate to that
url/directory then set response headers in your django app. Apache
will then read those response headers and serve the protected file.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: 3-legged-OAuth Logout

2011-07-25 Thread DrBloodmoney
On Mon, Jul 25, 2011 at 5:47 AM, Vignesh Sunder
 wrote:
> Hi. I was just curious to know about the logout functionality of
> OAuth..When a User logs out from the Consumer (After 3-legged OAuth
> login) site, the User's session happens to get flushed. But I believe
> this happens only on the Consumer side. However, if the User
> immediately tries to connect to the Server side, the User is
> automatically logged in. I am not sure if I have missed anything on
> this, but would appreciate if I am enlightened on the same: Would it
> be possible to inform the Server (by the Consumer) that the User has
> logged out and the User's session be flushed from the Consumer and the
> Server sides?
>
> Thanks
>

If you are logging out of Django (assuming your django app is the
consumer), the users session will get flushed from the database (or
whatever session is backed with). You'll probably still be logged into
the OAuth provider (Twitter, etc). If the person wishes to log out of
Twitter, that's where they are going to have to go in order to do
that. If they remain logged into Twitter and then start the OAuth
login flow from your app, when they get redirected to Twitter for
authentication/authorization, Twitter will read their cookie/session,
realize that the user is still logged in and has already approved
access for your application and will redirect without requiring
re-authorization.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Need help intercepting SQL

2011-07-11 Thread DrBloodmoney
I think that you would probably have better luck coming at it from the
other end. That is, in the database itself (stored procedure or
otherwise).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Complex Query help - get items from the org to which the user belongs

2011-07-07 Thread DrBloodmoney
On Thu, Jul 7, 2011 at 12:04 AM, Venkatraman S  wrote:
> I am doing some bechmarking on the performance of both the versions of the
> query:
> 1.
> Item.objects.filter(created_by__employees__org__in=u.employees_set.all().values_list('org'))
> and
> 2. Items.objects.extra(where=['created_by_id in (select e.user_id from
> myapp_employees e, myapp_organization o where e.org_id = o.id and o.id =
> (select o2.id from myapp_organization o2, myapp_employees e2 where e2.org_id
> = o2.id and e2.user_id=3 and e2.deleted=False)) '])
>
> I am seeing #1 to be faster(when i view from DDT). Will update in the next
> few days or probably early next week.
>
> -V

Personally, I'd add a FK on the Item to the Employee, particularly if
they're in the same app (Actually I'd replace the FK to User with one
to Employee). I suspect that is a simplified models.py so I don't
actually know if there would be a requirement to FK to User. (I also
try to limit my code touching django.contrib.auth since using it is my
biggest pain point for django).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dreamhost Virtualenv Question

2011-07-06 Thread DrBloodmoney
On Wed, Jul 6, 2011 at 3:31 AM, i...@webbricks.co.uk
 wrote:
> oh yeah
> http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/
>
> that page is my goto reference on building a virtualenv, you might
> have already found it, but if not...
>
> On Jul 5, 10:28 pm, Jeremy  wrote:
>> AHHH, that makes a little more sense.  I'm trying to install apps from
>> Github.  Things like Pinax, and different individual blogging apps so
>> that I can "plug" them into one Django project to give it multiple
>> bits of social functionality.  Obviously I'm having a lot of trouble
>> (some of it being that it sounds like I don't even know what I'm
>> saying).  I've tried to install these apps through PIP and other forms
>> on Dreamhost, but it keeps saying that I don't have permission.  The
>> way that I believed to get around this is to set up virtualenv on my
>> shared server space, and create the project inside of that, correct?
>> But if I do this, how can I view the project that I creating live?
>>
>> Again, if this all sounds foolish, keep in mind I'm incredibly new to
>> all these concepts and my not understand them enough.  I've been
>> looking for someone locally to give me some Django lessons, but I keep
>> coming up dry.
>>
>> Let me know if anyone can assist me.  Thanks guys.
>>

The two most important things to concern yourself with regarding
starting developing with virtualenv (which is a must):

- source /path/to/venv/bin/activate: this command tells the shell
(bash, zsh, etc) to use the python interpreter located at
/path/to/venv/bin/python instead of the system python interpreter (eg.
/usr/bin/python)

- the pythonpath for your virtualenv is going to be
/path/to/venv/lib/python/site-packages. I usually maintain a separate
directory containing packages I need (either at ~/libraries for global
libraries, third-party apps, etc on my dev box) and
/path/to/venv/libraries on production boxes. Then I symlink python
modules that I need to the /path/to/venv/lib/python/site-packages
directory. Then they'll be on your PYTHONPATH.

The above applies to developing on a *nix box. If you are developing
on windows, stop what you are doing and install virtualbox and ubuntu
or go fully over to a *nix box. You'll appreciate it this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Questions on markdown

2011-07-05 Thread DrBloodmoney
On Mon, Jul 4, 2011 at 2:22 PM, Petite Abeille  wrote:
>
> On Jul 4, 2011, at 8:08 PM, leo wrote:
>
>> what i want is
>
> To quote the friendly manual:
>
> "When you do want to insert a  break tag using Markdown, you end a line 
> with two or more spaces, then type return."
>
> http://daringfireball.net/projects/markdown/syntax#p

If you're copy/pasting test that's not Markdown, then Markdown will
not magically help you. If you have unformatted text that you want to
turn into html, you're probably going to have to do a little text
pre-processing. Good news: you're using Python and text processing is
easily in python.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Setting up EC2 for Django

2011-07-05 Thread DrBloodmoney
On Sat, Jul 2, 2011 at 10:14 AM, Soviet  wrote:
> Hello
> I need to set up EC2 instance to run Django+Python+PostgreSQL+Apache
> +Solr+nginx+Mercurial etc. This is all black magic for me - I was only
> using shared hosting like webfaction, where everything is dumb-
> friendly :). But you know, "the customer is always right", and I have
> to run it on Amazon. I did hours of googling, but everything is either
> old/outdated or doesn't cover the tools I have to install. So far I'm
> stuck on connecting to my instance through PuTTY :D.
>
> Can anyone provide some useful link or step by step tutorial? I have
> no experience using Unix command-line-stuff, but im a fast learner :).
> Any help would be appreciated. Also, beer is on me when we meet! :)

An easy way to practice learning how to admin linux servers is to
download virtualbox and then download a server image (*.iso) from your
linux distro of choice (I prefer the Ubuntu/Debian side of things..
rec Ubuntu server). You can set up and then destroy without doing any
damage so you can easily setup again. The only way to learn this stuff
is to just get your hands dirty... it's not hard just kind of hard to
google generally. It's better to have specific errors to google for.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Alternate user fields

2011-06-20 Thread DrBloodmoney
On Mon, Jun 20, 2011 at 5:16 PM, raj  wrote:
> Sorry, can you give me more details. What other things would I have to
> do to make these changes? thank you.
>
> On Jun 20, 3:08 am, Kenneth Gonsalves  wrote:
>> On Mon, 2011-06-20 at 00:03 -0700, raj wrote:
>> > Ya i got that working. Just another quick question, the django auth
>> > system took care of all the login/logout pages. Now that i have a
>> > changed user class up and running, will django automatically adapt to
>> > the new class? Like, in the html, if it says {% user.is_authenticated
>> > %}, will it automatically attribute that to the new user class? Thank
>> > you.
>>
>> no
>> --
>> regards
>> KGhttp://lawgon.livejournal.com
>> Coimbatore LUG roxhttp://ilugcbe.techstud.org/
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

I usually just write OneToOne against the User model for profiles. The
User.get_profile feels like such an anti-pattern and I think it's
going to go bye-bye sometime in the future anyways (particularly if we
get some kind of mechanism to lazy load a developer-defined User
model).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Unit-Testing Dilemma

2011-06-20 Thread DrBloodmoney
On Mon, Jun 20, 2011 at 3:52 PM, Nan  wrote:
> I'm not testing the third-party service.  I need to test *what I send
> to them*.  I.e. that the output of my_view is correct.  The trouble is
> that neither my_view nor the API call actually returns the output that
> I need to check.
>
> Does that make sense?

Mock is one good solution. Here's what I've done in the past
(basically half-assed mock):

1. Have representative data sets that are good for the service (eg.
whatever you send to them, and whatever they send you in return).
2. Monkey patch the call:

def hackety_patch():
from StringIO import StringIO
data = StringIO(testdata_response_from_API)
data.seek(0)
return data.read()

# in TestCase subclass
def setUp(self):
third_party.api.urllib2.urlopen = hackety_patch

def tearDown(self):
third_party.api.urllib2.urlopen = urllib2.urlopen

3. Break up your API calling code into more testable units to truly
isolate your independent code from the API calling code. It'll be much
easier to catch problems in the API integration code.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Updating static files: Still in browser cache

2011-06-09 Thread DrBloodmoney
On Thu, Jun 9, 2011 at 9:16 AM, Malcolm Box  wrote:
> On 9 June 2011 08:09, Thomas Guettler  wrote:
>>
>> My static files (JS/CSS) are cached in the browser. But if there is a bug
>> in a file, an update won't help people which have already cached the old
>> file.
>>
>> You would need a new URL for every change in the JS/CSS files.
>>
>
> Version all static assets, bump the version when you change them.

I keep the file name the same and append a querystring eg.
/static/js/mycustom.js?v=1001 then just increment the querystring on
versioning.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Chained forms

2011-05-31 Thread DrBloodmoney
On Tue, May 31, 2011 at 12:55 PM, Marc Aymerich  wrote:
> Hi!,
> I'm writing an admin action.
> This action needs to collect some information before execute the "final
> task".
> In order to collect this information the user should fill 3 consecutive
> forms, (once they submitted one, another is rendered).
> My question is,
> How can I store the form fields state submitted on each form, and retrieve
> this fields states on the final form, before execute the 'final task'?
> Thanks!
> --
> Marc

You should read the docs about Form Wizard:

https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How do you organize your deployment enviroment

2011-05-25 Thread DrBloodmoney
Yeah. That was the post I was thinking about. For some reason I
thought that it came from the core dev team. I still think that
migrations should be a part of a full-stack framework like django
(south is the first app I install in a new project). They might as
well pick the best-in-breed and throw it in.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How do you organize your deployment enviroment

2011-05-25 Thread DrBloodmoney
On Wed, May 25, 2011 at 9:31 AM, DK  wrote:
> 100% south migration :)

This.
I know that they have said that they weren't going to be putting South
into django (contrib?), but I wish they would. Most django devs should
be using it.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: South migration for fixtures

2011-05-25 Thread DrBloodmoney
On Wed, May 25, 2011 at 12:54 PM, Amit Sethi  wrote:
> Hi all , I might be wrong with some of the concepts as I am new to
> south. I am using south to migrate some fixture data for a django app.
> Also something worth noting is I am bringing south new into the django
> app it was not part of installed apps till now . So the workflow I
> have followed till now is
>
> run syncdb to install south
> create a fake initial migration using convert_to_south command
> create the actual schema migration script for my app using --auto

migrate here then (using default values if you are adding columns)
> create a data migration script with a forward function for the added field

migrate again

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django password reset modification

2011-05-06 Thread DrBloodmoney
On Fri, May 6, 2011 at 12:36 AM, Phui-Hock  wrote:
> On May 6, 4:22 am, Shawn Milochik  wrote:
>> This is a bad idea for multiple reasons. Don't do it.
>
> Huh, care to explain, please?

Please Please Please do not send plain text passwords via email. Please.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom form field

2011-04-20 Thread DrBloodmoney
On Wed, Apr 20, 2011 at 12:45 PM, Daniel Gagnon  wrote:
> Sure, here's a minimal version of them (I skipped fields that aren't too
> relevant to the problem at hand because there's many, including tons of
> foreign keys):
> class Target(Model):
>     name = CharField("Target Name", max_length=255, unique=True)
>     created = DateTimeField(auto_now_add=True, editable=False)
>     modified = DateTimeField(auto_now=True, editable=False)
> class Ticket(Model):
>     target = ForeignKey(Target, related_name="tickets")
>     reference = CharField(max_length=255)
>     created = DateTimeField(auto_now_add=True, editable=False)
>     modified = DateTimeField(auto_now=True, editable=False)

It probably is related to the this being a foreign key field and in
order for it to produce a valid object instance from the Target model,
it needs a queryset. Try to subclass from ModelChoiceField[1] and see
if that works.

[1] 
http://code.djangoproject.com/browser/django/trunk/django/forms/models.py#L891

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom form field

2011-04-20 Thread DrBloodmoney
On Wed, Apr 20, 2011 at 12:30 PM, Daniel Gagnon <redalas...@gmail.com> wrote:
> Thanks
> It still doesn't work though. I found out through logging that value that is
> receive is an int (the id) instead of being the object itself. How can I
> make my widget pass the object itself to the widget instead of passing
> object.id ?
> On Wed, Apr 20, 2011 at 12:17 PM, DrBloodmoney <drbloodmo...@gmail.com>
> wrote:
>>
>> On Wed, Apr 20, 2011 at 11:48 AM, Daniel Gagnon <redalas...@gmail.com>
>> wrote:
>> > So far, I have the following code:
>> > from django.forms.widgets import TextInput
>> > from django.forms.fields import Field
>> > class AutoCompleteWidget(TextInput):
>> >     def render(self, name, value, attrs=None):
>> >         if hasattr(value, 'name'):
>> >             v = value.name
>> >         else:
>> >             v = None
>> >         super(AutoCompleteWidget, self).render(self, name, v, attrs)
>> > class AutoCompleteField(Field):
>> >     widget = AutoCompleteWidget
>> >     def clean(self):
>> >         pass    # Not implemented yet
>> > class TicketForm(ModelForm):
>> >     target = AutoCompleteField()
>> >     class Meta:
>> >         model = Ticket
>> >         exclude = ('slug')
>> >
>> > When I use this code the whole form stops rendering! What's wrong with
>> > my
>> > widget?
>>
>> Take out the self in the super call
>> (ie) Change this:
>>
>> super(AutoCompleteWidget, self).render(self, name, v, attrs)
>>
>> to this:
>>
>> super(AutoCompleteWidget, self).render(name, v, attrs)
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

Could you also include the model?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom form field

2011-04-20 Thread DrBloodmoney
On Wed, Apr 20, 2011 at 11:48 AM, Daniel Gagnon  wrote:
> So far, I have the following code:
> from django.forms.widgets import TextInput
> from django.forms.fields import Field
> class AutoCompleteWidget(TextInput):
>     def render(self, name, value, attrs=None):
>         if hasattr(value, 'name'):
>             v = value.name
>         else:
>             v = None
>         super(AutoCompleteWidget, self).render(self, name, v, attrs)
> class AutoCompleteField(Field):
>     widget = AutoCompleteWidget
>     def clean(self):
>         pass    # Not implemented yet
> class TicketForm(ModelForm):
>     target = AutoCompleteField()
>     class Meta:
>         model = Ticket
>         exclude = ('slug')
>
> When I use this code the whole form stops rendering! What's wrong with my
> widget?

Take out the self in the super call
(ie) Change this:

super(AutoCompleteWidget, self).render(self, name, v, attrs)

to this:

super(AutoCompleteWidget, self).render(name, v, attrs)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Can't build Django documentation

2010-08-14 Thread DrBloodmoney
On Fri, Aug 13, 2010 at 11:11 PM, Kevin  wrote:
> I tried to build the Django docs and got an error.
>
> $ cd django/docs/
> $ make html
> sphinx-build -b djangohtml -d _build/doctrees   . _build/html
> Running Sphinx v1.0.1
> loading pickled environment... not yet created
> building [djangohtml]: targets for 427 source files that are out of
> date
> updating environment: 427 added, 0 changed, 0 removed
> /Users/haitran/Desktop/obnob_project/src/django_docs/_ext/
> djangodocs.py:91: DeprecationWarning: xfileref_role is deprecated, use
> XRefRole
>  xrefs = sphinx.roles.xfileref_role('ref', linktext, linktext,
> lineno, state)
> reading sources... [ 73%] ref/contrib/gis/
> commands
> Exception occurred:
>  File "/Users/src/django_docs/_ext/djangodocs.py", line 215, in
> parse_django_adminopt_node
>    from sphinx.directives.desc import option_desc_re
> ImportError: No module named desc
> The full traceback has been saved in /var/folders/od/
> odl44I41FT0yZPHQw8kT8E+++TM/-Tmp-/sphinx-err-RgDvku.log, if you want
> to report the issue to the developers.
> Please also report this if it was a user error, so that a better error
> message can be provided next time.
> Either send bugs to the mailing list at  group/sphinx-dev/>,
> or report them in the tracker at  sphinx/issues/>. Thanks!
> make: *** [html] Error 1
>
> The process fails when it tries to do an import:
>
> from sphinx.directives.desc import option_desc_re
>
> Why is there no module named desc?
>
> I am using:
> Python 2.6
> Sphinx 1.0.1
> Django 1.2.1
> Mac OS X 10.5.8

The docs [0] mention an incompatibility with the currently released
Sphinx. I can't build right now either, and I'm too lazy to install
Sphinx from source.

[0] http://docs.djangoproject.com/en/dev/intro/whatsnext/#as-html-locally

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: request.is_ajax() good practices

2010-07-21 Thread DrBloodmoney
On Wed, Jul 21, 2010 at 1:37 PM, Juan Hernandez  wrote:
> Hey there,
> I have been working a lot with request.is_ajax() to handle forms and the
> results have been great so fat yet, I have a question about good practices
> and best uses for this function.
> Lets say that I executed a function that returned True and instead of
> sending the boolean to the template, I do something like this:
> def ajaxblue(request):
> if request.is_ajax():
> message = "alert('Hello AJAX');"
> else:
> message = "Hello"
> return HttpResponse(message)
> this is a very simple function but it shows what I'm trying to say. The js
> alert renders itself directly to the template. It works perfectly but
> somehow I thing that I'm violating DRY or at least, good practices
> What do you guys think?
> Thanks a lot
> Juan
>

You should be leaving the js on the client side and instead pass
around json (or equivalent). So test request.is_ajax() and then handle
your ajax requests by passing HttpResponse(json,
mimetype="application/json")

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



HIPAA experience

2010-06-10 Thread DrBloodmoney
Hello,
I was hoping that some of the list members who have experience
building HIPAA-compliant (or SOX-compliant) django apps could share
some of their experiences.  We are beginning to research possibly
implementing some internal apps in our department, but of course
working with patient data requires compliance with HIPAA and now
HITECH.

Specific areas of interest/problems we are interested in solving with
django and python (crypto):

- Auditing (particulary SQL select auditing on sensitive (ie. PHI)
tables) and the need to identify specific user's select (ie. cannot be
database triggered since django connects with as a single user).
- PHI storage encryption as now required under HITECH (I would assume
most solutions would require pycrypto here).

Anyone care to share their experiences?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Why must {% extends '' %} be first value in template? Inconvenient for ajax versions.

2010-03-28 Thread DrBloodmoney
On Sat, Mar 27, 2010 at 9:29 PM, David Hollander  wrote:
> Hello. I am making a restaurant site with some visually candy that
> will load all new subpages via AJAX. And also load pages normally
> without AJAX if javascript is disabled.
>
> Ideally, I want to do:
>
> {% if not ajax %}
>    {% extends 'base.html' %}
> {% endif %}
> {% block content %}Content Here.{% endblock %}
>
> That way I can use the same template for an ajax request as a regular
> request. In a regular request where I pass ajax: False to the
> template, it will extend base.html and add all the background stuff
> such as html header, navigation menu, etc. But if it's ajax, it
> doesn't load any of that unnecessary stuff since that will already be
> present in the page with the ajax request.
> I know I can just return the whole page to an AJAX request and slice
> out the unncessary stuff with jQuery. Or I can create a seperate
> template for the AJAX version. But that would either be very
> inefficient OR violate the DRY principle.
>
> What is the best idiom to handle this situation?
>
> Thank you for your time.
> -David
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

I do it the other way with AJAX in mind, mostly because I want my code
to fail gracefully:

Make your non-javascript template with the fragments you will
otherwise return as html included in the template:

{% include "ajax_fragment.html" %}

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: AJAX Autocompletion Field

2010-02-16 Thread DrBloodmoney
I'll just point out that the jQuery Autocomplete plugin is included (will be
included) in the next jQueryUI release. I think it's been pretty easy to
hook into views

On Feb 15, 2010 6:00 AM, "Massimiliano della Rovere" <
massimiliano.dellarov...@gmail.com> wrote:

I'd use http://dajaxproject.com/

On Sun, Feb 14, 2010 at 06:36, Margie Roginski 
wrote: > Hi Jon, > > I h...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Complicated Form "Workflow" - Need ideas/direction

2009-12-15 Thread DrBloodmoney
When I run into similar situations with regards to flow,  interface, I try
to approach from a different angle.

In this case, where you have different checks (before they can create an
Event, the venue must exist, etc.) I line those up first.
- Create event view, select Venue.
- If venue does not exist, take to Add Venue view. Once completed, redirect
to Create Event View, etc.

On Dec 15, 2009 8:51 AM, "Baurzhan Ismagulov"  wrote:

On Tue, Dec 15, 2009 at 05:18:56AM -0800, derek wrote: > If you are serious
about doing this, you ma...
Thanks for the info, an interesting concept.

I personally have no problems with representing a web app as a state
machine, so continuations are for me too far an abstraction.

With kind regards, -- Baurzhan Ismagulov

http://www.kz-easy.com/ -- You received this message because you are
subscribed to the Google Grou...

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Working the tutorial - and I'm stuck

2009-11-03 Thread DrBloodmoney
Make sure that you have the CSRF middleware installed.

On Nov 3, 2009 12:09 PM, "Todd Blanchard"  wrote:

What did I screw up?
TemplateSyntaxError at /polls/1/

Invalid block tag: 'csrf_token'

Request Method:GETRequest URL:http://localhost:8000/polls/1/Exception Type:
TemplateSyntaxErrorException Value:

Invalid block tag: 'csrf_token'

Exception Location:/Library/Python/2.6/site-packages/django/template/__init__.py
in invalid_block_tag, line 335Python Executable:/usr/bin/pythonPython
Version:2.6.1


The forms bit.

views.py:

# Create your views here.
from django.template import Context, loader
from mysite.polls.models import Choice, Poll
from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.http import Http404
from django.template import RequestContext
# ...

def index(request):
latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
return render_to_response('polls/index.html', {'latest_poll_list':
latest_poll_list})


def detail(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
return render_to_response('polls/detail.html', {'poll': p},
   context_instance=RequestContext(request))


def results(request, poll_id):
return HttpResponse("You're looking at the results of poll %s." %
poll_id)

def vote(request, poll_id):
p = get_object_or_404(Poll, pk=poll_id)
try:
selected_choice = p.choice_set.get(pk=request.POST['choice'])
except (KeyError, Choice.DoesNotExist):
# Redisplay the poll voting form.
return render_to_response('polls/detail.html', {
'poll': p,
'error_message': "You didn't select a choice.",
}, context_instance=RequestContext(request))
else:
selected_choice.votes += 1
selected_choice.save()
# Always return an HttpResponseRedirect after successfully dealing
# with POST data. This prevents data from being posted twice if a
# user hits the Back button.
return HttpResponseRedirect(reverse('mysite.polls.views.results',
args=(p.id,)))

detail.html:

{{ poll.question }}

{% if error_message %}{{ error_message }}{% endif %}


{% csrf_token %}
{% for choice in poll.choice_set.all %}

{{ choice.choice }}
{% endfor %}






--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Newbie question regarding django-authopenid

2009-06-08 Thread DrBloodmoney

For those who have used django-authopenid [1], can you tell me if it
interferes with the built-in django user authentication system (users,
permissions, groups, etc).  I am going to attempt to get it running on
a small project, but I won't bother if it interferes with auth.

Thank you in advance for your thoughts,
Scott

[1] http://bitbucket.org/benoitc/django-authopenid/wiki/Home

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---