Re: django select extremely slow on large table

2015-01-22 Thread James Schneider
How many results do you typically get back from that query?

It sounds like the DB is highly optimized if you can gather results from
tables that large that quickly running the query outside of Django. If you
are returning a large dataset, then it is more likely that Django is
furiously coercing every row in the result set to the appropriate model,
which takes time. Anything above a couple hundred rows will probably be
noticeable, maybe even less.

If a large result set is desired, I would recommend you filter your query a
bit more to reduce the number of rows returned and look at using values()
which may help slightly.

Installing the Django debug toolbar will also help, as you will be able to
see how long each query takes, which will probably lead you to the culprit.
It has a sqlshell management command that also may be of use, printing out
information about the queries, etc.

You can also slice the query to only retrieve the first 100 rows, etc.

As quick validation, I'm guessing that if you look at your system process
manager while the query is running, you'll see a single python process
pegged at 100% for the duration of the query run. If the DB is at fault,
python should be sitting idle.

TL;DR; I don't think the query itself is at fault, probably too much data
being returned to process.

-James
On Jan 22, 2015 10:56 PM, "Anssi Kääriäinen"  wrote:

>
>
> Do you fetch all the results when running the query directly against
>> Oracle? Many Oracle SQL clients do not fetch all the results, instead they
>> fetch just the top 100 or so rows.markid =
>> models.CharField(unique=True, max_length=20, blank=True)
>>
> I missed the part where you said you are using cx_oracle directly. Still,
> make sure you fetch all the results (use list(cursor.fetchall() after
> execution).
>
> If you don't want to return all the results, you can use the .iterator()
> method in Django.
>
>  - Anssi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4fa8d059-6fec-4da7-9f24-9ae761e78327%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: django select extremely slow on large table

2015-01-22 Thread Anssi Kääriäinen


Do you fetch all the results when running the query directly against 
> Oracle? Many Oracle SQL clients do not fetch all the results, instead they 
> fetch just the top 100 or so rows.markid = 
> models.CharField(unique=True, max_length=20, blank=True)
>
I missed the part where you said you are using cx_oracle directly. Still, 
make sure you fetch all the results (use list(cursor.fetchall() after 
execution).

If you don't want to return all the results, you can use the .iterator() 
method in Django.

 - Anssi 

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


Re: django select extremely slow on large table

2015-01-22 Thread Anssi Kääriäinen
Do you fetch all the results when running the query directly against 
Oracle? Many Oracle SQL clients do not fetch all the results, instead they 
fetch just the top 100 or so rows.

 - Anssi

On Thursday, January 22, 2015 at 5:32:36 PM UTC+2, Joris Benschop wrote:
>
> Dear List,
>
> I'm trying to run a simple select on a very large Oracle table (1500 
> million records). 
>
> I create a standard django model:
> --
> class Marker(models.Model):
> marker_id = SYSGUID16Field(primary_key=True)  # This field type is a 
> guess.
> markid = models.CharField(unique=True, max_length=20, blank=True)
> crop = models.ForeignKey("variantdb_admin.Crop", blank=True, null=True)
> insid = models.CharField(max_length=5, blank=True)
> insdate = models.DateTimeField(blank=True, null=True)
>
> class Meta:
> managed = False
> db_table = "prod_schema"."marker"
> --
>
> then simply run:
> >>> x = Marker.objects.filter(markid = 'TO11')
> >>> print x
>
> in debugger, this basically creates the following simple query:
> DEBUG (44.120) QUERY = u'SELECT "PROD_SCHEMA"."MARKER"."MARKER_ID", 
> "PROD_SCHEMA"."MARKER"."MARKID", "PROD_SCHEMA"."MARKER"."CROP_ID", 
> "PROD_SCHEMA"."MARKER"."INSID", "PROD_SCHEMA"."MARKER"."INSDATE" FROM 
> "PROD_SCHEMA"."MARKER" WHERE "PROD_SCHEMA"."MARKER"."MARKID" = :arg0' - 
> PARAMS = (u'TO11',); args=('TO11',)
>
> As you see, in Django this takes 44 seconds to run. 
> If I run this exact same query with cx_oracle directly the response time = 
> < 0.1sec.
>
> For small tables the performance of django is quite good, so it almost 
> seems like django tries to do a count on the table before runnign the query 
> or something. Any suggestions on how I can make this lookup faster?
>
> thanks
> joris
>
>
>
>

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


Re: django select extremely slow on large table

2015-01-22 Thread Jani Tiainen
Hi,

1.5b rows is rather big data.

Could you test what .values() or .values_list() produces in terms of speed.

also print qs might actually pull in all selected records in Python memory so 
it may take a while to constuct bunch of objects.


On Thu, 22 Jan 2015 07:32:36 -0800 (PST)
Joris Benschop  wrote:

> Dear List,
> 
> I'm trying to run a simple select on a very large Oracle table (1500 
> million records). 
> 
> I create a standard django model:
> --
> class Marker(models.Model):
> marker_id = SYSGUID16Field(primary_key=True)  # This field type is a 
> guess.
> markid = models.CharField(unique=True, max_length=20, blank=True)
> crop = models.ForeignKey("variantdb_admin.Crop", blank=True, null=True)
> insid = models.CharField(max_length=5, blank=True)
> insdate = models.DateTimeField(blank=True, null=True)
> 
> class Meta:
> managed = False
> db_table = "prod_schema"."marker"
> --
> 
> then simply run:
> >>> x = Marker.objects.filter(markid = 'TO11')
> >>> print x
> 
> in debugger, this basically creates the following simple query:
> DEBUG (44.120) QUERY = u'SELECT "PROD_SCHEMA"."MARKER"."MARKER_ID", 
> "PROD_SCHEMA"."MARKER"."MARKID", "PROD_SCHEMA"."MARKER"."CROP_ID", 
> "PROD_SCHEMA"."MARKER"."INSID", "PROD_SCHEMA"."MARKER"."INSDATE" FROM 
> "PROD_SCHEMA"."MARKER" WHERE "PROD_SCHEMA"."MARKER"."MARKID" = :arg0' - 
> PARAMS = (u'TO11',); args=('TO11',)
> 
> As you see, in Django this takes 44 seconds to run. 
> If I run this exact same query with cx_oracle directly the response time = 
> < 0.1sec.
> 
> For small tables the performance of django is quite good, so it almost 
> seems like django tries to do a count on the table before runnign the query 
> or something. Any suggestions on how I can make this lookup faster?
> 
> thanks
> joris
> 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/7db20206-9af7-491f-a0ed-b84f43cd4096%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: Django with ExtJs, any app ?

2015-01-22 Thread Jani Tiainen
Hi,

Easier on what sense? I've had great success with django-rest-framework and 
ExtJS as is for a long time, without need to have an app to do anything for me.

On Thu, 22 Jan 2015 13:17:09 -0200
Fellipe Henrique  wrote:

> Hello,
> 
> There's any app to make easier manipulate data using Django and ExtJ?
> 
> T.·.F.·.A.·. S+F
> *Fellipe Henrique P. Soares*
> 
> e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
> *Blog: http://fhbash.wordpress.com/ *
> *GitHub: https://github.com/fellipeh *
> *Twitter: @fh_bash*
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAF1jwZEzk6TbTpNWtyiwYYJHf4Q8YVTs5VUvUgmmciT%2BZnze-A%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

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


Re: django select extremely slow on large table

2015-01-22 Thread Tim Chase
On 2015-01-22 17:14, Joris Benschop wrote:
> Thanks you for your response
> Unfortunately, yes, the 1.5b records is not something I have
> control over.
[snip] 
> WHERE "PROD_SCHEMA"."MARKER"."MARKID" = :arg0

Just out of curiosity, do you have an index on MARKER.MARKID ?  And
if so, is it combined with any other fields?

I don't know enough about Oracle to be sure, but it also looks like it
doesn't have an OFFSET/LIMIT, so it's doing some strange ROWNUM
chicanery to produce similar results.

-tkc



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


Re: sending email

2015-01-22 Thread Collin Anderson
Hi,

Just query the users you want.

to_emails = [u.email for u in User.objects.filter(username__in=['person1', 
'person2', 'person3'])]
send_mail('Subject here', 'Here is the message.', from_email_address, 
to_emails)

Collin

On Wednesday, January 21, 2015 at 11:29:51 PM UTC-5, suabiut wrote:
>
> Thanks,
> I am trying to send email to the users that their email address is stored 
> in the database on the auth_user table. can someone please point me to the 
> right direction.
>
> Cheers,
>
>
> On Thu, Jan 22, 2015 at 3:03 PM, Collin Anderson  > wrote:
>
>> Hi,
>>
>> Yes, this is possible. Something like:
>>
>> from django.core.mail import send_mail
>>
>> def authorized_leave(request):
>> form = MyForm()
>> if request.method == 'POST':
>> form = MyForm(request.POST)
>> if form.is_valid():
>> obj = form.save()
>> send_mail('Subject here', 'Here is the message.', '
>> fr...@example.com ', ['t...@example.com '])
>> return redirect('/done/')
>> return render(request, 'template.html', {form: 'form'})
>>
>> Collin
>>
>>
>> On Monday, January 19, 2015 at 10:02:45 PM UTC-5, suabiut wrote:
>>>
>>> Hi,
>>> I am trying to send an email to several users once a form is submit. I 
>>> have done the view.py to update the database once the form is submitted and 
>>> is working fine. what i want to accomplish when the form is submitted is to 
>>> update the database and at the same time send out email when a user click 
>>> on the Authorized leave button.
>>>
>>> here is the step i want to do:
>>>
>>>  [image: Inline image 1]
>>>
>>> 1) user click on the check box and this form below appears
>>>
>>>
>>> [image: Inline image 2]
>>>  2) the user then fill up the form and click on authorized leave button. 
>>> the form will stored the information into the database. which i have 
>>> already done it. what i wanted to do next is to also send a emails when the 
>>> authorized leave button is click. is it possible to send emails and also 
>>> save data to database when the authorized leave button is click. i want to 
>>> send email to the *Test User* which have his email address store in the 
>>> database. 
>>>
>>> template.html
>>> {%csrf_token%}
>>> 
>>> {{form.as_table}}
>>> 
>>> 
>>>   
>>>
>>>
>>> 
>>>
>>> please point me to the right direction.
>>>
>>> Cheers,   
>>>
>>>   -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/3df19a0c-2afc-4e17-b527-83d38a639611%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
>  

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


Re: How to use password hasher snippet in Django?

2015-01-22 Thread Tom Lockhart
On Jan 22, 2015, at 4:42 PM, Supermario  wrote:

> Many thanks for your help Thomas. Indeed I am in the middle of big escape 
> effort to get the heck away from Drupal.
> 
> I tested your snippet in the shell and DrupalPasswordHasher hashes perfectly 
> well there. 
> 
> However, when I integrate the hash into my project as per your explanation, 
> django-registration module still refuse to authenticate old drupal users. 
> 
> Any ideas on how to troubleshoot this?

I’m not using django-registration so don’t know if it uses some other mechanism 
to hash and compare passwords.

I might try putting a simple print statement into the hash routine to make sure 
that it is executing (run using the development server and just look for the 
print output on your console).

All password processors are executed in order until one of the verify() methods 
returns True.

Oh! You will also need to prepend “drupal” to each hashed password you bring 
over from the drupal database. Or do an explicit update of your new database to 
prepend that string to the hashed password field.

hth

- Tom


>  
> Cheers
> 
> On Thursday, January 22, 2015 at 4:12:07 AM UTC+1, Thomas wrote:
> On Jan 21, 2015, at 3:07 PM, Supermario  wrote:
> 
>> I am trying to move Druap 7 site to django 1.7 without invalidating user 
>> passwords, and this proved to be daunting.
>> 
>> Fortunately, I have found this SO question and this hashing snippet but 
>> there is no documentation and as a newbie to django, I have no clue how to 
>> integrate the snippet into my project.
>> 
> 
> I’ve enclosed a password processor I used in the past for a Drupal 
> conversion; the gist came from a web search and is attributed in the code but 
> has some minor fixes. I’ve actually included two processors, with one 
> disabled with “XXX” in the function name. I think I had trouble getting that 
> one to work.
> 
> You can create a “drupal” app, which just has an __init__.py and this file as 
> hashers.py
> 
> You will want to add “drupal” as one of your apps, then also define the 
> following in your settings.py:
> 
> PASSWORD_HASHERS = (
> 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
> 'drupal.hashers.DrupalPasswordHasher',
> 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
> 'django.contrib.auth.hashers.BCryptPasswordHasher',
> )
> 
> Since you are starting fresh, you can include only the recommended best 
> password hasher from Django plus the drupal hasher. And if you prefer you 
> could fold the hashers.py file into another existing app in your project.
> 
> Also, the structure of your project may be a bit different from mine since 
> the recommended Django layout has changed a bit over the last few versions.
> 
> hth, and enjoy getting the heck away from Drupal hell…
> 
> - Tom
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/aa905c13-b9b1-42ba-b0c2-4127d079a8c3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Please consider the environment before printing this message.
This message may be privileged and/or confidential, and the sender does not 
waive any related rights and obligations.  Any distribution, use or copying of 
this message or the information it contains by other than an intended recipient 
is unauthorized.  If you received this message in error, please immediately 
advise me by return e-mail or phone.  All information, references, images, 
programs, source code, or other materials whatsoever contained in, or supplied 
with, this document are TRADE SECRETS and governed by the Uniform Trade Secrets 
Act.  User assumes all direct and consequential liabilities and costs that 
result from any unauthorized disclosure or use of this information.

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


Re: makemigrations complains about a ForeignKey not being Unique

2015-01-22 Thread Collin Anderson
Hi,

I think you might want to use a common abstract base class. You want a 
completely separate database table for the two models, right?

Collin

On Wednesday, January 21, 2015 at 10:17:08 PM UTC-5, Samuel Jean wrote:
>
> Hi there, 
>
> Does anybody know of a way to trick Django 1.7 (or the proper way, if 
> any) to modify the property of an inherited field so that it has unique 
> property on the children only. 
>
> Consider this abstract model : 
>
> class UniqueObjectModel(models.Model): 
>  uuid = models.CharField(max_length=36, default=uuid4) 
>  pool = models.ForeignKey('Pool', related_name='+', to_field='uuid') 
>  ... 
>
>  class Meta: 
>  abstract = True 
>  unique_together = (('uuid', 'pool'),) 
>
> I would like the Pool model to inherit from UniqueObjectModel *but* have 
> its uuid field unique. 
>
> class Pool(UniqueObjectModel): 
>  def __init__(self, *args, **kwargs): 
>  super(Pool, self).__init__(*args, **kwargs) 
>  self._meta.get_field('pool').to = 'self' 
>  self._meta.get_field('uuid')._unique = True 
>
> However, Django still complains about Pool.uuid field not being unique. 
>
> $ python manage.py makemigrations myapp 
>
> CommandError: System check identified some issues: 
>
> ERRORS: 
> myapp.Controller.pool: (fields.E311) 'Pool.uuid' must set unique=True 
> because it is referenced by a foreign key. 
>
> Any ideas? 
>
> Thanks! 
>

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


Re: Remote Authentication (out-of-the-box)

2015-01-22 Thread Collin Anderson
Hi,

RemoteUserBackend is for Apache or Windows IIS, I don't think it's what you 
want.

Do you have a local copy of the user table on hand? If so just query the 
matching username and call "django.contrib.auth.login()" on it.

Otherwise, you'll need to use a custom backend.

Collin

On Wednesday, January 21, 2015 at 8:30:10 PM UTC-5, Cristian Bustos wrote:
>
> Hello Friends,
> Here is my question, Remote Authentication (out-of-the-box) django
> I have 2 projects Django:
>
>1. Users Api Django app (Django framework rest - token authentication) 
>- Server
>2. Django app (I need to authenticate users and consume APIs) - Client
>
> I can authenticate user, only use requests-python, but i need do remote 
> authentication with django
>
> This is my code:
> settings.py
>
> AUTHENTICATION_BACKENDS = ( 
> 'django.contrib.auth.backends.RemoteUserBackend', )
>
> MIDDLEWARE_CLASSES = ( '...', 
> 'django.contrib.auth.middleware.AuthenticationMiddleware', 
> 'django.contrib.auth.middleware.RemoteUserMiddleware',
>  '...', )
>
>
> view.py
> -
> class LoginRCS(View):
> template_name = 'userprofiles/login.html'
>
> def get(self, request, *args, **kwargs):
> return render(request, self.template_name )
>
> def post(self, request, *args, **kwargs):
> # inputBp and inputPassword come from login form
> if 'inputBp' in request.POST and 'inputPassword' in request.POST:
> inputBp = request.POST['inputBp']
> inputPassword = request.POST['inputPassword']
>
> # URL to get token from api user
> URL_API = 'http://localhost:7000/api/token/'
> payload = {'username': inputBp, 'password': inputPassword}
> headers = {'content-type': 'application/json'}
> r = requests.post(URL_API, data=json.dumps(payload), 
> headers=headers)
>
> if r.status_code == requests.codes.ok:
> # I have a token
> data = json.loads(r.text)
> token_auth = 'token ' + data['token']
>
> URL_CHECK_USER = '
> http://127.0.0.1:7000/api/users/?username='+inputBp 
> 
> payload_login = {'username': inputBp, 'password': 
> inputPassword}
> headers_login = {
> 'content-type': 'application/json',
> 'Authorization': token_auth }
> r_user = requests.get(URL_CHECK_USER, 
> data=json.dumps(payload_login), headers=headers_login)
>
> if r_user.status_code == request.codes.ok:
> # I have a user info (unsername, first_name, 
> last_name, email)
> data_user = json.loads(r_user.text)
>
> #
> # here need authentication
> # 
> # user = authenticate(username=my_user, password=my_bp)
>
> else:
> print 'Error'
> return render(request, self.template_name)
>
> thanks in advance,
> CB
>
>

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


Re: block php requests

2015-01-22 Thread Collin Anderson
Hi,

I had broken link emails enabled for a while. Over time, my nginx.conf 
config grew into this:

location /_vti_inf.html { return 404; }
location /crossdomain.xml { return 404; }
location ~/cache/eb91756ae6745d22433f80be4ec59445$ { return 404; } # 
some sort of plugin?
location ~\.php$ { return 444; }
location ~\.aspx?$ { return 444; }
location /account/submit/add-blog { return 444; }
location /blogs/my_page/add { return 444; }
location /my_blogs { return 444; }
location /YaBB { return 444; }
location /signup { return 444; }
location /register { return 444; }
location /user/register { return 444; }
location /member/register { return 444; }
location /forum/member/register { return 444; }
location /tools/quicklogin.one { return 444; }
location /mt.js { return 444; }
location ~\[PLM=0\] { return 444; }

I eventually just turned of the 404 emails and was able to delete all of 
that config :)

Actually, if you put an  (or do a similar 
request with ajax) on your 404 page, that would filter out a lot of spam.

Collin

On Wednesday, January 21, 2015 at 3:32:15 AM UTC-5, hinnack wrote:
>
> Hi,
> thanks for your reply.
> Blocking all requests in Apache seems to be the best way. Can you give an 
> example how to do that?
> As / is mapped to the wsgi app ( 
> https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/ )
> and a new files section does not the trick:
>
>  #PHP protection
>
> order allow,deny
>
> deny from all
>
> satisfy all
>
> 
>
>
> Am Dienstag, 20. Januar 2015 12:55:40 UTC+1 schrieb hinnack:
>>
>> Hi,
>>
>> I get a lot of intrusion checks on my website - especially for PHP 
>> (wordpress, joomla, …).
>> Today they all raise a 404 errors in python-django - so if you have 
>> emails enabled for 404 errors…
>>
>> What is the best way to block those requests in a standard apache 
>> deployment?
>> ( https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/modwsgi/ )
>>
>> regards
>>
>> Hinnack
>>
>

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


Re: Strange Behavior from the Django Admin (following tutorial on a shared server)

2015-01-22 Thread Collin Anderson
Hi,

What's likely happening is that django or passenger is crashing. Is there 
any log available?

Collin

On Wednesday, January 21, 2015 at 2:13:45 AM UTC-5, Ed Volz wrote:
>
> Hi all,
>
> New to Django so I was following along with the tutorial and can get to 
> the point of logging into the Administration portal (the main page works as 
> well).  Django is running with passenger in a virtualenv (python 2.7) on a 
> shared host.  I immediately receive a ERR_EMPTY_RESPONSE   when I click 
> log in, regardless of whether or not the credentials are correct.  The db 
> records a session on a correct log in even though the ERR_EMPTY_RESPONSE 
> remains.  I've confirmed the user is both is_active and is_staff using the 
> shell.  
>
> What's puzzling me is that the log in page loads the css files from the 
> STATIC_URL just fine, but there's nothing once served up the form is 
> submitted.  Any help would be appreciated.
>
> settings.py file 
>
> passenger_wsgi.py file:
> #!/usr/bin/env python2.7
> import sys,os
> # Tell Passenger to run our virtualenv python
> INTERP = "/home//djangoenv/bin/python"
> if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
> # Set up paths and environment variables
> sys.path.append(os.getcwd())
> os.environ['DJANGO_SETTINGS_MODULE'] = 'mynewsite.settings'
> # Set the application
> import django.core.handlers.wsgi
> # Use paste to display errors
> from paste.exceptions.errormiddleware import ErrorMiddleware
> from django.core.wsgi import get_wsgi_application
> application = get_wsgi_application()
> application = ErrorMiddleware(application, debug=True)
>
>
>

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


Re: Is Django suitable for this purpose?

2015-01-22 Thread Collin Anderson
Hi,

As others have mentioned, it's totally possible. Regardless of using Django 
or not, the integration could easily be the hardest part, and that's where 
the "up to a minute delay" could come in.

Collin

On Tuesday, January 20, 2015 at 4:52:33 PM UTC-5, Mike Taylor wrote:
>
> I want to have an appointment booking option built into a website for a 
> clinic.
>
> The feature needs to integrate with the software that runs their office ( 
> http://www.atlaschirosys.com/)
>
> In order to be fully useful, it would need to be virtually instantaneous 
> in filling the requested appointment spot.  A time lag of more than a 
> couple minutes would not be acceptable.
>
> So, is this even possible and is Django the best tool for building it?
>
> Thank you for ANY input.
>

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


Re: Binding model data to a formset without POST

2015-01-22 Thread Collin Anderson
Hi,

Interesting. I've never heard of someone wanting to show validation errors 
on the initial data when the page first loads.

I have however wanted to manually bind data to a form before. Last time I 
checked it's not super trivial, because you could for instance have a 
SplitDateTimeWidget which actually expects _two_ keys in the bound data.

If you're just doing basic fields, that should work. If you're doing 
anything more complicated, it might make sense to run the validation more 
by hand. If you could call field.clean() on the less raw data you could 
skip widgets and prefixes all together.

Collin

On Tuesday, January 20, 2015 at 8:06:06 AM UTC-5, Rob Groves wrote:
>
> Hi All,
> I am new to Django and am enjoying it very much.  Excellent documentation, 
> tutorials, and general environment to work in.  Good job Django developers!
>
> I have a question on binding data to a ModelFormset.  I have looked 
> extensively and not seen this particular issue covered before.
>
> I have a ModelFormset that I send to a template for custom rendering so I 
> can present the fields in a controlled tabular format.  The ultimate goal 
> is to use CSS to create a red bounding box around any fields with 
> validation errors and to set the "title" attribute of those input fields so 
> that the user can see what errors were generated  by hovering over the red 
> bounded field.  This presents a nice clean interface when there are 
> errors.  It all works great, with one annoyance if the model data starts 
> out with values that will generate validation errors (i.e. missing required 
> data).  
>
> I initially call the view with a GET, which creates the forms and 
> populates the form fields.  Since the data is not bound to forms at this 
> point, I can't validate and set the errors.  In order to validate the 
> fields and set the table error borders, I have to submit the form using 
> POST to bind the data, validate the form and generate the errors which 
> ultimately set an error_class for styling the table.  This means that I 
> have to "save" the from from my form page to get the table style I want.
>
> What I really want is to instantiate a ModelFormset, setting the instance, 
> but then to bind the data present in the instance and set errors by sending 
> is_valid() to the formset before rendering (i.e. on initial page rendering 
> with the GET, so no POST data).  It seemed to me that there should simply 
> be a bind_instance() function for all ModelFormsets that contain an 
> instance.  I looked and didn't find that.  Eventually, I just decided to 
> bind the data myself manually using the following helper function:
>
> # helper functions
> def bind_formset(formset):
> bindData={}
> # add management form data
> bindData[formset.get_default_prefix()+"-TOTAL_FORMS"]=str(formset.
> management_form['TOTAL_FORMS'].value())
> bindData[formset.get_default_prefix()+"-INITIAL_FORMS"]=str(formset.
> management_form['INITIAL_FORMS'].value())
> bindData[formset.get_default_prefix()+"-MIN_NUM_FORMS"]=str(formset.
> management_form['MIN_NUM_FORMS'].value())
> bindData[formset.get_default_prefix()+"-MAX_NUM_FORMS"]=str(formset.
> management_form['MAX_NUM_FORMS'].value())
> for form in formset:
> if form.instance:
> for fieldName,fieldValue in form.fields.iteritems():
> try:
> bindData[form.add_prefix(fieldName)]=getattr(form.
> instance,fieldName)
> except:
> # this is an added field, not derived from the model
> pass
> newFormset=formset.__class__(bindData,instance=formset.instance,
>   queryset=formset.queryset, error_class=
> formset.error_class)
> return newFormset
>
> This works!  My question... Is this a reasonable approach?  Or did I just 
> miss the obvious way of doing this?
>
> Thanks for any help!
>

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


Re: OneToOne field versus model inheritance

2015-01-22 Thread Collin Anderson
Hi,

Django doesn't really provide a way to create a subclass from an already 
existing object in the admin. It's actually pretty hard to do even in the 
code. So for that reason I'd recommend the non subclass with the 
OneToOneField.

Actually, if I were doing it, this is what I would do:

class User(AbstractBaseUser):
is_client = models.BooleanField(default=False)
is_member = models.BooleanField(default=False)
description = models.CharField(verbose_name=_('first name'), max_length=
255, blank=True)
# include both client and member fields here and have them be blank=True

Collin

On Tuesday, January 20, 2015 at 7:52:38 AM UTC-5, Paul Royik wrote:
>
> I have three models: Person, Client, Member
> Person is a base model, Client and Member are profiles for Person.
>
> class Person(AbstractBaseUser, PermissionsMixin):
> email = models.EmailField(
> verbose_name=_('email address'),
> max_length=255,
> unique=True,
> )
>
>
> class Client(User): #or maybe models.Model and explicit OneToField 
> first_name = models.CharField(verbose_name=_('first name'), 
> max_length=30)
> last_name = models.CharField(verbose_name=_('last name'), 
> max_length=30)
>
> class Member(User): #or maybe models.Model and explicit OneToField 
> description = models.CharField(verbose_name=_('first name'), 
> max_length=255)
># other stuff
>
>
> So, what I want?
> 1. In admin, when we add client or member, I want to fill field email 
> (fields from base class) as if it was in derived class. For example, in 
> admin list_display = ('email', 'first_name'). Not select boxes for user.
> 2. Person class can be instantiated separately and the "attached" to the 
> created profiel. Like person=Person(email="te...@gmail.com "), 
> client = Client(person=person,first_name="test"...). Especially, this 
> should work in forms. When user (person) is authenticated I want to give 
> ability to fill in profile (client) form and attach person to this form.
> 3. One person can have both accounts. If I delete client/member, 
> corresponding person should not be deleted.
>
> 3rd option actually is not necessary, but it is useful for me to know how 
> to do it.
>
> So, option 1 is perfectly solved by inheritance, Person is User, but this 
> approach fails when option 2 is implemented. Since Person and Client is 
> considered as one whole, I can't attach user, duplicate key error.
> Option 2 is resolved by extending models.Model and appending 
> person=models.OnetoOneField(Person,primary_key=True). However, admin is 
> broken (1st option), because Client don't have fields like email.
>
>
> So, what approach to take in order to solve above issues?
> Are there simple ways?
> If there are no simple ways, is there advanced way, like overriding 
> metaclass, object descriptors or writing custom OneToOne field?
>
> Any suggestions are welcomed.
>
> Thank you. 
>

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


Re: How to check appname via Django commands?

2015-01-22 Thread Collin Anderson
Hi,

I don't think the project name is stored in the database.

You can sometimes access the project name this way:

settings.SETTINGS_MODULE.split('.')[0]

Collin

On Tuesday, January 20, 2015 at 6:33:38 AM UTC-5, Sugita Shinsuke wrote:
>
> Hello Vijay
>
> Thank you for replying.
>
> But, I want to know the project name of django not app name.
>
>
> 2015年1月17日土曜日 23時18分46秒 UTC+9 Vijay Khemlani:
>>
>> What problem are you having exactly?
>>
>> Also I'm not sure what do you mean by "hierarchy" of the project folders, 
>> do you mean the order the apps appear in the INSTALLED_APPS setting?
>>
>> On Sat, Jan 17, 2015 at 6:38 AM, Sugita Shinsuke  
>> wrote:
>>
>>> Hi there.
>>>
>>> I use Django 1.6 version.
>>>
>>> The database of Django store the information of application.
>>> So, I know that if I  change the hierarchy of the Django project 
>>> folders, some trouble occurs.
>>> That is why, I'd like to check the name of my application.
>>>
>>> I think some of Django commands  like manage.py command can check the 
>>> application name in the database of Django project.
>>> Or, if you know other Django command. Could you tell me it?
>>>
>>> I would appreciate it if you would give me some advice.
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to django-users...@googlegroups.com.
>>> To post to this group, send email to django...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/django-users/4ea222eb-1fdd-44af-97c7-3f5bb05a13ef%40googlegroups.com
>>>  
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

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


Re: How to use password hasher snippet in Django?

2015-01-22 Thread Supermario
Many thanks for your help Thomas. Indeed I am in the middle of big escape 
effort to get the heck away from Drupal.

I tested your snippet in the shell and DrupalPasswordHasher hashes 
perfectly well there. 

However, when I integrate the hash into my project as per your explanation, 
django-registration module still refuse to authenticate old drupal users. 

Any ideas on how to troubleshoot this?
 
Cheers

On Thursday, January 22, 2015 at 4:12:07 AM UTC+1, Thomas wrote:
>
> On Jan 21, 2015, at 3:07 PM, Supermario  
> wrote:
>
> I am trying to move Druap 7 site to django 1.7 without invalidating user 
> passwords, and this proved to be daunting.
>
> Fortunately, I have found this 
> 
>  SO 
> question and this  hashing 
> snippet but there is no documentation and as a newbie to django, I have no 
> clue how to integrate the snippet into my project.
>
>
> I’ve enclosed a password processor I used in the past for a Drupal 
> conversion; the gist came from a web search and is attributed in the code 
> but has some minor fixes. I’ve actually included two processors, with one 
> disabled with “XXX” in the function name. I think I had trouble getting 
> that one to work.
>
> You can create a “drupal” app, which just has an __init__.py and this file 
> as hashers.py
>
> You will want to add “drupal” as one of your apps, then also define the 
> following in your settings.py:
>
> PASSWORD_HASHERS = (
> 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
> 'drupal.hashers.DrupalPasswordHasher',
> 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
> 'django.contrib.auth.hashers.BCryptPasswordHasher',
> )
>
> Since you are starting fresh, you can include only the recommended best 
> password hasher from Django plus the drupal hasher. And if you prefer you 
> could fold the hashers.py file into another existing app in your project.
>
> Also, the structure of your project may be a bit different from mine since 
> the recommended Django layout has changed a bit over the last few versions.
>
> hth, and enjoy getting the heck away from Drupal hell…
>
> - Tom
>
>

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


Re: Accessing Django test client in setUpClass

2015-01-22 Thread Russell Keith-Magee
Hi Nicole,

(I've added this answer to SO as well)

Short answer is no - but that's not the end of the story.

self.client is a convenience that is configured as part of the "pre-test"
sequence. This means it is configured on a per-test basis; so you can use
it in setUp(), but not setUpClass().

However, there's nothing especially magical about self.client - it's just
an instance of django.test.Client that Django sets up for you because it's
something that is very useful to have around. You can set up your own
client if you want - you just have to instantiate an instance of Client:

from django.test import Client
...
self.myclient = Client()

and then use self.myclient as you would self.client. This can be very
useful if you need to check "two user" behaviour - for example, checking
that if an admin approves an article, a user can then see it. You create
two clients, log them in with separate accounts, and then GET the same
article URL with each client. In your case, you could create a client
purely for class setup activities.

The only caveat on using django.test.Client in setUpClass() relate to
transactional side effects. setUpClass() doesn't fall inside the
transaction protection of a test case, so anything you do in setUpClass()
will be "permanent" on the test database. You'll need to manually roll back
or undo any database changes that setUpClass makes, or you'll get
cross-testcase side effects.

If you're using Django 1.8, you can use setUpTestData() instead - in this
case, anything the client does *would* be protected by a transaction.

Yours,
Russ Magee %-)


On Thu, Jan 22, 2015 at 5:08 PM, Nicole Harris  wrote:

> I just posted this on Stack Overflow and then realised I might have more
> luck here.
>
> Basically, I'd like to know if I can access self.client inside
> setUpClass(cls) when setting up a Django test:
>
> http://stackoverflow.com/questions/28084683/accessing-django-test-client-in-setupclass
>
> If anybody has any insight on this, I'd really appreciate it :)
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fb4e3cd7-a70a-4a7c-b61f-f6ef73d7e226%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: Communication between listboxes in form

2015-01-22 Thread Russell Keith-Magee
On Thu, Jan 22, 2015 at 4:17 PM, joulumaa  wrote:

> Hi, beginner question.
>
> I need to have two listboxes A and B on web page, When user selects one
> item from A it should add it in B.
>
> If I understand right, form A should somehow save change to database and
> wake up form B to update its query.
>
> Where should I start in documentation?
>
>
Hi,

This isn't really a Django question, per se - it's got more to do with
JavaScript on the client side.

The only Django component will be a form that contains 2 ManyToManyFields.
However, that just provides the way to render the initial A and B lists,
and commit them when they are saved.

The process of moving an item from one list to another will require
JavaScript. Django doesn't provide anything to do this out of the box.
There are plenty of toolkits to do this; it's up to you to investigate your
preferred option. However, jQuery is one place to start.

If you want to do this in a truly dynamic fashion - i.e., saving each
individual list change as it happens, rather than "make a bunch of changes,
and commit", you're in a whole other territory; you'll need to investigate
AJAX and APIs.

Yours
Russ Magee %-)

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


Re: Slow test startup under Django 1.7

2015-01-22 Thread Markus Holtermann
Hey Warren,

this is a known problem in 1.7. It is fixed in 1.8 
(see https://code.djangoproject.com/ticket/23745). Unfortunately, the 
changes made to reduce the amount of get_models() and render() calls are 
too invasive to backport them to 1.7.

If you have the time, could you try running your project on the 1.8 alpha 
version and check the changes out and provide some feedback on how that 
turned out?

Thanks in advance.

/Markus

On Thursday, January 22, 2015 at 9:47:22 PM UTC+1, Warren Smith wrote:
>
> I'm in the process of converting a large legacy app from Django 1.5 to 
> 1.7. I've got all the tests passing, so I'm researching an issue I noticed 
> during the course of my work: Test startup takes MUCH longer under Django 
> 1.7 than it did under 1.5. I've got a test that, when run by itself, took a 
> total of 5 seconds under 1.5. Under 1.7 it takes over a minute.
>
> To isolate the test startup, I setup a do-nothing test method within a 
> subclass of django.test.TestCase. I ran it under Django 1.5 and 1.7 with 
> similar results to the existing "real" test.
>
> I ran the do-nothing test within cProfile under Django 1.7 and found 
> something very interesting. According to pstats, the method 
> django.apps.config.AppConfig.get_models() was called 2.2+ MILLION times. 
> Even with 79 django apps in my INSTALLED_APPS setting, that seems excessive.
>
> I read the Django 1.7 release notes, especially the App Config stuff. I 
> noticed the warning about not importing models in the application root 
> module. I went through all of our internal apps and made sure they were not 
> importing models in the root module. I had to make some changes, moving 
> imports inside functions/methods. I also looked at my third-party 
> dependency apps. None of those were importing their models in their root 
> modules.
>
> After all that, though, I still see no change in behavior.
>
> I thought I might have some loop happening somewhere, though why it wasn't 
> infinite was interesting. It would be nice to know more about the context 
> of those get_models() calls. Perhaps I had a couple of mis-behaving apps 
> locked in a deadly embrace of some sort.
>
> I hacked on my locally installed django.apps.config.AppConfig class, 
> adding a class-level collections.Counter that gets incremented for 
> self.label by the get_models() method.
> I dumped the results to a json file within my do-nothing test. It wouldn't 
> be comprehensive, but at least it would show me what had happened before 
> the test ran.
>
> I expected to see a few big numbers and a lot of small ones. As often 
> happens when profiling, my expectations were completely wrong. All the 
> counts were very similar, all in the 6000-7999 range. All 79 of my apps 
> were represented.
>
> Is there some sort of cartesian product going on here?
>
> Is this behavior normal and expected?
>
>

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


Slow test startup under Django 1.7

2015-01-22 Thread Warren Smith
I'm in the process of converting a large legacy app from Django 1.5 to 1.7. 
I've got all the tests passing, so I'm researching an issue I noticed 
during the course of my work: Test startup takes MUCH longer under Django 
1.7 than it did under 1.5. I've got a test that, when run by itself, took a 
total of 5 seconds under 1.5. Under 1.7 it takes over a minute.

To isolate the test startup, I setup a do-nothing test method within a 
subclass of django.test.TestCase. I ran it under Django 1.5 and 1.7 with 
similar results to the existing "real" test.

I ran the do-nothing test within cProfile under Django 1.7 and found 
something very interesting. According to pstats, the method 
django.apps.config.AppConfig.get_models() was called 2.2+ MILLION times. 
Even with 79 django apps in my INSTALLED_APPS setting, that seems excessive.

I read the Django 1.7 release notes, especially the App Config stuff. I 
noticed the warning about not importing models in the application root 
module. I went through all of our internal apps and made sure they were not 
importing models in the root module. I had to make some changes, moving 
imports inside functions/methods. I also looked at my third-party 
dependency apps. None of those were importing their models in their root 
modules.

After all that, though, I still see no change in behavior.

I thought I might have some loop happening somewhere, though why it wasn't 
infinite was interesting. It would be nice to know more about the context 
of those get_models() calls. Perhaps I had a couple of mis-behaving apps 
locked in a deadly embrace of some sort.

I hacked on my locally installed django.apps.config.AppConfig class, adding 
a class-level collections.Counter that gets incremented for self.label by 
the get_models() method.
I dumped the results to a json file within my do-nothing test. It wouldn't 
be comprehensive, but at least it would show me what had happened before 
the test ran.

I expected to see a few big numbers and a lot of small ones. As often 
happens when profiling, my expectations were completely wrong. All the 
counts were very similar, all in the 6000-7999 range. All 79 of my apps 
were represented.

Is there some sort of cartesian product going on here?

Is this behavior normal and expected?

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


Suggestions Required

2015-01-22 Thread Aayush Aggarwal
I am developing an Web Application that basically does data analytics,so 
need suggestions how should i go about this?
Also is it advisable  use RPy2  to  interface with R from Python? 
Any other suggestions?

Thanks!

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


Django & Ember.js issue tracker

2015-01-22 Thread Rafał Pitoń


I've decided to start issue tracker on github to list all gotchas and 
differences between Ember.js defaults and conventions vs. Django ones I 
have encountered so far as well as solutions and fixes for those:

https://github.com/rafalp/django-ember-issues

I currently have file on two things here: trailing slashes and using django 
i18n in handlebars, but I will also add something about setting security 
policies within Ember & Django for communicating with each other in dev, 
and example for initializing Ember.js with data from Django.

I invite all Django dev's to share their "AHA!" moments wisdom as well as 
devs working on apps and addons to check "needs app" and "needs addon" 
labels to see if they can donate libraries solving those issues.

Cheers!

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


Re: makemigrate adds multiple migrations.AddField for same model (django 1.7.1)

2015-01-22 Thread pjotr
I created ticket for this: https://code.djangoproject.com/ticket/24203

On Friday, December 26, 2014 at 9:54:52 PM UTC+1, Collin Anderson wrote:
>
> Ohh, I see. Yes, this looks like a possible spot for optimization. I 
> wouldn't really call it a "bug", but a "cleanup/optimization". You could 
> probably open a ticket about it.
>
> On Tuesday, December 23, 2014 5:04:55 AM UTC-6, pjotr wrote:
>>
>> Sorry, all the ALTER statements are identical except the FIELDNAME. It 
>> adds 6 new fields.
>>
>> On Tuesday, December 23, 2014 4:46:42 AM UTC+1, Collin Anderson wrote:
>>>
>>> Hi,
>>>
>>> You're just using one database?
>>>
>>> Are all 6 ALTER statements identical?
>>>
>>> Collin
>>>
>>> On Sunday, December 21, 2014 5:27:06 PM UTC-6, pjotr wrote:

 Just realized the subject was wrong, it should be *makemigrations , 
 not makemigrate*

 On Sunday, December 21, 2014 8:36:29 PM UTC+1, pjotr wrote:
>
> Hi,
>
> I have a django model that I just added six new fields to. I ran 
> *makemigrations 
> *and after that noticed when we ran our rehearsal upgrade with dump 
> of the production database that things took longer than we expected, and 
> checked the processlist. We saw that there were six *alter table* 
> statements that was executed after each other, each taking around 15 
> minutes to run.
>
> My expectations were that the migration framework would optimise this 
> and only execute one alter table statement. But obviously it was not. Or 
> is 
> there a bug? :)
>
> Are there anyway to fix this, without having to change the migration 
> and perform the alter table statement with pure SQL?
>
> DB: MySQL
> Django 1.7.1
>
> The migrations generated were six of these (only showing one to reduce 
> post size):
>
> migrations.AddField(
> model_name='mymodel',
> name='field_a',
> field=models.BigIntegerField(help_text=b'Blablabla', null=True, 
> db_index=True),
> preserve_default=True,
> ),
>
>
> Regards, Peter Lauri
>
>

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


Refactoring normal view into class based view

2015-01-22 Thread akash nayyar



Hi guys any idea how the following view could be refactored into class based 
view? I want to convert this view into more structured class based view.


def student_application(request, project_slug):
  profile = StudentProfile.objects.get(user=request.user)
  project = Project.objects.get(slug=project_slug)
  new_invitation = ProjectInvitation(student=profile, project=project, 
state_student=ProjectInvitationState.ACCEPTED,
   student_application=True)

  form_application = ProjectApplicationForm(request.POST, 
instance=new_invitation)
  form_application.fields["previous_experience"].queryset = 
profile.practical_experiences

  if form_application.is_valid():
form_application.save()
action.send(profile, verb='has applied for', target=project)
messages.add_message(request, messages.SUCCESS, 'Thank you! Your 
application for project %s was successful and '
'will be reviewed shortly.' 
% project)
return HttpResponseRedirect(reverse('invitation_index'))
  else:
messages.add_message(request, messages.ERROR, 'There was a problem with 
your application.')
return HttpResponseRedirect(reverse('project_index'))

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


Unable to save object with images while using FormWizard in Django 1.7 and Python 3.4

2015-01-22 Thread Frankline
​Hi all​,
I am having a problem saving a Django form using the *FormWizard
*
while using *Django 1.7* and *Python 3.4*. Below is my code:

*models.py*

...class Advert(models.Model):
... # Some irelevant code removed for brevity
owner = models.ForeignKey(settings.AUTH_USER_MODEL, db_index=True,
blank=False, null=False)
title = models.CharField(_("Title"), max_length=120)
description = models.TextField(_("Description"), default='')
category = models.ForeignKey(AdCategory, db_index=True,
related_name='ad_category', verbose_name=_('Category'))
status = models.IntegerField(choices=ADVERT_STATES, default=0)
adtype = models.IntegerField(choices=ADTYPES, default=1)
price = models.DecimalField(_('Price'), max_digits=12,
decimal_places=2, blank=True, default=0,
help_text=_('Price'),
validators=[MinValueValidator(0)])
...class AdvertImage(models.Model):

def generate_new_filename(instance, filename):
IMAGE_UPLOAD_DIR = "advert_images"
old_fname, extension = os.path.splitext(filename)
return '%s/%s%s' % (IMAGE_UPLOAD_DIR, uuid.uuid4().hex, extension)

advert = models.ForeignKey(Advert, related_name='images')
image = models.ImageField(upload_to=generate_new_filename,
null=True, blank=True)


*forms.py*

from django.forms.models import inlineformset_factoryfrom django
import formsfrom django.forms import ModelForm, RadioSelect, TextInput
from .models import Advert, AdvertImage

class AdvertCategoryForm(ModelForm):

class Meta:
model = Advert
fields = ('category',)

class AdvertDetailsForm(ModelForm):

class Meta:
model = Advert
fields = ('title', 'description', 'location', 'adtype', 'price')

class AdvertImageForm(ModelForm):

class Meta:
model = AdvertImage
fields = ('image',)

AdvertImageFormset = inlineformset_factory(Advert, AdvertImage,
fields=('image',), can_delete=False, extra=3, max_num=3)


FORMS = [("ad_category", AdvertCategoryForm),
 ("ad_details", AdvertDetailsForm),
 ("ad_images", AdvertImageFormset)]

TEMPLATES = {"ad_category": "adverts/advert_category_step.html",
 "ad_details": "adverts/advert_details_step.html",
 "ad_images": "adverts/advert_images_step.html"}


*views.py*

...class AdvertWizard(LoginRequiredMixin, SessionWizardView):

form_list = FORMS
file_storage = FileSystemStorage(location=os.path.join(settings.MEDIA_ROOT))

def get_template_names(self):
return [TEMPLATES[self.steps.current]]

...

def done(self, form_list, **kwargs):
advert = Advert()
"""for form in form_list:for field, value in
form.cleaned_data.iteritems():setattr(advert, field,
value)"""

form_dict = {}
for form in form_list:
form_dict.update(form.cleaned_data)

advert.owner = self.request.user
advert.save()
redirect(advert)


​The problem occurs in the done method while saving the form:

ValueError at /ads/new

dictionary update sequence element #0 has length 3; 2 is required

Request Method:POSTRequest URL:http://localhost:8000/ads/newDjango Version:
1.7.1Exception Type:ValueErrorException Value:

dictionary update sequence element #0 has length 3; 2 is required

Exception 
Location:/home/frank/Projects/python/django/pet_store/src/petstore/apps/adverts/views.py
in done, line 147Python Executable:
/home/frank/.virtualenvs/petstore/bin/pythonPython Version:3.4.0

   -
   
/home/frank/Projects/python/django/pet_store/src/petstore/apps/adverts/views.py
in done
   1.

  form_dict.update(form.cleaned_data)

  ...
   ▶ Local vars 

However, when I replace the following code:

form_dict = {}
for form in form_list:
form_dict.update(form.cleaned_data)

with this one

for form in form_list:
for field, value in form.cleaned_data.iteritems():
setattr(advert, field, value)

I now get the following error:

AttributeError at /ads/new

'dict' object has no attribute 'iteritems'

Request Method:POSTRequest URL:http://localhost:8000/ads/newDjango Version:
1.7.1Exception Type:AttributeErrorException Value:

'dict' object has no attribute 'iteritems'

Exception 
Location:/home/frank/Projects/python/django/pet_store/src/petstore/apps/adverts/views.py
in done, line 140Python Executable:
/home/frank/.virtualenvs/petstore/bin/pythonPython Version:3.4.0Python Path:

['/home/frank/Projects/python/django/pet_store/src/petstore',
 '/home/frank/.virtualenvs/petstore/lib/python3.4',
 '/home/frank/.virtualenvs/petstore/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/frank/.virtualenvs/petstore/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/frank/.virtualenvs/petstore/lib/python3.4/site-packages'


Re: django select extremely slow on large table

2015-01-22 Thread Joris Benschop
Thanks you for your response
Unfortunately, yes, the 1.5b records is not something I have control over.

I agree the SYSGUID field needs working. However, if I change this field to
any other field type, the query still takes over 40 seconds.

class Marker(models.Model):
marker_id = models.BinaryField(primary_key=True)  # This field type is
a guess.
markid = models.CharField(unique=True, max_length=20, blank=True)
crop = models.ForeignKey("variantdb_admin.Crop", blank=True, null=True)
insid = models.CharField(max_length=5, blank=True)
insdate = models.DateTimeField(blank=True, null=True)

class Meta:
managed = False
db_table = "prod_schema"."marker"

DEBUG (58.566) QUERY = u'SELECT * FROM (SELECT "_SUB".*, ROWNUM AS "_RN"
FROM (SELECT "PROD_SCHEMA"."MARKER"."MARKER_ID",
PROD_SCHEMA"."MARKER"."MARKID", "PROD_SCHEMA"."MARKER"."CROP_ID",
"PROD_SCHEMA"."MARKER"."INSID", "PROD_SCHEMA"."MARKER"."INSDATE" FROM
"PROD_SCHEMA"."MARKER" WHERE "PROD_SCHEMA"."MARKER"."MARKID" = :arg0)
"_SUB" WHERE ROWNUM <= 1) WHERE "_RN" > 0' - PARAMS = (u'TO1',);
args=('TO1',)


thanks again for your help
joris


On Thu, Jan 22, 2015 at 4:51 PM, SK  wrote:

> To many calculations in the from_db_value function. Need optimizations. And 
> what about query limitations: 1.5b is really needed?
>
>
>
>
>  class SYSGUID16Field(models.Field):
>  default_error_messages = {
>  'invalid': "'%(value)s' is not a valid SYS_GUID."
>  }
>
>  description = "A connector to the SYS_GUID() fields for Oracle
>  Backends"
>
>  def __init__(self, *args, **kwargs):
>  kwargs['max_length'] = 16
>  super(SYSGUID16Field, self).__init__(*args,**kwargs)
>
>  def from_db_value(self, value, connection):
>  #print 'call from_db_value %s' % value
>  if value is None:
>  return value
>  return str(b2a_hex(value)).upper()
>
>
>
>
>
>
> четверг, 22 января 2015 г., 18:32:36 UTC+3 пользователь Joris Benschop
> написал:
>
>> Dear List,
>>
>> I'm trying to run a simple select on a very large Oracle table (1500
>> million records).
>>
>> I create a standard django model:
>> --
>> class Marker(models.Model):
>> marker_id = SYSGUID16Field(primary_key=True)  # This field type is a
>> guess.
>> markid = models.CharField(unique=True, max_length=20, blank=True)
>> crop = models.ForeignKey("variantdb_admin.Crop", blank=True,
>> null=True)
>> insid = models.CharField(max_length=5, blank=True)
>> insdate = models.DateTimeField(blank=True, null=True)
>>
>> class Meta:
>> managed = False
>> db_table = "prod_schema"."marker"
>> --
>>
>> then simply run:
>> >>> x = Marker.objects.filter(markid = 'TO11')
>> >>> print x
>>
>> in debugger, this basically creates the following simple query:
>> DEBUG (44.120) QUERY = u'SELECT "PROD_SCHEMA"."MARKER"."MARKER_ID",
>> "PROD_SCHEMA"."MARKER"."MARKID", "PROD_SCHEMA"."MARKER"."CROP_ID",
>> "PROD_SCHEMA"."MARKER"."INSID", "PROD_SCHEMA"."MARKER"."INSDATE" FROM
>> "PROD_SCHEMA"."MARKER" WHERE "PROD_SCHEMA"."MARKER"."MARKID" = :arg0' -
>> PARAMS = (u'TO11',); args=('TO11',)
>>
>> As you see, in Django this takes 44 seconds to run.
>> If I run this exact same query with cx_oracle directly the response time
>> = < 0.1sec.
>>
>> For small tables the performance of django is quite good, so it almost
>> seems like django tries to do a count on the table before runnign the query
>> or something. Any suggestions on how I can make this lookup faster?
>>
>> thanks
>> joris
>>
>>
>>
>>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/CYIxM8nZl1A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/29682a24-fdb6-4883-882e-58fb53d0a98c%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: django select extremely slow on large table

2015-01-22 Thread SK


To many calculations in the from_db_value function. Need optimizations. And 
what about query limitations: 1.5b is really needed?




 class SYSGUID16Field(models.Field):
 default_error_messages = {
 'invalid': "'%(value)s' is not a valid SYS_GUID."
 }

 description = "A connector to the SYS_GUID() fields for Oracle
 Backends"

 def __init__(self, *args, **kwargs):
 kwargs['max_length'] = 16
 super(SYSGUID16Field, self).__init__(*args,**kwargs)

 def from_db_value(self, value, connection):
 #print 'call from_db_value %s' % value
 if value is None:
 return value
 return str(b2a_hex(value)).upper()






четверг, 22 января 2015 г., 18:32:36 UTC+3 пользователь Joris Benschop 
написал:
>
> Dear List,
>
> I'm trying to run a simple select on a very large Oracle table (1500 
> million records). 
>
> I create a standard django model:
> --
> class Marker(models.Model):
> marker_id = SYSGUID16Field(primary_key=True)  # This field type is a 
> guess.
> markid = models.CharField(unique=True, max_length=20, blank=True)
> crop = models.ForeignKey("variantdb_admin.Crop", blank=True, null=True)
> insid = models.CharField(max_length=5, blank=True)
> insdate = models.DateTimeField(blank=True, null=True)
>
> class Meta:
> managed = False
> db_table = "prod_schema"."marker"
> --
>
> then simply run:
> >>> x = Marker.objects.filter(markid = 'TO11')
> >>> print x
>
> in debugger, this basically creates the following simple query:
> DEBUG (44.120) QUERY = u'SELECT "PROD_SCHEMA"."MARKER"."MARKER_ID", 
> "PROD_SCHEMA"."MARKER"."MARKID", "PROD_SCHEMA"."MARKER"."CROP_ID", 
> "PROD_SCHEMA"."MARKER"."INSID", "PROD_SCHEMA"."MARKER"."INSDATE" FROM 
> "PROD_SCHEMA"."MARKER" WHERE "PROD_SCHEMA"."MARKER"."MARKID" = :arg0' - 
> PARAMS = (u'TO11',); args=('TO11',)
>
> As you see, in Django this takes 44 seconds to run. 
> If I run this exact same query with cx_oracle directly the response time = 
> < 0.1sec.
>
> For small tables the performance of django is quite good, so it almost 
> seems like django tries to do a count on the table before runnign the query 
> or something. Any suggestions on how I can make this lookup faster?
>
> thanks
> joris
>
>
>
>

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


django select extremely slow on large table

2015-01-22 Thread Joris Benschop
Dear List,

I'm trying to run a simple select on a very large Oracle table (1500 
million records). 

I create a standard django model:
--
class Marker(models.Model):
marker_id = SYSGUID16Field(primary_key=True)  # This field type is a 
guess.
markid = models.CharField(unique=True, max_length=20, blank=True)
crop = models.ForeignKey("variantdb_admin.Crop", blank=True, null=True)
insid = models.CharField(max_length=5, blank=True)
insdate = models.DateTimeField(blank=True, null=True)

class Meta:
managed = False
db_table = "prod_schema"."marker"
--

then simply run:
>>> x = Marker.objects.filter(markid = 'TO11')
>>> print x

in debugger, this basically creates the following simple query:
DEBUG (44.120) QUERY = u'SELECT "PROD_SCHEMA"."MARKER"."MARKER_ID", 
"PROD_SCHEMA"."MARKER"."MARKID", "PROD_SCHEMA"."MARKER"."CROP_ID", 
"PROD_SCHEMA"."MARKER"."INSID", "PROD_SCHEMA"."MARKER"."INSDATE" FROM 
"PROD_SCHEMA"."MARKER" WHERE "PROD_SCHEMA"."MARKER"."MARKID" = :arg0' - 
PARAMS = (u'TO11',); args=('TO11',)

As you see, in Django this takes 44 seconds to run. 
If I run this exact same query with cx_oracle directly the response time = 
< 0.1sec.

For small tables the performance of django is quite good, so it almost 
seems like django tries to do a count on the table before runnign the query 
or something. Any suggestions on how I can make this lookup faster?

thanks
joris



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


Django with ExtJs, any app ?

2015-01-22 Thread Fellipe Henrique
Hello,

There's any app to make easier manipulate data using Django and ExtJ?

T.·.F.·.A.·. S+F
*Fellipe Henrique P. Soares*

e-mail: > echo "lkrrovknFmsgor4ius" | perl -pe \ 's/(.)/chr(ord($1)-2*3)/ge'
*Blog: http://fhbash.wordpress.com/ *
*GitHub: https://github.com/fellipeh *
*Twitter: @fh_bash*

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


Re: Data migration fails because contenttypes not yet ready

2015-01-22 Thread Markus Holtermann
Hi,

first of all, both, update_all_contenttypes and create_permissions, expect 
their respective app to be migrated completely in order to work as of 
1.7.4 
(https://github.com/django/django/commit/478546fcef38d95866a92bc44d10e15b26c7254c).

The "serialize model manager in migrations" issue, which is part of 1.8, 
will allow you to use custom methods on your model manager inside 
`RunPython` (e.g `MyUser.objects.create_a_fancy_user_account()`) and isn't 
related to the problem you are running into.

The sanest way to generate all ContentTypes and Permissions is to migrate 
those two apps explicitly before migrating the remaining apps:

$ python manage.py migrate contenttypes
$ python manage.py migrate auth
$ python manage.py migrate


That way you can make sure the contenttypes app is completely migrated and 
all contenttypes are created, the auth app is completely migrated and all 
permission are created, and last but not least the remaining apps should 
smoothly migrate forwards. There are thoughts about putting the migration 
graph and the respective model states before/after all migrations into the 
pre/post_migrate signals (#24100) as well as initial ideas emitting a 
signal after each migration (no ticket yet afaik). The latter could be used 
to tackle the above problem.

If you want to create a specific permission during a migration, do the 
following in `RunPython`:

def forwards(apps, schema_editor): 

Permission = apps.get_model('auth', 'Permission')

Permission.objects.create(...)


This is also the way to load initial data starting Django 1.7: using 
`RunPython` or `RunSQL`.

The django-migration-fixture app seems to do some crazy stuff in the 
management command that I'm not going to speculate about how long it's 
going to work. That is completely undocumented and internal API. Apart from 
that, the (de)serializers in django.core.serializers (specifically 
.python.Deserializer) use the global apps for deserialization. Thus, a 
fixture referring to a model that is later removed/renamed, or refers to a 
field that doesn't exist later or must not be null, cannot be applied when 
you run the migrations on an empty database.

/Markus

On Thursday, January 22, 2015 at 12:43:33 PM UTC+1, Daniel Hahler wrote:
>
> Hello,
>
> I was having the same issue as Torsten: it does not appear to be possible 
> to load initial data related to contenttypes or auth during migrations.
>
> As for the problem with contenttypes reported by Torsten, a workaround 
> appears to be calling `update_all_contenttypes` manually from your 
> migration (from django.contrib.contenttypes.management).
>
> But then there's the problem with creating auth.groups.
>
> I've tried the following via `RunPython`:
>
> from django.contrib.auth.management import create_permissions
> create_permissions(apps.get_app_config('auth'), verbosity=0)
>
> This aborts because `app_config.models_module` is None:
>
> app_config.__dict__
> {'models_module': None, 'name': 'auth', 'models': 
> OrderedDict([('group_permissions', ), ...]), 
> 'module': None, 'label': 'auth', 'verbose_name': 'Auth'}
>
> Is this related to https://code.djangoproject.com/ticket/23822 
> ("Serialize model managers in migrations"), and would be possible in Django 
> 1.8?
>
> I am trying to use https://github.com/alexhayes/django-migration-fixture, 
> which is meant to provide a convenient wrapper around the initial_data 
> fixtures (files). My PR with the changes mentioned above is viewable at: 
> https://github.com/alexhayes/django-migration-fixture/pull/2/files.
>
> What is the suggested way to have initial data with Django 1.7, given that 
> initial_data is not used for apps with migrations, and RunPython has the 
> above shortcomings?
>
>
> Thanks,
> Daniel.
>
> Am Dienstag, 21. Oktober 2014 19:42:34 UTC+2 schrieb Torsten Bronger:
>>
>> Hallöchen! 
>>
>> Markus Holtermann writes: 
>>
>> > Are you talking about Django 1.7 migrations or South? In the 
>> > former case you need to make sure that your datamigration depends 
>> > on the contenttypes application. 
>>
>> I'm talking about Django 1.7 migrations.  Unfortunately, 
>> contenttypes is already migrated before my app.  But this doesn't 
>> help because update_all_contenttypes is a post_migrate signal. 
>>
>> Tschö, 
>> Torsten. 
>>
>> -- 
>> Torsten BrongerJabber ID: torsten...@jabber.rwth-aachen.de 
>>   or http://bronger-jmp.appspot.com 
>>
>>

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

Accessing Django test client in setUpClass

2015-01-22 Thread Nicole Harris
I just posted this on Stack Overflow and then realised I might have more 
luck here.

Basically, I'd like to know if I can access self.client inside 
setUpClass(cls) when setting up a Django test:
http://stackoverflow.com/questions/28084683/accessing-django-test-client-in-setupclass

If anybody has any insight on this, I'd really appreciate it :)

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


Re: Data migration fails because contenttypes not yet ready

2015-01-22 Thread Daniel Hahler
Hello,

I was having the same issue as Torsten: it does not appear to be possible 
to load initial data related to contenttypes or auth during migrations.

As for the problem with contenttypes reported by Torsten, a workaround 
appears to be calling `update_all_contenttypes` manually from your 
migration (from django.contrib.contenttypes.management).

But then there's the problem with creating auth.groups.

I've tried the following via `RunPython`:

from django.contrib.auth.management import create_permissions
create_permissions(apps.get_app_config('auth'), verbosity=0)

This aborts because `app_config.models_module` is None:

app_config.__dict__
{'models_module': None, 'name': 'auth', 'models': 
OrderedDict([('group_permissions', ), ...]), 
'module': None, 'label': 'auth', 'verbose_name': 'Auth'}

Is this related to https://code.djangoproject.com/ticket/23822 ("Serialize 
model managers in migrations"), and would be possible in Django 1.8?

I am trying to use https://github.com/alexhayes/django-migration-fixture, 
which is meant to provide a convenient wrapper around the initial_data 
fixtures (files). My PR with the changes mentioned above is viewable at: 
https://github.com/alexhayes/django-migration-fixture/pull/2/files.

What is the suggested way to have initial data with Django 1.7, given that 
initial_data is not used for apps with migrations, and RunPython has the 
above shortcomings?


Thanks,
Daniel.

Am Dienstag, 21. Oktober 2014 19:42:34 UTC+2 schrieb Torsten Bronger:
>
> Hallöchen! 
>
> Markus Holtermann writes: 
>
> > Are you talking about Django 1.7 migrations or South? In the 
> > former case you need to make sure that your datamigration depends 
> > on the contenttypes application. 
>
> I'm talking about Django 1.7 migrations.  Unfortunately, 
> contenttypes is already migrated before my app.  But this doesn't 
> help because update_all_contenttypes is a post_migrate signal. 
>
> Tschö, 
> Torsten. 
>
> -- 
> Torsten BrongerJabber ID: torsten...@jabber.rwth-aachen.de 
>  
>   or http://bronger-jmp.appspot.com 
>
>

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


Re: Dynamically show or hide form fields?

2015-01-22 Thread Tobias Dacoir
ok, seems I'm stupid. The fields already have an id set, so I should be 
able to use javascript. Sorry for asking this stupid question. Still if 
someone has valid points as why I should use a different solution please 
let me know.

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


Dynamically show or hide form fields?

2015-01-22 Thread Tobias Dacoir
 In my Signup form the user has to chose his languages and afterwards his 
proficiency in that language. 
So based on the selection from forms.ChoiceField it should display one of 
two other ChoiceFields.

Example: 
Language = English
-> Display English Proficiency below 

Language = German
-> Display German Proficiency below 

Currently both Proficiency fields are always shown. I did some searching on 
how to accomplish this and I came up with buzzwords like AJAX (using dajax) 
or Crispyforms (3rd Party App) but it shold be possible to use simple 
javascript as well. 
I don't want to include another 3rd party app if possible since I use this 
for my signup form which is from django-allauth. The Signup form is 
inheriting from forms.Form currently: class SignupForm(forms.Form):

I don't know what will happen to django-allauth if I change this to 
something else. In the template it just calls {{ form.as_p }} so I have no 
idea on how to set custom classes / id's on those form fields. I didn't 
find anything about this in Django Documentation here: 
https://docs.djangoproject.com/en/1.7/ref/forms/fields/#choicefield

Can anyone please tell me what the best solution would be? If I have to 
include some 3rd party app is it likely to break django-allauth for the 
Signup form?

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


Re: {% url ... %} does not work for callable?

2015-01-22 Thread Torsten Bronger
Hallöchen!

Torsten Bronger writes:

> I cannot get the following working:
>
> In urls.py:
>
> url(r"^samples/(?P.+)/edit/$", sample.edit),
>
> In the template:
>
> {% url 'samples.views.sample.edit' sample_name="whatever" %}
>
> I constantly get a NoReverseMatch,

I solved the probem; it doesn't have directly to do with reverse
resolution of URLs.  Instead, I failed to add @wraps() to one of my
own decorators, and reserve() could not "recognize" the view
function anymore.

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com

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


Communication between listboxes in form

2015-01-22 Thread joulumaa
Hi, beginner question.

I need to have two listboxes A and B on web page, When user selects one 
item from A it should add it in B.

If I understand right, form A should somehow save change to database and 
wake up form B to update its query.

Where should I start in documentation?

-thanks

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