Re: How to implement multi-tenant, single DB, single site?

2011-06-04 Thread Doug Ballance
For our setup we created a separate user,site framework since we do a
form of vhosting that serves multiple sites from one instance. We have
a Site model that serves as the root tying all of our other models
together.  No abstract models or anything fancy, just a FK in each
model class pointing back to the Site model.  You only have one site,
but the concept could be the same.. instead of setting the site
instance for a request in middleware from ip/header info like we do,
you'd infer and organization instance from the logged on user.

For the view management I'd suggest looking at the class based views,
and creating a 'tenant aware' base class view that you can sublcass
for your individual views.  I used the generic class based views as a
guide for making my own.  I'd suggest starting by looking at the
source in django.views.generic.list and django.views.generic.detail.
The get_queryset()/get_object methods are the main points of
interest.  If you have a middlware set the user (or use django's user
model) object on the request, you can alter your get_queryset() method
to restrict the query to only objects the user (or that users
organization) is allowed since the request will be available on the
class as self.request.

For my use, I have a similar base class with an altered dispatch()
method that wraps the base dispatch method in a try/except looking for
an AuthError exception.  In my view subclasses I override
get_queryset() to limit queryset per request (to the site/user), and
do additional permissions checking in get_context_data() raising an
AuthError exception if there is a permission error.  The altered
dispatch is responsible for returning an error page or redirecting to
a login if AuthError is raised at any point in the view process.






-- 
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: accessing views outside a module

2011-06-04 Thread Martin
I think this depends on how you set your python path.
Mine is usually set to a virtualenv AND to /foo/bar/yourproject/ (the path
to your project).

That means you can do the following imports in any file:

from a.views import yourview
from b.views import yourview

Best regards,
Martin

On Sun, Jun 5, 2011 at 9:28 AM, Bobby Roberts  wrote:

> let's say i've got two apps in my project... app a and app b
>
>
> how do i access views in app a from app b views?
>
> --
> 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.



Re: confused over use of XYZ.objects.get() method

2011-06-04 Thread Javier Guerra Giraldez
I have never seen that usage of Meta.  where is it documented?

-- 
Javier

-- 
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 dev/test/production environments on the server (dreamhost)

2011-06-04 Thread Javier Guerra Giraldez
On Sat, Jun 4, 2011 at 12:29 AM, AJ  wrote:
> My application does require emailing users and members of the website. This
> is mostly system mail and users will not email amongst themselves.

on webapp servers i usually install ssmtp.  it's not for handling
user's email, nor for receiving messages.  it simply allows the
application to send messages to users' existing email accounts (hosted
somewhere else).

the advantage is that there's no daemon to keep running and taking care of.

-- 
Javier

-- 
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.



accessing views outside a module

2011-06-04 Thread Bobby Roberts
let's say i've got two apps in my project... app a and app b


how do i access views in app a from app b views?

-- 
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.



How to implement multi-tenant, single DB, single site?

2011-06-04 Thread br
I have been scouring the group and interwebs and it seems multi-tenant
comes up quite frequently in various scenarios, and mine is probably a
common one.  However, I haven't been able to distill a Djangooey best-
practice from what i've read, so I figure it won't hurt to bring it up
again.

Here is my situation:

1 site, 1 DB, multiple organizations, each with multiple users, 1
login page and set of client pages.  Not concerned about admin
implementation too much, since we are keeping that to system admins
(us) only.  Also, seems like the Sites framework won't be much help in
my scenario, unless i'm misunderstanding it.

So far, I have created a Organization model, with (automatic) id,
name, slug, and timezone fields,  and a "BaseOrganizationalModel"
Abstract model with a foreign key to an Organization, which i can
extend in any models that need to pertain to an organization.   Seemed
like the way to get started; correct me if I'm wrong. :)

The part I'm getting hung up on is how to manage this in the views and
to associate a user, and each request, with an organization, so that,
in a simple example, if i am in a view that returns a context
containing a list of objects of a model that extends
BaseOrganizationalModel, that I get only the objects that pertain to
the organization of the logged-in user.

Should I write a decorator? Some Middleware? A custom Manager?   (none
of which i've done before, but I'm happy to jump in)

A push in the right direction would be helpful and also pointers to
any apps, code snippets, or discussion that help with implementation
of this type of framework .

Thanks!

-- 
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.



Translating tooltip key to tooltip text: use ugettext() and il8n?

2011-06-04 Thread Margie Roginski
I am trying to figure out if using the il8n stuff is the right
approach for translating keyword names into multiline descriptions for
use in ajax tooltips. The idea is I want to have a url that is like
this:

   url(r'tooltip/(?P)/$', get_tooltip)

Then in my get_tooltip() view method I'd have something like this:

def get_tooltip(request, tooltip_key):
  return HttpRepsponse(ugettext(tooltip_key))


The overall idea is that when the user clicks on a '?' next to a
particular field, I'd use a jquery plugin to send a request for the
tooltip description using a url that contains the field name in the
 portion of the url.  Then I'd decode that to the full
tooltip description using ugettext().  I'm thinking this would allow
me to generate the tooltip description right now in my default
language, but provide a mechanism for the future that would allow me
to create tooltip descriptions in other languages as well.

I haven't used this il8n support before, so I'm not sure if this is a
good approach or if there is some better way to be doing this.  Once
concern I have is that we aren't currently using il8n for anything
right now, so perhaps it is overkill to enable this just for these
tooltips.  Perhaps I should just be using a custom solution, or
perhaps there is something more standard that folks are using?

Anyone with some experience in this area that can comment?

Much appreciated,

Margie

-- 
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: save out a test database?

2011-06-04 Thread Margie Roginski
At the time I asked the question I just had the sense that I wanted to
debug an issue by bringing up the web interface midway through my
test.   I attempted to do things like stop midway through the test via
set_trace() and then ctrl-c, then look at the db from a runserver run
that was pointing to the test database, but I find that the test
database is empty, as if the data has not yet been written out to it
by the test.

Perhaps if I call dumpdata from the call_command as you suggest, that
will get around this.

Maybe I don't even need this.  It just seemed nice to be able to debug
a test from the web interface, but in reality, now that I am off and
running writing tests, I guess I haven't ended up needing it after
all ...

In any case, thanks for your response.

Margie

On Jun 4, 5:47 am, Karen Tracey  wrote:
> On Thu, Jun 2, 2011 at 10:04 AM, Margie Roginski
> wrote:
>
> > Karen Tracy, if you are reading this, could you comment?
>
> > As the person that seems to be most knowledgable about django testing
> > (your Django 1.1 Testing book is fantastic - I highly recommend it!),
> > can you confirm that something like this is the best way to go?  It
> > seems strange to me that there is no more standard way of dumping the
> > database from inside a test so that the state can be replicated for
> > use in a runserver environment.
>
> Well, usually you want to go the other way: ensure your test run replicates
> your real running environment. I'm a little unclear on why you want to save
> the DB state from during a test?
>
> Probably  easier than using serialize directly, particularly if you want the
> whole DB, would be to call the dumpdata command via 
> call_command:https://docs.djangoproject.com/en/1.3/ref/django-admin/#running-manag...
>
> Karen
> --http://tracey.org/kmt/

-- 
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: confused over use of XYZ.objects.get() method

2011-06-04 Thread Ryan
Right, if what you have typed in your post is the code you are actually 
trying to use, there are two problems that jump out at me.

The first is that *question = models.CaaQuestion(pk=210) *will actually 
create a new question with the primary key 210, not fetch one from the 
database, so when you try to use this to find answers in the subsequent 
lines it will not find anything as it is not currently in any of those 
tables.

The second if the FieldError you are receiving.  This is because the 
question_id and assessment_id arguments should have double underscores to 
tell django that you are trying to span a relationship.  So these two should 
actually be question__id and assessment__id.  However the line above that 
with question = question and assessment = assessment should work fine when 
you have a question that is actually in the database.

Hope that helps you,

Ryan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/VHF3WmMyZVVCSVlK.
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.



confused over use of XYZ.objects.get() method

2011-06-04 Thread Fred
according to the docs, .get(**kwargs) is the signature.

I have a model where I have 2 foreign keys that are unique together:

class CaaAnswer(models.Model):
question =  models.ForeignKey(CaaQuestion)
assessment = models.ForeignKey(Assessment)
mds  = models.CharField(max_length=3, blank=True, default='')
user = models.IntegerField(default=0)

class Meta:
db_table = 'caaanswers'
managed = IS_CAA_MANAGED
unique_together = ("question", "assessment")

question = models.CaaQuestion(pk=210)
assessment = models.Assessment.objects.get(pk=18424)
okanswer = models.CaaAnswer.objects.filter(question=question,
assessment=assessment)
failanswer = models.CaaAnswer.objects.filter(question_id=210,
assessment_id=18424)
failanswer = models.CaaAnswer.objects.get(question=question,
assessment=assessment)

FieldError: Cannot resolve keyword 'assessment_id' into field. Choices
are: assessment, id, mds, question, user

Whenever a user takes a certain (frequent) action I have to execute
this for ~1000 records and compute the "mds" field individually for
each record.  I would like to make it efficient.

-- 
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.



Custom Link in the Django Admin Site

2011-06-04 Thread Cody Woolaver
Hello,

So the site that im developing with releases software over our webpage for
the clients to use. We have build a management system to do this with and it
works prety well. The current method in which we do things was with the wsgi
passenger and i finally convinced them to go django. In the old system they
use to store the distribution program's version within a python file that
had to be manually altered. With the beautiful layout of the django admin
site i would like to be able to do that within that system. The problem im
having is that i only seem to be able to apply
django.admin.site.registration to a model and it would be pointless to make
an entire table to only represent one row; plus the site would give the
ability to add more rows to that database which could cause errors. I just
need a very nice and easy way to store 3 digits that can easily be read and
changed.

tl;dr: Registering more links to the django admin site that are not models.

Thanks for your time
~Cody Woolaver

-- 
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: Aw: Re: Setting up dev/test/production environments on the server (dreamhost)

2011-06-04 Thread ApogeeGMail
+1 for Webfaction
On Jun 4, 2011, at 4:48 AM, Martin Brochhaus wrote:

> +1
> 
> Hosting 20 (or more) on Webfaction. Awesome service. Awesome speed. Peace of 
> mind.
> 
> Best regards,
> Martin
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/aWJyUXNMNmdTWDBK.
> 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.



Re: Preview for the new website..

2011-06-04 Thread Shamail Tayyab


On Jun 4, 5:09 pm, Kenneth Gonsalves  wrote:
> On Sat, 2011-06-04 at 04:58 -0700, Shamail Tayyab wrote:
> > I'ld like you to review my work and do tell me the goods and more
> > important, the bads..
>
> cool - what happens to non facebook users? also would love to see a
> comparison between rails and django from you.

Hey,

  Yes, definitely.. next move is to get non-facebook users (are there
any?) to log in via standard login...

As per rails, definitely rails is one "the" framework. Used Django
because I knew python where as my knowledge of ruby wasn't that good.
So I thought it'll aid me in making it up.
Rails definitely scores in its active record things, but rest of the
things are mostly same. (+ for rails)

Somehow I felt that python is more lazy (as in lazy programmers) in
its design approach (good for me) and things are very transparent and
does NOT play magic.
At-least a + for newbies, but at broader level, that "magic" aspect
helps..

Personally, I am a fan of >>> import this, which clearly states
"Explicit is better than implicit."

So a + to django in this.

I guess the score levels ;-)


Tx

> 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.



Re: save out a test database?

2011-06-04 Thread Karen Tracey
On Thu, Jun 2, 2011 at 10:04 AM, Margie Roginski
wrote:

> Karen Tracy, if you are reading this, could you comment?
>
> As the person that seems to be most knowledgable about django testing
> (your Django 1.1 Testing book is fantastic - I highly recommend it!),
> can you confirm that something like this is the best way to go?  It
> seems strange to me that there is no more standard way of dumping the
> database from inside a test so that the state can be replicated for
> use in a runserver environment.
>
>
Well, usually you want to go the other way: ensure your test run replicates
your real running environment. I'm a little unclear on why you want to save
the DB state from during a test?

Probably  easier than using serialize directly, particularly if you want the
whole DB, would be to call the dumpdata command via call_command:
https://docs.djangoproject.com/en/1.3/ref/django-admin/#running-management-commands-from-your-code

Karen
-- 
http://tracey.org/kmt/

-- 
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: Preview for the new website..

2011-06-04 Thread Kenneth Gonsalves
On Sat, 2011-06-04 at 04:58 -0700, Shamail Tayyab wrote:
> I'ld like you to review my work and do tell me the goods and more
> important, the bads..
> 
> 

cool - what happens to non facebook users? also would love to see a
comparison between rails and django from you.
-- 
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://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.



Re: Django 1.3 docs PDF

2011-06-04 Thread wrongway
Thank u so much!! Great!!

On Jun 2, 5:47 am, Oscar Carballal  wrote:
> Hello,
>
> I've just created a PDF (5.6MB, 1042 pages) with all the django 1.3
> docs [|], just in case someone need it (sometimes it's useful to have
> the docs offline).
>
> Cheers,
> Oscar
>
> [1]http://clionesoftware.com/files/docs/django1.3.pdf

-- 
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.



Preview for the new website..

2011-06-04 Thread Shamail Tayyab
Hi guys,

   From some time I've been working on this http://tunesdiary.com
which is now running live on Django.

It was a cool learning experience with my first site in Django after I
came in from rails background and this group had been real supporting
to me (thanks for the support guys, this is one real active group).
Few things that I liked about Django are:

* ORM/Signals - definitely makes your life so simple..
* Inbuilt support for authentication and its applicability..
* Middleware approach towards design..
* Powerful templating - especially the templatetags thing.
* And a lot more..

I'ld like you to review my work and do tell me the goods and more
important, the bads..

With best regards

--
Shamail Tayyab

P.S The site uses Facebook to login (as of now), I definitely has a
lot of plans to fix that, but being alone on this work is not
permitting time to get around to add standard login and some other
contexts like twitter/openID.

-- 
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.



Odp: Reasons to use managers

2011-06-04 Thread Tomasz Zieliński
If you use manager method, you can keep your schema unchanged/normalized 
and employ e.g. Memcached or Redis to store the result of your computation.
This might or might not fits your use case, of course.

--
Tomasz Zielinski
pyconsultant.eu

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/eDQyT2hZM0NtakVK.
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.



Aw: Re: Setting up dev/test/production environments on the server (dreamhost)

2011-06-04 Thread Martin Brochhaus
+1

Hosting 20 (or more) on Webfaction. Awesome service. Awesome speed. Peace of 
mind.

Best regards,
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/aWJyUXNMNmdTWDBK.
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.



connection refused when running django-celery

2011-06-04 Thread Kenneth Gonsalves
hi,

I am trying django-celery, but on running:

python manage.py celeryd -l info

I get this error:

[2011-06-04 01:08:51,946:
WARNING/MainProcess]


  
 -- cel...@xlquest.web
v2.2.6  
   
 
-   

--- * ***  * --
[Configuration] 
  
-- * -  ---   . broker:
amqplib://root@localhost:5672/  
 
- ** --   . loader:
djcelery.loaders.DjangoLoader   
 
- ** --   . logfile:
[stderr]@INFO   
 
- ** --   . concurrency:
2   
 
- ** --   . events:
OFF 
 
- *** --- * ---   . beat:
OFF 
 
-- ***

   
--- * - [Queues]
 --   . celery:  exchange:celery (direct) binding:celery


[Tasks]


[2011-06-04 01:08:51,968: INFO/PoolWorker-1] child process calling
self.run()
[2011-06-04 01:08:51,974: INFO/PoolWorker-2] child process calling
self.run()
[2011-06-04 01:08:51,980: WARNING/MainProcess] cel...@xlquest.web has
started.
[2011-06-04 01:08:51,983: ERROR/MainProcess] Consumer: Connection Error:
[Errno 111] Connection refused. Trying again in 2 seconds...

I know this is a bit OT here, but I hope some one can throw light on
this
-- 
regards
KG
http://lawgon.livejournal.com
Coimbatore LUG rox
http://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.