Re: Revisiting the case-sensitive login for the default user manager

2014-12-20 Thread Collin Anderson
Hi Roman,

That might be good enough, as long as you don't have any name conflicts 
already. Just make sure it prevents new users from signing up with a 
different case of an existing username.

Collin

On Friday, December 19, 2014 10:53:23 AM UTC-5, Roman Onosovski wrote:
>
> Hello fellow Djangoers, I am new to the framework and just recently built 
> a site using it.
> However I was not aware of the username hurdle until just recently.
> I did some research and found that I can make my own user manager and etc.
>
> Now this is probably a bit of a hack, but tell me what you think.
>
> I am on 1.6.5 and I did this: 
>
> from:
>
> def get_by_natural_key(self, username):
> return self.get(**{self.model.USERNAME_FIELD: username})
>
> to:
>
> def get_by_natural_key(self, username):
> return self.get(username__iexact=username)
>
> It works and does what I need it to do. How illegal is this and what 
> potential problems can this create that I may not see now?
>
> Thanks guys
>

-- 
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/bad5dd74-8cd9-44f3-9d35-0ae8c1d7c42c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Raw access to cache table

2014-12-20 Thread Collin Anderson
Hi Erik,

If you want a nicer interface, I just ran manage.py inspecdb on one of my 
databases and got this for the cache table. Not sure why django still does 
it by hand.

class Cache(models.Model):
cache_key = models.CharField(primary_key=True, max_length=255)
value = models.TextField()
expires = models.DateTimeField()

class Meta:
managed = False
db_table = 'cache_table'

Collin

On Friday, December 19, 2014 8:03:39 AM UTC-5, Erik Cederstrand wrote:
>
>
> > Den 18/12/2014 kl. 12.20 skrev Erik Cederstrand  >: 
> > 
> > Hi list, 
> > 
> > I'm using Django as a hub to synchronize data between various external 
> systems. To do this, I have some long-running Django management commands 
> that are started as cron jobs. To ensure that only one job is working on a 
> data set at any one time, I have implemented a locking system using the 
> Django cache system. 
> > 
> > Due to my less-than-stellar programming talent, a cron job may need to 
> be killed once in a while. To avoid leaving orphaned locks in the cache, I 
> want to clean up any locks before exiting, and I may not know which cache 
> keys exist at the time of exit. Therefore, I want to write a signal handler 
> that searches the Django cache for any entries that can be traced to the 
> current process (my cache keys can be used for this purpose) and delete 
> those. 
> > 
> > AFAICS, the Django cache API can't be used for this. There's 
> cache.clear() but I don't want to delete all cache entries. I'm using the 
> database backend, so I'm thinking I could access the database table 
> directly and issue any custom SQL on that. But it does feel hackish, so 
> maybe one of you have a better approach? Maybe I got the whole thing 
> backwards? 
>
> Just to wrap this up, I wrote a function to get all or some cache entries. 
> Most of the code is copy-paste from django.core.cache.backends.db. 
>
>
> def get_cache_entries(key_prefix=None): 
> db = router.db_for_read(cache.cache_model_class) 
> table = connections[db].ops.quote_name(cache._table) 
> with connections[db].cursor() as cursor: 
> sql = "SELECT cache_key, value FROM %s" % table 
> params = None 
> if key_prefix: 
> sql += " WHERE cache_key LIKE %s" 
> params = (key_prefix + '%',) 
> cursor.execute(sql, params=params) 
> rows = cursor.fetchall() 
> res = {} 
> for row in rows: 
> value = connections[db].ops.process_clob(row[1]) 
> res[row[0]] = pickle.loads(base64.b64decode(force_bytes(value))) 
> return res 
>
>
> Erik

-- 
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/d7a0d445-5966-45d3-946f-d88f3e600bb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Where to put my bugfix tests?

2014-12-20 Thread Андрей Маслов
Hello everyone.

I decided to make my first bugfix :)
Ticket: https://code.djangoproject.com/ticket/24008

And I have a question for where to put my tests?
Should I create a new file?
Or take already written and add my code (unfortunately I did not find 
anything related to ValidationError testing)?

Thanks in advance.

-- 
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/ba071c8a-41dc-417c-92d5-9e9f4c59e65d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Random row

2014-12-20 Thread Dariusz Mysior
I change it on

import csv, random

def new_name():
with open('PL_surnames.csv', newline='') as csvfile:
namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|') 

random_choice=random.choice(namesreader)
return random_choice
print(new_name())



No I have this message

Traceback (most recent call last):
  File "C:/Python31/csv", line 10, in 
print(new_name())
  File "C:/Python31/csv", line 8, in new_name
random_choice=random.choice(namesreader*len(namesreader))
TypeError: object of type '_csv.reader' has no len()
>>> 



W dniu sobota, 20 grudnia 2014 22:37:23 UTC+1 użytkownik Dariusz Mysior 
napisał:
>
> Why I get only last row from my csv file, why I don't get in any time 
> ranom row :/
>
> import csv, random
>
> def new_name():
> with open('PL_surnames.csv', newline='') as csvfile:
> namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|') 
> for row in namesreader:
> #print (','.join(row))
> random_choice=random.choice(row)
> return random_choice
> print(new_name())
>
>
>

-- 
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/ca92d760-6ab0-4e06-818b-ed1b64a749b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelAdmin with inlines: How to learn if/what has changed before the models are saved?

2014-12-20 Thread Alex Haylock
On 18/12/14 17:19, Carsten Fuchs wrote:
> I would like to find out if anything has changed in the parent
> model or the related (inline) models, and depending on the result,
> update one of the parent model's fields before it is saved.
> 
> Can you please tell me how can this be achieved?


Take a look at the Django signal dispatcher:
https://docs.djangoproject.com/en/dev/topics/signals/

Specifically, the 'update_fields' argument passed to the 'pre_save'
signal should provide what you need:

https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_save

Regards,

Alex.

-- 
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/5495EE89.6040504%40mykolab.com.
For more options, visit https://groups.google.com/d/optout.


Re: Random row

2014-12-20 Thread Cal Leeming
Doh sorry, hit return too quickly.

return random.choice(namesreader)

On Sat, Dec 20, 2014 at 9:42 PM, Cal Leeming  wrote:

> Somewhat off-topic for django-users, this would have been better placed on
> StackOverflow.
>
> If I understood your question correctly, I think you need to remove the
> "for row in namesreader" and replace with;
>
> namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
> return random.choice(row)
>
> On Sat, Dec 20, 2014 at 9:37 PM, Dariusz Mysior 
> wrote:
>
>> Why I get only last row from my csv file, why I don't get in any time
>> ranom row :/
>>
>> import csv, random
>>
>> def new_name():
>> with open('PL_surnames.csv', newline='') as csvfile:
>> namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
>> for row in namesreader:
>> #print (','.join(row))
>> random_choice=random.choice(row)
>> return random_choice
>> print(new_name())
>>
>>
>>  --
>> 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/07b16c6a-ca3a-4b42-8c72-33981c05d317%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/CAHKQagG26jujYzcnzmhU20eU61NXcfwxjkqSZwt256GpOrdS-A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Random row

2014-12-20 Thread m1chael
you keep overwriting your random_choice every time the loop is run,
getting the last result is expected


On Sat, Dec 20, 2014 at 4:37 PM, Dariusz Mysior  wrote:
> Why I get only last row from my csv file, why I don't get in any time ranom
> row :/
>
> import csv, random
>
> def new_name():
> with open('PL_surnames.csv', newline='') as csvfile:
> namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
> for row in namesreader:
> #print (','.join(row))
> random_choice=random.choice(row)
> return random_choice
> print(new_name())
>
>
> --
> 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/07b16c6a-ca3a-4b42-8c72-33981c05d317%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/CAAuoY6P-D047pgcQhxZQJ1Y9v6vHUkJyr3H-DiDm9aB6NSvCXQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Random row

2014-12-20 Thread Cal Leeming
Somewhat off-topic for django-users, this would have been better placed on
StackOverflow.

If I understood your question correctly, I think you need to remove the
"for row in namesreader" and replace with;

namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
return random.choice(row)

On Sat, Dec 20, 2014 at 9:37 PM, Dariusz Mysior 
wrote:

> Why I get only last row from my csv file, why I don't get in any time
> ranom row :/
>
> import csv, random
>
> def new_name():
> with open('PL_surnames.csv', newline='') as csvfile:
> namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
> for row in namesreader:
> #print (','.join(row))
> random_choice=random.choice(row)
> return random_choice
> print(new_name())
>
>
>  --
> 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/07b16c6a-ca3a-4b42-8c72-33981c05d317%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/CAHKQagEW5MgpEWnKnrPz%2Bk%3DWKVoDpXF%3Dq8PH%3Dse1p_d8CtY-WA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Random row

2014-12-20 Thread Dariusz Mysior
Why I get only last row from my csv file, why I don't get in any time ranom 
row :/

import csv, random

def new_name():
with open('PL_surnames.csv', newline='') as csvfile:
namesreader = csv.reader(csvfile, delimiter=' ', quotechar='|') 
for row in namesreader:
#print (','.join(row))
random_choice=random.choice(row)
return random_choice
print(new_name())


-- 
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/07b16c6a-ca3a-4b42-8c72-33981c05d317%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(yet another) Custom templatetag raising KeyError when DEBUG=False

2014-12-20 Thread Alexandre Provencio
Hello all, this is a cross post i made on stackoverflow
http://stackoverflow.com/questions/27503581/yet-another-custom-templatetag-raising-keyerror-when-debug-false

I'm trying to use a custom templatetag (this one actually:
https://djangosnippets.org/snippets/2875/), on my project which works
fine as long as DEBUG=True. When it's False, the relevant error part
is:

File "...app/templatetags/helper_tags.py", line 15, in change_lang
path = context['request'].path
File "...local/lib/python2.7/site-packages/django/template/context.py",
line 56, in __getitem__
raise KeyError(key)
KeyError: 'request'

I've seen a lot of questions like this and I have already done the
settings that all of them seen to suggest which are:

1) views.py uses django.shortcuts.render:

from django.shortcuts import render
def home(request):
return render(request, 'home.html')

2) settings.py contains:

ALLOWED_HOSTS = ['*']

from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
"django.core.context_processors.request",
)

I've also created a new project with the same Django version (1.6.2)
that tries to imitate the problematic project as much as possible, and
for my despair it works fine also when DEBUG=False.

Any hints on this is very much appreciated.

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/CALaPA7BtpQsXj%2BQPPXetq8RtaTB_RjC_jm7HDE8Zt0i_L0tc9Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Database queries location

2014-12-20 Thread pythonista
Thank you for your response.  

Most of my data is complex raw sql.
I had placed it in the views and it is working as expected

I would like to migrate the raw sql to managers, 
Can you point me to one or more good examples of how the manager is coded 
and how the sql interacts with the views.

Thanks


On Friday, December 19, 2014 7:06:54 AM UTC-5, aRkadeFR wrote:
>
> Depend exactly on what to compute for your post data. 
>
> I would almost write no logic code in the views. 
>
> I split every application as follow: 
> - managers.py: All the logic as a table level (raw SQL, complex queries) 
> - models.py: All logic as a row level / object level (python computing 
> data) 
> - forms.py: All logic as forms data / processing / validation for 
> request data 
>
> Have a good one, 
>
> aRkadeFR 
>
> On 12/18/2014 10:12 PM, pythonista wrote: 
> > I understand that functions can be placed in the models fille 
> > 
> > However if I have complex queries that receive post input does the 
> > 
> > 
> > Query live in the model  the views or an external module 
> > 
>
>

-- 
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/949a0a58-bc51-4bbc-91bb-87e29b5b5f4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.