Wednesday, November 30, 2011

Re: Unable to load application to production environment

Do you add the path of your project to system path?
Try this:
      os.path.append('/path/to/your/project/')

2011/12/1 Ganesh Kumar <bugcy013@gmail.com>
Hi guys,

I am trying to load to my application to production environment,
It will work on test server, How to do this please guide me.

my settings file:-
   'registration',
   'fileupload',
   'password_required',

those application cant load at production time.

error says:-
No module named registration

-Ganesh
Did I learn something today? If not, I wasted 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Regards~
Peng Jia

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Unable to load application to production environment

Hi guys,

I am trying to load to my application to production environment,
It will work on test server, How to do this please guide me.

my settings file:-
'registration',
'fileupload',
'password_required',

those application cant load at production time.

error says:-
No module named registration

-Ganesh
Did I learn something today? If not, I wasted 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Django admin URL redirect problem in admin page

Dear All,

In one of my django app, I extended the django User model and created
a new 'UserProfile ' model. But when I'm trying to add new user
through this model in admin page, the URL is not redirecting to
successful page, instead its stopped on 'admin/auth/user/add/?
_popup=1' this URL. (user is created but not redirecting to success
page)

Here is the code

class UserProfile(User):

age = models.CharField(max_length=20, blank=True, null=True)
education = models.CharField(max_length=50, blank=True,
null=True,
choices=EDUCATION_CHOICES)

class TestPopulation(models.Model):

user = models.ManyToManyField(UserProfile, blank=True, null=True)
questionnaire = models.ManyToManyField(Questionnaire, blank=True,
null=True)

def __unicode__(self):
return "%s" % (self.user)

This creating creating the user object in admin page but not
redirecting to successpage, instead its stopped at 'admin/auth/user/
add/?_popup=1'

Any suggestions?

--
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+unsubscribe@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

On Wed, Nov 30, 2011 at 7:43 PM, jim <jmpmcmanus@gmail.com> wrote:
> I'm trying to use request.POST.copy() to get a hidden field in an html
> template.  The hidden field looks like:
>
> <input type="hidden" value="{% if post.url %}{{ post.url }}{%else
> %}""{%endif%}" name="url" />
>
> I also tried:
>
> <input type="hidden" value="{{ post.url }}" name="url" />
>
> 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 <form></form> 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

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

I'm trying to use request.POST.copy() to get a hidden field in an html
template. The hidden field looks like:

<input type="hidden" value="{% if post.url %}{{ post.url }}{%else
%}""{%endif%}" name="url" />

I also tried:

<input type="hidden" value="{{ post.url }}" name="url" />

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?

Thanks
Jim

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: converting a large site to Django

Hi,ne
Thank you for your quick reply :)

Actually, I am a little concerned that I may have a lot of work ahead
of me!

I have an existing php based website that is used to advertise holiday
accommodation, and the pages that contain advert listings are
dynamically recreated every 24 hours.

I needed to implement a search feature, and this seemed much easier to
write in python than php, so on a new server I created a django
project, and basically all this contains is the modified home page of
the existing website with the search that generates a list of results.

Now I need to move across the rest of the website to the new server,
and I need to do this with minimal effort. I also need to preserve the
existing page URLs.

It maybe the case that there are no real shortcuts, but I just didn't
want to make unnecessary work for myself!

If anyone has some tips, please let me know.

Thanks again for the support

Mark


On Nov 30, 5:21 pm, creecode <creec...@gmail.com> wrote:
> Hello Mark,
>
> On Wednesday, November 30, 2011 8:46:28 AM UTC-8, marjenni wrote:
>
> All seems good, but what I need to know is what is the easiest/> quickest way of moving across the rest of the website onto this new
> > server? Will I need an entry for each page in the urls file?
>
> It will be hard for us to answer that question unless we know more about
> how/where the old webpages are stored and how you would like to store them
> in your Django based website.
>
> You have several options:
>
>     Use an app like Flatpages <https://docs.djangoproject.com/en/1.3//ref/contrib/flatpages/>, which
> comes with Django.  Webpages are stored in the database.  It might be
> pretty easy to populate your Django website with some python code you would
> write that would grab your old webpages, massage them, and store them into
> your new website database.
>
>     If the old webpages are static, you could put them into the static area
> of your website.
>
> Give us more detail and we can probably be of more help.
>
> Toodle-looooooooooooooooo..................
> creecode

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

LocalWiki, a crazy-easy-to-use django-based geographic wiki, released!

Folks-

We just made the first general public release of LocalWiki, a really
easy to use wiki that focuses on geographic communities. It's all
Django-based. Check it out:

http://localwiki.org

Django devs will probably want to check out http://dev.localwiki.org
and follow our 'manual' installation instructions :)

But check out how we've packaged the whole project as a single easy-to-
install Ubuntu package. We modeled the management system after Trac,
which seems to be the most widely installed Python-based web app
("localwiki-manage" is an alias to a 'python manage.py' inside a well-
contained virtualenv) Making it this easy to install (for non-
Djangonauts) was a big challenge, but I'm there's some stuff others
can learn.

-Philip

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Two Servers plus one Load Balancer Vip Advice for DB?

Hi Django users,

So I have two servers behind a vip. I currently have it setup so if
one server goes down it uses the other http server which works great.
However I tried to set up mysql master - master and I keep getting
duplicate key errors and grind the process to a hault and causes a
real headache.

My only requirment is that if one server goes down the system will
still work, either physical or software server. So what would your
advice be? This isnt a high volumn system but it needs high
availability due ot the fact I use this as a tools mainsite and
configuration system.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

RE: MS Access integration with DJango through conversion to (Postgres or MySQL) xor direct interaction

There's a free access to mysql converter; try google; I forgot the name
and have it on a different computer than this one. Contact list again
if you cannot find it and I'll look harder.

-----Original Message-----
From: django-users@googlegroups.com
[mailto:django-users@googlegroups.com] On Behalf Of Alec Taylor
Sent: Wednesday, November 30, 2011 12:58 AM
To: django-users@googlegroups.com
Subject: MS Access integration with DJango through conversion to
(Postgres or MySQL) xor direct interaction

Good afternoon,

Is there an ORM library for python/django which integrates with MS
Access? - I know SQLalchemy dropped support after 0.4, but maybe
there's another to use?

Alternatively how would I convert one to PostgreSQL or MySQL then
interpret it into ORM syntax for use in i.e. SQLalchemy?

Thanks for all suggestions,

Alec Taylor

--
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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Feature Flipping with Gargoyle and Waffle

We just put out a post about feature flipping using Gargoyle or Waffle:

http://tech.yipit.com/2011/11/30/getting-to-continuous-deployment-in-django-feature-flipping/
---
Adam Nelson
CTO, Yipit
Join the Yipit Team and work with Python, Django, MongoDB, jQuery, Backbone.js and Sass @ http://yipit.com/jobs/

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

django south

Is there anyone available late next week to give a webinar on django
south? No need for a detailed presentation, but more to be around to
answer questions (I think that 9am EST would cover most time zones)?
If so, please contact me off list about dates/times/compensation.

The goal would be to offer another django chat.

Best,
William

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Website Statistics - What should I use to have Google Analytics in Django?

Google gives you a small piece of javascript that you need to insert
into your pages to track them. So, all you need to do is to insert
that code into your templates...

On 11/30/11, Carlos Daniel Ruvalcaba Valenzuela <clsdaniel@gmail.com> wrote:
> A quick Google revealed that there is already a
> django-google-analytics package, why not try to check it out?
> otherwise you could as last resort just put their tracking code on
> your master template and be done with it.
>
> http://code.google.com/p/django-google-analytics/
>
> Regards,
> Carlos Ruvalcaba
>
> --
> 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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Website Statistics - What should I use to have Google Analytics in Django?

* Andre Lopes <lopes80andre@gmail.com> [2011-11-30 20:25+0000]:
> I need to track visitors with Google Analytics. What should I use to
> get Google Analytics working on Django?

Are you serious?

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Website Statistics - What should I use to have Google Analytics in Django?

A quick Google revealed that there is already a
django-google-analytics package, why not try to check it out?
otherwise you could as last resort just put their tracking code on
your master template and be done with it.

http://code.google.com/p/django-google-analytics/

Regards,
Carlos Ruvalcaba

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Website Statistics - What should I use to have Google Analytics in Django?

Hi,

I need to track visitors with Google Analytics. What should I use to
get Google Analytics working on Django?

What is my best choice?

Best Regards,

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: unit tests and 'system' tests with history



On Wed, Nov 30, 2011 at 2:48 AM, Gelonida N <gelonida@gmail.com> wrote:
2.) Stress / System tests
----------------------------------

These are often called 'integration tests', and are used to test whether all of the (properly unit-tested) components of the system actually function properly when assembled together.
 

I'd also like to do some other tests, where I work on a system and where
I am able to suffer from my history.

Example (the example is perhaps too simple to see what I'm aiming it)
- I create an entry
- I rename an entry
- I remove an entry

If I had three independent tests I would never find out if I had a weird
bug, which would make the system fail if I tried to remove an entry
which has been renamed before.

As an aside, I'm not sure that I would use this sort of test framework for these kinds of bugs -- there are just too many ways for the system to fail if you start thinking this way:
  • What if it only fails when the entry has been renamed?
  • What if it only fails when the entry has been renamed to something longer?
  • What if it only fails when the entry has been renamed while someone else was editing it?
  • What if it only fails when the entry has a name with no vowels in it, which was also used as another user's password, but not in the last six weeks? :)
You can only simulate so many conditions, and lots of bugs can lurk undetected even with a whole suite of such tests. Even worse, if the code changes, then the exact bug that you were testing for might appear to be fixed, but actually changes very slightly, and doesn't get picked up any more.

In a case like this, I would normally wait to find out that there was a problem in the first place, and then institute a 'regression test' -- figure out the cause of the original bug (say, renaming the entry put the record into an inconsistent state) and then set up a test which:
  1. instantiates a correct record directly
  2. performs the rename operation that was failing
  3. checks that the record is still consistent under every constraint.
And I would do all of these at the lowest level that makes sense -- certainly not by starting at the HTTP level.
 
What would be a recommended way to run such system tests?

'just create a unit test, which is just calling sunb tests explicitely
in the required order?)

For integration testing, that's exactly what I do -- set up a unit test (not really a unit test in this case, but it's a subclass of unittest.TestCase) that uses the django test client to perform a small sequence of operations; usually a GET, checking the returned context, and then a POST, checking the return status (200 for form errors; 30x for successful redirects). I will set up any required objects in the database first (in fixtures, setUp or the test method itself), and test them afterwards.

Usually there aren't too many of these tests, though -- just enough that I know that the GET and POST methods are not failing spectacularly. The actual logic is tested with a bunch of much faster unit tests.


As part of these system tests I would like to add some of my unit tests,
but such, that the data base is NOT reset after each test run.

As a rule, I find it makes much more sense to declare the state of the database before each test, and then just test a few operations. As long as you properly test the consistency of the data after each operation, then you shouldn't run into the "cascading failures" that you can get if each test is dependent on the ones before it (or worse, cascading successes, if one bug cancels out the effects of the another)

If you're actually looking for stress-testing, then there are a number of other frameworks for that (ab, Bees with Machine Guns, etc) that will tell you how your site performs under load. Host-based testing should be there to tell you that your site behaves predictably and correctly under normal operation.

Ian
 


As you can see from my previous questions I'm used to 'non-atomic'
testing (This was for systems which needed a very huge startup time
and where taking snapshots was virtually impossible)

Thus I often combined unit tests / system tests.

These stress tests shall be able to run for several hours / days,
whereas unit tests would run in a few minutes.


Thanks for any suggestions


--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Regards,
Ian Clelland
<clelland@gmail.com>

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Django or python question about classes

Thanks for the link Tom.

I'll read that in details later (it's a little bit complicated) an for
my POC I'll just use a not DRY method !!! :-)

Regards

Youpsla

On 28 nov, 17:16, Tom Evans <tevans...@googlemail.com> wrote:
> On Mon, Nov 28, 2011 at 4:07 PM, youpsla <youp...@gmail.com> wrote:
> > Hello,
> > in my code, I like to overrride the form_valid() method in both
> > CreateView and UpdateView generic class views.
>
> > I've put my code in views.py.
>
> > class MyCreateView(UpdateView):
> >    .....
> >    def form_valid(self, form, **kwargs):
> >        some code
>
> > class MyUpdateView(CreateView):
> >    .....
> >    def form_valid(self, form, **kwargs):
> >        some code
>
> > The both form_valid() methods are exactly the same (Only the
> > dispatch() method differ from both classes).
>
> > My question is : is there a way of doing this more in a DRY way ?
>
> > Thanks in advance.
>
> > Best regards
>
> > Alain
>
> http://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are...
>
> Cheers
>
> Tom

--
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+unsubscribe@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

> > Well I agree that if the category doesn't exist he will get a 404. But
> > if the Category exists and there are no items in the 'table', it will
> > not be empty, it will also raise a 404 too.  That's why I wrote :
>
> >> 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" !
>
> No. with the line below items will be empty ant not 404.
>
> items= get_object_or_404(Category,name=category).items().filter(name=item)
>
> or  items without the brackets. (not sure about the syntax at the moment)
>
> The above is the same as:
>
> # This could produce 404
> category = get_object_or_404(Category,name=category)
>
> # This will result in an empty queryset and not 404
> items = category.items().filter(name=item)
>
> It is also obvious that the last line does not produce 404 since 404 is HTML related and the line above is a DB query which at most should result in something empty.

Yes, sorry I misread what you said. I read it correctly shortly after
posting and that's why I deleted my post like 1 min after posting it,
didn't think you would still get it though !

> I just saw your answer about using NoSQL. Sorry, forgot about that.
> In that case I cannot help you.

Okay ! Anyway thank you for your help, your infos about the urls and
configuring the site to send 404 errors are also really appreciated ;)

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Retrieve object model admin userid & password?

On Wed, Nov 30, 2011 at 10:22 AM, Tim Sawyer <list.django@calidris.co.uk> wrote:
You can't retrieve the password, as that would be a security flaw.  The security works by hashing the password entered into the login form, and comparing the hashed version with the one stored on the database.  Hash functions are quick to run one way, but difficult to reverse, hence it's difficult to get back the password used.

You can reset a users password in the admin site - login to admin, open the user up, then use the change password link next to the user's password field.

This, of course, supposes that the password you've forgotten isn't the only admin password.  If it is, then you could delete the row from the auth_user database table and do a syncdb - that should prompt you to create a superuser, if I recall correctly.

Yes, yes and yes.

If you have console access, you can also do this:

manage.py changepassword username_goes_here

That will allow you to reset anybody's password; superuser or otherwise.

-- 
Regards,
Ian Clelland
<clelland@gmail.com>

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Retrieve object model admin userid & password?

You can't retrieve the password, as that would be a security flaw. The
security works by hashing the password entered into the login form, and
comparing the hashed version with the one stored on the database. Hash
functions are quick to run one way, but difficult to reverse, hence it's
difficult to get back the password used.

You can reset a users password in the admin site - login to admin, open
the user up, then use the change password link next to the user's
password field.

This, of course, supposes that the password you've forgotten isn't the
only admin password. If it is, then you could delete the row from the
auth_user database table and do a syncdb - that should prompt you to
create a superuser, if I recall correctly.

HTH,

Tim.

On 30/11/11 18:10, Marc Edwards wrote:
> I am working through some authentication examples.
>
> When I created my first database, I "recall" entering a username and
> password, but entering what I recall was the correct input is not
> authenticating.
>
> Is there an easy way to reset or retrieve the username and password
> that was used to create the object 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Retrieve object model admin userid & password?

I am working through some authentication examples.

When I created my first database, I "recall" entering a username and
password, but entering what I recall was the correct input is not
authenticating.

Is there an easy way to reset or retrieve the username and password
that was used to create the object 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Cache timeout

On Sat, Nov 26, 2011 at 4:07 PM, Addy Yeow <ayeowch@gmail.com> wrote:
> If I use cache_page() decorator for my view function, will the TIMEOUT be
> able to take precedence over CACHE_MIDDLEWARE_SECONDS?
>
> In my settings.py,
>
> CACHES = {
>     'default': {
>         'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
>         'LOCATION': os.path.join(WEB_ROOT, "django_cache"),
>         'TIMEOUT': 5184000,
>     }
> }
> CACHE_MIDDLEWARE_SECONDS = 86400
>

TIMEOUT (from CACHES) is never used with the cache_page decorator.
TIMEOUT is only used when no timeout is specified when
adding/setting/updating an item in the cache, and cache_page always
does specify a timeout.

The cache_page decorator is a special invocation of the
CacheMiddleware, which is a mixin of both UpdateCacheMiddleware and
FetchFromCacheMiddleware, the former of which is documented as
follows:

* The number of seconds each page is stored for is set by the "max-age" section
of the response's "Cache-Control" header, falling back to the
CACHE_MIDDLEWARE_SECONDS setting if the section was not found.

The cache_page decorator adjusts this slightly, so that if a timeout
is specified within the tag, this is used instead of using
settings.CACHE_MIDDLEWARE_SECONDS as a default, but it will always use
'max-age' from the 'Cache-Control' header in preference to either of
these.

eg:

@cache_page
def foo():
# This will be cached for CACHE_MIDDLEWARE_SECONDS if no max-age

@cache_page(15 * 60)
def bar():
# This will be cached for 15 minutes if no max-age

Cheers

Tom

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: What server configuration should I use for a Django site like this?

Build it on 512 Linode, upgrade to 1024 if necessary. Linode are so
far ahead of the competition Price/Performance ratio, I wouldn't
bother with anyone else (VPS).

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Fixture migrations using South?

I have some test fixtures with scenarios under test. Later, I need to
migrate (with South) the DB schema around, which of cours necessitates
changing domain and test code.

A common problem I run into, though, is that I also need to migrate
the data in my fixtures. It is possible to create a new DB, sync it
to a given migration point, load the fixture, run the remaining
migrations, and dump a new fixture, then drop the extra db. But it
seems like a very awkward dance given how often I have the problem.

Is there already a solution to this? It seems to me that South could
manage some book keeping to maintain what fixtures are at which
migration level, and a new south command could manage the migration of
fixtures.

./manage migrate --fixtures [all other options staying the same]

I imagine this would read/write some bookmark files to each affected
app's ./fixtures/ directory. If the bookmark file didn't exist, the
0001 schema would be assumed. Otherwise it'd be something along the
lines of:
fixture_file.name.south, and contents would roughly mirror
south_migrationhistory, perhaps in JSON format.

Thoughts?

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: converting a large site to Django

Hello Mark,

On Wednesday, November 30, 2011 8:46:28 AM UTC-8, marjenni wrote:

All seems good, but what I need to know is what is the easiest/
quickest way of moving across the rest of the website onto this new
server? Will I need an entry for each page in the urls file?

It will be hard for us to answer that question unless we know more about how/where the old webpages are stored and how you would like to store them in your Django based website.

You have several options:

    Use an app like Flatpages < https://docs.djangoproject.com/en/1.3//ref/contrib/flatpages/ >, which comes with Django.  Webpages are stored in the database.  It might be pretty easy to populate your Django website with some python code you would write that would grab your old webpages, massage them, and store them into your new website database.

    If the old webpages are static, you could put them into the static area of your website.

Give us more detail and we can probably be of more help.

Toodle-looooooooooooooooo..................
creecode

--
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/-/MskCEcMHZvsJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: converting a large site to Django

Do the pages that you're moving across to the new site need to be
change-able through the admin system, or are they static HTML that won't
change?

Only use flatpages if you want them to be editable through the web.

Tim.

On 30/11/11 17:09, Juan de Dios Manjon Perez wrote:
> Try flatpages https://docs.djangoproject.com/en/dev/ref/contrib/flatpages/
>
> -Juande
>
> On Wed, 30 Nov 2011 08:46:28 -0800 (PST), marjenni wrote:
>> Hi,
>> I am working on a website with many pages (in the hundreds).
>>
>> I have recreated the website front page on a new server with the
>> desired new functionality implemented in Python and Django.
>>
>> All seems good, but what I need to know is what is the easiest/
>> quickest way of moving across the rest of the website onto this new
>> server? Will I need an entry for each page in the urls file?
>>
>> Many thanks for all your help
>>
>> Mark
>

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: converting a large site to Django

Try flatpages
https://docs.djangoproject.com/en/dev/ref/contrib/flatpages/

-Juande

On Wed, 30 Nov 2011 08:46:28 -0800 (PST), marjenni wrote:
> Hi,
> I am working on a website with many pages (in the hundreds).
>
> I have recreated the website front page on a new server with the
> desired new functionality implemented in Python and Django.
>
> All seems good, but what I need to know is what is the easiest/
> quickest way of moving across the rest of the website onto this new
> server? Will I need an entry for each page in the urls file?
>
> Many thanks for all your help
>
> Mark

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Cache timeout

u can test by yourself. 
yes, i don't know the answer, neather

在 2011-11-27 上午12:08,"Addy Yeow" <ayeowch@gmail.com>写道:
If I use cache_page() decorator for my view function, will the TIMEOUT be able to take precedence over CACHE_MIDDLEWARE_SECONDS?

In my settings.py,

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
        'LOCATION': os.path.join(WEB_ROOT, "django_cache"),
        'TIMEOUT': 5184000,
    }
}
CACHE_MIDDLEWARE_SECONDS = 86400

--
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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

converting a large site to Django

Hi,
I am working on a website with many pages (in the hundreds).

I have recreated the website front page on a new server with the
desired new functionality implemented in Python and Django.

All seems good, but what I need to know is what is the easiest/
quickest way of moving across the rest of the website onto this new
server? Will I need an entry for each page in the urls file?

Many thanks for all your help

Mark

--
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+unsubscribe@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

> Well I agree that if the category doesn't exist he will get a 404. But
> if the Category exists and there are no items in the 'table', it will
> not be empty, it will also raise a 404 too. That's why I wrote :
>
>> 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" !

No. with the line below items will be empty ant not 404.

items= get_object_or_404(Category,name=category).items().filter(name=item)

or items without the brackets. (not sure about the syntax at the moment)

The above is the same as:

# This could produce 404
category = get_object_or_404(Category,name=category)

# This will result in an empty queryset and not 404
items = category.items().filter(name=item)

It is also obvious that the last line does not produce 404 since 404 is HTML related and the line above is a DB query which at most should result in something empty.

I just saw your answer about using NoSQL. Sorry, forgot about that.

In that case I cannot help you.

Good Luck

--
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+unsubscribe@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

Well that should work pretty well with an SQL database. But as I said
my database is a NoSQL one, here I need to have one "table" per
category. So creating another Categorylist table just for fun and put
all the category names into, then hit it in order to check if the
category exists just seems wrong to me.
I thought of retrieving a list of the table names from the database
and check if the category the user want is in that list but for that I
must import another module.

On Nov 30, 1:41 pm, Ivo Brodien <i...@brodien.de> wrote:
> > I don't quite understand what you mean here. You want me to create a
> > CategoryModel of which all my Category models should be derived ? If
> > that's it, how can it help me to determine if URL is valid or not, I
> > can't see how that works.
>
> Sorry, it was DrBloodmoney, who wrote this:
>
> > class Category(models.Model):
> >    name = models.CharField.... # should be unique
>
> > class Item(models.Model):
> >  name = models.CharField()
> >   category = models.ForeignKey(Category, related_name='items')
>
> in your view you do so:
>
> def view(request, category, item):
>      items= get_object_or_404(Category,name=category).items().filter(name=item)
>      ....
>
> That's it.
>
> Now if someone enters a category by hand which does not exist, he gets a 404. If the category exists, but there is no item with such a name items will be empty.
>
> Bye
> Ivo

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Process management with Supervisord

Thank you for the reply.

Best Regards,


On Wed, Nov 30, 2011 at 2:51 PM, DrBloodmoney <drbloodmoney@gmail.com> wrote:
> On Wed, Nov 30, 2011 at 9:35 AM, Andre Lopes <lopes80andre@gmail.com> 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+unsubscribe@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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Creating an app for recurring features

Hi,


I have made several projects now for internal use and some of the functionality keeps coming back.
For instance, language selection, user authentication, ad syncronization of users.

I want to put these in seperate apps that I can easily install in a project. All projects use virtualenv.
My first try is with the language stuff as this is only some settings and a view.
I've put the urls.py, views and so on in a seperate dir and then copied this dir in my current project.
Made a setup.py file to install the app with "python setup.py develop".

This works, and I can access the view from the project. So far so good.
I'm however not sure this is the right way to put some recurring functionality in a reusable app.
Some questions that arise:

- For the language selection view, I use small flags to make the language selection nicer.
These images are installed in the static directory of the application.
I then "installed" them in my project by including the correct dir in STATICFILES_DIRS
in the projec settings and then collected them with "python manage.py collectstatic --link"
I know I could have linked to the files but this seemed more Django like, yet, I'm not
sure this is the right way.

- I would like to be able to test the application. I thought that I could get away with a
minimal system (virtualenv + django) but it seems I need a rather complete settings.py
file and a typical project/app structure setup. I don't have that, so testing doesn't work.
How can I test the application code? Is there another way besides creating a full django project?

The settings file of the application (comments etc. left out)
=======================================
ugettext = lambda s: s
LANGUAGES = (
('nl', ugettext('Dutch')),
('fr', ugettext('French')),
('en', ugettext('English')),
)
DEFAULT_LANGUAGE = 1
LANGUAGE_CODE = 'nl'


USE_I18N = True
USE_L10N = True
=======================================

In my testproject, I made these changes to load the app succesfully.

1. I enabled- the LocaleMiddleware
2. I add the app to the INSTALLED_APPS
3. I load the language app settings file at the end of the projecs settings.py
This feels kind of hackish.
4. I add the path with the app static files to STATICFILES_DIRS
5. Add the app urls to the test project urls.

As I said, this is for local projects only, not meant to be distributed to the outside world.

Regards,
Benedict

--
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+unsubscribe@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

> Sorry, it was DrBloodmoney, who wrote this:
>
> > class Category(models.Model):
> >    name = models.CharField.... # should be unique
>
> > class Item(models.Model):
> >  name = models.CharField()
> >   category = models.ForeignKey(Category, related_name='items')
>

Oh that, yes I intended to do so.

>Now if someone enters a category by hand which does not exist, he gets a >404. If the category exists, but there is no item with such a name items will >be empty.

Well I agree that if the category doesn't exist he will get a 404. But
if the Category exists and there are no items in the 'table', it will
not be empty, it will also raise a 404 too. That's why I wrote :

>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" !

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Process management with Supervisord

On Wed, Nov 30, 2011 at 9:35 AM, Andre Lopes <lopes80andre@gmail.com> 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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Try to follow the Tutorial "Wiki in 20 minutes" on ShowMeDo

Hi Guys,

at first: please excuse my bad english. I hope you can understand what
i mean.
i just started working with Django and used the tutorial @
djangoproject.com.
After i completed it i tried to rebuild the djangotutorial for
wikicamp shown on ShowMeDo ( http://showmedo.com/videotutorials/video?name=1100000&fromSeriesID=110
). I recognized that it's an old version of django he used, so i
successfully solved all issues until I tried to rebuild the first half
of the third video. Its about manytomany relations.
Now I got the problem, when i send the form with the Pagedata and one
or More Tags (there is the ManyToMany relation, On or More pages can
have one or more Tags) it tells me that the needed model doesn't
exists. And it calls the model wiki_page_tags , but i got a model Page
and a model Tags.
The error message shows following code phrase:

for tag in tag_list:
page.tags.add(tag)

As attachment there are the Views.py and the Models.py. If You need
more Information to solve my problem, please let me know.

I use a SQLite DB and thats my views.py:

from djangotutorial.wiki.models import Page, Tag
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django import forms

class SearchForm(forms.Form):
text = forms.CharField(label="Enter search term")
search_content = forms.BooleanField(label="Search content",
required=False)

def search_page(request):
if request.method == "POST":
f = SearchForm(request.POST)
if not f.is_valid():
return render_to_response("wiki/search.html", {"form":f},
context_instance=RequestContext(request))
else:
pages = Page.objects.filter(name__contains =
f.cleaned_data["text"])
contents = []
if f.cleaned_data["search_content"]:
contents = Page.objects.filter(content__contains =
f.cleaned_data["text"])

return render_to_response("wiki/search.html", {"form":f,
"pages":pages, "contents":contents},
context_instance=RequestContext(request))
f = SearchForm()
return render_to_response("wiki/search.html", {"form":f},
context_instance=RequestContext(request))

specialPages = {"SearchPage": search_page}

def view_page(request, page_name):
if page_name in specialPages:
return specialPagespage name(request)
try:
page = Page.objects.get(pk=page_name)
except Page.DoesNotExist:
return render_to_response('wiki/create.html',
{'page_name':page_name})
content = page.content
return render_to_response("wiki/view.html",
{"page_name":page_name, "content":content})

def edit_page(request, page_name):
try:
page = Page.objects.get(pk=page_name)
content = page.content
except Page.DoesNotExist:
content = ""
return render_to_response("wiki/edit.html",
{"page_name":page_name, "content":content},
context_instance=RequestContext(request))

def save_page(request, page_name):
content = request.POST["content"]
tag_list = []
if "tags" in request.POST:
tags = request.POST["tags"]
tag_list = [Tag.objects.get_or_create(name=tag) for tag in
tags.split()]
try:
page = Page.objects.get(pk=page_name)
page.content = content
for tag in tag_list:
page.tags.add(tag)
except Page.DoesNotExist:
page = Page(name=page_name, content=content)
page.save()
return HttpResponseRedirect("/wiki/page/" + page_name + "/")

and the models.py:
from django.db import models

# Create your models here.

class Tag(models.Model):
name = models.CharField(max_length=20, primary_key=True)

class Page(models.Model):
name = models.CharField(max_length=20, primary_key=True)
content = models.TextField(blank=True)
tags = models.ManyToManyField(Tag)

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Process management with Supervisord

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?


Best Regards,

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: MS Access integration with DJango through conversion to (Postgres or MySQL) xor direct interaction

An access database should not be used for a production site. There are
various ways/tools for migrating from access to other databases.
Search for how to export from ms access and it should turn up a lot of
different methods for migrating to mysql or postresql.

Access to MySQL example - http://www.kitebird.com/articles/access-migrate.html

Regards,
Michael

On Nov 30, 12:58 am, Alec Taylor <alec.tayl...@gmail.com> wrote:
> Good afternoon,
>
> Is there an ORM library for python/django which integrates with MS
> Access? - I know SQLalchemy dropped support after 0.4, but maybe
> there's another to use?
>
> Alternatively how would I convert one to PostgreSQL or MySQL then
> interpret it into ORM syntax for use in i.e. SQLalchemy?
>
> Thanks for all suggestions,
>
> Alec Taylor

--
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+unsubscribe@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


I don't quite understand what you mean here. You want me to create a
CategoryModel of which all my Category models should be derived ? If
that's it, how can it help me to determine if URL is valid or not, I
can't see how that works.

Sorry, it was DrBloodmoney, who wrote this:

class Category(models.Model):
   name = models.CharField.... # should be unique

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

in your view you do so:

def view(request, category, item):
     items= get_object_or_404(Category,name=category).items().filter(name=item)
     ....

That's it.

Now if someone enters a category by hand which does not exist, he gets a 404. If the category exists, but there is no item with such a name items will be empty.

Bye
Ivo

Re: Delete a many to many field who is in another table

I try to make this using delete, remove...... Also I using too
if request.POST.get('experimentosDelete','')!='':
for i in
request.POST.getlist('experimentosDelete'):

exp=Experimentos.objects.get(proyecto=datos,id=i)

exp.experimentos=[]

.......
I don't know how to make this......
Anyone who say me ??? Thanks a lot

--
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+unsubscribe@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

Hello,


>As Reinout suggested you should have a CategoryModel which you can check >if a Category exists and the get the items of show that the category does not >exist or 404 if somebody entered a wrong URL/Category. Checking against the >DB is probably the same thing you want to do, but it uses the DB and not a >List/Dict which you have to maintain manually somehow.

I don't quite understand what you mean here. You want me to create a
CategoryModel of which all my Category models should be derived ? If
that's it, how can it help me to determine if URL is valid or not, I
can't see how that works.


>I think you care too much about people entering wrong URLs. People are >clicking links on your webpage, right? Or do you give him instructions to >write urls in the adress field?

Yes they click links on the webpages :)

1) use the url tag or get_absolute_url of your models to produce the
urls in your template
2) configure your site to send you 404 errors which have a referer
(read below and [1])

>404 errors
>Django can also be configured to e-mail errors about broken links (404 "page >not found" errors). Django sends e-mails about 404 errors when:
>DEBUG is False
>SEND_BROKEN_LINK_EMAILS is True
>Your MIDDLEWARE_CLASSES setting includes CommonMiddleware (which it >does by default).
>If those conditions are met, Django will e-mail the users listed in the >MANAGERS setting whenever your code raises a 404 and the request has a >referer. (It doesn't bother to e-mail for 404s that don't have a referer – those >are usually just people typing in broken URLs or broken Web 'bots).

Wow that's nice to know, thanks for all these infos !


On Nov 30, 11:15 am, Ivo Brodien <i...@brodien.de> wrote:
> Hi,
>
> > That's why I'm
> > considering checking at the beginning of the view with a list/dict
> > filled with category names and one filled with item names to make sure
> > that the category is in the list/dict and same for the item before
> > hitting the database, and if not respond with a 404.
>
> As Reinout suggested you should have a CategoryModel which you can check if a Category exists and the get the items of show that the category does not exist or 404 if somebody entered a wrong URL/Category. Checking against the DB is probably the same thing you want to do, but it uses the DB and not a List/Dict which you have to maintain manually somehow.
>
> I think you care too much about people entering wrong URLs. People are clicking links on your webpage, right? Or do you give him instructions to write urls in the adress field?
>
> As long as you produce correct urls the code works and only should show 404 if someone messed with the URL.
>
> Consider doing this:
>
> 1) use the url tag or get_absolute_url of your models to produce the urls in your template
> 2) configure your site to send you 404 errors which have a referer (read below and [1])
>
> 404 errors
> Django can also be configured to e-mail errors about broken links (404 "page not found" errors). Django sends e-mails about 404 errors when:
> DEBUG is False
> SEND_BROKEN_LINK_EMAILS is True
> Your MIDDLEWARE_CLASSES setting includes CommonMiddleware (which it does by default).
> If those conditions are met, Django will e-mail the users listed in the MANAGERS setting whenever your code raises a 404 and the request has a referer. (It doesn't bother to e-mail for 404s that don't have a referer – those are usually just people typing in broken URLs or broken Web 'bots).
>
> bye
>
> [1]https://docs.djangoproject.com/en/1.3/howto/error-reporting/

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Delete a many to many field who is in another table

On Wed, Nov 30, 2011 at 11:42 AM, jose osuna perez
<jose.osuna.perez@gmail.com> wrote:
> Hi, I am finally going to finish the project started and where I end
> up liking this xD Django that the problem I have is the clearing of a
> field.
> ...
> I try like this:
>
> if request.POST.get('experimentosDelete','')!='':
>                                                 for i in request.POST.getlist('experimentosDelete'):
>                                                        exp=Experimentos.objects.get(proyecto=datos,id=i)
>                                                        exp.experimentos.remove(request.POST.get('experimentosDelete'))
>

The remove() method takes objects, not ids.

https://docs.djangoproject.com/en/1.3/ref/models/relations/#django.db.models.fields.related.RelatedManager.remove

Cheers

Tom

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: What server configuration should I use for a Django site like this?

Hi, I recently launched a Django project on a Linode 1024.

I serve django with nginx, run mysql, and a bunch of other stuff. I routinely have about 500MB of free RAM. I wouldn't recommend a Linode 512, you will swap a lot.

--
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/-/4yCrwpaF_7oJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: Delete a many to many field who is in another table

Hi,
after:

exp.experimentos.remove(request.POST.get('experimentosDelete'))

You should do:

exp.save()

I hope this helps.
Salvatore.

--
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/-/qDb9Yfp_mCgJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Delete a many to many field who is in another table

Hi, I am finally going to finish the project started and where I end
up liking this xD Django that the problem I have is the clearing of a
field.
I have the following tables.

class Proyectos(models.Model):
titulo=models.CharField(max_length=100)
creacion=models.DateField(default=datetime.datetime.now)
estado=models.CharField(max_length=30)
objetivo=models.TextField(null=True)
conclusion=models.TextField(null=True)
porcentaje=models.IntegerField()
modificado=models.DateTimeField(default=datetime.datetime.now)
autor=models.IntegerField()
usuarios=models.ManyToManyField(User)
proyectos_rel=models.ManyToManyField("self")
documentos=models.ManyToManyField(Documentos)
class Meta:
db_table='Proyectos'
def __unicode__(self):
return self.titulo

class Experimentos(models.Model):
titulo=models.CharField(max_length=100)
creacion=models.DateField(default=datetime.datetime.now)
estado=models.CharField(max_length=30)
objetivo=models.TextField(null=True)
conclusion=models.TextField(null=True)
porcentaje=models.IntegerField()
modificado=models.DateTimeField(default=datetime.datetime.now)
autor=models.IntegerField()
proyecto=models.ForeignKey(Proyectos)
usuarios=models.ManyToManyField(User)
experimentos=models.ManyToManyField("self")
documentos=models.ManyToManyField(Documentos)
class Meta:
db_table='Experimentos'
.
I want to eliminate only one of the experiments which may contain a
Project
I try like this:

if request.POST.get('experimentosDelete','')!='':
for i in request.POST.getlist('experimentosDelete'):
exp=Experimentos.objects.get(proyecto=datos,id=i)
exp.experimentos.remove(request.POST.get('experimentosDelete'))

The result is that it does nothing ....... and otherwise remove whole
objects, not the relationship.I don't know .
I greatly appreciate your help in all questions.

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

save_model on django.contrib.auth.admin.UserAdmin not called by password change form

Hello,

I would like to get control on the password change form of the admin
site.

I put the following code in the admin.py:

class MyUserAdmin(UserAdmin):
def save_model(self, request, obj, form, change):
...
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)

The problem is that when user calls the password change build form the
save_model method is not called.

is there a way to intercept the password change action ?

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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

unit tests and 'system' tests with history

I started implementing tests for my django application.


I anticipate two kind of tests:


1.) Unit tests
---------------

The unit tests should be as the uni tests are implemented in django.

They should be 'atomic' independent, could be executed in any order and
should always yield the same results


2.) Stress / System tests
----------------------------------

I'd also like to do some other tests, where I work on a system and where
I am able to suffer from my history.

Example (the example is perhaps too simple to see what I'm aiming it)
- I create an entry
- I rename an entry
- I remove an entry

If I had three independent tests I would never find out if I had a weird
bug, which would make the system fail if I tried to remove an entry
which has been renamed before.


What would be a recommended way to run such system tests?

'just create a unit test, which is just calling sunb tests explicitely
in the required order?)

As part of these system tests I would like to add some of my unit tests,
but such, that the data base is NOT reset after each test run.


As you can see from my previous questions I'm used to 'non-atomic'
testing (This was for systems which needed a very huge startup time
and where taking snapshots was virtually impossible)

Thus I often combined unit tests / system tests.

These stress tests shall be able to run for several hours / days,
whereas unit tests would run in a few minutes.


Thanks for any suggestions


--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: django tests. where to create users

On 11/29/2011 12:34 PM, Piotr Zalewa wrote:
> I use all solutions, depending on the needs.
>
> When I'm testing a usage of many objects I use fixtures (also with users
> as I'm "pretending" that users created them)
>
> When there is a test involving a user I create this object, either in
> test or the setUp.
>
> On 11/28/11 01:58, Gelonida N wrote:
>> Hi,
>>
>> I'd like to run some django tests, which use the test client and which
>> should check, that certain users can only access certain contents.
>>
>> Where would you create this users / passwords.
>> - With a fixture
>> - as part of a test class in the SetUp section and tear
>> it down afterwards?
>
> There is no need to remove them
> Just create a user in setUp if you need it for all tests, if for a part
> of the tests only - create 2 test classes and create a user in one of
> them only

Thanks. Yes I noticed meanhwile as well that the the database is reset
implicitely.

>
>> - create a custom test runner with a setup phase ?
>
> I've got it as well - I don't create users there, but I've got a few
> other methods which are useful for more than one app.
>
I mightl look at something like this.
If you midofied the database there, then would this become the initial
state for each test?
Reading the doc I assume yes.

>> Is there any other recommended code section, which could do the setup
>> prior to running tests.
>>
>> Ideally I'd like to avoid fixtures.
>
> Is there a reason?
>
Two reasons:

Migrations:
------------
Fixtures are rather sensitive to migrations
(so as part of the migration steps I had to regenerate them)

Lack pseudo randomness:
--------------------------
It's a question of taste, but I like a certain amount of controlled
randomness in my tests and data sets. (The idea is to log the random
seed in order to be able to reproduce failures)
So a test covers all the anticipated boundary cases (if the amount is
small enough) , but explores some others as well.
As soon a s a new killer data set is found it can be
added as a separate test (or fixture).


--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Re: django tests. where to create users

On 11/29/2011 11:45 AM, Tom Christie wrote:
> What's wrong with just creating them in the .setUp()?
>
> Don't sweat the small amount of time it'll take to re-create the users
> on each test run, it's almost certainly not worth worrying about.
>

Well this is what I'm doing at the moment.
And I think you're right for this case:
Creating users will not be where a considerable amnount of time is
spent.

I'm just learning to use Django-testing / unit tests and as I could
imagine other setup activities which would consume more time
for setup I wanted to see whether there are ways to do some
programatical setup of 'fixtures' before the first test is run.

Basically I'd like to be sure I know my tools.

--
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+unsubscribe@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

Hi,

That's why I'm
considering checking at the beginning of the view with a list/dict
filled with category names and one filled with item names to make sure
that the category is in the list/dict and same for the item before
hitting the database, and if not respond with a 404.

As Reinout suggested you should have a CategoryModel which you can check if a Category exists and the get the items of show that the category does not exist or 404 if somebody entered a wrong URL/Category. Checking against the DB is probably the same thing you want to do, but it uses the DB and not a List/Dict which you have to maintain manually somehow.

I think you care too much about people entering wrong URLs. People are clicking links on your webpage, right? Or do you give him instructions to write urls in the adress field?

As long as you produce correct urls the code works and only should show 404 if someone messed with the URL.

Consider doing this:

1) use the url tag or get_absolute_url of your models to produce the urls in your template
2) configure your site to send you 404 errors which have a referer (read below and [1])

404 errors

Django can also be configured to e-mail errors about broken links (404 "page not found" errors). Django sends e-mails about 404 errors when:
If those conditions are met, Django will e-mail the users listed in the MANAGERS setting whenever your code raises a 404 and the request has a referer. (It doesn't bother to e-mail for 404s that don't have a referer – those are usually just people typing in broken URLs or broken Web 'bots).


bye