Re: invalid syntax inside urls.py

2012-12-18 Thread Chris Cogdon
Need a comma between the view name, and {'queryset...' and your parenthesis 
are not nested properly.

On Tuesday, December 18, 2012 12:19:24 PM UTC-8, maiquel wrote:
>
> 'm trying to do the following
>
> Artigo.objects.all () inside urls.py
>
> urlpatterns = patterns ('',
>  # url (r '^ blog / $', 'blog.views.archive_index.index')
>  (r '^ $', 'django.views.generic.date_based.archive_index'
>  {'queryset': Artigo.objects.all ()), # invalid syntax
>  'date_field', 'publication'})
>  (url (r '^ admin /', include (admin.site.urls)),
> )
>
> []`s
>
> Maiquel Knechtel
>

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



Re: Strange behavior using ModelForms

2012-12-18 Thread Chris Cogdon
Rather than comparing to instance, why not compare to request.user ?

On Tuesday, December 18, 2012 1:11:21 PM UTC-8, fvianna wrote:
>
> Hello everyone,
>
> I want to apologize if I came to the wrong place to talk about this, but 
> I've been using Django for a while now, and crossed to a very strange 
> behavior that hits me as bug, but I'm not quite sure. First time trying to 
> get a little deeper and maybe report something to help the community.
>
> Django's "How to contribute" page lead me to FAQ, and then here.
>
>
>
> So, I have a ModelForm to edit some of my auth.User data, here it is:
>
> class UserForm(ModelForm):
> """ ModelForm for user relevant fields """
>
> class Meta:
> model = User
> fields = ('first_name', 'last_name', 'email')
>
> def clean_email(self):
> cleaned_data = super(UserForm, self).clean()
> unavailable_error = ValidationError("Unavailable")
> invalid_error = ValidationError("Invalid")
>
> email = cleaned_data.get("email")
> if email:
> try:
> user_from_form_email = User.objects.get(email=email)
> if user_from_form_email != self.instance:
> raise unavailable_error
> except User.DoesNotExist:
> pass
> except User.MultipleObjectsReturned:
> raise unavailable_error
> else:
> raise invalid_error
>
> # Always return the full collection of cleaned data.
> return cleaned_data.get("email")
>
> Pretty straightforward, with a "unique" verification for the email.
> In my view, I receive the form with some edited data from a user. The view 
> looks as it follows (just ignore the ajax stuff and error returning):
>
>
> def edit_basic_info(request, id):
> response = {'success': False, 'errors': []}
>
> if request.method == 'POST' and request.is_ajax():
> u_form = UserForm(request.POST, instance=request.user)
>
> if u_form.is_valid():  
> if u_form.instance.email != u_form.cleaned_data['email']:
> tmp_profile = u_form.instance.get_profile()
> tmp_profile.email_confirmed = False
> tmp_profile.save()  
> 
>   u_form.save()
> response['success'] = True
> else:
> response['errors'].append(u_form.errors)
>
>
> When I get to test if the form e-mail is diferent from the instance e-mail 
> in order to set a flag in my model, both emails 
>
> u_form.instance.email
>
> and
>
> u_form.cleaned_data['email']
>
> are the same. After some debugging, I realized they become the same after 
> calling "is_valid" to the bound form. Now, I'm not sure if I am missing 
> something conceptually about ModelForms binding.
> Its very ackward to me that I can have a 'instance' field in a ModelForm, 
> but can't distiguish the data after performing the validation. In my case 
> specifically, I need to check first if the email provided by the user is 
> valid, and only then check if its diferent from the instance's e-mail in 
> order to set my flag. But I can't do it, or I will lose the new e-mail 
> provided by the user in the form.
>
> Can anyone enlighten this matter? Is this behavior expected? 
> Thank you for your time. 
>

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



Re: template caching context variables when no caching enabled.

2012-12-18 Thread Chris Cogdon
Parameter 2 to "render_to_response" is only expecting a dictionary, not a 
Context/RequestContext, so, it will grab your 'dictionary-like object' and 
wrap it in its own Context, meaning that none of your template context 
processors will run  (since those require a RequestContext)

I suggest using the even more shortcutty "render":

return render ( request, 'document_manager/document_revert.html', context )

which to me is just cleaner than anything


> Any idea why this happens?
>

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



Re: Converting Django app into a Desktop app

2012-12-18 Thread Chris Cogdon
No Python included with xampp... this makes me sad ;_;


On Tuesday, December 18, 2012 11:43:56 AM UTC-8, peter_julian wrote:
>
>  You can use xampp. Create a automatic installer that install xampp and 
> django with your app.
> Just like Kordi EDMS. http://www.kordil.net/.
>  

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



Re: problem with timeout

2012-12-18 Thread Chris Cogdon
Nice find!

If you turn debugging on for "django.db.backends", it will show you what 
SQL queries are being issued, and the time taken for each.

LOGGING['handlers']['console'] = { 'level':'DEBUG', 'class': 
'logging.StreamHandler' }
LOGGING['loggers']['django.db.backends'] = { 'handlers':['console'], 
'level':'DEBUG' }

(you could also just modify the existing LOGGING variable)

On Monday, December 17, 2012 11:42:07 PM UTC-8, Szabo, Patrick (LNG-VIE) 
wrote:
>
>   Nevermind…select_related() did the trick. 
>
> 226 queries cut to 4…amazing this little statement J
>
>
>   

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



Re: cached template loader

2012-12-18 Thread Chris Cogdon
your two versions are actually identical :)

The missing comma, I assume, was missing 
after django.template.loaders.app_directories.Loader ... without the comma 
there, python sees two strings right next to each other, and thus 
concatenates them, resulting in a single parameter 
: 
'django.template.loaders.app_directories.Loaderdjango.template.loaders.filesystem.Loader'

On Tuesday, December 18, 2012 2:40:02 AM UTC-8, Tom Martin wrote:
>
> I had the same problem and discovered that I was missing a comma in the 
> settings file:
>
> TEMPLATE_LOADERS = (
> ('django.template.loaders.cached.Loader, (
> 'django.template.loaders.app_directories.Loader',
> 'django.template.loaders.filesystem.Loader,
> ))
> )
>
> should have been:
>
> TEMPLATE_LOADERS = (
> ('django.template.loaders.cached.Loader, (
> 'django.template.loaders.app_directories.Loader',
> 'django.template.loaders.filesystem.Loader,
> ))
> )
>
> Pretty subtle issue, I'm not sure how the missing comma causes it.
>
> On Tuesday, July 6, 2010 1:45:27 PM UTC+1, Sævar Öfjörð wrote:
>>
>> I've also tried passing this through 
>> django.shortcuts.render_to_response, but I get the same error. 
>> - Sævar 
>>
>> On Jul 6, 2:41 pm, Sævar Öfjörð  wrote: 
>> > Hi, I've been using the default template loaders and it works fine. 
>> > Now I want to add the cached template loader, but I get an error. 
>> > 
>> > I'm using a wrapper function to return responses that include the 
>> > request in the context, like this: 
>> > 
>> > # file helpers/helpers.py 
>> > from django.template import RequestContext, loader 
>> > from django.http import  HttpResponse 
>> > 
>> > def return_response(request, dictionary, template, headers={}): 
>> > t = loader.get_template(template) 
>> > c = RequestContext(request, dictionary) 
>> > res = HttpResponse(t.render(c)) 
>> > for h, v in headers.iteritems(): 
>> > res[h] = v 
>> > return res 
>> > 
>> > The stacktrace: 
>> > 
>> > Traceback: 
>> > File "/home/django/project/virtualenv/lib/python2.6/site-packages/ 
>> > django/core/handlers/base.py" in get_response 
>> >   106. response = middleware_method(request, 
>> > e) 
>> > File "/home/django/project/virtualenv/lib/python2.6/site-packages/ 
>> > django/core/handlers/base.py" in get_response 
>> >   100. response = callback(request, 
>> > *callback_args, **callback_kwargs) 
>> > File "/home/django/project/project/views.py" in index 
>> >   24.   return helpers.return_response(request, d, 'frontpage.html') 
>> > File "/home/django/project/project/helpers/helpers.py" in 
>> > return_response 
>> >   129.  t = loader.get_template(template) 
>> > File "/home/django/project/virtualenv/lib/python2.6/site-packages/ 
>> > django/template/loader.py" in get_template 
>> >   157. template, origin = find_template(template_name) 
>> > File "/home/django/project/virtualenv/lib/python2.6/site-packages/ 
>> > django/template/loader.py" in find_template 
>> >   128. loader = find_template_loader(loader_name) 
>> > File "/home/django/project/virtualenv/lib/python2.6/site-packages/ 
>> > django/template/loader.py" in find_template_loader 
>> >   104. func = TemplateLoader(*args) 
>> > 
>> > Exception Type: TypeError at / 
>> > Exception Value: __init__() takes exactly 2 arguments (1 given) 
>> > 
>> > Is there some different way I should approach the template loading?
>
>

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



Re: web gui for email server

2012-12-18 Thread Chris Cogdon
I don't know of any. (Nothing comes up 
on http://www.djangopackages.com/grids/g/email/) But I might be able to say 
why you might not find any.

Desktop e-mail clients usually consist of the interface plus a local cache. 
The client connects to the mail storage and (via POP or IMAP) retrieves 
what messages there are, and may retrieve a copy of the messages, and cache 
them for quicker access and indexing.

Conversely, a web based client often does _not_ include a cache, but 
instead simply uses a connection to the mail storage via IMAP as its 
database, which still has some rudimentary features such as searching and 
indexing, etc. So, why bother having a separate database if IMAP does just 
about all you need?

And since there's no local database, the actual web app itself becomes 
stateless, and thus a lot of Django's benefit is not used. Sure, there can 
be some.. such as maintaining session state separately from the IMAP 
connection.




On Tuesday, December 18, 2012 8:02:13 AM UTC-8, davidjensen wrote:
>
> I am using the mailgun emailserver which has an api but not a web gui. 
> mailgun suggests using an desktop client. Are there web guis for email 
> servers written for django?
>

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



Re: Converting Django app into a Desktop app

2012-12-18 Thread Chris Cogdon
I think what Loai is asking for is a way to "wrap up" the python/django 
application, along with a light-weight webserver (not as light-weight as 
"runserver" though), so it looks like a stand-alone application... apart 
from needing to run a web browser to connect to it.

I, too, am very interested in this.

Just doing some cursory poking around, here's some starting points:

Python Freeze: http://wiki.python.org/moin/Freeze

cx_Freeze: http://cx-freeze.sourceforge.net

Py2Exe: http://wiki.python.org/moin/Py2Exe

py2app: http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html


These handle turning the python program into a stand-alone executable. It 
doesn't solve the web-server issue, though. There are a ton of choices 
there (eg: gunicorn, twisted, tornado, web.py) but I have no opinion on 
which one is going to both "freeze" well, serve static files well, and work 
well with Django



On Tuesday, December 18, 2012 8:06:19 AM UTC-8, Loai Ghoraba wrote:
>
> Hi
>
> I am very comfortable with Django, and I was wondering about whether there 
> is some way to convert a Django web app into a Desktop app (may be not 
> 100%), so that I can distribute it to users. May be wrapping it in a light 
> web server "if there is something like this". 
>
> Thanks
>

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



Re: IntegrityError

2012-12-17 Thread Chris Cogdon
I'd need to see the source for Job and that other model, plus a proper 
exception traceback, so I can tell at what point the IntegrityError is 
being thrown.

also, you should not be using form.save() there... if you do a commit=False 
to get a copy of the model, you only need to save that model... re-saving 
the form again is probably an error.

On Monday, December 17, 2012 10:55:00 PM UTC-8, sandy wrote:
>
> On Tue, Dec 18, 2012 at 2:48 AM, Satinderpal Singh 
> > wrote: 
> > I created a search box for searching the information about the client 
> > so that this information uses to create the report. 
>
> add these lines : 
>
> > def search(request): 
>  
> >   {% endfor %} 
> > 
> > i want to get job id to be saved through header view: 
> > def header(request): 
>job =Job.objects.get(id=request.GET['q']) 
> > if request.method=='POST': 
> > form = headForm(request.POST) 
> > if form.is_valid(): 
> > cd = form.cleaned_data 
>profile = form.save(commit=False) 
>profile.job = job 
>profile.save() 
>form.save() 
> > HttpResponseRedirect(reverse('Automation.report.views.result')) 
> > 
> > But get the following error: 
> > IntegrityError at /report/header/ 
> > (1048, "Column 'job_id' cannot be null") 
> > 
> > Please anybody tell me where i am wrong? 
> > 
> Hope this helps you. 
>
> -- 
> Sandeep Kaur 
> E-Mail: mkaur...@gmail.com  
> Blog: sandymadaan.wordpress.com 
>

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



Re: IntegrityError

2012-12-17 Thread Chris Cogdon
Can you post the code for the model, and the complete exception trace? I 
ask you use something that will properly maintain the intending, such as 
pastebin or dpaste.

On Monday, December 17, 2012 1:18:54 PM UTC-8, Satinderpal Singh wrote:
>
> I created a search box for searching the information about the client 
> so that this information uses to create the report. 
> def search(request): 
> query = request.GET.get('q', '') 
> if query: 
> results = Job.objects.filter(id = 
> query).values('client__client__name','client__client__address_1','clientjob__material__name','suspencejob__field__name','id','job_no','date','site','report_type',)
>  
>
> else: 
> results = [] 
> return render_to_response("report/search.html", {"results": 
> results,"query": query}) 
>
> I want to save the value of job in the report table to create a report 
> like: 
>   {% for job in results %} 
> Job Id : {{ job.id }} 
> Name:{{job.client__client__name}} 
> Job No. : {{job.job_no}} 
> Site : {{job.site}} 
> Reference Letter No : {{job.Reference_Letter_no}} 
> Letter Date : {{job.Letter_date}} 
> Address : {{job.client__client__address_1}} 
> Material : {{job.clientjob__material__name}} 
> Report 
>   {% endfor %} 
>
> i want to get job id to be saved through header view: 
> def header(request): 
> if request.method=='POST': 
> form = headForm(request.POST) 
> if form.is_valid(): 
> cd = form.cleaned_data 
> form.save() 
> return 
> HttpResponseRedirect(reverse('Automation.report.views.result')) 
>
> But get the following error: 
> IntegrityError at /report/header/ 
> (1048, "Column 'job_id' cannot be null") 
>
> Please anybody tell me where i am wrong? 
>
>
>
>
> -- 
> Satinderpal Singh 
> http://satindergoraya.blogspot.in/ 
> http://satindergoraya91.blogspot.in/ 
>

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



Re: Unexpected behavior with regexp model filtering (Sqlite)

2012-12-17 Thread Chris Cogdon
And for completeness, here's how django implements the regex function when 
using sqlite3:

def _sqlite_regexp(re_pattern, re_string):
try:
return bool(re.search(re_pattern, re_string))
except:
return False



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



Re: Unexpected behavior with regexp model filtering (Sqlite)

2012-12-17 Thread Chris Cogdon
Django uses "search" rather than "match" for the _regex option. If you want 
match, make sure the regex starts with a ^

On Monday, December 17, 2012 6:55:09 PM UTC-8, Beni wrote:
>
> Hi,
>
> I'm getting stuck on figuring out why regex searches are matching any part 
> of a field when I use my model's regexp filter (instead of matching 
> linearly); they're behaving like calls to re.search instead of re.match.
>
> Since I'm using Sqlite, I registered my own function based on Python's 
> re.match. I tried testing the function in a shell by directly connecting to 
> the database to search the field and comparing those results to using the 
> model's regexp filter. The filter returns significantly more items and when 
> I test to see if they are strict matches for the regexp the 'extra' ones 
> fail. 
> I'm attaching a transcript of the shell tests.
>
> Any insight or advice would be greatly appreciated.
>
> Beni
>

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



Re: Django back button issue after log-out

2012-12-17 Thread Chris Cogdon
But that means you're going to need to wrap _all_ your views in that 
structure, and that also means that none of those views will be cacheable.

That could be desirable, depending on your application.

You might also want to consider using @vary_on_cookie, which means that the 
cache will be specific to that user only for the current cookie values. a 
"logout" will clear the session cookies, and thus the cache is invalid.

On Monday, December 17, 2012 6:07:49 AM UTC-8, Ashish Sable wrote:
>
> yup... Got the solution just the bower cache needs to be cleared.
>
> from django.views.decorators.cache import cache_control
>
> @cache_control(no_cache=True, must_revalidate=True, no_store=True)
> def view():
>
> After logout it will render to login page.
>
> On Monday, 17 December 2012 18:39:25 UTC+5:30, ke1g wrote:
>>
>>
>>
>> On Mon, Dec 17, 2012 at 5:14 AM, Ashish Sable wrote:
>>
>>>
>>> I have written simple registration(login,logout) Django apps.
>>>  when i click on logout and then back button from browser 
>>> it shows me previous page. it should redirect me to login page. please 
>>> help
>>>
>>>
>>  The back button in your browser just shows you cached stuff.  It doesn't 
>> contact the server, so there is nothing Django can do.
>>
>

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



Re: How to stop my views from cacheing

2012-12-17 Thread Chris Cogdon
What you're doing is saying "any _new_ results returned from this view are 
uncacheable", but that doesn't impact the results that are in the cache 
already.

Read up on this section to see how to "invalidate" the existing cache:

https://docs.djangoproject.com/en/1.4/topics/cache/#cache-versioning


On Monday, December 17, 2012 7:26:45 PM UTC-8, Dwayne Ghant wrote:
>
> Thanks Chris,
>
> That's exactly what I thought I was doing. Can you please tell me what 
> missed? How, exactly do unclear the cache; if that's not what I'm currently 
> doing?
>
> On Monday, December 17, 2012, Chris Cogdon wrote:
>
>> You'll need to clear the cache. Remember, once the view is cached, django 
>> wont go down to the view until the cache thinks the content has expired.
>>
>>
>> On Monday, December 17, 2012 5:14:56 PM UTC-8, Dwayne Ghant wrote:
>>>
>>> Hello All: 
>>>
>>> I have a python view that I'm building but the for some strange reason 
>>> the view keeps caching.  Just to give an example: 
>>>
>>> @api_view(['POST'])
>>> @parser_classes((XMLParser,))
>>> @cache_page(0)
>>> @cache_control(private=True)
>>> def test_view(request, format=None):
>>> return Response({'received data TESTING2': 'testing'})
>>>
>>> Doesn't return "received data TESTING2': testing ." Instead, it keep 
>>> returning the old cached information. Can some please tell me how to 
>>> explicitly turn off caching while I'm still developing?  It a pain!! I I 
>>> have listed the references below that I used to trouble shoot: 
>>>
>>> https://docs.djangoproject.**com/en/dev/topics/cache/?from=**
>>> olddocs#the-per-view-cache<https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs#the-per-view-cache>
>>> https://docs.djangoproject.**com/en/dev/ref/settings/#std:**
>>> setting-CACHES<https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-CACHES>
>>> https://docs.djangoproject.**com/en/dev/topics/cache/<https://docs.djangoproject.com/en/dev/topics/cache/>
>>>
>>>
>>> Any help would be deeply appreciated. 
>>>
>>> Thanx
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/ImrvggfbaEkJ.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>

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



Re: How to stop my views from cacheing

2012-12-17 Thread Chris Cogdon
You'll need to clear the cache. Remember, once the view is cached, django 
wont go down to the view until the cache thinks the content has expired.


On Monday, December 17, 2012 5:14:56 PM UTC-8, Dwayne Ghant wrote:
>
> Hello All: 
>
> I have a python view that I'm building but the for some strange reason the 
> view keeps caching.  Just to give an example: 
>
> @api_view(['POST'])
> @parser_classes((XMLParser,))
> @cache_page(0)
> @cache_control(private=True)
> def test_view(request, format=None):
> return Response({'received data TESTING2': 'testing'})
>
> Doesn't return "received data TESTING2': testing ." Instead, it keep 
> returning the old cached information. Can some please tell me how to 
> explicitly turn off caching while I'm still developing?  It a pain!! I I 
> have listed the references below that I used to trouble shoot: 
>
>
> https://docs.djangoproject.com/en/dev/topics/cache/?from=olddocs#the-per-view-cache
> https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-CACHES
> https://docs.djangoproject.com/en/dev/topics/cache/
>
>
> Any help would be deeply appreciated. 
>
> Thanx
>
>

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



How to distribute a hybrid Django project/app ??

2012-12-17 Thread Chris Cogdon
[Firstly, sorry if this appears to be a repost: I'd written a lengthy 
question previously and posted, but never saw it up in the listing. Did the 
ThreadMonster eat it?]

I'm putting the final touches on a art show management tool, written for 
Django of course, and I am seeing opinions on the best way to arrange its 
structure to be as useful as possible to others.

I want to both have this able to be used as a stand-alone application, with 
minimal interaction with Django, and also as an application that can be 
used in a larger project. The two aren't necessarily compatible, but I've 
seen a few projects now seem to fit both bills well and am considering 
using this pattern.

The project is distributed as one directory tree using the Django-1.4 
struture, with some minor re-arrangements of the settings files

ProjectName
+-- __init__.py (so that ProjectName can be imported as a python Module)
+-- ProjectName
+-- common_settings.py
+-- App1
+-- App2
+-- manage.py
+-- local_settings.py (imports common_settings)

If someone wanted to just use this as a standalone application (in the 
general sense), then they'd make changes to local_settings.py, syncdb and 
migrate, then start up whatever webservice they wanted configured.

If someone wanted to use the apps provided in their own Django project, 
then they'd install the above directory as a python package, then include 
ProjectName.App1 in their INSTALLED_APPS setting. The internal ProjectName 
and any settings files are now ignored.


In either case, the entire tree above would be available as a PyPI package, 
as well as via github.


Does that sound like a good, useful, plan? In the alternate, does anyone 
have other suggestions worth looking at ?

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



Re: django doesn't send me error mails

2012-12-17 Thread Chris Cogdon
I don't have any magic answers for you yet.

My only suggestion would be to find out what's different in the environment 
between running as uwsgi and running under runserver. Perhaps something in 
the environment, or perhaps the username under which django runs in either 
case.

/var/log/maillog is going to provide good information... see if you can get 
hold of it from your provider.



On Monday, December 17, 2012 8:30:36 AM UTC-8, Ali Vakilzade wrote:
>
> ok, after this answer a said I sghoulf test django internal server
> I simply started server with runserver
> (didn't change email backend)
> and the mail sending worked!
>
> so now I think It's a uwsgi related problem
> but I couldn't fine anything about that
>
> (there was a page on stackoverflow saying run uwsgi in threader mode but 
> it didn't help)
>
> http://stackoverflow.com/questions/8549371/mysterious-issue-with-django-uwsgi-send-email
>
>
> در دوشنبه 17 دسامبر 2012، ساعت 7:07:18 (UTC+3:30)، Chris Cogdon نوشته:
>>
>> My best guess is that the mail transport agent on the server is rejecting 
>> the mail because something is different from mail that is send through 
>> other places in your django code. Perhaps the mail "sender" is not correct, 
>> for example?
>>
>> Unfortunately, looking at the mail log is the best way to see what's 
>> happening. If that's not available, you might want to see what is being 
>> sent.
>>
>> Set this:
>>
>> EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
>>
>> and then run your project with "runserver". The mail that it tries to 
>> send will be sent to the console instead. Check out the "from" headers and 
>> make sure they make sense. Compare that to the other kinds of email that 
>> are sent.
>>
>> (Make sure you're still running with DEBUG=False)
>>
>>
>>
>> On Sunday, December 16, 2012 2:18:26 PM UTC-8, Ali Vakilzade wrote:
>>>
>>> I don't have access to that file on server.
>>> and log from uwsgi doesn't have any error massage about mail sending
>>>
>>> can it be a python3 branch related bug?
>>>
>>>
>>> در دوشنبه 17 دسامبر 2012، ساعت 1:36:05 (UTC+3:30)، Chris Cogdon نوشته:
>>>>
>>>> Oh... there's your problem... you've set the admin email to ... i'm 
>>>> sure that doesn't exist! :)
>>>>
>>>> Seriously, though... all that looks correct. Can you check your 
>>>> server's /var/log/maillog to see if the mail is being accepted?
>>>>
>>>> On Sunday, December 16, 2012 1:33:01 PM UTC-8, Ali Vakilzade wrote:
>>>>>
>>>>> I can send mails using send_mail or mail_admins methods
>>>>>
>>>>> but django it self doesn't send me any mail on 404 error or 500 error.
>>>>>
>>>>> I have even added  raise Exception('Test') to my view function
>>>>> I see the 500 error for that but no mail was sent
>>>>>
>>>>> This is my settings.py: http://dpaste.com/846959/
>>>>>
>>>>> I use :
>>>>> django from git master
>>>>> python 3.2
>>>>>
>>>>>

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



Re: django doesn't send me error mails

2012-12-16 Thread Chris Cogdon
My best guess is that the mail transport agent on the server is rejecting 
the mail because something is different from mail that is send through 
other places in your django code. Perhaps the mail "sender" is not correct, 
for example?

Unfortunately, looking at the mail log is the best way to see what's 
happening. If that's not available, you might want to see what is being 
sent.

Set this:

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

and then run your project with "runserver". The mail that it tries to send 
will be sent to the console instead. Check out the "from" headers and make 
sure they make sense. Compare that to the other kinds of email that are 
sent.

(Make sure you're still running with DEBUG=False)



On Sunday, December 16, 2012 2:18:26 PM UTC-8, Ali Vakilzade wrote:
>
> I don't have access to that file on server.
> and log from uwsgi doesn't have any error massage about mail sending
>
> can it be a python3 branch related bug?
>
>
> در دوشنبه 17 دسامبر 2012، ساعت 1:36:05 (UTC+3:30)، Chris Cogdon نوشته:
>>
>> Oh... there's your problem... you've set the admin email to ... i'm 
>> sure that doesn't exist! :)
>>
>> Seriously, though... all that looks correct. Can you check your server's 
>> /var/log/maillog to see if the mail is being accepted?
>>
>> On Sunday, December 16, 2012 1:33:01 PM UTC-8, Ali Vakilzade wrote:
>>>
>>> I can send mails using send_mail or mail_admins methods
>>>
>>> but django it self doesn't send me any mail on 404 error or 500 error.
>>>
>>> I have even added  raise Exception('Test') to my view function
>>> I see the 500 error for that but no mail was sent
>>>
>>> This is my settings.py: http://dpaste.com/846959/
>>>
>>> I use :
>>> django from git master
>>> python 3.2
>>>
>>>

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



Re: django doesn't send me error mails

2012-12-16 Thread Chris Cogdon
Oh... there's your problem... you've set the admin email to ... i'm 
sure that doesn't exist! :)

Seriously, though... all that looks correct. Can you check your server's 
/var/log/maillog to see if the mail is being accepted?

On Sunday, December 16, 2012 1:33:01 PM UTC-8, Ali Vakilzade wrote:
>
> I can send mails using send_mail or mail_admins methods
>
> but django it self doesn't send me any mail on 404 error or 500 error.
>
> I have even added  raise Exception('Test') to my view function
> I see the 500 error for that but no mail was sent
>
> This is my settings.py: http://dpaste.com/846959/
>
> I use :
> django from git master
> python 3.2
>
>

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



Re: getting "DateTimeField received a naive datetime" error but have no DateTimeFields

2012-12-16 Thread Chris Cogdon
Awesome. Thanks for the update.

On Sunday, December 16, 2012 3:56:22 AM UTC-8, bobhaugen wrote:
>
> Wrapping this up:  the problem was caused by South, happened in migrate 
> (found via stack trace).  When I upgraded South, the problem went away.

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



Re: getting "DateTimeField received a naive datetime" error but have no DateTimeFields

2012-12-14 Thread Chris Cogdon
Well, I did all that (and I learned a few things in the process that will 
be useful for my own project... thank you!)

I never got the warnings you got, but I got three errors along the lines of:

==
ERROR: test_mismatched_agents1 
(valuenetwork.valueaccounting.tests.CompensationTest)
--
Traceback (most recent call last):
  File 
"/Users/ccogdon/dev/valuenetwork/valuenetwork/valuenetwork/valueaccounting/tests.py",
 
line 30, in setUp
self.agent_A.save()
  File 
"/Users/ccogdon/dev/valuenetwork/valuenetwork/valuenetwork/valueaccounting/models.py",
 
line 196, in save
super(EconomicAgent, self).save(*args, **kwargs)
  File 
"/Users/ccogdon/dev/valuenetwork/lib/python2.7/site-packages/django/db/models/base.py",
 
line 463, in save
self.save_base(using=using, force_insert=force_insert, 
force_update=force_update)
  File 
"/Users/ccogdon/dev/valuenetwork/lib/python2.7/site-packages/django/db/models/base.py",
 
line 551, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, 
using=using, raw=raw)
  File 
"/Users/ccogdon/dev/valuenetwork/lib/python2.7/site-packages/django/db/models/manager.py",
 
line 203, in _insert
return insert_query(self.model, objs, fields, **kwargs)
  File 
"/Users/ccogdon/dev/valuenetwork/lib/python2.7/site-packages/django/db/models/query.py",
 
line 1576, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
  File 
"/Users/ccogdon/dev/valuenetwork/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 
line 910, in execute_sql
cursor.execute(sql, params)
  File 
"/Users/ccogdon/dev/valuenetwork/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py",
 
line 337, in execute
return Database.Cursor.execute(self, query, params)
IntegrityError: valueaccounting_economicagent.created_date may not be NULL


Want me to grab a different revision from git ?

On Friday, December 14, 2012 5:27:04 PM UTC-8, bobhaugen wrote:
>
> Also, I recognize this is way beyond the call of duty, but if you 
> really want to reproduce the problem, you might need to follow: 
> https://github.com/valnet/valuenetwork/blob/master/docs/install.txt 
>
> On Fri, Dec 14, 2012 at 7:06 PM, Chris Cogdon > 
> wrote: 
> > Checked out the code and attempted to run "manage.py test", but clearly 
> I 
> > don't have all the required modules installed. Sure is a lot of them! 
>

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



Re: getting "DateTimeField received a naive datetime" error but have no DateTimeFields

2012-12-14 Thread Chris Cogdon
Checked out the code and attempted to run "manage.py test", but clearly I 
don't have all the required modules installed. Sure is a lot of them!

Are you running tests using "manage.py test" ??  If so, have you considered 
that its not _your_ code that is showing up those errors, but that of one 
of the other modules? Take your module out of INSTALLED_APPS and re-run 
test. Still happening? Then it ain't you! :)


On Friday, December 14, 2012 4:09:25 PM UTC-8, bobhaugen wrote:
>
> On Fri, Dec 14, 2012 at 6:07 PM, Chris Cogdon > 
> wrote: 
> > Throw the code up somewhere I can see the results for myself? 
>
>
> https://github.com/valnet/valuenetwork/blob/master/valuenetwork/valueaccounting/tests.py
>  
>

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



Re: getting "DateTimeField received a naive datetime" error but have no DateTimeFields

2012-12-14 Thread Chris Cogdon
Throw the code up somewhere I can see the results for myself?

On Friday, December 14, 2012 3:52:11 PM UTC-8, bobhaugen wrote:
>
> But sincerely, Chris, thanks for hanging in there on this.  I baffled. 
>
> On Fri, Dec 14, 2012 at 5:51 PM, Bob Haugen > 
> wrote: 
> > On Fri, Dec 14, 2012 at 5:42 PM, Chris Cogdon 
> > > 
> wrote: 
> >> Okay, so when you create your datetimes, are you defining them with a 
> >> timezone ? 
> > 
> > I tried that; did not make any difference.  The error messages came up 
> > before any of the test setup code ran.  (I put a pdb trace in at the 
> > start; the error messages had already happened.) 
> > 
> > I did not create any datetimes.  I did create dates, but they did not 
> > cause any errors. The errors had already arisen way before then. 
>

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



Re: Modelform and Ajax (Select a valid choice..... Error)

2012-12-14 Thread Chris Cogdon
Good... but we'd all appreciate knowing what was wrong, so we can guide 
others :)

On Thursday, December 13, 2012 9:05:44 PM UTC-8, siddharth56660 wrote:
>
> Hey Chris 
>
> Thanks for the replybut i figured it out what was wrong. 
> :) 
> -Siddharth 
> On Thu, Dec 13, 2012 at 6:09 PM, Chris Cogdon > 
> wrote: 
> > How are you populating the choices in the ChoiceField? Remember, you 
> need to 
> > do this on BOTH the POST AND the non-POST versions of creating the form. 
> > 
> > But ChoiceField is a Form field, not a Model field... so its not 
> perfectly 
> > clear what you're asking. 
> > 
> > 
> > On Tuesday, December 11, 2012 3:39:48 AM UTC-8, siddharth56660 wrote: 
> >> 
> >> Hi, 
> >> 
> >> I am facing problem in handling modelform and ajax together. 
> >> The situation is:- 
> >> I am using modelform to get display the form as ul in the template. 
> >> I have 3 ChoiceFields (country, state,city). On select of a country 
> >> from the dropdown, the valid states dropdown gets populated and on 
> >> select of a state the respective city dropdown gets populated. 
> >> For achieving the above functionality I am calling an ajax function 
> >> which returns me the available data of the other dropdown in Json Form 
> >> {stat_id, stat_name} 
> >> I am able to populate the data in next dropdown i.e state and city, 
> >> but when i click submit form it shows "Select a valid choice. 8 is not 
> >> one of the available choices" 
> >> 8 happens to be the stat_id in this case. 
> >> I have gone through google but dint find anything useful. Help is 
> >> really appreciated. 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msg/django-users/-/NEBq73A9EyEJ. 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > To unsubscribe from this group, send email to 
> > django-users...@googlegroups.com . 
> > For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en. 
>

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



Re: Helptext forms forms

2012-12-14 Thread Chris Cogdon
"Support": sure! I won't "do the work" for you though :)

Okay, Just reading through the django code, and I'm seeing that the 
help_text is _not_ emitted in the field's widget, but in the _html_output 
method of BaseForm In other words, you don't need to update the widget. 
Useless doing so.

So, to ask about the options above, do you want to override the behaviour 
of the admin, or your own code?

Do you use this often enough that you'll want to change the behaviour of 
as_p, as_table or as_ul, or are you happy to just take control of things on 
that side, yourself?

The standard behaviour is to put the help text into xxx ... its perfectly possible to use jQuery to 
replace all of those instances with whatever HTML you want.


So... which route is going to get you what you need ?


On Friday, December 14, 2012 12:52:23 PM UTC-8, 4 The good Life we work 
wrote:
>
> Hallo Chris, 
>
> thank you for the good explanation. 
> I'm then afread that I have to create my own widget for this. Can you 
> support me on this? 
>
> Thanks, 
> Tony Michael 
>
> On Fri 14 Dec 2012 08:45:40 PM CET, Chris Cogdon wrote: 
> > If you're designing your own HTML (eg: this is not in the admin) then 
> > there's nothing stopping you rendering the help text any way you want. 
> Eg: 
> > 
> > 
> > {{ form.field1 }} > onclick="showpopuphelp('{{ form.field1.help_text }}');return false;" /> 
> > 
> > (that might not exactly work as written, but using it to give you the 
> > gist of things... my preference would be to put the text into a  > class="fieldhelp> and use jQuery magic to wrap it up) 
> > 
> > If you were doing this a lot, and would prefer to stick with using {{ 
> > form.as_table }} (for example) and rely on the default HTML generators 
> > for each field, then you'll need to create your own widgets, probably 
> > inheriting from the standard widgets, and override the html generators. 
> > 
> > 
> > If you wanted to change how the fields were being displayed in the 
> > ADMIN, then that will require overriding the field widgets in the 
> > ModelAdmin's with your own widgets created the same way above. 
> > 
> > 
> > 
> > On Friday, December 14, 2012 5:16:49 AM UTC-8, 4 The good Life we work 
> > wrote: 
> > 
> > Hallo, 
> > I'm wondering if there is a better way to have helptext informs than 
> > help_text which is displayed under the form. 
> > Something like FIEDL ? while ? is a button I can click on and it 
> > displays the helptext. 
> > 
> > I'll welcome an example. 
> > 
> > Thanks, 
> > Tony 
> > 
>

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



Re: getting "DateTimeField received a naive datetime" error but have no DateTimeFields

2012-12-14 Thread Chris Cogdon
Okay, so when you create your datetimes, are you defining them with a 
timezone ?

On Friday, December 14, 2012 1:05:19 PM UTC-8, bobhaugen wrote:
>
> On Fri, Dec 14, 2012 at 3:02 PM, Chris Cogdon > 
> wrote: 
> > Nothing definitive, but from checking the location of the code that is 
> > raising the warning, I suspect one of the following: 
> > 
> > 1. USE_TZ is not set in your production code, but _is_ set in your 
> settings 
> > file for your tests. Of course, your code should work either way for the 
> > most flexibility. 
>
> USE_TZ is set in settings.py (in production code) 
> > 
> > 2. The test database you are using (ie, from fixtures or otherwise) has 
> > non-timezone dates and times, and USE_TZ is set in your testing settings 
> > files. In these cases your test data and the USE_TZ setting should be 
> > matching. 
>
> No fixtures. Creating test objects in the test setup code. 
>

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



Re: Model's optional __unicode__() return values?

2012-12-14 Thread Chris Cogdon
oops... that should be "if x is not None", not "where x is not None"... 
Clearly I am still half in SQL mode :)

On Friday, December 14, 2012 3:41:01 PM UTC-8, Chris Cogdon wrote:
>
> The pattern I use is ", ".join ( [ unicode(x) for x in ( thing_a, thing_b, 
> getattr(obj,"optional_attribute",None ), ...etc... ) where x is not None ] )
>
>
> On Friday, December 14, 2012 2:49:16 PM UTC-8, mhulse wrote:
>>
>> Hello, 
>>
>> This is probably a dumb question, but... 
>>
>> What's the best way to handle optional __unicode__() return values? 
>>
>> In this situation, I'm wanting to return the __unicode__ values from 
>> other models. 
>>
>> I've found myself doing a lot of this: 
>>
>> def __unicode__(self): 
>> return _(u'%s%s%s') % (self.target, (' | ' if self.page_type else 
>> ''), (self.page_type if self.page_type else '')) 
>>
>> Which works, but seems clunky. 
>>
>> I've tried: 
>>
>> return _(u'%s') % ' | '.join(filter(None, (self.target, getattr(self, 
>> 'page_type', None 
>>
>> But that gives me: 
>>
>> Caught TypeError while rendering: sequence item 0: expected string, 
>> Target found 
>>
>> Tips would be appreciated. :) 
>>
>> Thank you! 
>>
>> Cheers, 
>> M 
>>
>

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



Re: Model's optional __unicode__() return values?

2012-12-14 Thread Chris Cogdon
The pattern I use is ", ".join ( [ unicode(x) for x in ( thing_a, thing_b, 
getattr(obj,"optional_attribute",None ), ...etc... ) where x is not None ] )


On Friday, December 14, 2012 2:49:16 PM UTC-8, mhulse wrote:
>
> Hello, 
>
> This is probably a dumb question, but... 
>
> What's the best way to handle optional __unicode__() return values? 
>
> In this situation, I'm wanting to return the __unicode__ values from 
> other models. 
>
> I've found myself doing a lot of this: 
>
> def __unicode__(self): 
> return _(u'%s%s%s') % (self.target, (' | ' if self.page_type else 
> ''), (self.page_type if self.page_type else '')) 
>
> Which works, but seems clunky. 
>
> I've tried: 
>
> return _(u'%s') % ' | '.join(filter(None, (self.target, getattr(self, 
> 'page_type', None 
>
> But that gives me: 
>
> Caught TypeError while rendering: sequence item 0: expected string, Target 
> found 
>
> Tips would be appreciated. :) 
>
> Thank you! 
>
> Cheers, 
> M 
>

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



Re: getting "DateTimeField received a naive datetime" error but have no DateTimeFields

2012-12-14 Thread Chris Cogdon
Nothing definitive, but from checking the location of the code that is 
raising the warning, I suspect one of the following:

1. USE_TZ is not set in your production code, but _is_ set in your settings 
file for your tests. Of course, your code should work either way for the 
most flexibility.

2. The test database you are using (ie, from fixtures or otherwise) has 
non-timezone dates and times, and USE_TZ is set in your testing settings 
files. In these cases your test data and the USE_TZ setting should be 
matching.

On Friday, December 14, 2012 11:43:09 AM UTC-8, bobhaugen wrote:
>
> Thanks for the reply.
>
> On Friday, December 14, 2012 1:27:03 PM UTC-6, Chris Cogdon wrote:
>>
>> Would be nice to know what function's raising that error, and where the 
>> value came from. Requesting traceback, database type (tried it with more 
>> than one database type), and other information.
>>
>> It's in a test.   No real traceback, just a bunch of the same error 
> messages:
>
> ./manage.py test valueaccounting
> Creating test database for alias 'default'...
> /home/bob/.virtualenvs/vn2/lib/python2.6/site-packages/django/db/models/fields/__init__.py:808:
>  
> RuntimeWarning: DateTimeField received a naive datetime (2012-12-14 
> 19:41:27.469600) while time zone support is active.
>   RuntimeWarning)
> /home/bob/.virtualenvs/vn2/lib/python2.6/site-packages/django/db/models/fields/__init__.py:808:
>  
> RuntimeWarning: DateTimeField received a naive datetime (2012-12-14 
> 19:41:27.507916) while time zone support is active.
>   RuntimeWarning)
>
> Database is sqlite. 
>

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



Re: validation error in Django Admin

2012-12-14 Thread Chris Cogdon
Thanks for the follow up!

On Wednesday, December 12, 2012 4:21:59 PM UTC-8, Mike Dewhirst wrote:
>
> I'm getting an unexpected validation error in Admin which baffles me. 
> Any hints appreciated ... here is the traceback 
>
> http://dpaste.com/844972/ 
>
> At the bottom of the traceback where the error is raised, the local vars 
> are ... 
>
> self  
> value u'33' 
> key 'pk' 
>
> When I save the item, it auto-generates many-to-many connections to a 
> few standard images in the database via a through table. However there 
> is a rule which says "if ever these two images are connected to an item, 
> only keep this one and drop that one." 
>
> I use a post-save signal to "drop that one" using ... 
>
>Item_Pictogram.objects.filter(item=instance, pictogram=pic, 
> via='auto').delete() 
>
> The local var value above being u'33' happens to be the exact pk of the 
> Item_Pictogram record I want to delete - I checked in Postgres. 
>
> The pk should be an integer but I suppose that's nothing. 
>
> Thanks for any help 
>
> Mike 
>

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



Re: Helptext forms forms

2012-12-14 Thread Chris Cogdon
If you're designing your own HTML (eg: this is not in the admin) then 
there's nothing stopping you rendering the help text any way you want. Eg:


{{ form.field1 }}

(that might not exactly work as written, but using it to give you the gist 
of things... my preference would be to put the text into a https://groups.google.com/d/msg/django-users/-/ebt7rZSPRHQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Local thread variable (attempting to create a connection pool)

2012-12-14 Thread Chris Cogdon
What you essentially want is a common pattern called a "singleton": 
something that there is only one of, like "None" and "Elipsis". You can do 
something workable, but ugly, using module-level variables, but there are 
known patterns for creating singletons

Here's some starters:

http://stackoverflow.com/questions/42558/python-and-the-singleton-pattern




On Friday, December 14, 2012 9:33:19 AM UTC-8, Rafael Almeida wrote:
>
> Hello,
>
> I have a django application which needs to connect to some backend 
> services. Problem is I don't want to create a new connection everytime, but 
> to use a connection pool. One connection per thread would be fine, but I 
> don't know how to use django in order to achive that. I'd like to perhaps 
> save those connections on cache subsystem, but I don't know how to create 
> one key per thread, per worker.
>
> Thank you for your help,
> Rafael
>

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



Re: GeoDjango annotate distance

2012-12-14 Thread Chris Cogdon
Just did a cursory read of the geodjango documentation for the first 
time...the querysets being returned from "all()" (or really, just objects) 
need to be GeoQuerySets which have a default "position" as part of their 
specification (I think), also such modules need to inherit from the geo 
version of model.Model AND use a special GeoManager. So, once you use that 
special manager, there is a point, boundary or area tat all the geo 
functions refer to.

On Wednesday, December 12, 2012 1:15:44 PM UTC-8, mikegolf wrote:
>
> Hi,
> I've recently started learning GeoDjango and I'm a bit confused. 
> There's a GeoQuerySet method "distance" which annotates each object with 
> the distance to the given point, like that:
>
> pnt = 'POINT(coords... coords ...)'
> MyModel.objects.all().distance(pnt)
>
> but what field of the object does it take to calculate the distance?
> I'd like to do "classic" annotation, like that:
>
> MyModel.objects.all().annotate(distance_to_pnt = 
> Distance('location_attribute_of_MyModel', pnt))
>
> any tips?
> thanks
> mg
>

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



Re: getting "DateTimeField received a naive datetime" error but have no DateTimeFields

2012-12-14 Thread Chris Cogdon
Would be nice to know what function's raising that error, and where the 
value came from. Requesting traceback, database type (tried it with more 
than one database type), and other information.


On Friday, December 14, 2012 9:46:33 AM UTC-8, bobhaugen wrote:
>
> RuntimeWarning: DateTimeField received a naive datetime (2012-12-14 
> 17:39:38.878379) while time zone support is active.
>
> This is happening in my tests, but not in normal code.
>
> From dropping a trace in, it looks like it is happening before the test 
> setup even runs.
>
> I double-checked my models,  not a DateTimeField in the lot. Nor anywhere 
> else in my code except for South migrations, where it is found in 
> models['auth.user']. (But I'm not creating any Users in my test code, 
> either...)
>
> The tests run ok, but the error messages will be disconcerting to people 
> who install my open-source project code.
>
> Any clues?
>
> Thanks.
>
>

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



Best way to distribute a "standalone django application" ?

2012-12-14 Thread Chris Cogdon
I've been developing an art show management application (in both the 
general and Django senses) for the past few years, and have had it up on 
sourceforge and github for a while. It's very close to being "complete" and 
I'd like to make sure its as useful as possible to as wide an audience.

However, i'd like to distribute it in a form that is useful to both parties 
that want a "drop in and go" installation, and others that might use it as 
an app in a larger Django site. However, the two seem at loggerheads:

The first suggests I should have a single check out or download that 
includes the artshow app, the project, settings files (with instructions to 
modify certain parts). While the second suggests I should have a python 
module usable as a Django app, and include instructions on the required 
additions to middleware, context processors, and app-specific settings, and 
ensure it's installable from PyPI.

Catering for the one makes it harder for the other. Does anyone have 
suggestions on the "better" solution, or even some combination that caters 
to both well?

Project is currently here: http://github.com/chmarr/artshow-jockey/

Its currently in the former state, but with some "replaceable" components 
split out as a separate app. This was done mostly to demonstrate how to 
create a replaceable "Person" model, and did it in a way that shows that 
it's already effectively replaced. As is, the installation instructions for 
the django-noob are very simple, and I'd like to keep that attribute. Also, 
I'm considering rolling "peeps" "tinyreg" and the other "replaceable" 
modules back into the "artshow" module regardless... if anything to just 
make it look cleaner.

One idea that came to mind is to have the github repository show as a 
"stand alone application", just as it is now, but have the PyPI package 
only download the "artshow" component. Anyone that wants to both use 
artshow in their own Django site, but use the git checkout for the module, 
can simply check artshow-jockey out somewhere and put that into the python 
path. Does that seem feasible?

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



Re: How Alter Table to add foreign key to Django Models

2012-12-14 Thread Chris Cogdon
It doesn't look like you're using Django at all. I suggest taking your 
question to the support community for the database you're using.



On Thursday, December 13, 2012 4:53:25 AM UTC-8, laxglx wrote:
>
> Can anybody plz tell me how to add a foreign key an existing table using 
> SQL Queries?
> >> I got the command, nut can't understand 
>
> ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) 
> REFERENCES addresses (address) MATCH FULL;
>
>
> What's  "distfk" here if it is key name what is (address) ? and what is 
> addresses(address)?
> And What does mean Match Full
>
>
> Thanks in advance 
> laxglx
>

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



Re: How Alter Table to add foreign key to Django Models

2012-12-14 Thread Chris Cogdon
Are you sure you're using Django? This SQL statement does not look like 
something django would have emitted. Perhaps your query is best taken to 
the support community for the database you're using. Our advice here may 
not be relevant to you.

The issue you're having is what the South package is designed to solve. 
South will want to see your model before you added the foreign key, but 
once you initialise it in that state, it will handle that for you.

To answer the specific questions (because I'm nice):

'distfk' is just a name for the constraint. It can be anything, really. The 
first 'address' is the column in the distributors table. The 
'addresses(address)' refers to the address column in the 'addresses' table. 
'MATCH FULL' is the type of uniqueness constraint you're putting in place. 
You should check the manual for the database for details. (looks like 
MySQL?)



On Thursday, December 13, 2012 4:53:25 AM UTC-8, laxglx wrote:
>
> Can anybody plz tell me how to add a foreign key an existing table using 
> SQL Queries?
> >> I got the command, nut can't understand 
>
> ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) 
> REFERENCES addresses (address) MATCH FULL;
>
>
> What's  "distfk" here if it is key name what is (address) ? and what is 
> addresses(address)?
> And What does mean Match Full
>
>
> Thanks in advance 
> laxglx
>

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



Re: django book example HELP..

2012-12-13 Thread Chris Cogdon
Typo on that typo! That slash should also be inside the parenthesis:

(r'^time/plus/(\d{1,2})/$', hours_ahead)

Note, though, I tend not to be so specific with URL matching... consider if 
someone hacked a URL to read time/plus/999/ ... The above will cause a 404, 
where letting it through to your code, with something like (\d+) gives you 
the opportunity to respond instead with something more specific to the 
error, such as redirecting to a "sensible default" along with a message. 
The "correct behavior" depends on your application design.


On Thursday, December 13, 2012 1:32:30 AM UTC-8, 向浩 wrote:
>
> (r'^time/plus/\d{1,2}/$', hours_ahead),this line,you should use () for 
> d{1,2}
> (r'^time/plus/\(d{1,2})/$', hours_ahead)  
>
> 在 2011年2月18日星期五UTC+8下午11时04分13秒,Dipo Elegbede写道:
>>
>> Hi all,
>>
>> i am currently reading the django book and following the examples step by 
>> step.
>>
>> I have a view defined as follows:
>>
>> from django.http import Http404, HttpResponse
>> import datetime
>>
>> #def myhome(request):
>> #message = """
>> #MY HOME
>> #
>> #
>> #This is my 
>> way of 
>> saying welcome!
>> #
>> #
>> # 
>> #"""
>> #return HttpResponse(message)
>> #
>> #def hello(request):
>> #return HttpResponse("Hello World")
>> #
>> #def current_time(request):
>> #now = datetime.datetime.now()
>> #html = "It is now %s." % now
>> #return HttpResponse(html)
>> 
>> def hours_ahead(request, offset):
>> try:
>> offset = int(offset)
>> except ValueError:
>> raise Http404()
>> dt = datetime.datetime.now() + datetime.timedelta(hours=offset)
>> html = "In %s hour(s), it will be %s." % 
>> (offset, dt)
>> return HttpResponse(html)
>>
>> (All the commented area work just fine )
>>
>> and I have a url.py like this:
>>
>> from django.conf.urls.defaults import *
>> from mysite.views import *
>> from django.contrib import admin
>> admin.autodiscover()
>>
>> urlpatterns = patterns('',
>> (r'^$', myhome),
>> (r'^polls/', include('mysite.polls.urls')),
>> (r'^hello/$', hello),
>> (r'^time/$', current_time),
>> (r'^time/plus/\d{1,2}/$', hours_ahead),
>> )
>>
>> when i try to run localhost:8000/time/plus/3, I get the following error:
>>
>> TypeError at /time/plus/4/
>> hours_ahead() takes exactly 2 arguments (1 given)
>> Request Method: GET
>> Request URL: http://localhost:8000/time/plus/4/
>> Django Version: 1.2.1
>> Exception Type: TypeError
>> Exception Value: 
>> hours_ahead() takes exactly 2 arguments (1 given)
>> Exception Location: 
>> c:\Python26\lib\site-packages\django-1.2.1-py2.6.egg\django\core\handlers\base.py
>>  
>> in get_response, line 100
>> Python Executable: c:\Python26\python.exe
>> Python Version: 2.6.4
>> Python Path: ['c:\\users\\owner\\desktop\\djtask\\mysite', 
>> 'c:\\Python26\\lib\\site-packages\\django-1.2.1-py2.6.egg', 
>> 'c:\\Python26\\lib\\site-packages\\pip-0.8.2-py2.6.egg', 
>> 'C:\\Windows\\system32\\python26.zip', 'c:\\Python26\\DLLs', 
>> 'c:\\Python26\\lib', 'c:\\Python26\\lib\\plat-win', 
>> 'c:\\Python26\\lib\\lib-tk', 'c:\\Python26', 
>> 'c:\\Python26\\lib\\site-packages', 
>> 'c:\\Python26\\lib\\site-packages\\PIL', 
>> 'c:\\Python26\\lib\\site-packages\\wx-2.8-msw-unicode']
>> Server time: Fri, 18 Feb 2011 15:51:57 +0100
>>
>> My understanding of the error message is that I supplied, 1 argument when 
>> the view function, hours_ahead was expecting 2 but really, i don't have a 
>> hang of where to put the other argument. I am following the examples in the 
>> book.
>>
>> I must be missing something, kindly help me out.
>>
>> thank you.
>>  
>>
>>
>>
>>
>>
>>
>> -- 
>> Elegbede Muhammed Oladipupo
>> OCA
>> +2348077682428
>> +2347042171716
>> www.dudupay.com
>> Mobile Banking Solutions | Transaction Processing | Enterprise 
>> Application Development
>>  
>

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



Re: Project path

2012-12-13 Thread Chris Cogdon
Totally agreed... including being the separate repositories. If I check out 
the framework for use on my desktop I should _not_ be seeing the runtime 
configuration (including secrets and passwords) for the production systems, 
and viccyverca.

On Thursday, December 13, 2012 9:43:30 AM UTC-8, Tom Evans wrote:
>
> On Wed, Dec 12, 2012 at 9:32 PM, Chris Cogdon > 
> wrote: 
> > The BIG advantage here is that you're not checking anything into the SCM 
> > that must remain secret, or must change (or very likely to change) 
> between 
> > installations, but all other settings are source controlled. 
>
> The big disadvantage is that the configuration of your production 
> website instances are not in a VCS, you cannot track or merge changes 
> to them or their ancestors, and if a box goes kabluie, you can't 
> instantly re-create it. Configuration is code, code lives in a VCS. 
>
> (Our configuration files live in a separate repository to the project 
> or app code, and are finangled into place based upon the hostname) 
>
> Cheers 
>
> Tom 
>

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



Re: IntegerField and SmallIntegerFields maps to the same db type on Oracle.

2012-12-13 Thread Chris Cogdon
According to the docs, oracle uses 1 byte for the magnitude, and 1 or more 
bytes for significant digits.

HOWEVER, it assigns that space dynamically, so even if you say NUMBER(11), 
you will still only need 2 bytes to represent the number "5". All 
NUMBER(11) gives you is some range checking on input.

So, from that, I read that there's no real benefit from using 
SmallIntegerField, since it'll still only take up as much space as you 
need. Any range checking can be done in the Model's save method, or a 
Form's clean methods, and be much more specific to the application's 
requirements than oracle's range checking can provide.

On Thursday, December 13, 2012 9:28:22 AM UTC-8, Tom Evans wrote:
>
> Oracle may use the exact same datatype underneath for all NUMBER 
> (speculation). The value in brackets could simply be the default 
> number of digits presented. 
>
> Cheers 
>
> Tom 
>

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



Re: select_for_update().get(...), what happens on DoesNotExist?

2012-12-13 Thread Chris Cogdon


On Thursday, December 13, 2012 10:23:52 AM UTC-8, Carsten Fuchs wrote:
>
> Our database is Oracle; 
> with 
> <
> https://docs.djangoproject.com/en/1.4/ref/models/querysets/#select-for-update>
>  
>
> saying both "Returns a queryset that will lock rows ..." and "All 
> matched entries will be locked ..." I nourished the silent hope that 
> maybe it kept and matched the query rather than flagging individual 
> rows.  ;-) 
>

No nourishment, but fortunately no calories either :)
 

>
> > However, not all is lost here. 
> > 
> > When you create new rows, those rows are _invisible_ to any other 
> > transaction until you do a commit. So, as long as you arrange things so 
> > that there's a final commit after you've done all the manipulations you 
> > want, you won't have those rows stomped on by any other transaction. 
>
> Ok, thanks, I was in fact not quite aware that the newly created rows 
> are invisible until the end of the transaction. 
>
> However, that still doesn't stop a second process that enters the same 
> code while the first is still running, from doing the same computations, 
> too, eventually committing a transaction that creates (attempts to) 
> another row with the same data again, doesn't it? 
>
> Is it a sound idea to work-around this problem by running a 
> select_for_update() query on *other* rows (a few that are known to 
> exist, or even all) of the same model, just to obtain a dummy lock until 
> the first process is done? 
>
> Or even better, lock the single row in another model that tells us that 
> meets_requirements() == False, i.e. our cache needs updating? It would 
> still only be a "dummy" lock, of course, so I'm unsure if this is 
> reasonable at all. 
>
> Or does some kind of best practice exist that suggests how such a 
> problem is normally solved? 
>

This will depend on the problem, but let me site a simple example for how 
this is often solved.

Lets say your process is to read in rows matching a certain criteria, and 
write a new row somewhere else. Since you say you cant guarantee that, 
during this process, another process might kick off that will try to do the 
same thing, here's the avoidance strategies:

1. As part of the process, the "input rows" are changed so that they no 
longer match the criteria. This means that you're putting a "select for 
update" on those rows and that will stop a second process trying the same 
row-level lock. The second process will block until the first 
completes/commits, and when unblocked those rows no longer match the 
criteria, and are no longer returned in the query.

This sounds most like what you're doing now.


2. The output rows have a unique constraint put on them, so if the same 
input rows are processed, the INSERT will fail. In this case a) you'll need 
to make sure you trap the exception and handle it gracefully AND b) ensure 
Django isn't going to undo your work and use an UPDATE instead

This is generally only feasible if you can ensure that there's a consistent 
mapping between output and input rows


3. Make the whole process "idempotent"... meaning that you can re-run it 
any number of times and it will have no further impact on your data model.

Eg: if your input is "all data in time range :00-:05" and your output is a 
summary then all you're losing if you re-run it is a touch of performance. 
This wont work, of course, if your process is "summarise and delete source 
data", in which case you'll need to lock input rows AND possibly the output 
row, and also adjust your code so that if it thought it was creating an 
output row, but it suddenly exists, that you can switch over to updating it 
instead.



I hope that gives you sufficient options.







>

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



Re: Modelform and Ajax (Select a valid choice..... Error)

2012-12-13 Thread Chris Cogdon
How are you populating the choices in the ChoiceField? Remember, you need 
to do this on BOTH the POST AND the non-POST versions of creating the form.

But ChoiceField is a Form field, not a Model field... so its not perfectly 
clear what you're asking.


On Tuesday, December 11, 2012 3:39:48 AM UTC-8, siddharth56660 wrote:
>
> Hi, 
>
> I am facing problem in handling modelform and ajax together. 
> The situation is:- 
> I am using modelform to get display the form as ul in the template. 
> I have 3 ChoiceFields (country, state,city). On select of a country 
> from the dropdown, the valid states dropdown gets populated and on 
> select of a state the respective city dropdown gets populated. 
> For achieving the above functionality I am calling an ajax function 
> which returns me the available data of the other dropdown in Json Form 
> {stat_id, stat_name} 
> I am able to populate the data in next dropdown i.e state and city, 
> but when i click submit form it shows "Select a valid choice. 8 is not 
> one of the available choices" 
> 8 happens to be the stat_id in this case. 
> I have gone through google but dint find anything useful. Help is 
> really appreciated. 
>

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



Re: validation error in Django Admin

2012-12-13 Thread Chris Cogdon
I'm going to take a guess that when you "drop one" of them, deleting it, 
there's still a query going on that might want to refer to the other one, 
and the to_python fails because that reference doesn't exist anymore.

You might have better luck if you're using a OneToOne or ForeignKey 
(onetomany), which will let django manage that relationship for you. 

On Wednesday, December 12, 2012 4:21:59 PM UTC-8, Mike Dewhirst wrote:
>
> I'm getting an unexpected validation error in Admin which baffles me. 
> Any hints appreciated ... here is the traceback 
>
> http://dpaste.com/844972/ 
>
> At the bottom of the traceback where the error is raised, the local vars 
> are ... 
>
> self  
> value u'33' 
> key 'pk' 
>
> When I save the item, it auto-generates many-to-many connections to a 
> few standard images in the database via a through table. However there 
> is a rule which says "if ever these two images are connected to an item, 
> only keep this one and drop that one." 
>
> I use a post-save signal to "drop that one" using ... 
>
>Item_Pictogram.objects.filter(item=instance, pictogram=pic, 
> via='auto').delete() 
>
> The local var value above being u'33' happens to be the exact pk of the 
> Item_Pictogram record I want to delete - I checked in Postgres. 
>
> The pk should be an integer but I suppose that's nothing. 
>
> Thanks for any help 
>
> Mike 
>

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



Re: select_for_update().get(...), what happens on DoesNotExist?

2012-12-12 Thread Chris Cogdon
The question is going to be very database specific. "select for update" 
works by putting in row-level locks in the database. If the row does not 
exist, then it won't get a lock on it, and I know of no databases that will 
maintain the query so that any newly created rows automatically get a lock 
on it.

However, not all is lost here.

When you create new rows, those rows are _invisible_ to any other 
transaction until you do a commit. So, as long as you arrange things so 
that there's a final commit after you've done all the manipulations you 
want, you won't have those rows stomped on by any other transaction.


>

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



Re: ImageField in admin always required

2012-12-12 Thread Chris Cogdon


NOTE: I tried adding null=True, blank=True to forms.ImageField however I 
> get errors __init__() got an unexpected keyword argument so I guess I can't 
> use them options. If I comment out the def formfield_for_dbfield(self, 
> db_field, **kwargs): then the ImageField is not required as expected.
>

"ImageField is not required as expected" Isn't that what you want? :)

Anyway, the attribute for allowing a FormField to be "left blank" is 
required=False... blank=True and null=True are for ModelFields

If that knowledge doesn't give you any joy, try constructing a simple model 
that is not inherited from AbstractBaseUser... does that still end up 
having the picture be required?


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



Re: Project path

2012-12-12 Thread Chris Cogdon
Not sure if you're willing to consider an alternate, here, but this is a 
issue Iv'e gone through a lot, and came up with my own solution. The major 
issue is that I not only want to change the top level paths, but also need 
to change database targets and a few other settings, between all the 
different dev/beta/production sites AND to make sure that the majority of 
my settings can be checked into our SCM. Here's what I came up with.

Rename settings to common_settings.py

Have a local_settings.py that is NOT checked into the SCM (perhaps provide 
a local_settings.py.example containing the minimum settings that need to be 
changed).

local_settings.py contains:

from projectname.common_settings import *

DATABASES = ...
SECRET_KEY = ...
STATIC_ROOT = ...

and anything else that _must_ change between installations.

Then change manage.py and wsgi.py so that it loads "common_settings" rather 
than "projectname.settings"

and done.

The BIG advantage here is that you're not checking anything into the SCM 
that must remain secret, or must change (or very likely to change) between 
installations, but all other settings are source controlled.

Although not necessary to rename settings.py, i do this to catch code that 
improperly imports settings, rather than django.conf.settings



>

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



Re: Datastructure using django.

2012-12-12 Thread Chris Cogdon
I've no answers for you, but you might want to have a look at other 
applications that use those products and see how they work.

I know that "zinnia", a Django-based blog framework, uses "mptt", so you 
might want to have a look there. I've used zinnia, and I've never had to do 
any "reload" so to speak when I add in categories into the tree.

On Monday, December 10, 2012 10:15:41 AM UTC-8, Subhodip Biswas wrote:
>
> Hi all, 
>
> I am trying to implement a tree structure using django. There are two 
> packages I am looking at mptt and treebeard. Treebeard seems easy. 
>
> I have however two questions:
>
> 1. With mptt I found that if you have moved one child to another parent 
> both db and instance is updated but you need to reload or reregister every 
> time you call such action.Is there a better way of doing this?
>
> 2. If my child have more than one parent, the structure does not remain a 
> tree anymore. It becomes a graph i guess, How do you handle such situation. 
>
> 3. How do I add treebeard or mptt into django admin. If I have one field 
> name and I register it in admin.py. I get error regarding depth,path, 
> numchild and name should be present. How do I handle this situation.
>
> Apologies for asking so many questions.
>
>
> -
> Regards
> Subhodip Biswas
>
>
> GPG key : FAEA34AB
> Server : pgp.mit.edu
> http://subhodipbiswas.wordpress.com
> http:/www.fedoraproject.org/wiki/SubhodipBiswas
>
>

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



Re: Model method versus overriding save()

2012-12-12 Thread Chris Cogdon
On Sunday, December 9, 2012 9:08:18 PM UTC-8, Mike Dewhirst wrote:
>
> On 10/12/2012 10:59am, Victor Hooi wrote: 
> > Also - in terms of using them with QuerySets - there aren't any 
> > workarounds to use model methods with QuerySets are there? It seems like 
> > that would be a definite argument in favour of using the second method, 
> > right? 
>
> I'm not sure what you mean exactly here but you can use them in model 
> methods. Use the class manager. 
>
> ClassName.objects.filter(thing=self.this, whatever=self.that, etc=etc) 
>
 
What I believe Victor is asking for is that the model method is on the left 
hand side of that equals.

On my understanding of the framework, my best answer is "no", because the 
query system is unable to construct a SQL query that will encompass your 
model method, since that's in python.

This is a very classic "pre-calculate vs re-calculate" argument that a lot 
of applications go through. Django handles a bunch of these using "lazy" 
queries, that don't bother calculating things until it really needs them, 
but even so, needs some hints to get best performance (see things like 
select_related and prefetch_related). 

Here's some options for you:

1. Stick with a model method. Do most of your querying through django's 
ORM, but then do a post-filter in python using the results of the model 
method. This saves database space, and if the pre-filter result set is 
small, this will be pretty fast still. Howerver, if this is called a _lot_ 
you'll be hurt on performance.

2. Whenever you "save" a model, re-calculate the field and save it. This is 
very flexible, while chewing up a bit of space. This opens up the 
possibility of a desync between the source data and the calculated, but 
should be rare if you're never saving the model data outside of the save 
method (and your database handles transactions properly). Very fast if 
you're doing a lot of searching vs updating. But if you're updating FAR 
more often than running your search, you're wasting performance on the 
rarely used pre-calculation

3. If the calculation can be done at the database level, use the "extra" 
ORM method to do a search. This is better than 1, but will take a fair bit 
more database knowledge to get going, AND might tie you to a specific 
database implementation.

3a. Use a database "view" that presents the pre-calculation, making the ORM 
query a lot simpler. This means ensuring that you are allowed to update a 
view (postgresql 9.3 planned) or can somehow do a query on the view (which 
is a different table according to django). More django work here, and again 
might tie you to a particular database implementation


So, my guess is... as long as you're doing a reasonable number of "queries" 
versus "updates" to the table, to make the pre-calculation worthwhile, just 
go ahead and set that pre-calculation in the model's save() method,

 

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



Re: IOError, Permission Denied using Amazon s3 w/ django-storage?

2012-12-09 Thread Chris Cogdon
If you're using ImageField, that by default verifies that what you've 
uploaded is in fact an image. It uses PIL (python image library, aka 
python-imaging) to do that. make sure you have PIL installed and it is 
working.

On Sunday, December 9, 2012 12:40:22 AM UTC-8, easypie wrote:
>
> I got it working by granting 775 permission for that fold and its 
> sub-folder where the files had to be created and lacked enough privilege to 
> do so. Now everything works! ...I just need to figure out why the uploads 
> won't accept .jpg files =\
>
> On Saturday, December 8, 2012 11:18:25 PM UTC-8, easypie wrote:
>>
>> I encountered an error where whenever I go to upload a file, it tells me 
>> that a folder doesn't have enough permission. What kind of permission do we 
>> give these folders? I use Apache server. Do I change the whole project 
>> folder to group www-data? Then set chmod to 775 to the project folder and 
>> all files in the project recursively? Here is my traceback error log: 
>> http://dpaste.org/5KUMf/!
>>
>

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



Re: Model method versus overriding save()

2012-12-09 Thread Chris Cogdon
Even though I'm a total database junkie (and where by that I mean 
postgresql > mysql :) ), I have to agree with Mike. If you can keep it in 
the model layer, do that. Once you start putting optimisations into the 
database layer, you lose a lot of portability between databases: there is 
no such thing as "standard SQL" for anything other than toy applications. 
Optimisation tend to be very engine-specific.

However, just remember that those optimisations are possible, and the 
database is far more reliable for maintaining your invariants than the 
client is.



On Sunday, December 9, 2012 3:30:01 AM UTC-8, Mike Dewhirst wrote:
>
>
>
> For the sake of maintainability it might be better to keep all database 
> manipulation in the model layer rather than split it betweem models and 
> database. 
>
>
>
> and, well, that code is part of the 
> > code base too. 
>
> Which means you need to keep pretty comprehensive documentation if you 
> are doing database stuff in two areas. 
>
> Personally, I'd keep it all in the django ORM until the project is 
> mature and requires the final molecule of optimisation. 
>
> Mike 
>
> > 
> >- Tom 
> > 
> >> 
> >> Derek 
> >> 
> >> [1] https://docs.djangoproject.com/en/dev/topics/signals/ 
> >> 
> >> On Saturday, 8 December 2012 04:27:50 UTC+2, Chris Cogdon wrote: 
> >> 
> >> It's a simple performance vs storage question. 
> >> 
> >> Storing a calculatable field also risks it getting out of sync 
> >> with reality, but if you're doing the query on that _so_ much, 
> >> then its usualyl worth it. 
> >> 
> >> Also, with the right database and a trigger, that's something the 
> >> database can ensure for you. Ie, a field that the database updates 
> >> for you. 
> >> 
> >> 
> >> On Friday, December 7, 2012 5:54:37 PM UTC-8, Victor Hooi wrote: 
> >> 
> >> Hi, 
> >> 
> >> I have a "ranking" field for an item that returns an integer 
> >> between 1 to 10 based on a number of criteria of each item. 
> >> 
> >> My question is - what are the pros and cons of using a model 
> >> method to return this, versus overriding the save() method and 
> >> saving it directly into a normal IntegerField on that item? 
> >> 
> >> I understand that model methods *won't* let me use them within 
> >> QuerySet filters on that item - is there any way around that? 
> >> 
> >> If I just override the model's save() method to get it 
> >> recalculate and save that field each time, I can use it within 
> >> QuerySet filters. Any cons with that approach? 
> >> 
> >> What do you guys tend to use in your projects? 
> >> 
> >> Cheers, 
> >> Victor 
> >> 
> >> -- 
> >> You received this message because you are subscribed to the Google 
> >> Groups "Django users" group. 
> >> To view this discussion on the web visit 
> >> https://groups.google.com/d/msg/django-users/-/G7fp5OLkapgJ. 
> >> To post to this group, send email to 
> >> django...@googlegroups.com. 
>
> >> To unsubscribe from this group, send email to 
> >> django-users...@googlegroups.com . 
> >> For more options, visit this group at 
> >> http://groups.google.com/group/django-users?hl=en. 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> > Groups "Django users" group. 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > To unsubscribe from this group, send email to 
> > django-users...@googlegroups.com . 
> > For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en. 
>
>

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



Re: Model method versus overriding save()

2012-12-07 Thread Chris Cogdon
It's a simple performance vs storage question.

Storing a calculatable field also risks it getting out of sync with 
reality, but if you're doing the query on that _so_ much, then its usualyl 
worth it.

Also, with the right database and a trigger, that's something the database 
can ensure for you. Ie, a field that the database updates for you.


On Friday, December 7, 2012 5:54:37 PM UTC-8, Victor Hooi wrote:
>
> Hi,
>
> I have a "ranking" field for an item that returns an integer between 1 to 
> 10 based on a number of criteria of each item.
>
> My question is - what are the pros and cons of using a model method to 
> return this, versus overriding the save() method and saving it directly 
> into a normal IntegerField on that item?
>
> I understand that model methods *won't* let me use them within QuerySet 
> filters on that item - is there any way around that?
>
> If I just override the model's save() method to get it recalculate and 
> save that field each time, I can use it within QuerySet filters. Any cons 
> with that approach?
>
> What do you guys tend to use in your projects?
>
> Cheers,
> Victor
>

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



Re: Django gracefully shutdown

2012-12-07 Thread Chris Cogdon
I would actually suggest using gunicorn to run django as a stand-along app 
server listening on localhost:some-local-port, and use nginx proxy passing 
to redirect queries to / to the local port.

But that said, once a request is served, the listening processes are 
essentially idle. So, either just shut down enginx, or set up a redirect to 
a "we're under maintenance" page, so the requests dont go through to 
django, or if you're running gunicon, shutting that down will let the 
existing requests complete, then detach... so nginx wont have a proxyport 
to connect to.

fastcgi is pretty "old" now, and my personal opinion is that it should 
probably be avoided. gunicon can talk directly to a wsgi application, so 
its just about a drop-in replacement.


On Friday, December 7, 2012 12:25:55 PM UTC-8, Odagi wrote:
>
>
> Hello! 
>
> After lot of work I'm ready to deploy my site on production. I'll use 
> Nginx with uWSGI or fastCGI (not sure yet), and my doubt is how can I 
> shutdown my production Django app gracefully (for make changes for 
> example). Of course I can kill django-python-fcgi processes and restart 
> everything again but is that correct? Can someone give me some hints please?
>
> Thanks!
>

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



Re: Internal Error after chaning SITE domain name and modifying html file...?

2012-12-07 Thread Chris Cogdon
Okay, I've never tried using virtualenv's with django before... but from 
what I've read, one of the most important things to do is ensure that the 
virtualenv site-packages directory is the first thing in sys.path the 
wsgi.py file there doesn't seem to be manipulating sys.path at all.


On Friday, December 7, 2012 1:21:01 PM UTC-8, easypie wrote:
>
> Here's my wsgi.py file located in my project: http://dpaste.org/dBRqQ/
>

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



Re: Internal Error after chaning SITE domain name and modifying html file...?

2012-12-07 Thread Chris Cogdon
Run ./manage.py shell ... since that imports settings, that should also 
fail, and will perhaps give you more information

Django isn't very good at showing you the "root cause" when a module fails 
to import, unfortunately, you might want to figure out a way of importing 
them manually and seeing what happened.


On Friday, December 7, 2012 12:03:27 AM UTC-8, easypie wrote:
>
> I'm getting an 500 internal error. I did two things before this happened. 
> (1) I modified a single html file then (2) logged into admin panel and 
> changed the SITE's domain name. Afterward, I restarted the server but the 
> website kept responding w/ 500 error. Here's the apache error log: 
> http://dpaste.org/crfbg/
>

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



Re: Multiple stackinline all sharing relation need assistance

2012-12-05 Thread Chris Cogdon
When you say "recommendations inline lists work history from all users" do 
you mean its showing up as multiple fields, or do you mean the selection 
box that gives you the option of adding a recommendation from the list of 
possible recommendations ?


On Wednesday, December 5, 2012 8:06:55 PM UTC-8, Detectedstealth wrote:
>
> Hi,
>
> I have a custom user who has work experience, and for each work experience 
> there can be multiple recommendations for the work experience.
>
> My models:
> CustomUser
>
> class WorkExperience(models.Model):
>
> user = models.ForeignKey(CustomUser, verbose_name=_('user profile'))
>
> company = models.CharField(_('company name'), max_length=150)
>
> location = models.CharField(_('job location'), max_length=150)
>
> position = models.CharField(_('position'), max_length=150)
>
> start_date = models.DateField(_('started position'))
>
> end_date = models.DateField(_('finished position'), null=True, blank=
> True)
>
> description = models.TextField(_('details'), help_text=_('Write a 
> short description about your role and experience when at this position.'))
>
> 
>
> last_edited = models.DateTimeField(default=timezone.now)
>
> date_added = models.DateTimeField(default=timezone.now)
>
> 
>
> def __unicode__(self):
>
> return "%s - %s" % (self.company, self.position)
>
> 
>
> class Recommendation(models.Model):
>
> user = models.ForeignKey(CustomUser, verbose_name=_('recommended user'
> ))
>
> workexperience = models.ForeignKey(WorkExperience, verbose_name=_('work 
> experience'))
>
> details = models.TextField(_('recommendation'))
>
> approved = models.BooleanField(default=False)
>
> is_spam = models.BooleanField(default=False)
>
> date_added = models.DateTimeField(default=timezone.now)
>
> admin.py
>
> class ExperienceInline(admin.StackedInline):
>
> model = WorkExperience
>
> fieldsets = (
>
> (None, {
>
> 'fields': (
>
> 'company', 
>
> 'position',
>
> 'location',
>
> ('start_date','end_date'),
>
> 'description'
>
> )
>
> }),
>
> )
>
> class RecommendationInline(admin.StackedInline):
>
> model = Recommendation
>
> class CustomUserAdmin(UserAdmin):
>
> ...
> inlines = [ExperienceInline, RecommendationInline]
>
>
> The problem is the recommendations inline lists work history from all 
> users instead of showing only the work experience from the selected user. 
> Is it possible to list only work experience  belong to the selected user?
>
>

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



Re: Help with registration backend

2012-12-05 Thread Chris Cogdon
In the end all you need to do is create a User object and possibly set a 
password on it. That's it. Create your own form for it and go wild.

I strongly suggest wrapping the view in a @has_perm decorator so that only 
people who are allowed to create users (or some other permission) can get 
to the view. Even if a user doesnt have "staff" privileges (ie, cant get to 
the admin screens) the "admin.create_user" privilege is useful for this 
purpose.

I have an application that creates users with an admin method, but 
immediately sends the user a "we created a user for you, follow this link 
to create a password" email message, where the link is derived from the 
admin "reset_password" code.

if you want to take a look at that: http://github.com/chmarr/artshow-jockey

The relevant function is in artshow/admin.py, 
ArtistAdmin.create_management_users()

and the link just goes to wherever the password_reset link would have taken 
them. Unlike django-registration, the built-in password reset function is 
totally stateless. The "code" is actually a hash of various variables 
including the user id, the time the reset was request, SECRET_KEY... so it 
doesnt actually need to store the codes used. it can just check the hash 
for validity.



On Wednesday, December 5, 2012 4:27:43 PM UTC-8, Johnny Pyhtonic wrote:
>
> Thanks for the idea. I followed up on this found that the 
> django-registration backend is really only ment for anonymous account 
> creation - it will log an athenticated user out upon reaching the page. The 
> deal seems to be that in order the create an account, the user must not 
> already have an account (must be anonymous). Makes sense for lots of 
> situations, just not mine. So how do you make it so that only an 
> authenticated user is able to create an account that only an anonymous user 
> is allowed to make?
>
> Well, I was able to come up with a little hack whereby anonymous users are 
> redirected away from the accounts/registration page, but athenticated users 
> will continue toward the page, they're just logged out before they get 
> there. It seems to work, however I'm not too happy with it.
>
> My new question is, how to I go about making my own account creation page? 
> For instance can I just make a form that gathers all the fileds I want 
> (Name, password, etc), build a view and a template? Or is there something 
> special that the the django-registration backend is doing that I don't 
> realize? That's the part I'm concerned about. Should I inherit from the 
> django-registration backend and build on that? Is there a ready made 
> solution I don't know about that would allow an authenticated user to 
> create accounts?
>
> I feel a bit unsure about how to proceed. Anyone have advice?
>
> Thanks!
>
> On Monday, December 3, 2012 6:10:07 PM UTC-4, Chris Cogdon wrote:
>>
>> modify the urlconf so that the function to send out registration keys can 
>> only be executed if someone is already logged in and/or has the right kind 
>> of permission.
>>
>> eg, instead of
>>
>>  url(  some-re   some_function )
>>
>> you can use
>>
>>  url ( some-re, login_required(some_function) )
>>
>> or has_perm, or a myriad of other decorators/wrappers.
>>
>>
>>
>> On Monday, December 3, 2012 1:40:02 PM UTC-8, Jason Pythonic wrote:
>>>
>>> Hi All,
>>>
>>> First time poster here, so apologies if this question has been covered - 
>>> believe me, I've searched, but I might be too far off base to know what to 
>>> search for.
>>>
>>> Here's my issue. I'm working on a site that is currently setup to enroll 
>>> users via the django-registration user registration backend.
>>>
>>> User accounts are created by navigating to my_site/accounts/register/, 
>>> entering a username, an e-mail address, and a password. Once this form is 
>>> filled out, an activatation link is e-mailed to the new user by clicking on 
>>> a button. When the user receives this email, they simply follow the link to 
>>> activate their account. That all works. The problem I have is that 
>>> absolutely anyone can come along and create their own account simply by 
>>> going to my_site/accounts/register/ and sending themselves an activation 
>>> e-mail. I need a way to ensure that only my website's user is authorized to 
>>> create users, and I'm really just not sure of how to go about tackling this.
>>>
>>> I'd sure appreciate it if someone could provide direction how to do this.
>>>
>>> Just to summarize, I only want *my *site

Re: pyodbc utf-8

2012-12-05 Thread Chris Cogdon
You're totally correct. This is why I said "but please find out what pyodbc 
uses" :)

sqlite3 uses %s

On Wednesday, December 5, 2012 3:46:01 PM UTC-8, Dennis Lee Bieber wrote:
>
> On Wed, 5 Dec 2012 13:13:31 -0800 (PST), Chris Cogdon 
> > 
>
> declaimed the following in gmane.comp.python.django.user: 
>
>   
> > Good: 
> > 
> > cursor.execute("SELECT x.t_name, x.t_user, y.t_mail FROM tttaad20 as 
> x, 
> > tttcmf20 as y WHERE (x.t_name = y.t_name) AND (x.t_user = %s)", ( 
> form, 
> > ) ) 
> > 
> > Note that we are no longer using the python % operator. %s here is 
> specific 
> > to db-api2, but please find out what pyodbc requires. it could be %s, 
> could 
> > be ?, or something else. 
>
> DB-API2 does NOT mandate using %s -- that is just one of something 
> like four or five permitted styles; the style choice is determined by 
> the actual adapter used. 
>
> From PEP 249: 
>
> > paramstyle 
> >   
> > String constant stating the type of parameter marker 
> > formatting expected by the interface. Possible values are 
> > [2]: 
> > 
> > 'qmark' Question mark style, 
> > e.g. '...WHERE name=?' 
> > 'numeric'   Numeric, positional style, 
> > e.g. '...WHERE name=:1' 
> > 'named' Named style, 
> > e.g. '...WHERE name=:name' 
> > 'format'ANSI C printf format codes, 
> > e.g. '...WHERE name=%s' 
> > 'pyformat'  Python extended format codes, 
> > e.g. '...WHERE name=%(name)s' 
> > 
>
> MySQLdb uses %s (MySQL did not have prepared statements prior to 
> v5; 
> everything was sent as fully formatted statements, and MySQLdb uses 
> Python string interpolation to generate the statements -- after passing 
> each parameter through a function that escapes special characters and 
> wraps SQL quotes around it). [probably works with "pyformat" too] 
>
> SQLite3 uses ? 
> -- 
> Wulfraed Dennis Lee Bieber AF6VN 
> wlf...@ix.netcom.com 
> HTTP://wlfraed.home.netcom.com/ 
>
>

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



Re: pyodbc utf-8

2012-12-05 Thread Chris Cogdon
Perhaps you can help the django team figure out why the ORM doesn't work 
with MSSQL? I understand that its not technically supported, but there must 
be SOME people working on it.

If you're going straight to pyodbc, then this is likeyl to be a 
python/pyodbc issue, and not django. So... you're not going to get the 
level of help here that you might from the pyodbc user's group. We'll try, 
but no guarantees.

For starters, you should read the docs on pyodbc. The way you're handling 
the execute statement is very bad, and will open you to SQL injection 
attacks. It might also be the reason it doesnt work.

bad:

cursor.execute("SELECT x.t_name, x.t_user, y.t_mail FROM tttaad20 as x, 
tttcmf20 as y WHERE (x.t_name = y.t_name) AND (x.t_user = '%s')"%form)

Good:

cursor.execute("SELECT x.t_name, x.t_user, y.t_mail FROM tttaad20 as x, 
tttcmf20 as y WHERE (x.t_name = y.t_name) AND (x.t_user = %s)", ( form, 
) )

Note that we are no longer using the python % operator. %s here is specific 
to db-api2, but please find out what pyodbc requires. it could be %s, could 
be ?, or something else.
The 2nd parameter to "execute" must be a sequence. So if there's just one 
element, make sure you use ( elem, ) or [ elem ]

In this form, the execute statement will do all the proper quoting for you.

Now, the error that you're getting is likely in the rows = 
unicode(cursor.fetchall(), 'utf-8') line

cursor.fetcall() returns a list of tuples. you cant unicode convert all 
that at once. you have to do it on the individual elements.


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



Re: HELP!!! Admin Site app name rename

2012-12-05 Thread Chris Cogdon
Most objects have a way of giving them a "label" attribute, or even a 
"short_description" attribute. So, if you didn't want to go to the trouble 
of internationalizing (i17ning?) your application, just use those idioms to 
create visible names for your custom-created models and forms, etc.

To change the django-supplied names, then that should just be a matter of 
switching the language in the settings.

If you want to change the "Django Administration" name to something app 
specific, then I would supply a new admin/base_site.html template (copy the 
one from django-source/contrib/admin/templates/admin, modify it, and put it 
into a templates/admin folder in your own app)



On Tuesday, December 4, 2012 8:58:38 PM UTC-8, Pedro J. Aramburu wrote:
>
> I hope someone could help me. My main language is Spanish but when I write 
> code I like it to be en english. Being that way it will be easier to open 
> source something in the future. The main problem is the app name in the 
> Admin Site. 
> For example, I'm writing a kind of eCommerce site without the ability to 
> make transactions (or buy) online. So it's more like a product 
> catalog/catalogue. For that reason I created a catalog app with the desired 
> modules, etc. When I configure the admin site then, I have the Catalog 
> section with the CRUD for the models but, as my main language is Spanish, 
> my clients also read Spanish so instead of "Catalog" it should say 
> "Catálogo".
> I've read the documentation and googled a lot and find some "solutions" 
> but they were pretty old. The most promising was to modify the admin site 
> templates and put something like the following on the __init__.py file:
>
> from django.utils.translation import ugettext_noop as _
>
> _('Catalog')
>
>
> That way the makemessages would pick the string and then I could translate 
> it. Well, it didn't work.
>
> I found that the templates have some translation applied to them but I 
> then realized that the app.name isn't translated but the surroundings are 
> (
> https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/index.html).
>  
> The app.name is just a string interpolation.
>
> Have been any progress regarding this subject? Have anyone had to deal 
> with something like this? Can I change the app name in some way or the 
> app_label? What's the difference? How should approach it? Isn't somewhere a 
> verbose_name for apps or something? Even if it's hard coded, with no 
> translation.
>
> Thank you in advance for your time.
>

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



Re: django + fastcgi + lighttpd outlog and errlog not working

2012-12-05 Thread Chris Cogdon
Another way would be to set up a receiver for a signal, emit a message via 
the logging module, configure LOGGING to log those messages to stderr.

Question for others: Is there a good document on what signals django sends?

Since I have it available, here's how you would adjust the LOGGING setting 
to send all messages up to the DEBUG level to stderr:

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'': {
'handlers': ['console'],
'level': 'DEBUG',
},
}
}


I added the 'console' handler and the '' (empty string) logger as 
differences from the default.

Of course, if you want to make your signal receiver send to a different 
logger name (eg: "request"), you only then have to have a logger for that:

'request': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},


I dont have sample code for setting up the signal receiver, nor which 
> signal to receive even, handy. Perhaps someone else could help, there?
>

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



Re: django synchronize database over REST

2012-12-05 Thread Chris Cogdon
If you're not using synchronous replication (ie, something like a two-phase 
commit, or something very close to it), then it is impossible to come up 
with a generic solution for replication. you might be able to "come close", 
but how to deal with desync is application specific.

Ie, say you had two users do a thing on both systems, but the thing is 
contradictory, and thus cannot be replicated. How do you solve this "in the 
background" ?? Well, that's something that can only be decided by the 
application. And, in fact, what actions are considered contradictory is 
also application-specific.

So, for the most part you're going to have to come up with it yourself.



On Wednesday, December 5, 2012 9:50:34 AM UTC-8, psychok7 wrote:
>
> So I have this 2 applications connected with a REST API (json messages). 
> One written in Django and the other in Php. I have an exact database 
> replica on both sides (using mysql).
>
> My question is, how can i keep this 2 applications databases synchronized?
>
> In other words, when i press "submit" on one of them, i want that data to 
> be saved on the current app database, and on the remote database for the 
> other app using rest.
>
> Is there a django app that does that? i read about django-synchro but 
> didn't see anything REST related.
>
> And i would like to keep things asynchronous, in other words the user must 
> be able to keep using the app while this process is running on the 
> background and keeping data consistent.
>

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



Re: Inline formset with different default values for each "extra" row

2012-12-04 Thread Chris Cogdon
Because Lee Hinde's thread is broken, I'm going to take a punt at what the 
question is :)

in a formset (inline, model, or just a plain one), the "initial" parameter 
to the instantiation of the form takes an list of dictionaries. Each 
element in the list is the initial data for _that_ row... so if you want 5 
different part numbers, for example, do this.


formset = MyFormSet ( ..other params.., 
 
initial=[{'partno':10},{'partno':11},{'partno':12},{'partno':13},{'partno':14}] 
)

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



Re: It's magic the view does not exist for django but it worked 5 secondes before and it still exist

2012-12-04 Thread Chris Cogdon
tl;dr :)

I am going to guess that the server is not recognising tyour changes when 
you save them, and perhaps one copy of a server thinks the state is X, and 
the other thinks its Y, so you'll get different results each time you 
refresh.

Are you running with manage.py runserver? When you save your file, 
manage.py should detect this and "reload". If it doesn't, something is awry.

If you're using a normal webserver, and wsgi.py (the usual case, nowadays) 
whenever you make changes to your .py files, you _must_ either restart the 
webserver, or simply touch the wsgi.py file to update its timestamp.


On Saturday, April 7, 2012 7:27:07 AM UTC-7, Bussiere wrote:
>
> i've got this error :
> ViewDoesNotExist at /invitation/ 
>
> Could not import jackpoint.invitation.views.index. View does not exist in 
> module jackpoint.invitation.views.
>
>
> But yes it exist and worked fine 5 secondes before.
>
>
> the image of eclipse :
>
> http://dl.dropbox.com/u/19753332/wtf.png
>
>
> all the other view works well.
>
>
>
> And when i close and reopen firefox, all the views works fine and that one 
> appaeras 5 secondes freeze then say it doesn't exist.
>
>
> the view is here :
>
> https://github.com/bussiere/jackpoint/blob/master/jackpoint/jackpoint/invitation/views.py
>  
>
>
> regards
>
> bussiere
>
>
>
>

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



Re: how do I resolve this error: " (552, '5.6.0 Headers too large (32768 max)') "

2012-12-04 Thread Chris Cogdon
That's a message returned by your Mail Transport Agent. Django has no 
control.

Either adjust the settings in your MTA or adjust your mail-send to send in 
batches.

And, given that it sounds like you're sending to tens of thousands of 
users, please make sure those users are in the "Bcc" rather than "To" or 
"Cc". Or you're going to get some pretty irate recipients.


On Tuesday, December 4, 2012 3:43:03 PM UTC-8, Mark Webster wrote:
>
> While testing out a Django application which uses django's core mail  
> 'send_mail' the following occurs while sending a message to a large number 
> of email recipients.
>
>
>  (552, '5.6.0 Headers too large (32768 max)')
>
> is there a configuration setting on the django send_mail side which will 
> resolve this? 
>
>
>

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



Re: Bulk db insert with a file through admin form

2012-12-04 Thread Chris Cogdon
My suggestion is to not have any kind of model-linked-file. Use a standard 
Form that accepts a file, then as part of the POST processing, you open the 
file, do all the necessary reading and object creation, then return a 
render/redirect for success. You might want to wrap the entire view in a 
commit_on_success decorator which will deal with the case of a mid-file 
error.


If you think this is going to take a LONG time to process, risking the 
browser timing out, then a far more complex but reliable route is:

- DO create a model for your file uploads. All the process does is accept 
the upload and stick it in a file.
- Create a background process (cron job, etc) that reads in any uploaded 
files and does the processing, then deletes or marks the file as "processed"
- On error, you can stick a error message in a "processing_errors" 
TextField, for example.

Downside is that the uploader will not immediately be notified of a 
successful processsing

YOu could decide to process "in the background" if the file exceeds a 
certain size.

You could also decide to record who uploaded the file, then on completion 
or error, email the user with the appropriate message.



On Monday, December 3, 2012 7:32:18 PM UTC-8, MNG1138 wrote:
>
> Say I've got a model like this:
>
> class Product(models.Model):
>
> name = models.CharField(max_length=200)
>
> class ProductItem(models.Model):
>  product = models.ForeignKey(Product)
>  serialnumber = models.charField()
>  sold = models.BooleanField(default=False)
>
> ProductItem represents physical products in the store.  I have a file with 
> thousands of serial #'s for the product.  In the product form in the admin, 
> I'd like to upload this file, parse the serial #'s and create rows in 
> ProductItem.  I could add a FileField to Product and create a custom 
> storage that parses the file and creates ProductITems.  Or I could override 
> save for the Product model.  Both of these solutions are non-optimal, as I 
> will have a FileField in Product and db that I don't need.
>
> Is there any way to add a 'dummy' FileField just for the form that doesn't 
> result in a DB row?  Or is the answer to create a custom admin form?  Any 
> good tutorials or examples for doing creating a custom admin form?
>
> Thanks,
> Mark
>
>
>
>

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



Re: Using clean_fields and full_clean in django Admin

2012-12-04 Thread Chris Cogdon
Best thing I can suggest is to create a clean_FIELDNAME method in the 
ModelForm... this method should use self.cleaned_data['FIELDNAME'] to 
retrieve the value. check it, and return it if things are good, or raise 
ValidationError if things are bad.

An alternate is to make the adjustment to the Model Field... when you 
create the country,CharField... pass a callback function through the 
validators attribute to validate.

This way you'll validate at the model level, rather than the form level.

On Tuesday, December 4, 2012 3:40:41 AM UTC-8, nav wrote:
>
> Dear Folks,
>
> I have an Admin form which has two textfields namely country and state. I 
> have made it more user friendly by making textfield a dropdown with the 
> value to select for those fields.
>
> The model i have has some constraints which I cannot change i.e. that the 
> country value must be a 2 letters in length such as 'US' for United States 
> as these codes are unique. Simlarly for states of a country which can have 
> code up to 10 letters in length. Since my dropdown contains the names and 
> not the codes I need a way to excude them from validation change there 
> values so that they are database friendly and save them. 
>
> After much research I came across two methods full_clean() and 
> clean_fields() which is where the key lies but I have no idea how to use 
> them. 
>
> So far the validation errors on country and state keep firing and there 
> does not seem a way to stop it. Secondly if you exclude fields from 
> validation do I access them directly using the POST data and modify them 
> before saving?
>
> The relevant code is below:
>
> class GroupAdminForm(forms.ModelForm):
> 
> creator = 
> CustomCreatorChoiceField(queryset=User.objects.order_by('last_name'))
> country = 
> CustomLocationChoiceField(queryset=Country.objects.order_by('name'))
> state = 
> CustomLocationChoiceField(queryset=Subdivision.objects.order_by('name'))
> 
> def clean_fields(self, exclude=['country', 'state']): # or I could use 
> full_clean
> print "Inside clean_fields"
> return
>
> def __init__(self, *args, **kwargs):
> super(GroupAdminForm, self).__init__(*args, **kwargs)
> self.fields['country'].initial = DEFAULT_COUNTRY
>
> My model is below:
>
> class Group(models.Model):
>
> # Name of the group
> name = models.CharField(max_length=100)
> # Longer description of group
> description = models.TextField(blank=True)
> # Group owner
> creator = models.ForeignKey(User, related_name='groups_created')
> # Creation date
> creation_date = models.DateTimeField()
>
> # Country foreign key to Country table in Geography App
> country = models.CharField(max_length=2, null=True, default='US')
>
> # State foreign key to State table in Geography App
> state = models.CharField(max_length=10, null=True, blank=True)
>
> # City where group is located
> city = models.CharField(max_length=40, null=True, blank=False)
>
> # Public (searchable) group
> public = models.BooleanField(default=True, null=False)
>
> Please do let me know if anything else is needed.
>
> Cheers,
> nav
>
>
>

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



Re: django + fastcgi + lighttpd outlog and errlog not working

2012-12-04 Thread Chris Cogdon
I believe you only get the per-request logs when you're running the 
development server (runserver). When you're running in fastcgi mode (and 
its been a while since I have), you'll only get entries in outlog and 
errlog if you actually send stuff to stdout and stderr yourself. And THAT 
will require fiddling with the LOGGING settings.


On Tuesday, December 4, 2012 10:17:59 AM UTC-8, Gontran Magnat wrote:
>
> Hello, 
>
> I'm running a django app on lighttpd with fastcgi.
> For debugging matters I would need the output logs that usually are 
> displayed on the console.
> Because I run my application in a daemonize mode I tried to use the outlog 
> and errlog options but it did not work.
>
> Here is the command I run: 
>
> python manage.py runfcgi method=threaded host=127.0.0.1 port=3033 workdir=
> /mydir/finderauto_dj/ outlog=out.log errlog=err.log
>
>
> The out.log and err.log files are created but when I access my website, 
> this should produce this kind of logs:
> [03/Dec/2012 23:09:11] "GET /admin/recherches/alert/4/ HTTP/1.1" 200 11844
>
> However, both out.log and err.log files remain empty.
>
> Then I tried to use the daemonize=false option in order to have directly 
> the output: 
>
> python manage.py runfcgi method=threaded host=127.0.0.1 port=3033
>  daemonize=false
>
>
> I get nothing either...
>
> Anybody for helping me?
>
>

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



Re: Limiting the entry that loaded in django admin.

2012-12-03 Thread Chris Cogdon
raw_id_fields is the first step.

also look at django-ajax-selects, which gives you a lot of interesting 
abilities.

On Monday, December 3, 2012 8:13:02 PM UTC-8, Bo Lang wrote:
>
> Hi all, 
> need some input here. 
>
> I have a site with > 15000 images, using django photologue. 
>
> When we create a Post (that has Images field in it) from django admin, 
> all of the images will be loaded in a dropdown. 
>
> Before this, it was not create any problem. 
> Now, after the number of images getting bigger,  big chance we got 
> timeout when try 
> to create/edit Post. 
>
> I think it is possible to limit the loaded images (although i don't know 
> how to do it). 
> But, which images that should be loaded? 
>
> Any advice? 
>
>
> Thanks before. 
>

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



Re: Help with registration backend

2012-12-03 Thread Chris Cogdon
modify the urlconf so that the function to send out registration keys can 
only be executed if someone is already logged in and/or has the right kind 
of permission.

eg, instead of

 url(  some-re   some_function )

you can use

 url ( some-re, login_required(some_function) )

or has_perm, or a myriad of other decorators/wrappers.



On Monday, December 3, 2012 1:40:02 PM UTC-8, Jason Pythonic wrote:
>
> Hi All,
>
> First time poster here, so apologies if this question has been covered - 
> believe me, I've searched, but I might be too far off base to know what to 
> search for.
>
> Here's my issue. I'm working on a site that is currently setup to enroll 
> users via the django-registration user registration backend.
>
> User accounts are created by navigating to my_site/accounts/register/, 
> entering a username, an e-mail address, and a password. Once this form is 
> filled out, an activatation link is e-mailed to the new user by clicking on 
> a button. When the user receives this email, they simply follow the link to 
> activate their account. That all works. The problem I have is that 
> absolutely anyone can come along and create their own account simply by 
> going to my_site/accounts/register/ and sending themselves an activation 
> e-mail. I need a way to ensure that only my website's user is authorized to 
> create users, and I'm really just not sure of how to go about tackling this.
>
> I'd sure appreciate it if someone could provide direction how to do this.
>
> Just to summarize, I only want *my *site's user to be allowed to create 
> new users. How do I accomplish this?
>
>
> Thanks,
> Jason
>

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



Re: Escape percent sign in QuerySet.extra() method

2012-12-02 Thread Chris Cogdon


On Sunday, December 2, 2012 1:55:05 AM UTC-8, Martin Svoboda wrote:
>
> Hello,
> I'm want to use functionality of postgresql module 
> pg_trgmin django. 
> pg_trgm uses special operator % (percent sign). I don't know how 
> should I escape it in query extra method.
>
> # pure SQL
> SELECT content, similarity(content, 'string') AS sml
>   FROM table
>   WHERE content % 'str'
>   ORDER BY sml DESC, content;
>
> # This throws exception IndexError 'tuple index out of range'
> # I tried to escape percent sign with %%, or \%, but I always get same 
> exception
> objects = MyModel.objects.extra(
> select={'rank': 'similarity(content, %s)'},
> select_params=[content],
> where='content % %s',
> params=[content],
> order_by=['-rank']
> )
>
> # Raw query works ok
> objects = MyModel.objects.raw('''SELECT *, similarity(content, %s) AS sml 
> FROM table WHERE content %% %s ORDER BY sml DESC''', [content, content])
>
> Can you help me how write percent sign in extra() method?
>

While this should not fix anything, can you try breaking it down like so.

objects = MyModel.objects.extra(
where='content % %s',
params=[content],
)

objects = objects.extra(
select={'rank': 'similarity(content, %s)'},
select_params=[content],
order_by=['-rank']
)

That'll give us a hint at which of the two parts are giving us a problem.


>

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



Re: Django apache mod_wsgi permission denied

2012-12-01 Thread Chris Cogdon


On Saturday, December 1, 2012 3:47:39 AM UTC-8, Loai Ghoraba wrote:
>
> no I mean the root of my project guys :) thanks a lot :D which lives in 
> path/to/my/project :)
>

Oh thank god for that!

I'd actually done something similiar once... I'd removed a bunch of 
permissions using chmod -R /   rather than chmod -R . ... This was on an 
oldold NCR Tower 32 running SVR3. I ended up writing a program to go 
through the archives on tape (yes, tape) and copy only the permission bits 
from all the tape files.

Anyway, a better form of that command is chmod -R a+rX

The capital X means "only set the execute bit if any execute bits are set". 
If you use lower-case x, then you'll send up setting the execute bit for 
normal files, too, which is another potential security risk. If you want to 
fix this up, do:

find . -type f -print0 | xargs -0 chmod a-x
chmod a+x manage.py # Restore x for the Django management command

Protip: always use the -print0 | xargs -0  form of the "find/xargs" 
pattern, as this will prevent spaces in your paths from causing havoc.

I wish I knew of a better way to set the x bits all the way up the tree, 
without giving someone a program to run, the best I can come up with is:

cd static
chmod a+x . .. ../.. ../../.. ../../../.. ../../../../.. ../../../../../.. 
../../../../../../..

and hope that's enough :)


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



Re: calling the view function in the other view function

2012-12-01 Thread Chris Cogdon


On Friday, November 30, 2012 9:22:08 PM UTC-8, Satinderpal Singh wrote:
>
> On Sat, Dec 1, 2012 at 4:45 AM, Chris Cogdon > 
> wrote: 
> > It's generally very messy for one "view" function to call another. 
> Then what is the fun of making the function, if it is not reusable. 
> > 
> > Better solution is to factorise out the common parts into a third 
> function, 
> > then make sure each of your two "view" functions have the required 
> > render_to_response. 
>
> What will i do if i have a large number of views having the common part. 
>

Take the common part out of each view and put it in a non-view (ie, not 
connected from a URLConf) function, then each of your view functions calls 
it.

Eg:

def view1 ( request ):

val1, val2, val3 = do_common_stuff ( request )
# non-common stuff here

return render ( request, "templatename", vars )

def view2 ( request ):

   val1, val2, val3 = do_common_stuff ( request )
   # non common stuff here

return render ( request, "templatename2", vars )

def do_common_stuff ( request ):

# all your common code here

return computed_val1, val2, val3



In other words, unless you really know what you're doing, once you return 
the HttpResponse object, that should be the last thing you do.

Note, though. that if your "common code" wants to WRITE INTO the 
HttpResponse object, thats fine too... just create one and then pass it as 
a parameter to your common function.

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



Re: Django apache mod_wsgi permission denied

2012-12-01 Thread Chris Cogdon


On Friday, November 30, 2012 8:53:42 PM UTC-8, Mike Dewhirst wrote:
>
> On 1/12/2012 3:48pm, Loai Ghoraba wrote: 
> > I have ran chmod o+rx on the root directory, isn't this enough (isn't 
> > chmod applied to all folders down recursively ?) ? 
>
> No. You need chmod -R o+rx
>

Oh hell no, don't do that... that will impact the ENTIRE FILESYSTEM


>

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



Re: Django apache mod_wsgi permission denied

2012-11-30 Thread Chris Cogdon
Make sure all the directories, from static leading all the way up to the 
root, are chmod a+x

On Friday, November 30, 2012 4:00:55 PM UTC-8, Loai Ghoraba wrote:
>
> Hi 
>
> I have installed apache and mod_wsgi and my basic site *skeleton is 
> running* on local host, but with NO static files loaded such as css, when I 
> try to access a static file (e.g:http://localhost/static/css/base.css) it 
> says that I don't have permission to access the file, same goes to media 
> files 
>
> I have followed the steps in the presentation slides 
> http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-pycon-sydney-2010.pdf
>  and 
> made the directories accessible to others via chmod o+rx 
> , my  httpd.conf part is :
>
> WSGIScriptAlias / /home/loai/workspace/Faculty/Faculty/wsgi.py
> WSGIPythonPath /home/loai/workspace/Faculty
>
> Alias /media/ /home/loai/workspace/Faculty/Faculty/media
> Alias /static/ /home/loai/workspace/Faculty/Faculty/static
>
> 
> Order deny,allow
> Allow from all
> 
>
> 
> Order deny,allow
> Allow from all
> 
>
> Thanks
>
>

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



Re: how to use named urls from apps

2012-11-30 Thread Chris Cogdon
And, don't forget, the form is:

{% load url from future %}
{% url 'auth_login' %}

OR

{% url auth_login %}

The former is highly recommend, as the latter is deprecated and will become 
the default in a future Django release.

If you ever get messages such as "view not found for reverse"... this has 
been my culprit 90% of the time.

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



Re: admin foreign key issues

2012-11-30 Thread Chris Cogdon



> class CategoryAdmin(admin.ModelAdmin): 
> list_display = ('name') 
> list_filter = ('name') 
> admin.site.register(Category, CategoryAdmin) 
>
> But that fails with 'CategoryAdmin.list_display' must be a list or tuple. 
>

use:   list_display = ('name',)

Note the trailing comma, there?

In python, a tuple with a single element must use the form ( x, )  or it is 
indistinguishable from a parenthesised expression. 
 

>
>

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



Re: calling the view function in the other view function

2012-11-30 Thread Chris Cogdon
It's generally very messy for one "view" function to call another.

Better solution is to factorise out the common parts into a third function, 
then make sure each of your two "view" functions have the required 
render_to_response.

Also, I highly recommend using the "render" shortcut, which would turn your 
more complex calls into this:

return render ( request, 'report/report_base.html', {'Head':Head,} )


On Thursday, November 29, 2012 10:31:03 PM UTC-8, Satinderpal Singh wrote:
>
> I have to call a function into another function which displays the 
> values from the database to the browser, like this: 
>
> def result(request): 
> zee = head.objects.aggregate(Max('id')) 
> mee = zee['id__max'] 
> Head = head.objects.filter(id = mee) 
> return render_to_response('report/report_base.html', 
> {'Head':Head,},context_instance=RequestContext(request)) 
>
> def result_cube(request): 
> Head = result(mee) 
> organisation = Organisation.objects.all().filter(id = 1) 
> return render_to_response('report/cube.html', { 'Head':Head, 
> 'organisation':organisation},context_instance=RequestContext(request)) 
>
> I want to call "result" view in the "result_cube",  as it displays the 
> html data but not showing the data from the database. 
>
> -- 
> Satinderpal Singh 
> http://satindergoraya.blogspot.in/ 
> http://satindergoraya91.blogspot.in/ 
>

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



Re: Noobe alert

2012-11-30 Thread Chris Cogdon
Check the error log for nginx to see if there's any hint of why the statics 
aren't showing up.

My best guess is that the web server is running as a user that does not 
have access to the files, and the error log should be showing up with 
various "permission denied" messages.

The usual culprit is that while the static directory and files are readable 
by everyone, the parent directories do not have the "execute" permission 
bit set. On a directory "execute" means the ability to trasverse the 
directory and get access to the contents, but not get a directory listing.

To fix, try something like this:

chmod a+x /var /var/www /var/www/virtualenv-test 
/var/www/virtualenv-test/ENV /var/www/virtualenv-test/ENV/testsite 
/var/www/virtualenv-test/ENV/testsite/static



On Saturday, November 17, 2012 11:28:01 AM UTC-8, Gerald Klein wrote:
>
> Hi, I finally got a project in Django and I have a "what I hope is an easy 
> question" I started to set up a production server and yes the admin css 
> dissappeared, I went though the docs and followed them. I used the Collect 
> Static Files method and still no joy. Here is my info: 
>
> #settings.py
> MEDIA_ROOT = '/var/www/virtualenv-test/ENV/testsite/media/'
> MEDIA_URL = 'http://localhost/media/'
> STATIC_ROOT = '/var/www/virtualenv-test/ENV/testsite/static/'
> STATIC_URL = 'http://localhost/static/'
>
> #niginx
>
>
> root /var/www/virtualenv-test/ENV/testsite;
>
> location /media/ {
> root /var/www/virtualenv-test/ENV/testsite/media;
> }
>
> location /static/ {
> root /var/www/virtualenv-test/ENV/testsite/static;
> }
>
> My project is located in /var/www/virtualenv-test/ENV/
>
> the project is testsite so the hierarchy inside ENV is:
>
> testsite/
> media/
> static/all files from collect static files
> testsite/
> __init__.py
> settings.py
> urls.py
> wsgi.py
> manage.py
>
> I am using version (1, 4, 2, 'final', 0). 
>
> If somebody can point out the probably obvious problem that I am missing I 
> would greatly appreciate it. 
>
> thanks in advance for your help
>
> --jerry
>
> -- 
>
> j...@zognet.com 
>
> 708-599-0352
>
>
> Arch Awesome, Ranger & Vim the coding triple threat.
>
> Linux registered user #548580 
>
>
>
>  

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



Re: Error: No module named books

2012-11-29 Thread Chris Recher
Thanks for the help everyone. I was using 1.4.x, not the 1.0 the book is 
based on. After fooling around with the commands for a bit, I was able to 
figure out that the problem was in the INSTALLED_APPS section - I included 
'mysite.books', but the new way to do that is just 'books'.

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



Error: No module named books

2012-11-29 Thread Chris Recher
Hi all,

I'm working through the Django book and I've run into an error that wasn't 
predicted. I've got a project called mysite. I used "python manage.py 
startapp books" to create an app called books inside of it. I added a few 
models to the models.py file inside books, then tried to use "python 
manage.py validate". I got "Error: No module named books" in return. 
__init__.py is perfectly intact in both the second mysite directory and the 
books directory. I've added mysite.books to INSTALLED_APPS. All the results 
I could find searching for this problem deal with someone that's made a 
spelling mistake somewhere. I've been through my files multiple times, and 
my spelling is pristine. I figure I'm making an obvious, beginner's mistake 
- could anyone help?

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



Re: Is there a recommended pattern for creating "replaceable" apps?

2012-11-28 Thread Chris Cogdon
Alright! I've gone through the documentation, and waded through a lot of 
the Django source code that implements the AUTH_USER_MODEL setting (via 
Meta.swappable, and Model._meta.swapped, etc) and while I am not saying 
that this isn't a good idea, it seems very heavyweight for what I was 
trying to do. In particular, there are a lot of places in the contrib.admin 
code that checks for model._meta.swapped and disables functionality if it 
indeed is swapped out, even outside the case of the User model.

Ie, I fear that if I use this paradigm, I'll continually be discovering 
circumstances where this or that neato feature in the admin screens stops 
working for me.

What Meta.swappable seems to promote is the idea of being able to replace a 
model with another, while still being able to access that model in all the 
same locations it would have been visible in before being swapped, AND 
ensuring that whenever any application requests a auth.User object, they 
actually get an instance of the replaced object (with some limitations). 

That's totally awesome, but far more than what I needed, which was a way to 
allow my app (artshow) to have a reference to a settings-configurable 
Person model with no changes to either the artshow app, or the app that 
supplies the Model. Ie, I'm looking for a configurable "has-a" 
relationship, than a configurable "is-a" relationship. "has-a" seems a 
*lot*simpler!

So, I'd like to present to you what I've done with my own code. I've gone 
through several iterations and have boiled it down to what I think is the 
simplest possible representation. Feedback and comments are gratefully 
received, and if you think it's useful, I'll provide a HOWTO incorporating 
all the (useful) feedback.

Requirements for a solution:

   - Zero changes are allowed to the component/application that is 
   providing the model (the target)
   - All references to the configurable model in the source app are foreign 
   keys (models.ForeignKey, models.OneToOneField, etc)

Implementation:

   - The documentation for the source app provides a list of "attribute, 
   field and method" requirements for the target. If the target cannot provide 
   these, a "Proxy Model" needs to be created.
   - If the source app needs to run any search queries on the target, a 
   proxy is certainly required to provide methods to return tuples of strings 
   (for "search_fields" in admin models) and a Q object (for searching via 
   querysets) 
   - A setting is provided to indicate which target model is providing the 
   functionality. This points to either the TargetModel or the ProxyModel if 
   required.
   - The model module for the source app creates an alias for the 
   replaceable model using: ReplaceableModel = models.loading.get_model ( 
   *settings.SETTING_NAME.split('.',1) )
  - This works better than using settings.SETTING_NAME everywhere, as 
  it allows views, etc, to use "models.ReplaceableModel.objects..." etc.
   - The ProxyModel is created specifically to match the requirements of 
   the source app, and the features of the target app. This is set up as a 
   Meta.proxy = True
  - If the source app needs to display some kind of attribute in 
  templates, and it is not provided by the Target Model, a method (or 
  property) is created in the proxy.
  - If the source app needs to create different kinds of searches in 
  admin screens, since search_fields needs real fields to search on, a 
method 
  on the proxy is created. returning a tuple of strings: e.g.: 
@staticmethod 
  def get_blah_search_fields ( prefix ): return ( prefix+"attr1", 
  prefix+"attr2" )
  - If the source app needs to create queryset style fields, a similar 
  method is provided returning a Q object. e.g.: @staticmethod def 
  get_blah_search_q ( search_str, prefix ): return 
  Q(**{prefix+"attr1__icontains":search_str} | 
  Q(**{prefix+"attr2__icontains":search_str})
  - __unicode__ can be overridden if a customized default 
  representation is required.
   
In addition, the source app probably needs a good way of finding and 
attaching instances of the Replaceable Model. With no change, the above 
will supply a selection box or a pop-up window (with raw_id_fields), but 
I've found using django-ajax-selects to be excellent. If the TargetModel 
supplies a LookupChannel for those objects, you'll need to create a new 
LookupChannel with a 'model' attribute of "ReplaceableModel" instead. 
Usually simply inheriting from the existing LookupChannel and overriding 
the model attribute works. Otherwise the LookupChannel will return the 
wrong kinds of objects and you won't be able to do assignments, etc.

Now, the above isn't really documentation, I've got a branch with all the 
above changes checked into github that people can poke at:

https://github.com/chmarr/artshow-jockey/tree/peeps2

The parts relevant to this discussion are:

   - ARTSHOW_PERSON_CLASS in artshowproje

Re: Can't get Web font loader in django

2012-11-21 Thread Chris Pagnutti
Sounds like a great idea.  I'm going to give it a try.  In the meantime, 
though...why can I get the script no problem using a non-django, pure 
html+js page?

On Tuesday, November 20, 2012 6:58:17 PM UTC-5, Issam Outassourt wrote:
>
> {
>  "error": {
>   "errors": [
>{
> "domain": "usageLimits",
> "reason": "dailyLimitExceededUnreg",
> "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use 
> requires signup.",
> "extendedHelp": "https://code.google.com/apis/console";
>}
>   ],
>   "code": 403,
>   "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use 
> requires signup."
>  }
> }
>
>
> When I follow the link you passed through, I (give it a try) found this more 
> detailed response.
> What you actually need to do is within your view that renders the page 
> requirements log in to your google
>
> account, retrieve the file, and pass it to your template so it incorporates 
> your response within the html
> web page.
>
> In your head section template all you need to do is something of this kind :
>
> {% for jsscript in jsscript_list %}
> 
> {{ jsscript }}
> 
>
> {% endfor %}
>
> assuming that jsscript is the text jsscript that you want to add to your web 
> page.
> You can use pycurl's python module to request the .js file that's needed.
>
> Hope this helped,
>
> Issam
>
>
>
> 2012/11/21 Chris Pagnutti >
>
>> Hi.  I'm trying to get the Google Web Font loader via
>> http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"</a>;>
>> in my  section.
>> But when I load the page I get (in Chromium's console) this message:
>> GET https://www.googleapis.com/webfonts/v1/webfonts 403 (Forbidden)
>> HOWEVER, if I call the webfonts.js script in a pure HTML/Javascript page 
>> (not running behind the django development server) it works fine.
>>
>> I can request other googleapis resources without problems, e.g.
>> http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"</a>;>
>> 
>> works fine.
>>
>> Any ideas about what's going wrong?
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msg/django-users/-/U-KJVz1N_McJ.
>> To post to this group, send email to django...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> django-users...@googlegroups.com .
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>

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



Can't get Web font loader in django

2012-11-20 Thread Chris Pagnutti
Hi.  I'm trying to get the Google Web Font loader via
http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js";>
in my  section.
But when I load the page I get (in Chromium's console) this message:
GET https://www.googleapis.com/webfonts/v1/webfonts 403 (Forbidden)
HOWEVER, if I call the webfonts.js script in a pure HTML/Javascript page 
(not running behind the django development server) it works fine.

I can request other googleapis resources without problems, e.g.
http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js";>
works fine.

Any ideas about what's going wrong?

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



Re: Is there a recommended pattern for creating "replaceable" apps?

2012-11-20 Thread Chris Cogdon


On Monday, November 19, 2012 9:36:40 PM UTC-6, Russell Keith-Magee wrote:
>
>
> See the development docs for custom user models to see how this works in 
> practice, and adapt for your purposes. I'm intentionally going to leave the 
> rest vague. Call it an entrance exam -- if you can't work out what's going 
> on from what I've given you here and reading Django's source code, you 
> probably shouldn't be playing around with this sort of experimental 
> feature. However, I'm happy to answer specific questions if you get stuck 
> deep in the grass.
>
> Once again, I must stress that this is unofficial, and you'll be in 
> experimental territory if you do this. The reason this is unofficial is 
> because some on the core team are concerned about reopening old wounds -- 
> essentially, swapping models can lead to all sorts of headaches, and the 
> Django project has had these headaches in the past. Consider, for example, 
> if a user changes the CUSTOM_PERSON_MODEL after they've synchronised. 
> Hilarity *will* ensue. There's also problems related to forms and setting 
> an implied contract around your swappable model.
>
> However, it *can* work; and to my mind, we're all consenting adults, so as 
> long as we all understand the potential pitfalls, this is the sort of thing 
> that may be useful. 
>
> If I haven't scared you off by this point, I certainly hope you'll have a 
> tinker and see if this might be palatable for your project.
>

Sorry, not scared me off yet :) I'll go take a look at that code. I *was *aware 
of the replaceable User model, but didn't consider that perhaps this was 
also setting a standard framework for any replaceable model.

If the framework is simple enough, I could gear my own application to use 
it and dropship code from 1.5 into my own project, much like Django 
dropshipped dictconfig for the logging module.

Thanks for the reference, and I'll shoot you questions if/when I have them.


>>

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



Using South with Custom User Model

2012-11-20 Thread Chris Pagnutti
I'm wondering if anyone has ever had success with using South when you have 
AUTH_USER_MODEL set to a custom User model.  I've made various attempts, 
which are basically all the same steps but in different orders.
Basically, my problems is related to this ticket

http://south.aeracode.org/ticket/1179

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



Is there a recommended pattern for creating "replaceable" apps?

2012-11-19 Thread Chris Cogdon
Hi folks!

I'm creating an application to manage an art show (with art pieces to view 
and sell, silent and voice auctions, and a sales process). To have this 
work, it of course needs to keep track of people (including names, 
addresses, email, etc). But to make this more useful to anyone, I want to 
include the ability to replace the included "Person" model with another, 
should the implementor so choose.

What I've done so far is to split the Person model into another app (called 
Peeps) and removed all but a few necessary linkages between the Artshow and 
Peeps app. It was reasonably simple, but a few things seem "dirty" so I'm 
wondering if anyone else has a more experienced or authoritative suggestion 
for this.

I'll detail the points below, but if anyone wants to look at the code, 
please visit my github 
at https://github.com/chmarr/artshow-jockey/tree/peeps  (the "peeps" branch 
has the progressive changes on it).

Details:


   - I'm supplying the code as a combination of a project and two apps, 
   both to make it easier for a "quick start", and to put more of the 
   information that is not immediately related to either the Artshow or Peeps 
   app at the project level.
   


   - I've created a settings called ARTSHOW_PERSON_CLASS which is currently 
   set to "peeps.person"
   - I should probably rename it to ARTSHOW_PERSON_MODEL ??
  - there doesn't seem to be a clean way of turning a text string into 
  a reference to the Model class. I've extracted a line from the django 
core 
  code:
   

from django.db.models.loading import get_model
> from django.conf import settings
> model = get_model ( *settings.ARTSHOW_PERSON_CLASS.split('.',1) )


But there's no official django function to do this. Given this usage, 
perhaps we should ask this to be exposed for 1.5 ??


   - The Artshow app needs the app to have the following attributes: name, 
   email, reg_id, comment, mailing_label(as function).
   - Is there a better method of supporting a replaceable model? Eg: using 
  ARTSHOW_PERSON_CLASS pointing to some kind of proxy class that will map 
the 
  Artshow app requirements to what the Person model can provide?
  - Can this be done in a way to avoid name clashes in the attributes? 
  For example, I have used a single field called "name", while many contact 
  managers might use first and last name, and use "name" for some other 
  purpose.
  - In which app would this linkage code reside? Since its the binding 
  between two otherwise unrelated apps, it seems appropriate to put that at 
  the _project_ level, rather than app. That make sense?
   


   - When selecting a person, I'm using the ajax_select app, which seems to 
   be able to be easily changed if I replace the Person model. ajax_select 
   requires a little code to make this work. As per the above question, 
   where's the best place to have this reside?
   

Thanks for any comments!  If there's already some info out there, or a 
sample project that does this "replaceable model" thing well, I'd 
appreciate a reference. If there isn't such a thing, I'm more than happy to 
create a "HowTo" with all the information I can put together.

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



Re: TemplateDoesNotExist Error...

2012-11-19 Thread Chris Cogdon
If you're sure your error appears at the "txt=" line, look at the 
definition for that template. There is a good chance it's trying to pull in 
a template (via an include, or a extends) that doesn't exist.

If you need more debugging, you can always modify the LOGGING variable to 
drop a bunch of logging into a file onto the web server.


On Monday, November 19, 2012 3:12:56 PM UTC-6, rmschne wrote:
>
> I have moved to a new laptop which is both my development and production 
> platform. The only change in infrastructure is that I run Python, Django, 
> and all else in a virtual environment (VirtualEnv).  
>
> I am not using Django to run on a web server.  
>
> I have a function which produces a set of HTML files.  The first calls
>
> t=get_template('soc_ad_host_and_guest_list.html')  
> txt=smart_str(t.render(Context({ ... more stuff })))
>
> and the above works fine.
>
> On the second call to a different template which a) does exist, and b) is 
> in the template folder defined by TEMPLATE_DIRS,
>
>  t=get_template('soc_ad_table_guest_list_for_prog.html')
>  txt=smart_str(t.render(Context({'host_list': hostlist,})))and at the 
> statement txt= I get the Django Error: TemplateDoesNotExist
>
> Since I'm not on a web server I can't see the so-called "post mortem" 
> message.  But the template files 'soc_ad_table_guest_list_for_prog.html' 
> does indeed exist, its permissions are 770 (same as the first template that 
> does work).
>
> Suggestions? Any more debugging I can turn on?
>

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



Re: Django in virtualenv + nginx + uwsgi set up guide

2012-11-16 Thread Chris Pagnutti
Yep.  I got the server up and running, and that was definitely the most
useful resource.  Thanks.

On Fri, Nov 16, 2012 at 5:30 PM, I単igo Medina  wrote:

>
> Thanks for sharing. Good reference. :)
>
> iñ
>
> --**-
> grosshat.com
> Servicios de desarrollo web, usabilidad y sistemas
>
>
> On Fri, 16 Nov 2012, Leonardo M. Millefiori wrote:
>
>  Hi Chris,
>> you may get some ideas from this long guide, which is fairly recent:
>>
>> [1]
>> http://www.abidibo.net/blog/**2012/04/30/deploy-django-**
>> applications-nginx-uwsgi-**virtualenv-south-git-and-**fabric-part-1/<http://www.abidibo.net/blog/2012/04/30/deploy-django-applications-nginx-uwsgi-virtualenv-south-git-and-fabric-part-1/>
>> [2]
>> http://www.abidibo.net/blog/**2012/05/23/deploy-django-**
>> applications-nginx-uwsgi-**virtualenv-south-git-and-**fabric-part-2/<http://www.abidibo.net/blog/2012/05/23/deploy-django-applications-nginx-uwsgi-virtualenv-south-git-and-fabric-part-2/>
>> [3]
>> http://www.abidibo.net/blog/**2012/06/04/deploy-django-**
>> applications-nginx-uwsgi-**virtualenv-south-git-and-**fabric-part-3/<http://www.abidibo.net/blog/2012/06/04/deploy-django-applications-nginx-uwsgi-virtualenv-south-git-and-fabric-part-3/>
>> [4]
>> http://www.abidibo.net/blog/**2012/06/20/deploy-django-**
>> applications-nginx-uwsgi-**virtualenv-south-git-and-**fabric-part-4/<http://www.abidibo.net/blog/2012/06/20/deploy-django-applications-nginx-uwsgi-virtualenv-south-git-and-fabric-part-4/>
>> [5]
>> http://www.abidibo.net/blog/**2012/06/29/deploy-django-**
>> applications-nginx-uwsgi-**virtualenv-south-git-and-**fabric-part-5/<http://www.abidibo.net/blog/2012/06/29/deploy-django-applications-nginx-uwsgi-virtualenv-south-git-and-fabric-part-5/>
>>
>> It helped me a lot, and it's very complete, covering also fabric tool.
>>
>> Enjoy it, and good luck!
>>
>>
>> 2012/11/9 Chris Pagnutti 
>>
>>  Hi.  I'm looking for a recent guide for setting up nginx to serve django
>>> projects in a virtualenv via uwsgi.  I can find a whole pile of them, but
>>> they're all so different, and some are dated.  I'm looking for something
>>> complete and recent that actually works.  Ideally, I'd like it to be for
>>> a
>>> Debian-based system, but I think if the guide is good, I should be able
>>> to
>>> do it for any distro.
>>>
>>> Thanks a whole bunch.
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/**msg/django-users/-/oqNciN_**d9QUJ<https://groups.google.com/d/msg/django-users/-/oqNciN_d9QUJ>
>>> .
>>> To post to this group, send email to django-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscribe@**googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/**group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>>> .
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to django-users+unsubscribe@**
>> googlegroups.com .
>> For more options, visit this group at http://groups.google.com/**
>> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
>> .
>>
>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to django-users+unsubscribe@**
> googlegroups.com .
> For more options, visit this group at http://groups.google.com/**
> group/django-users?hl=en<http://groups.google.com/group/django-users?hl=en>
> .
>
>

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



Re: index_together...shouldn't indexes be created AFTER populating the table?

2012-11-14 Thread Chris Pagnutti
Awesome.  So I don't even have to declare the "index_together" in the 
django models?  I can just create them afterwards using pure mysql?

LOAD DATA INFILE is wicked fast!!! Thanks a ton for that one.

On Wednesday, November 14, 2012 4:36:49 PM UTC-5, Javier Guerra wrote:
>
> On Wed, Nov 14, 2012 at 3:49 PM, Chris Pagnutti 
> > wrote: 
> > Thanks for your reply.  The tables I'm dealing with are entirely static, 
> but 
> > some have many millions of records, which is why I want my indexes to 
> work 
> > as good as possible.  If I create my indexes manually AFTER populating 
> the 
> > tables, will queries made via the django db api on those tables use 
> those 
> > indexes properly? 
>
> of course.  although in your case what i'd do is: 
>
> - create the table with indexes 
> - suspend them 
> - bulk-insert the data 
> - resume (and rebuild) indexes 
>
> it's mostly the same as you propose, but i just like having as much of 
> the description as possible in the Django model declaration. 
>
> OTOH, if you insert millions of records offline, you might not want to 
> do it with Django.  MySQL has the LOAD DATA INFILE command and 
> mysqlimport utility, for exactly this scenario.  The docs also advice 
> using ALTER TABLE tbl_name DISABLE/ENABLE KEYS commands to 
> suspend/resume indexing. 
>
>
> > I'm thinking the answer is yes, since the use of the indexes happens at 
> the 
> > mysql level, and django just has to issue the select statement. 
>
> exactly.  the choice of indexing strategy is done by the RDMS on a 
> per-statement basis. 
>
> in fact, since the index_together wasn't available, i have done 
> exactly that (create without indexes, add them manually) more than 
> once.  usually i intend to add the ALTER TABLE commands to 
> sql/modelname.sql files as described in 
>
> https://docs.djangoproject.com/en/1.4/howto/initial-data/#providing-initial-sql-data
>  
>
>
> finally, the top authority in bulk-insertion of data to Django is Cal 
> Leeming (a regular on this list); i haven't been able to see his 
> webinar yet, but i'm sure he has lots of insight to add to this. 
>
> -- 
> Javier 
>

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



Re: How to configure nginx to serve mail for django

2012-11-14 Thread Chris Pagnutti
Webmail function as a django application = Totally awesome idea.

I'll probably need some other email addresses for non-administrator users,
so a friendly client would be nice.  Roundcube should do the trick for now,
but integrating the webmail into the django app itself would be rad.



On Wed, Nov 14, 2012 at 4:37 PM, Dennis Lee Bieber wrote:

> On Wed, 14 Nov 2012 11:41:11 -0800 (PST), Chris Pagnutti
>  declaimed the following in
> gmane.comp.python.django.user:
>
> > Good point.  At the moment, sending mail is my priority, but eventually
> > I'll want to receive and view mail as well.  Most guides I can find
> relate
> > to setting up both sides of the story, so I figure I might as well just
> do
> > it all at once.
> >
>
> Well... The SMTP daemon should also handle the "receive" part; if
> properly configured with local user account mailboxes... (pre-spam era
> one could connect to any SMTPd to transfer mail; mail didn't have to
> either come from an internal user account or be sent to a local user
> account -- these days, that would be considered an open relay)
>
> I presume you have some sort of shell access to the server since
> you
> are doing configuration. Basic shell mail clients didn't* need POP3;
> they directly access the mailbox(es) on the machine itself. So if your
> intent is purely to receive mail being sent to /you/ as administrator of
> the server, you may not need the POP3/IMAP/Webmail stuff. Those
> protocols are meant for when the server is used to store emails that
> will be accessed from other computers at ad-hoc intervals. Since this is
> a Django group -- have you considered making the webmail function a
> Django application?
>
>
>
> * It's been too many years, but the first mail client I used on my old
> Amiga ONLY knew how to read a mailbox (AmigaElm); sending email invoked
> a subprocess that took the composed mail and submitted it to a queue
> directory -- it knew nothing about SMTP or POP3. I had to run a
> simplified SMTP to process the outgoing queue, and a timed job to do
> POP3 fetching into the mailbox. My first real Python program was to
> create an outgoing SMTPd, because the two packages I'd tried had flaws
> (one would block if it couldn't get to a destination host, the other
> never sent to CC/BCC addresses).
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: index_together...shouldn't indexes be created AFTER populating the table?

2012-11-14 Thread Chris Pagnutti
Thanks for your reply.  The tables I'm dealing with are entirely static,
but some have many millions of records, which is why I want my indexes to
work as good as possible.  If I create my indexes manually AFTER populating
the tables, will queries made via the django db api on those tables use
those indexes properly?

I'm thinking the answer is yes, since the use of the indexes happens at the
mysql level, and django just has to issue the select statement.

On Wed, Nov 14, 2012 at 3:42 PM, Javier Guerra Giraldez
wrote:

> On Wed, Nov 14, 2012 at 3:14 PM, Chris Pagnutti
>  wrote:
> > The new index_together feature is great, but I think it's best to create
> an
> > index on a table AFTER the table is filled, and assuming there won't be
> many
> > new inserts.
>
> AFAIK, this is an optimization advice applicable only for mostly-static
> tables.
>
> > But in django, syncdb creates the index at the same time the
> > table is created, and of course, the table is initially empty.  How does
> > django deal with this?
>
> nothing to deal with, this is normal behaviour in all SQL-based databases.
>
> > Does it know to drop the index before inserting new
> > records and re-create the index afterwards?
>
> hell, no!, that would be hideously inefficient!
>
> what could be workable is to do that only on really big batch inserts,
> only if the indexes don't carry a restriction (like UNIQUE indexes),
> and really part of an off-line operation, not in the normal HTTP
> request processing.
>
> --
> Javier
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



index_together...shouldn't indexes be created AFTER populating the table?

2012-11-14 Thread Chris Pagnutti
Hi.  The new index_together feature is great, but I think it's best to 
create an index on a table AFTER the table is filled, and assuming there 
won't be many new inserts.  But in django, syncdb creates the index at the 
same time the table is created, and of course, the table is initially 
empty.  How does django deal with this?  Does it know to drop the index 
before inserting new records and re-create the index afterwards?

If not, can I syncdb, drop the index manually in mysql, populate the table, 
then re-create the index manually (as long as I use the same index name 
that django chose)?  Will django be none-the-wiser if I do this?

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



Re: How to configure nginx to serve mail for django

2012-11-14 Thread Chris Pagnutti
Good point.  At the moment, sending mail is my priority, but eventually 
I'll want to receive and view mail as well.  Most guides I can find relate 
to setting up both sides of the story, so I figure I might as well just do 
it all at once.

On Tuesday, November 13, 2012 2:39:11 PM UTC-5, Dennis Lee Bieber wrote:
>
> On Mon, 12 Nov 2012 20:48:04 -0500, Chris Pagnutti 
> > declaimed the following in 
> gmane.comp.python.django.user: 
>
> > Not sure.  It's VPS and I was handed a Debian install with practically 
> > nothing on it.  I even had to install make to be able to compile nginx. 
> >  I'm looking into setting up Postfix+Dovecot+Roundcube (or SquirrelMail) 
> > 
>
> As I recall, your problem was to SEND mail. From a quick Google 
> session, Dovecot and Roundcube are not products for sending mail -- 
> Dovecot being a POP3/IMAP server and Roundcube a web-mail interface. 
> Were you planning on hosting /mailboxes/ for users? 
>
> Postfix (alternatively, Sendmail, qmail, exim -- though qmail has 
> fallen behind in features) is the only item in the list needed to send 
> email /out/.  {If I recall, it would also be used to receive mail sent 
> to your server, and /that/ would then need to be placed into a local 
> account mailbox -- you may need a POP3/IMAP server if you want to later 
> read those [presuming the only inbound is stuff for the sysop: 
> postmas...@.xxx, ad...@.xxx, something like that] without SSH 
> into the server environment}. 
>
> {Hmmm, http://en.wikipedia.org/wiki/Exim implies the default SMTPd for 
> Debian is exim} 
>
>
>
>
> -- 
> Wulfraed Dennis Lee Bieber AF6VN 
> wlf...@ix.netcom.com 
> HTTP://wlfraed.home.netcom.com/ 
>
>

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



Re: How to configure nginx to serve mail for django

2012-11-12 Thread Chris Pagnutti
Not sure.  It's VPS and I was handed a Debian install with practically
nothing on it.  I even had to install make to be able to compile nginx.
 I'm looking into setting up Postfix+Dovecot+Roundcube (or SquirrelMail)

On Mon, Nov 12, 2012 at 8:37 PM, Dennis Lee Bieber wrote:

> On Mon, 12 Nov 2012 12:51:57 -0800 (PST), Chris Pagnutti
>  declaimed the following in
> gmane.comp.python.django.user:
>
> > Yeah.  Makes good sense.  I guess that Postfix is one of the more popular
> > options.  Is there any reason why I should NOT use postfix.
> >
> Well, do you already have access to a running SMTP daemon? (Does
> your server machine respond to local connection attempts on port 25? Is
> the server machine part of a network that may have an SMTPd located on
> another machine?
> ).
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: How to configure nginx to serve mail for django

2012-11-12 Thread Chris Pagnutti
Yeah.  Makes good sense.  I guess that Postfix is one of the more popular 
options.  Is there any reason why I should NOT use postfix.

On Monday, November 12, 2012 1:47:03 PM UTC-5, Nikolas Stevenson-Molnar 
wrote:
>
>  The nginx configuration examples you link to are all POP3 or IMAP. 
> Sending mail is SMTP. But even then, you need an SMTP server to proxy *to*. 
> In these examples, nginx is simply acting as a proxy, not as an actual mail 
> server. I would recommend using a bona fide SMTP server. Or use one already 
> available to you from your mail provider (e.g., if you use GMail, you can 
> configure Django to use GMail's mail servers to send email).
>
> _Nik
>
> On 11/12/2012 10:22 AM, Chris Pagnutti wrote:
>  
> Hi.  I'm using nginx+uwsgi to serve a django app.  I'd like to configure 
> it to be able to send mail with django's send_mail() and send_mass_mail() 
> functions.  I've played with the nginx configuration files using the 
> examples here 
> http://wiki.nginx.org/Configuration#Mail_examples
>  
>  I have a very simple view that just does 
>  
> from django.core.mail import send_mail
> send_mail('Subject here', 'Here is the message.', 'fr...@example.com 
> ',
> ['t...@example.com '], fail_silently=False)
>
>  
>  but with my email addresses in there of course.  The view doesn't throw 
> any exceptions, but it also doesn't send the email (or do anything else for 
> that matter).  Can someone help me with getting nginx to serve email for 
> django, or at least point me in the right direction?  Thanks to all.
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/django-users/-/yfrTK_xhMpUJ.
> To post to this group, send email to django...@googlegroups.com
> .
> To unsubscribe from this group, send email to 
> django-users...@googlegroups.com .
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>  

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



How to configure nginx to serve mail for django

2012-11-12 Thread Chris Pagnutti
Hi.  I'm using nginx+uwsgi to serve a django app.  I'd like to configure it 
to be able to send mail with django's send_mail() and send_mass_mail() 
functions.  I've played with the nginx configuration files using the 
examples here
http://wiki.nginx.org/Configuration#Mail_examples

I have a very simple view that just does 

from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', 'f...@example.com',
['t...@example.com'], fail_silently=False)


but with my email addresses in there of course.  The view doesn't throw any 
exceptions, but it also doesn't send the email (or do anything else for 
that matter).  Can someone help me with getting nginx to serve email for 
django, or at least point me in the right direction?  Thanks to all.

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



Django in virtualenv + nginx + uwsgi set up guide

2012-11-08 Thread Chris Pagnutti
Hi.  I'm looking for a recent guide for setting up nginx to serve django 
projects in a virtualenv via uwsgi.  I can find a whole pile of them, but 
they're all so different, and some are dated.  I'm looking for something 
complete and recent that actually works.  Ideally, I'd like it to be for a 
Debian-based system, but I think if the guide is good, I should be able to 
do it for any distro.

Thanks a whole bunch.

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



Re: Help with Custom model field and Custom validation for EmailField().

2012-11-03 Thread Chris Pagnutti
I've never done it myself, but I think you'd just define the clean method
in your Form's class (i.e. in forms.py), and the first line in your clean()
method should call the parent classes, clean() method - to do this you need
to call the super() method, which is just regular python.  It think the
call would look something like this

super(YourFormClass,self).clean()

On Sat, Nov 3, 2012 at 6:55 AM, Dilip M  wrote:

> Hi Chris,
>
> Thank you very much for your time on this. I am not able to make out on
> how could I put this under clean() method. Ex: What does "you must call the
> * parent class's clean()"* mean in "if you would like to override the
> clean() method and maintain the _default validation_, you must call the
> parent class's clean() method."
>
> This clean() method will go in models.py? or forms.py? Any simple examples
> would be of great help!
>
> Many thanks...Dilip
>
>
>
> On Fri, Nov 2, 2012 at 8:12 PM, Chris Pagnutti 
> wrote:
>
>> Ahh.  Just saw your link to overriding the clean() method.  So you could
>> put all the same logic above into the clean() method instead.
>>
>>
>> On Friday, November 2, 2012 4:36:20 AM UTC-4, Dilip M wrote:
>>
>>> Hi,
>>>
>>> I am new to Django. Went through docs before posting this.. I have a
>>> model and form like this.
>>>
>>> models.py:
>>>
>>> class Recipients(models.Model):
>>>  dev = models.EmailField()
>>>  qa = models.EmailField()
>>>  cc = models.MultipleEmailField()
>>>
>>> forms.py:
>>>
>>> class RecipientsForm(forms.**ModelForm):
>>>
>>> class Meta:
>>> model = Recipients
>>>
>>>
>>> Now I want to,
>>>
>>> 1. Add *additional* validation for models.EmailField(). Something like
>>> check if email id entered exists in LDAP db.
>>> 2. Create new model custom field MultipleEmailField(), which would split
>>> emails separated by comma and uses modified validation of
>>> models.EmailField() done in step 1.
>>>
>>> I am going through docs, but not able to figure out how to put things
>>> together! Here is what I understood.
>>>
>>> MultipleEmailField() should go in /fields.py. But how to
>>> make it to run default validation of models.EmailField() and than do custom
>>> validation?
>>>
>>>
>>> Any help appreciated..
>>>
>>>
>>> Thanks. Dilip
>>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



Re: Help with Custom model field and Custom validation for EmailField().

2012-11-02 Thread Chris Pagnutti
Ahh.  Just saw your link to overriding the clean() method.  So you could 
put all the same logic above into the clean() method instead.

On Friday, November 2, 2012 4:36:20 AM UTC-4, Dilip M wrote:
>
> Hi,
>
> I am new to Django. Went through docs before posting this.. I have a model 
> and form like this.
>
> models.py:
>
> class Recipients(models.Model):
>  dev = models.EmailField()
>  qa = models.EmailField()
>  cc = models.MultipleEmailField()
>
> forms.py:
>
> class RecipientsForm(forms.ModelForm):
>
> class Meta:
> model = Recipients
>
>
> Now I want to,
>
> 1. Add *additional* validation for models.EmailField(). Something like 
> check if email id entered exists in LDAP db.
> 2. Create new model custom field MultipleEmailField(), which would split 
> emails separated by comma and uses modified validation of 
> models.EmailField() done in step 1.
>
> I am going through docs, but not able to figure out how to put things 
> together! Here is what I understood.
>
> MultipleEmailField() should go in /fields.py. But how to 
> make it to run default validation of models.EmailField() and than do custom 
> validation?
>
>
> Any help appreciated..
>
>
> Thanks. Dilip
>

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



Re: Help with Custom model field and Custom validation for EmailField().

2012-11-02 Thread Chris Pagnutti
Again, I'm not sure, but I think to do it at Model validation level you'd 
have to modify some of the django core files themselve.  I think what 
you're looking for is in django.core.validators (in my install this file is 
at /lib/python2.7/site-packages/django/core/validators.py, or you can just 
search for validators.py on your system)  But I've had my own troubles that 
I thought I could solve by modifying the django files themselves (and it 
works), but everyone that helped me advised that this is not the best way 
to do it, because future updates of django itself will break your changes.

I think the best way to do it is in your view that handles the form.  For 
point 2., just make you MultipleEmailField() a CharField instead, and 
validate it in your view.  For example, you could do something like this 
(note that I'm pulling lots of this from the docs and here 
http://stackoverflow.com/questions/3217682/checking-validity-of-email-in-django-python,
 
and I haven't tested it)

from django.shortcuts import render
from django.http import HttpResponseRedirect

def your_form_handling_view(request):
if request.method == 'POST': # If the form has been submitted...
form = YourForm(request.POST) # A form that you created in your 
forms.py
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data...get all the fields 
that require further validation
your_multipleemail_field = 
form.cleaned_data['your_multipleemail_field']
# perform the extra validation here, for example
extra_validation_passes = True
for email in your_multipleemail_field.split(','):
if email_id_exists(email) and not(validateEmail(email)): 
 #assuming some_field is the email id and email_id_exists() is your 
function that validates it
#Create your custom errors here
form.your_multipleemail_field.errors = "Email id 
already exists in LDAP or is invalid"
extra_validation_passes = False
if extra_validation_passes:
return HttpResponseRedirect('/thanks/') # Redirect after 
POST
return render(request, 'template_with_your_form_on_it.html', 
{'form': form,}) #Now this form goes back to the template with your custom 
errors.

else:
form = YourForm() # An unbound form

return render(request, 'template_with_your_form_on_it.html', {'form': 
form,})

This is a separate global function you might want to put somewhere other 
than views.py (maybe models.py, but don't forget to import it in views.py 
if you do this)

def validateEmail( email ):
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
try:
validate_email( email )
return True
except ValidationError:
return False


Again, not sure if this works, I've never added custom errors to a form 
like this, but I think forms are normal objects and if the .errors are just 
strings, I don't see why it wouldn't work. In fact it probably doesn't work 
but it might give you some ideas.  Of course, you could split the 
conditional "if email_id_exists(email) and not(validateEmail(email)):" to 
test them separately to give more precise error messages.

Hope that helps.

On Friday, November 2, 2012 4:36:20 AM UTC-4, Dilip M wrote:

> Hi,
>
> I am new to Django. Went through docs before posting this.. I have a model 
> and form like this.
>
> models.py:
>
> class Recipients(models.Model):
>  dev = models.EmailField()
>  qa = models.EmailField()
>  cc = models.MultipleEmailField()
>
> forms.py:
>
> class RecipientsForm(forms.ModelForm):
>
> class Meta:
> model = Recipients
>
>
> Now I want to,
>
> 1. Add *additional* validation for models.EmailField(). Something like 
> check if email id entered exists in LDAP db.
> 2. Create new model custom field MultipleEmailField(), which would split 
> emails separated by comma and uses modified validation of 
> models.EmailField() done in step 1.
>
> I am going through docs, but not able to figure out how to put things 
> together! Here is what I understood.
>
> MultipleEmailField() should go in /fields.py. But how to 
> make it to run default validation of models.EmailField() and than do custom 
> validation?
>
>
> Any help appreciated..
>
>
> Thanks. Dilip
>

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



<    1   2   3   4   5   6   7   8   9   10   >