[Newbie] Console output using runserver..

2011-12-02 Thread vivek_12315
I have been working on a simple project. I use Django app server and
use it like:

##
C:\search\pysolr\webinterface>python manage.py runserver 8081
Validating models...
0 errors found

Django version 1.0.2 final, using settings 'webinterface.settings'
Development server is running at http://127.0.0.1:8081/
Quit the server with CTRL-BREAK.
##

Few months back, when i used this command, and any of my python view
files used "print" statements for debugging, I would get the output in
this command prompt window.

But, nowadays, when i fire this command, my print outputs are not
coming on the screen.

Could anyone tell me what I am doing wrong ?

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.



Re: run form save in background

2011-12-02 Thread Martin Ostrovsky
I'd rip out the non-db stuff from the form.save() method and put those
in an asynchronous queue. Then you can have another process which
polls the queue and performs these other tasks after the database
save.

So for example, you would do the following:

instance = form.save()
# push your task to the queue
return HttpResponse('Done!')

Celery will do what I've described above nicely for you.

On Dec 2, 2:41 pm, brian  wrote:
> I'm having problems with a save method taking too long and the user
> thinking there is a problem with the website so they hit refresh which
> causes the data to be submitted multiple times.
>
> I have this in the view:
> -
> if form.is_valid():
>   form.save()
>   return HttpResponseRedirect('/thanks/')
> -
>
> The save method takes a little time.  It saves to db, sends a couple
> of emails, and interfaces with another software package(which is the
> time hog).  I want to be able to show the thanks page and then call
> the save method.
>
> It seems like celery(http://www.celeryproject.org/) is the best
> choice.  When I read the doc it said because of race conditions, be
> careful of passing models to celery tasks.  With my form I want it to
> save a unique instance for every time the form is submitted so I think
> I can pass the form to the task.
>
> Does anyone have suggestions or other recommendations about this?  Is
> there an easier way to do this?
>
> Brian

-- 
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: deleting my old messages

2011-12-02 Thread Nikolas Stevenson-Molnar
If you're using the Gmail web interface, you can restrict your search to
a date range. For example, searching for "from:g.statk...@gmail.com
to:django-users@googlegroups.com after:2011/11/1" would return all
messages sent by you to the Django users group since Nov of this year.

_Nik

On 12/2/2011 12:39 PM, gintare wrote:
> Hello,
>
> Could you please delete all my posts. I look through them and copied
> all needed information. I am not able to find the new questions among
> old messages. After deletion the search with my name as a keyword will
> give me the latest questions.
>
> regards,
> gintare statkute
>

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



deleting my old messages

2011-12-02 Thread gintare
Hello,

Could you please delete all my posts. I look through them and copied
all needed information. I am not able to find the new questions among
old messages. After deletion the search with my name as a keyword will
give me the latest questions.

regards,
gintare statkute

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



run form save in background

2011-12-02 Thread brian
I'm having problems with a save method taking too long and the user
thinking there is a problem with the website so they hit refresh which
causes the data to be submitted multiple times.

I have this in the view:
-
if form.is_valid():
  form.save()
  return HttpResponseRedirect('/thanks/')
-

The save method takes a little time.  It saves to db, sends a couple
of emails, and interfaces with another software package(which is the
time hog).  I want to be able to show the thanks page and then call
the save method.

It seems like celery(http://www.celeryproject.org/) is the best
choice.  When I read the doc it said because of race conditions, be
careful of passing models to celery tasks.  With my form I want it to
save a unique instance for every time the form is submitted so I think
I can pass the form to the task.

Does anyone have suggestions or other recommendations about this?  Is
there an easier way to do this?

Brian

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



Data validation in both forms and models

2011-12-02 Thread zobbo
Consider the following situation. An Order and OrderLine model, one
Order can have multiple OrderLines against it. An order line contains
a part number and quantity. This data can enter the system in two ways
- by a normal model admin form and also through a batch process
importing order data from edi files.

For the sake of this example I shall say there is one rule - which is
that all the quantities on order lines must add up to 5. If the user
is entering the data through the admin, we do not allow for an order
to be saved unless the total quantity is five. For data coming in
through EDI we allow for the data to be saved and a status field is
marked to show the order is not valid.

If I code this validation rule on the form then my model has no access
to that rule and I can't use it for edi processing. If I code this
rule into the model, my model only knows about what is written already
to the database. If I change my order lines in admin to add up to 6 my
model won't know about those lines until they're written to the
database.

So I am left with the idea that I have to put my validation rules in a
third place - where both my admin forms and models can access them. My
solution is to have this code expecting to be passed an instance of a
model so I have written code for the admin side that constructs
temporary model instances from submitted forms for this purpose. This
(so far) seems to work but the whole solution feels a little clunky

Does anybody else have to deal with this issue or have any suggestions
for alternative ways of dealing with it?

Ian

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



admin media files are not showing up in deployment

2011-12-02 Thread Nikhil Verma
Hi

I am deploying my project.my configuration is like this :-



WSGIScriptAlias /
/home/nikhil/workspace/CPMS-Source/careprep/apache/django.wsgi

ServerName localhost

Alias /media/ /home/nikhil/workspace/CPMS-Source/careprep/media/

Alias /static/ /home/nikhil/workspace/CPMS-Source/careprep/media/


Order allow,deny
Allow from all




My settings.py file :-

STATIC_ROOT = ''

# URL prefix for static files.
# Example: "http://media.lawrence.com/static/;
STATIC_URL = '/static/'

# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/;, "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'

# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
#('/home/user/workspace/CPMS-Source/careprep/media/')
)

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

My media is present in
/home/nikhil/workspace/CPMS-Source/careprep/media/

The problem is my admin files is are not coming up.Every media files in
project is coming except the admin media.all its css ,js,img are not coming.

Thanks in advance
-- 


Regards
Nikhil Verma
+91-958-273-3156

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



Modelformset issues after applying POST data

2011-12-02 Thread wchildsuk
Hi,

I'm having issues once I apply POST data to a model formset. I have  a
custom queryset applied to the form which works perfectly well when
the form is first generated.

If I have a validation error on the form the returned form seems to
drop the queryset and all records from the model are shown on the
form.

I've put my code into pastebin in case I've done something really
stupid, http://pastebin.com/BmGUqMNa

Any help would be great.

Thanks

Wes

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



Admin changelist filters affecting the add button

2011-12-02 Thread Michel Thadeu Sabchuk
Hi guys!

I didn't find anything suitable about it. I want to create a way to
the admin "add" button be affected by the changelist filter. Suppose I
have a list of blog posts and I filtered it by category:

.../admin/blog/post/?category=1

I want that the add button have the same query string:

.../admin/blog/post/add/?category=1

This way, the category will be preselected on the create form. This
already works except by the query string reusing.

What do you think about my idea? I can try to implement it but I
wanted to ask here before start working ;)

Best regards,

--
Michel Sabchuk
http://turbosys.com.br/

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



Re: How to deploy new code to the Production Server?

2011-12-02 Thread kenneth gonsalves
On Fri, 2011-12-02 at 12:04 +, Tom Evans wrote:
> > you put your passwords and keys under version control?
> 
> Where else would you put them? Not every VCS is wide open to view, our
> configuration VCS is highly locked down, but you need to record the
> information _somewhere_ in order to do coherent SCM. 

sorry - I was thinking open source.
-- 
regards
Kenneth Gonsalves

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



Re: How to deploy new code to the Production Server?

2011-12-02 Thread jpk
On Fri, Dec 2, 2011 at 6:54 AM, kenneth gonsalves
 wrote:
> On Fri, 2011-12-02 at 11:29 +, Bjarni Rúnar Einarsson wrote:
>> (for example
>> as someone recommended earlier, skipping settings.py), you are IMO
>> asking for trouble and it is probably a sign that your processes are
>> broken. :-)
>
> you put your passwords and keys under version control?
> --
> regards
> Kenneth Gonsalves
>
> --
> 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.
>
>

Check out https://code.djangoproject.com/wiki/SplitSettings
Personally, I use the second example, "Multiple setting files
importing from each other".

You can put settings common to both development and production in
settings.py and keep it in version control, but have a
settings_local.py or something that has things like database
connection information (including passwords), SECRET_KEY, and whatever
else would be secret or different between development/production.
Then .gitignore settings_local.py.  I also keep a
settings_local.py.template in version control that's just a
fill-in-the-blank of settings_local.py for quick set up on a new dev
machine or production server.

-- 


John P. Kiffmeyer
Email/XMPP: j...@thekiffmeyer.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: How to deploy new code to the Production Server?

2011-12-02 Thread jpk
On Fri, Dec 2, 2011 at 5:30 AM, Benedict Verheyen
 wrote:
> On 2/12/2011 11:14, Andre Lopes wrote:
>> Thanks for the replies,
>>
>> I'm using Nginx + Gunicorn + Supervisor + Virtualenv
>>
>> My goal is to deploy the code to the Production in a One Click Step. I
>> think I will read on Fabric to achieve this.
>>
>> More read also about Pip, I don't know how Pip Freeze works.
>>
>> If you have some more clues, you are welcome.
>>
>>
>> Best Regards,
>>
>
> If you want 1 click, you'll need fabric, read up on that.
> As for pip, pip can be used to install the various dependencies of your
> project in your virtualenv.
> You can then list these dependencies with this command:
>    pip freeze > requirements.txt
>
> This writes them into a file named requirements.txt that you can then
> use to setup the dependencies of your virtualenv on the production server.
>
>    pip install -r requirments.txt
>
> You only do this to setup the production server, it's not needed to transfer
> code, that you do with git (or mercurial, hg, ...).
>
>
> 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+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

You might find this useful:
http://python.mirocommunity.org/video/1689/pycon-2010-django-deployment-w

It's jacobian's django deployment workshop from pycon 2010, so it's
about 3h long.  It's worth watching front to back, but he only spends
a little time on deployment tools.  (The rest is nginx, apache,
postgre, memcached, etc.)  The tl;dw is: check out fabric, puppet, and
buildout for automating these things.

Cheers,
john

-- 


John P. Kiffmeyer
Email/XMPP: j...@thekiffmeyer.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: How to deploy new code to the Production Server?

2011-12-02 Thread Tom Evans
On Fri, Dec 2, 2011 at 11:54 AM, kenneth gonsalves
 wrote:
> On Fri, 2011-12-02 at 11:29 +, Bjarni Rúnar Einarsson wrote:
>> (for example
>> as someone recommended earlier, skipping settings.py), you are IMO
>> asking for trouble and it is probably a sign that your processes are
>> broken. :-)
>
> you put your passwords and keys under version control?

Where else would you put them? Not every VCS is wide open to view, our
configuration VCS is highly locked down, but you need to record the
information _somewhere_ in order to do coherent SCM.

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



Re: How to deploy new code to the Production Server?

2011-12-02 Thread kenneth gonsalves
On Fri, 2011-12-02 at 11:29 +, Bjarni Rúnar Einarsson wrote:
> (for example
> as someone recommended earlier, skipping settings.py), you are IMO
> asking for trouble and it is probably a sign that your processes are
> broken. :-) 

you put your passwords and keys under version control?
-- 
regards
Kenneth Gonsalves

-- 
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: Creating an app for recurring features

2011-12-02 Thread Benedict Verheyen
On 30/11/2011 16:10, Benedict Verheyen wrote:


Hi,


I managed to create the standalone application, that's the good news.
I have some questions on testing the app below.

I ended up making a virtualenv for the application. Afterwards, I copied the 
relevant files
(templates, view, urls, static) to this directory.
I still need to add docs, complete test suites, manifest.In and other text 
files.
But what I have now works.

To test it, I made a new project, copied the application directory to the 
projects src
and installed it from there with "python setup.py develop".

application directory
├── bin
│   ├── activate
│   ├── ...
├── include
│   └── ...
├── lib
│   └── python2.7
├── src
│   ├── django
├── manage.py
├── setup.py
└── mycompany_language
├── __init__.py
├── settings.py
├── static
│   └── mycompany_language
├── templates
│   └── mycompany_language
├── tests
│   ├── __init__.py
│   ├── runtests.py
│   ├── testsettings.py
│   ├── tests.py
├── urls.py
└── views
├── __init__.py
├── views_language.py


What I spent most time on, was figuring out how I could run the tests to
test the application. "python manage.py test" doesn't work if I use
the "normal" settings.py as it only contains a few constants.
The error is: there is no database defined in there.
I use the settings file to specify LANGUAGES, DEFAULT_LANGUAGE and LANGUAGE_CODE
and nothing more.

After looking at some other apps, I figured out that I could use a second
settings file specific to testing (testsettings.py).
If I specify this testsettings file in the "python manage.py test" command,
the command "python manage.py test 
--settings=mycompany_language.tests.testsettings" works.
However, running a specific test fails:

$ python manage.py test --settings=mycompany_language.tests.testsettings 
mycompany_language.SetLanguageTest
>>> "App with label company_language is missing a models.py module."

Indeed, in this example, I don't have models.py file and providing an empty one 
seemed weird.
Besides, the settings file doesn't have a proper INSTALLED_APPS stance.
Anyway, I then tried to run the tests from the tests directory without manage.py


In tests.py, I have this at the top
=
import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'testsettings'
from django.conf import settings
...
=

testsettings.py
=
APP_PATH=os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
PROJECT_PATH=os.path.abspath(os.path.join(APP_PATH,".."))
sys.path += [APP_PATH, PROJECT_PATH]
# Import main settings
from mycompany_language.settings import *
...
=

I could then run the tests from the test directory with "python tests.py"
This complained about not finding the module company_language.tests
ImportError: No module named company_language.tests

This is why i added these 3 lines to testsettings.py

APP_PATH=os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
PROJECT_PATH=os.path.abspath(os.path.join(APP_PATH,".."))
sys.path += [APP_PATH, PROJECT_PATH]

And then running the tests finally worked.

I do have some questions:
1. Is there a problem with running application tests not via "python manage.py 
test"?
If the latter is preferable, I suppose I do have to specify the APP in there.
I would like to avoid putting too much in the settings file as I just meant to 
use it
for some application specific settings.

2. Is it ok to specify application specific constants in the settings file?
In my test project, I then access them like this:
from mycompany_language.settings import *

For the doc, I will look into Sphinx.

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



Re: How to deploy new code to the Production Server?

2011-12-02 Thread Bjarni Rúnar Einarsson
I considered it very important to be able to keep all configurations
under revision control and have the ability to review the changes
between what is live, what is tested and what is in development.  As
soon as you start leaving things out of revision control (for example
as someone recommended earlier, skipping settings.py), you are IMO
asking for trouble and it is probably a sign that your processes are
broken. :-)

I use git branches to manage my differences between development,
production and testing.  Everything that matters at all is in git, I
can rebuild my entire site using a script which also lives in git.

Now, obviously each of these environments will be slightly different -
at the very least domain names and port numbers will differ and in my
case I also use mock back-end databases during development and real
ones in testing and production.  Also, the deployment scripts
themselves (I am a dinosaur who uses ssh, rsync and makefiles) are
different on each branch.

So all three branches are different, and I don't want to risk losing
the differences when I merge.  But aside from these deliberate
deviations, I want to keep the three branches as closely synchronized
as possible.

They key to making this work, is all development happens on the main
branch, and production and testing branch off dev and are updated
using the `git rebase` command. If you don't know `git rebase`, I
highly recommend learning it, it's like magic. :-)  When I update my
production branch it automates these steps:

   1. reverts all differences between production and the dev branch point
   2. applies the development progress (moving the branch point to the head)
   3. reapplies the patches that got reverted in 1.

Basically, this moves the branch point forward, bringing both branches
back in sync without losing the deliberate deviations.

Sometimes there is some manual work involved in resolving conflicts,
but that is a good thing as those are generally things which have
changed and deserve extra attention during deployment.

At any time if I want to compare what is in production with the
testing or development trees, I can just run `git diff production` or
`git diff testing` to see all the differences.

I've been working this way for a bit over a year, developing and
running the pagekite.net site and service, and I really like it.

-- 
Bjarni R. Einarsson
Founder, lead developer of PageKite.

Make localhost servers visible to the world: http://pagekite.net/

-- 
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: Bulk import of data

2011-12-02 Thread Cal Leeming [Simplicity Media Ltd]
Faster in what sense? Prototyping/development time, or run time?

If it's only a few MB, I see little reason to go as far as to writing it in
C. Unless you are performing the same import tens of thousands of times,
and the overhead in Python adds up so much that you get problems.

But, quite frankly, you'll max out MySQL INSERT performance before you max
out Pythons performance lol - as long as you don't use the ORM for inserts
:)

Cal

On Fri, Dec 2, 2011 at 5:21 AM, Nathan McCorkle  wrote:

> would interfacing with SQL via C or C++ be faster to parse and load
> data in bulk? I have files that are only a few MB worth of text, but
> can take hours to load due to the amount of parsing I do, and the
> number of database entries each item in a file makes
>
> On Mon, Nov 28, 2011 at 3:28 AM, Anler Hernandez Peral
>  wrote:
> > Hi, this is probably not your case, but in case it is, here is my story:
> > Creating a script for import CSV files is the best solution as long as
> they
> > are few, but in my case, the problem was that I need to import nearly 40
> > VERY BIG CSV files, each one mapping a database table, and I needed to
> do it
> > quickly. I thought that the best way was to use MySQL's "load data in
> > local..." functionality since it works very fast and I could create only
> one
> > function to import all the files. The problem was that my CSV files were
> > pretty big and my database server were eating big amounts of memory and
> > crashing my site so I ended up slicing each file in smaller chunks.
> > Again, this is a very specific need, but in case you find yourself in
> such
> > situation, here's my base code from which you can extend ;)
> >
> > https://gist.github.com/1dc28cd496d52ad67b29
> > --
> > anler
> >
> >
> > On Sun, Nov 27, 2011 at 7:56 PM, Andre Terra 
> wrote:
> >>
> >> This should be run asynchronously (i.e. celery) when importing large
> >> files.
> >> If you have a lot of categories/subcategories, you will need to bulk
> >> insert them instead of looping through the data and just using
> >> get_or_create. A single, long transaction will definitely bring great
> >> improvements to speed.
> >> One tool is DSE, which I've mentioned before.
> >> Good luck!
> >>
> >> Cheers,
> >> AT
> >>
> >> On Sat, Nov 26, 2011 at 8:44 PM, Petr Přikryl  wrote:
> >>>
> >>> >>> import csv
> >>> >>> data = csv.reader(open('/path/to/csv', 'r'), delimiter=';')
> >>> >>> for row in data:
> >>> >>> category = Category.objects.get_or_create(name=row[0])
> >>> >>> sub_category = SubCategory.objects.get_or_create(name=row[1],
> >>> >>> defaults={'parent_category': category})
> >>> >>> product = Product.objects.get_or_create(name=row[2],
> >>> >>> defaults={'sub_category': sub_category})
> >>>
> >>> There are few potential problems with the cvs as used here.
> >>>
> >>> Firstly, the file should be opened in binary mode.  In Unix-based
> >>> systems, the binary mode is technically similar to text mode.
> >>> However, you may once observe problems when you move
> >>> the code to another environment (Windows).
> >>>
> >>> Secondly, the opened file should always be closed -- especially
> >>> when building application (web) that may run for a long time.
> >>> You can do it like this:
> >>>
> >>> ...
> >>> f = open('/path/to/csv', 'rb')
> >>> data = csv.reader(f, delimiter=';')
> >>> for ...
> >>> ...
> >>> f.close()
> >>>
> >>> Or you can use the new Python construct "with".
> >>>
> >>> P.
> >>>
> >>> --
> >>> 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.
> >
> > --
> > 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.
> >
>
>
>
> --
> Nathan McCorkle
> Rochester Institute of Technology
> College of Science, Biotechnology/Bioinformatics
>
> --
> 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.
> 

Re: double trailing slash in url

2011-12-02 Thread Karen Tracey
On Thu, Dec 1, 2011 at 6:34 PM, Brian Craft wrote:

> I don't think so. It's not issuing a redirect. It's just serving the
> view, even though the url spec doesn't match.
>
>
I suspect your web server is collapsing the multiple slashes into a single
one, so that the Django code doesn't even see them.

Try using the dev server to access the url with multiple slashes -- the dev
server won't collapse the slashes,  so I suspect you'll see the 404 you are
expecting for that case.

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: division breaks makemessages djangojs

2011-12-02 Thread Karen Tracey
On Thu, Dec 1, 2011 at 6:09 AM, Michael  wrote:

> [snipped description of makemessages for javascript failing to find some
> strings]
>

>
I am using Django 1.3.1,
>
> Well, I am happy again since I found out what the problem is. I write
> this here, because I havent found out how to report the bug -- anyway,
> probably someone should try to reproduce this.
>

https://code.djangoproject.com/changeset/16333 completely replaced the
Javascript parsing code used by makemessages, fixing several known problems
with that code. That change was done after 1.3 was released, and was not
back-ported to the 1.3.X branch, so it will be available in an official
release with 1.4.

I expect if you try your problematic Javascript code with current Django
svn trunk code, it will find all the strings correctly. If it does not then
the way to report the problem would be to open a ticket here:

https://code.djangoproject.com/newticket

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: How to deploy new code to the Production Server?

2011-12-02 Thread Benedict Verheyen
On 2/12/2011 11:14, Andre Lopes wrote:
> Thanks for the replies,
> 
> I'm using Nginx + Gunicorn + Supervisor + Virtualenv
> 
> My goal is to deploy the code to the Production in a One Click Step. I
> think I will read on Fabric to achieve this.
> 
> More read also about Pip, I don't know how Pip Freeze works.
> 
> If you have some more clues, you are welcome.
> 
> 
> Best Regards,
> 

If you want 1 click, you'll need fabric, read up on that.
As for pip, pip can be used to install the various dependencies of your
project in your virtualenv.
You can then list these dependencies with this command:
pip freeze > requirements.txt

This writes them into a file named requirements.txt that you can then
use to setup the dependencies of your virtualenv on the production server.

pip install -r requirments.txt

You only do this to setup the production server, it's not needed to transfer
code, that you do with git (or mercurial, hg, ...).


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



Re: Pointing to Memcached on Remote Server

2011-12-02 Thread Medhat Gayed
Hi Matt,

Did you check that port 11211 is open for connections on the remote server?

Regards,
Medhat

On Fri, Dec 2, 2011 at 2:49 PM, mattym  wrote:

> Hi all -
>
> I am stuck on this one. Caching with memcached works when I reference
> the local box holding Django. But when I point my setting to a remote
> box it does not cache:
>
> This is with Django 1.3 using python-memcached on the localbox in a
> virtualenv
>
>  'default': {
>'BACKEND':
> 'django.core.cache.backends.memcached.MemcachedCache',
>#'LOCATION': ['127.0.0.1:11211',]  # This works
>'LOCATION': ['xx.xxx.xxx.xx:11211',]  # This remote one does not
>}
>
> My settings file appears to have the proper middleware installed:
>
>  "django.middleware.gzip.GZipMiddleware",
>  "django.middleware.cache.UpdateCacheMiddleware",
>"django.contrib.sessions.middleware.SessionMiddleware",
>"django.contrib.auth.middleware.AuthenticationMiddleware",
>"django.contrib.redirects.middleware.RedirectFallbackMiddleware",
>"mezzanine.core.middleware.DeviceAwareUpdateCacheMiddleware",
>"django.middleware.common.CommonMiddleware",
>"django.middleware.csrf.CsrfViewMiddleware",
>"mezzanine.core.middleware.DeviceAwareFetchFromCacheMiddleware",
>"mezzanine.core.middleware.AdminLoginInterfaceSelector",
>"django.middleware.cache.FetchFromCacheMiddleware",
>
> I've checked that memcached is running on the remote box. I am
> probably overlooking something simple.
> Any help is greatly appreciated.
>
> Thanks,
> Matt
>
> --
> 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: How to deploy new code to the Production Server?

2011-12-02 Thread Andre Lopes
Thanks for the replies,

I'm using Nginx + Gunicorn + Supervisor + Virtualenv

My goal is to deploy the code to the Production in a One Click Step. I
think I will read on Fabric to achieve this.

More read also about Pip, I don't know how Pip Freeze works.

If you have some more clues, you are welcome.


Best Regards,



On Fri, Dec 2, 2011 at 10:08 AM, kenneth gonsalves
 wrote:
> On Fri, 2011-12-02 at 09:00 +, Andre Lopes wrote:
>> How can I have the two environments(Development and Production) in
>> Git? Should I use two new Branches(Development and Production). Please
>> give me a clue on this.
>
> have two branches (and do not put settings.py under version control)
>>
>> Other question... when I finish to upload/push the code to the
>> Production server I need to restart the Gunicorn(serves Django
>> website). How can I do this?
>
> use supervisord
>>
>> And the most important question... Should I use Git to do this or I
>> have better options?
>
> I personally prefer mercurial - bitbucket rocks.
> --
> regards
> Kenneth Gonsalves
>
> --
> 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: Django

2011-12-02 Thread Victor Hooi
Hi,

The XML files are all configuration files, storing things like boolean 
configuration flags, timeout values, username/passwords, IP addresses and 
ports etc.

Some of them will maps somewhat logically to the relational model - for 
example, they'll be a configuration for an application, as well as each of 
it's sub-modules, as well as usernames/passwords linked to the application 
etc.

I've included three example XSD files - hopefully that will give you a 
better idea.

The reason we're using Django is I was hoping to leverage off the 
Django-admin, as well as Django forms, if need be, to provide an easy 
interface to edit the files, and enforce some validation rules (many of 
which aren't really contained in the XML/XSD files).

And the other issue is the configuration format may change over time, so 
we'll need to keep the models.py up-to-date, not sure of the best way to do 
that.

Cheers,
Victor

-- 
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/-/s3td-Oy5jG8J.
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.



CConfigRefData.xsd
Description: Binary data


CConfigFIXAA.xsd
Description: Binary data


CConfigXXX.xsd
Description: Binary data


Re: How to deploy new code to the Production Server?

2011-12-02 Thread kenneth gonsalves
On Fri, 2011-12-02 at 09:00 +, Andre Lopes wrote:
> How can I have the two environments(Development and Production) in
> Git? Should I use two new Branches(Development and Production). Please
> give me a clue on this.

have two branches (and do not put settings.py under version control)
> 
> Other question... when I finish to upload/push the code to the
> Production server I need to restart the Gunicorn(serves Django
> website). How can I do this?

use supervisord
> 
> And the most important question... Should I use Git to do this or I
> have better options? 

I personally prefer mercurial - bitbucket rocks.
-- 
regards
Kenneth Gonsalves

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



Re: How to deploy new code to the Production Server?

2011-12-02 Thread Benedict Verheyen
On 2/12/2011 10:00, Andre Lopes wrote:
> Hi,
> 
> I'm new to Django. I need to setup Git to deploy a Django website to
> the production server. My question here is to know what is the best
> way of doing this.
> 
> By now I only have a Master branch. My problem here is that
> Development environment is not equal to the Production environment.
> How can I have the two environments(Development and Production) in
> Git? Should I use two new Branches(Development and Production). Please
> give me a clue on this.
> 
> Other question... when I finish to upload/push the code to the
> Production server I need to restart the Gunicorn(serves Django
> website). How can I do this?
> 
> And the most important question... Should I use Git to do this or I
> have better options?
> 
> Best Regards,
> 

To actually answer your question more completely, we would need to know
more on your development and production environment, in other words,
what tools are you using.

In my setup, git contains only the project code, no distinction here
to development or production environment.
I use virtualenv and pip to setup my environment. Installing on production
can be as simple as doing a "pip freeze > requirements.txt" to get all
the installed packages and installing them on the server is
possible via "pip install -r requirments.txt".

I manage gunicorn with supervisord. It's a great tool.
If you don't have supervisord or another tool to manage the gunicorn instances,
you'll need to stop the gunicorn processes manually (kill if working on Linuix)
and start them again. (gunicorn_django -c )
You really should be looking at a tool to manage them.

Fabric is a tool that can help you automate some of these tedious tasks.

In short:
- If not done yet, have a look at virtualenv and pip and use them to setup
  your environment on your development and production machine. On the production
  machine you can setup the exact same environment by using the requirements
  from the pip freeze command as explained above.
- Develop, commit to git (only code)

- On the server, go into the virtualenv, pull in the code
- Restart the gunicorn processes preferably via supervisord or another tool

- Have a look at Fabric to automate these steps

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



Re: Pointing to Memcached on Remote Server

2011-12-02 Thread Joey Espinosa
Matt,

Do you have the port open on the public-facing side of the remote IP? In
other words, from another computer outside of that remote computer's
network, can you run "nmap -p 11211 xx.xxx.xxx.xx"? (obviously you'd need
nmap for this, but you get what I'm trying to imply)
--
Joey "JoeLinux" Espinosa*
*





On Thu, Dec 1, 2011 at 8:49 PM, mattym  wrote:

> Hi all -
>
> I am stuck on this one. Caching with memcached works when I reference
> the local box holding Django. But when I point my setting to a remote
> box it does not cache:
>
> This is with Django 1.3 using python-memcached on the localbox in a
> virtualenv
>
>  'default': {
>'BACKEND':
> 'django.core.cache.backends.memcached.MemcachedCache',
>#'LOCATION': ['127.0.0.1:11211',]  # This works
>'LOCATION': ['xx.xxx.xxx.xx:11211',]  # This remote one does not
>}
>
> My settings file appears to have the proper middleware installed:
>
>  "django.middleware.gzip.GZipMiddleware",
>  "django.middleware.cache.UpdateCacheMiddleware",
>"django.contrib.sessions.middleware.SessionMiddleware",
>"django.contrib.auth.middleware.AuthenticationMiddleware",
>"django.contrib.redirects.middleware.RedirectFallbackMiddleware",
>"mezzanine.core.middleware.DeviceAwareUpdateCacheMiddleware",
>"django.middleware.common.CommonMiddleware",
>"django.middleware.csrf.CsrfViewMiddleware",
>"mezzanine.core.middleware.DeviceAwareFetchFromCacheMiddleware",
>"mezzanine.core.middleware.AdminLoginInterfaceSelector",
>"django.middleware.cache.FetchFromCacheMiddleware",
>
> I've checked that memcached is running on the remote box. I am
> probably overlooking something simple.
> Any help is greatly appreciated.
>
> Thanks,
> Matt
>
> --
> 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.



rename a model field

2011-12-02 Thread Nikhil Verma
I have models.py

title  = models.CharField(max_length=80)

to this

ic_name= models.CharField(max_length=80)

I don't want to delete the field.


I have this option
class Migration:


def forwards(self, orm):

# Rename 'name' field to 'full_name'
db.rename_column('app_foo', 'name', 'full_name')

Its giving me an error

Caught TypeError while rendering: coercing to Unicode: need string or
buffer, tuple found

I will appreciate if anyone can tell me a easy way.Thanks in advance




-- 
Regards
Nikhil Verma
+91-958-273-3156

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

2011-12-02 Thread Reinout van Rees

On 02-12-11 01:39, Victor Hooi wrote:

Is there an easier way of achieving the main goal - editing XMl
configuration files through a Django interface? Things I should be aware of?



Depends a LOT on the kind of XML files. Are they the document kind, 
mixed content all around? Like a HTML file? Or are they the structured 
kind with a fixed structure?


Your main problem will probably be mapping the xml structure to a 
relational model.


Some brainstorming:

- Look at a nosql backend for Django: a nosql database might store xml 
in a more xml-friendly way.


- First convert the xml to json? Might be easier to store?

- Convert the .xsd schema to .rng or something like that: more readable. 
And, importantly, easier parseable by a python script: you could write 
your own models.py generator this way :-)


- Do you want to store it in separate models or in one big chunk of 
xml/json? Depends on how you want to edit.




Reinout

--
Reinout van Reeshttp://reinout.vanrees.org/
rein...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

--
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 deploy new code to the Production Server?

2011-12-02 Thread Andre Lopes
Hi,

I'm new to Django. I need to setup Git to deploy a Django website to
the production server. My question here is to know what is the best
way of doing this.

By now I only have a Master branch. My problem here is that
Development environment is not equal to the Production environment.
How can I have the two environments(Development and Production) in
Git? Should I use two new Branches(Development and Production). Please
give me a clue on this.

Other question... when I finish to upload/push the code to the
Production server I need to restart the Gunicorn(serves Django
website). How can I do this?

And the most important question... Should I use Git to do this or I
have better options?

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