Re: manage.py not able to run any commands

2019-12-18 Thread Ian Githungo
First you have to check if you have activated your Visual environment which
you have installed Django

On Tue, Dec 17, 2019, 2:36 PM Phil Yang  wrote:

> Hi,
> All of a sudden, when I tried to run manage.py runserver, it didn't
> produce any output, and it didn't do anything. In fact, the manage.py
> script seems to not be able to run other commands, such as startapp or
> createsuperuser.
>
> I've already used the command many times prior, and it has always worked
> perfectly.
>
> Yes, Python is installed (I can run other scripts), but manage.py seems to
> have an issue.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c4b172e2-15a9-4fbf-96b6-e137086f614e%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANW_d%2Bh4cJf9QD_CKOXsoHKryYuCHsiDUCnXybJy1%2BMJcbJniw%40mail.gmail.com.


Re: manage.py can't run any commands

2019-12-18 Thread Ian Githungo
have you checked the virtual environment which you have installed the
version of Django you are currently using?


On Tue, Dec 17, 2019 at 2:36 PM Phil Yang  wrote:

> Hi,
> The manage.py script for all my projects has suddenly stopped working. It
> can't run any commands, such as runserver or startapp.
>
> Python is installed correctly; I have tested this with other scripts. I
> deleted Django and reinstalled, the problem still persists.
>
> Basically, whenever I run manage.py, there is no output.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c0c868e0-f780-43c0-aced-a7d2bfffdaf0%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANW_d%2BhThGL5csf3haf6t8hiG2%3DJqTJYOzi-JgvaENL_o8SdyA%40mail.gmail.com.


Deleting a record exactly once

2019-08-01 Thread Ian Hoffman
Hi everyone,

I work on a medium-sized app where we might have tens of concurrent 
requests in flight at once. The application runs on Django 1.11, Python 3.5.

The problem I have is this: the web client requests to delete a record. On 
a successful delete, the app creates an "audit" record memorializing this 
delete, containing information about the record which was deleted. This is 
used in ETL jobs later. (I know there might be better ways of doing this 
sort of tracking, but I'm not looking to change that right now.)

Now, it's possible that, by toggling a button, the web client can send a 
stream of delete and create requests for this record. These may be received 
out-of-order by various server instances running in the cloud. So the 
following sequence (corresponding to CREATE -> DELETE -> CREATE -> DELETE) 
can happen:

   1. Request: Create record 1 for Server A 
   2. Request: Create record 1 for Server B
   3. Server A: Record 1 created, audit record cut
   4. Server B: No-op (Record 1 already exists)
   5. Request: Delete record 1 for Server A
   6. Request: Delete record 1 for Server B
   7. Server A: Record 1 deleted, audit record cut
   8. Server B: Record 1 deleted, audit record cut

This demonstrates that we may have 2 delete audit records for a single 
create audit record, which is just wrong. 

I tried a fix along the following lines:

records = Record.objects.filter(pk=...)
record = objects.first()
num_deleted, _ = records.delete()
if num_deleted == 1:
Audit.objects.create_from_record(record) 

I had hoped this would work because, according to the Django docs, "The 
delete() is applied instantly.". 

However, I still seem to be able to trigger the race condition. 

I'm considering handling this on the frontend by queuing requests and 
waiting for the server to return a response before firing the next one, but 
it'd be nice to have a backend that can actually defend against this sort 
of thing. I'm also considering using a mutex, but it seems like Django 
should provide this functionality.

Wondering if anyone has suggestions around how to handle race conditions 
like this one. This can't be an uncommon problem, can it?

Any feedback is very much appreciated!

Thanks,
Ian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7438f2b4-9e47-4a1a-9087-667be14b027c%40googlegroups.com.


AttributeError: 'Settings' object has no attribute 'SATIC_ROOT'

2017-09-21 Thread Ian Likono
Iam following up a tuitorial on Django 
https://www.youtube.com/watch?v=9Wbfk16jEOk=192s. 

I have followed everything up as he has instructed but after running server 
i get the error:
(tryTen) root@likono:~/Desktop/tryTen/tryten# python manage.py runserver
Performing system checks...

Unhandled exception in thread started by 
Traceback (most recent call last):
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/utils/autoreload.py",
 
line 227, in wrapper
fn(*args, **kwargs)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py",
 
line 125, in inner_run
self.check(display_num_errors=True)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/core/management/base.py",
 
line 359, in check
include_deployment_checks=include_deployment_checks,
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/core/management/base.py",
 
line 346, in _run_checks
return checks.run_checks(**kwargs)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/core/checks/registry.py",
 
line 81, in run_checks
new_errors = check(app_configs=app_configs)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/core/checks/urls.py",
 
line 16, in check_url_config
return check_resolver(resolver)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/core/checks/urls.py",
 
line 26, in check_resolver
return check_method()
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/urls/resolvers.py",
 
line 254, in check
for pattern in self.url_patterns:
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/utils/functional.py",
 
line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/urls/resolvers.py",
 
line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", 
self.urlconf_module)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/utils/functional.py",
 
line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/urls/resolvers.py",
 
line 398, in urlconf_module
return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
  File "/root/Desktop/tryTen/src/tryten/urls.py", line 30, in 
urlpatterns += static(settings.STATIC_URL, 
document_root=settings.SATIC_ROOT)
  File 
"/root/Desktop/tryTen/local/lib/python2.7/site-packages/django/conf/__init__.py",
 
line 57, in __getattr__
val = getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'SATIC_ROOT'

*Here *

*is my setting.py file:*"""Django settings for tryten project.

Generated by 'django-admin startproject' using Django 1.11.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=jh1ap8w5b93l3e$p)#h1wrax3+=(@=%6dgha*_s3fgll@a03m'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'profiles',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'tryten.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'tryten.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases


Re: Running django on demand via my PyQt4 Standalone app

2016-10-26 Thread Dam ian
yeah you are right with the WoW effect :) and i know this framework but its 
to complex for me :P i prefere to use PyQt4, for example you have something 
like QT Designer where you can graphically deploy and customize the whole 
UI and then convert to pure python, what make me my work easier. If kivy 
had a usable graphicall editor i think i will choose this framework :) 

I used to do home automation, so I know you need an interface with very 
> high "WOW!" factor AND PORTABILITY. That is why I proposed you check kivy (
> http://kivy.org 
> ).
>  
> kivy is the kick-ass interface I'd use, bar none.
>
> this of course my opinion and recomendation, but you know YAHOO.
>

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


Re: Running django on demand via my PyQt4 Standalone app

2016-10-25 Thread Dam ian
Hi again,

and thanks for the answer and Tips 

@Mario R. Osorio 
>I cannot understand is why would you need django for admin, but use some 
other standalone (desktop?) application for everything else.  You should 
try and stay either on the django or on the standalone application. 

i think i must add why i need to use a "desktop app" and a web server for 
the "desktop app" :). The desktop app i need for something like this



for the user to control all devices @home, its a home Automatisation 
Controlling UI (wirten in PyQt)and second part - the web part (django) i 
need to setup the whole system, to add new hardware micro controller to 
customize the whole UI. I could add the whole settings / customizing stuff 
to the UI but from the user experience side it would not be optimal, u know 
what i mean? This UI should be only to Control not to setup things.


@all others

now the SQL part in PyQt i do whit QSql and its ok for me,if i use django 
it's not a problem for me to use only for the web part the django way. 

Why i would use django because in the future i will develop some Smart 
Phone app to Control the system too and i read that django add 
automatically some API what make me easier to add the communication between 
the mobile app and my standalone application

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


Running django on demand via my PyQt4 Standalone app

2016-10-24 Thread Dam ian
Hi,

I work on some Smart Home UI / Controlling system using PyQt4, now I'm in 
the point where i need a Web Server to share a "Admin Page" to let the user 
change some Smart Home settings (via web page of course :p ). I searched 
the internet for a answer / idea and I think that the django server would 
be the best solution, e.g. like django my "APP" also use a SQLite DB. I 
need that the server is running only if the user activate the "Admin Mode" 
and want do some change to the UI / App and only locally.

unfortunately i still learning python and my knowledge is not on the level 
to do this in the right way and I thought, that maybe someone of you can 
help me:


Q1: Is it good idea to start a new QThread who runs the script 
os.system("web/manage.py runserver")?
Q2: If yes - how can i stop the server - maybe through terminating the 
QThread?
Q3: If no - what is the best method to start a django server on demand via 
my PyQt4 App and to stop it?
Q4: can i share my DB whit django, is this a good idea?
Q5: can i access from django server my app components class, variable etc. 
and vice versa ( if the server is running)?
Q6: can u point me where i can find some documentation or example to get 
closer to my goal?


i know there many ways how to do this ( or not) but I would like to achieve 
it via the "pythonic way" / best practices
if someone from you can hep me I would be very grateful 

Cheers Damian

PS. Sorry for my not best english

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


Subscribe / unsubscribe to data streams over websocket channel

2016-09-30 Thread Ian Danforth
Hello!

 Channels + databinding is a great way to push updates to clients of an 
API. I'm wondering however if there are any good examples of the client 
being able to subscribe and unsubscribe to streams of data over an existing 
websocket/channel pair (while making use of databinding)

 For example, github.com will send a message like this from the client to 
the server when it wants to get a particular data stream over the websocket:

subscribe:tenant:1:repo:51179261:branch:master

 I'd like to provide this kind of protocol to my clients. I think it may 
have to go into a custom consumer, but any examples / insights into this 
pattern would be greatly appreciated.

Ian

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


Re: Tutorial missing import: Http404

2015-04-10 Thread John Matthew Ian Davis

On Friday, April 10, 2015 at 3:33:36 PM UTC-7, Ramiro Morales wrote:
>
> On Fri, Apr 10, 2015 at 6:31 PM, John Matthew Ian Davis <
> johnmatth...@gmail.com > wrote:
>
>> obviously one needs to change:
>>
>> from django.http import HttpResponse, 
>>
>> to
>>
>> from django.http import HttpResponse, Http404
>>
>
> If you are talking about part 3 of the tutorial then it in fact contains 
> an import of Http404 and it's intrdroduced together with the first piece of 
> code that uses it.
>
> It's right in the views.py snippet located under the "Raising a 404 error" 
> section title: 
> https://docs.djangoproject.com/en/1.8/intro/tutorial03/#raising-a-404-error
>
> Regards,
>
> -- 
> Ramiro Morales
> @ramiromorales
>

 You (and the page) are completely correct, and I missed the relevant line, 
reading through, a half dozen times in a row. Apologies. 

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


Tutorial missing import: Http404

2015-04-10 Thread John Matthew Ian Davis
obviously one needs to change:

from django.http import HttpResponse, 

to

from django.http import HttpResponse, Http404

but that's a speed-bump that should not be in the tutorial.

NameError at /polls/34/ 

global name 'Http404' is not defined

 Request Method: GET  Request URL: http://localhost:8000/polls/34/  Django 
Version: 1.8  Exception Type: NameError  Exception Value: 

global name 'Http404' is not defined

 Exception Location: 
/home/john/Documents/code/python/django/djangostart/polls/views.py 
in detail, line 19  Python Executable: /usr/bin/python  Python Version: 
2.7.6  Python Path: 

['/home/john/Documents/code/python/django/djangostart',
 '/usr/local/lib/python2.7/dist-packages/Django-1.8-py2.7.egg',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

 Server time: Fri, 10 Apr 2015 21:30:24 +

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


Stopping request when exception occurs (admin interface)

2014-11-26 Thread ian . k
Hi there,

Hopefully an easy question. I've overridden save_model() in my admin page, 
and I'm wrapping my obj.save() call in a try/catch so that I can catch a 
RecordModifiedError. 

def save_model(self, request, obj, form, change):
 
from concurrency.exceptions import RecordModifiedError
from django.http import HttpResponse
try: 

obj.save()
#other stuff

except RecordModifiedError:
self.message_user(request,
"[!] Record modified. Please try again.",
level="error")
return None

The message saying record modified is shown when it should be. However, 
there is also a message at the top saying that the save was successful, 
when in fact it was not. 
What's the proper way to stop the success message from occurring? Can I 
clear it, or stop the request? Return None doesn't seem to help.

Thanks!

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


Has anyone successfully used django-concurrency?

2014-11-21 Thread ian . k
 res, None))
  File 
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py",
 line 258, in __init__
super(ResultList, self).__init__(*items)
  File 
"/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templatetags/admin_list.py",
 line 185, in items_for_result
f, attr, value = lookup_field(field_name, result, cl.model_admin)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/util.py", 
line 254, in lookup_field
value = attr(obj)
  File "/usr/local/lib/python2.7/dist-packages/concurrency/admin.py", line 37, 
in action_checkbox
get_revision_of_object(obj
  File "/usr/local/lib/python2.7/dist-packages/concurrency/api.py", line 23, in 
get_revision_of_object
return getattr(obj, get_version_fieldname(obj))
  File "/usr/local/lib/python2.7/dist-packages/concurrency/core.py", line 22, 
in get_version_fieldname
return obj._concurrencymeta._field.attname
AttributeError: 'Configuration' object has no attribute '_concurrencymeta'
[21/Nov/2014 20:29:51] "GET /test/common/configuration/ HTTP/1.1" 500 368613


I also changed {{ obj.pk }} to {{ obj|identity }} in 
delete_selected_confirmation.html as directed in the documentation. 
<https://django-concurrency.readthedocs.org/en/latest/admin.html>

Does anyone know how to set this project up? Any help at all would be 
greatly appreciated.

Thanks!

Ian

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


django-locking

2014-11-21 Thread ian . k
Hi everyone,

I'm posting new message because I have a different question. Has anyone had 
any luck using django-locking (https://github.com/RobCombs/django-locking) 
with a modern version of Django's admin interface? 

I've got it mostly working with my project. Basically Django is set up to 
add and remove fields from "Configuration"s. We have our own database 
object called "Configuration", with a number of fields that the admin 
interface edits. You can create more than one Configuration, and edit 
existing ones. (This is what we're trying to add locking to.)

Right now, when we go in to edit a Configuration, there's a 404 error in 
the console when it tries to access 
/admin/ajax/test/common/configuration/is_locked/?_=1416587837817.


It looks like it for some reason is not checking the lock on a specific 
Configuration. I think it should be doing this: 
/admin/ajax/test/common/configuration/1/is_locked/?_=1416587837817.


So I went to my browser, and tried accessing 
/admin/ajax/test/common/configuration/1/is_locked/?_=1416587837817. This 
gives a 404, 
saying configuration object with primary key u'1/is_locked' does not exist.

So I think there's two issues here:
1. It is not checking the lock status for a specific Configuration. (not 
adding the /1/ )
2. Even if it does, it is getting an error when it tries to look for 
is_locked in the database?

Does anyone know how to fix either of these issues?
I'm on Django 1.6.8, and using the latest version of django-locking from 
the GitHub page.

Any help would be greatly appreciated. Thank you!

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


Re: Trying to use django-locking (I know it's old)

2014-11-20 Thread ian . k
*I have since fixed the above issue, but am encountering another one.*

It's now saying in the console:
Not Found: /admin/ajax/test/common/configuration/1/is_locked/

But, entering /admin/ajax/test/common/configuration/1/ into a browser is 
working perfectly - showing me the first Configuration item in my project. 

Do you know what could be causing this? The other parts of the added code 
seem to be located just fine.

Thanks!
Ian



On Thursday, November 20, 2014 11:02:29 AM UTC-7, ia...@me.com wrote:
>
> Hi there,
>
> I'd like to try and add django-locking (
> https://github.com/RobCombs/django-locking) to my Django project's admin 
> page. (version 1.6.8)
>
> I've installed the egg file and fixed an import statement that used 
> deprecated code. When running step 7 of the installation steps (see github 
> page above), it's complaining now that my settings object has no ADMIN_URL 
> attribute. I can't find any documentation about how to properly set this 
> attribute, or if it's out of date, what to replace it with. The actual 
> exception is this:
>
>   File 
> "/usr/local/lib/python2.7/dist-packages/django_locking-0.3.2-py2.7.egg/locking/admin.py",
>  
> line 15, in 
> class LockableAdmin(admin.ModelAdmin):
>   File 
> "/usr/local/lib/python2.7/dist-packages/django_locking-0.3.2-py2.7.egg/locking/admin.py",
>  
> line 17, in LockableAdmin
> class Media:
>   File 
> "/usr/local/lib/python2.7/dist-packages/django_locking-0.3.2-py2.7.egg/locking/admin.py",
>  
> line 21, in Media
> _s.ADMIN_URL + "ajax/variables.js",
>   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", 
> line 55, in __getattr__
>     return getattr(self._wrapped, name)
> AttributeError: 'Settings' object has no attribute 'ADMIN_URL'
>
>
> Please help if you can. Thanks!
> - Ian
>

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


Trying to use django-locking (I know it's old)

2014-11-20 Thread ian . k
Hi there,

I'd like to try and add django-locking 
(https://github.com/RobCombs/django-locking) to my Django project's admin 
page. (version 1.6.8)

I've installed the egg file and fixed an import statement that used 
deprecated code. When running step 7 of the installation steps (see github 
page above), it's complaining now that my settings object has no ADMIN_URL 
attribute. I can't find any documentation about how to properly set this 
attribute, or if it's out of date, what to replace it with. The actual 
exception is this:

  File 
"/usr/local/lib/python2.7/dist-packages/django_locking-0.3.2-py2.7.egg/locking/admin.py",
 
line 15, in 
class LockableAdmin(admin.ModelAdmin):
  File 
"/usr/local/lib/python2.7/dist-packages/django_locking-0.3.2-py2.7.egg/locking/admin.py",
 
line 17, in LockableAdmin
class Media:
  File 
"/usr/local/lib/python2.7/dist-packages/django_locking-0.3.2-py2.7.egg/locking/admin.py",
 
line 21, in Media
_s.ADMIN_URL + "ajax/variables.js",
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", 
line 55, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'ADMIN_URL'


Please help if you can. Thanks!
- Ian

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


Re: Problems connecting to an oracle legacy db

2014-06-04 Thread Ian
On Wednesday, June 4, 2014 2:38:34 AM UTC-6, Vittorio wrote:
>
> #models.py 
> ... 
> class magazzino_vista_lista(models.Model): 
> id_ordine = models.IntegerField(null=False, blank=False, 
> db_column='ID_ORDINE') 
> cod_magazzino_galileo = models.CharField(max_length=48, 
> db_column='COD_MAGAZZINO_GALILEO') 
> cod_magazzino_ext = models.CharField(max_length=48, 
> db_column='COD_MAGAZZINO_EXT') 
> qta = models.IntegerField(null=False, blank=False, db_column='QTA') 
> class Meta: 
> managed = False 
> db_table = u'noema.magazzino_vista_lista' 
> verbose_name_plural = "CC specifica ordini vista" 
>
> * See the real oracle table is named 'noema.magazzino_vista_lista' as 
> in the sql I called before under python * 
>
>
Django currently doesn't understand schemas, and it quotes and treats the 
"noema." as being part of the table name rather than a schema. There's a 
hacky way (which basically amounts to SQL injection by the developer) to 
make it quote the schema and table separately, but I recommend creating 
synonyms to your tables in the schema that Django actually connects to.

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


Re: can't compare datetime.datetime to datetime.date

2014-01-27 Thread ian
You're comparing pub_date, which is a datetime.date, to timezone.now(), 
which is a datetime.datetime. Check the docs 
at http://docs.python.org/2/library/datetime.html for more.

In order to convert timezone.now() to a date, just call 
timezone.now().date(), like:

In [1]: from django.utils import timezone

In [3]: timezone.now()

Out[3]: datetime.datetime(2014, 1, 27, 14, 42, 29, 408491, tzinfo=)

In [4]: timezone.now().date()

Out[4]: datetime.date(2014, 1, 27)

On Monday, January 27, 2014 5:38:20 AM UTC-8, Rafał Szymański wrote:
>
> Hi again
>
> I wolud like ask another question.
> If someone would be so kind and help that will be great.
> I'm in the begining of django tutorial.
>
> I use python3.3 and django1.6
>
> I get error:
> can't compare datetime.datetime to datetime.date
>
> Here is my code:
>
> import datetime
> from django.utils import timezone
> from django.db import models
>
> class Poll(models.Model):
> question = models.CharField(max_length=200)
> pub_date = models.DateField('date published')
> def was_published_recently(self):
> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
> def __str__(self):
> return self.question
>
> class Choice(models.Model):
> poll = models.ForeignKey(Poll)
> choice_text = models.CharField(max_length=200)
> votes = models.IntegerField(default=0)
> def __str__(self):
> return self.choice_text
>
> Thanks in advance
> Rafał
>

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


Storages API modified_time() and timezones.

2013-10-18 Thread Ian Lewis
Hi,

I'm trying to get a handle on the modified_time() method in the Storages
API. I couldn't find any hints in the doc as to what the right way to
implement the modified_time() method was in regard to timezones. Currently
it looks like the default FileSystemStorage backend returns the modified
time as returned from os.path.getmtime() which is in the system timezone.

Should the modified time as returned by modified_time() be in the system
timezone (this is not the TIME_ZONE setting)? i.e. the FileSystemStorage is
the de-facto standard?

The reason I ask this is because it raises an issue when using other
different backends together since the collectstatic command will compare
modified times of files from the different backends to determine if it
needs to update the file. We have problems with this because some systems
like AWS's S3 will return the modified time in UTC or some other timezone
and need to be converted.

-- 
Ian

http://www.ianlewis.org/

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


PyCon APAC CFP

2013-07-03 Thread Ian Lewis
Hey Django users!

I wanted to get the word out that we are accepting talks for this year's
PyCon APAC in Tokyo Japan. If you have ever wanted to visit Tokyo and you
have a Python topic you are passionate about then this is your chance!

The conference is formatted into 4 tracks, 2 Japanese and 2 English tracks.
We are especially looking for English speakers to give talks so be sure
submit a talk proposal. I was a bit late getting the word out to the U.S.
mailing lists so there is only a week left to submit proposals. Don't sit
on it!
http://apac-2013.pycon.jp/speakers/cfp.html

More info about PyCon APAC

The conference is being held on Sept. 14th-15th with tutorials on the 13th
and development sprints being held on the 16th. We are hoping to have up to
500 participants this year (PyCon JP sold out at 400 last year). George
Brandl (@birkenfeld) is our first keynote speaker. We have another really
exciting keynote speaker lined up.

You can find out more about the conference details on the about page:
http://apac-2013.pycon.jp/about/index.html

The conference venue is the Kogakuin University Shinjuku Campus in the
heart of Tokyo. Anyone coming to the conference won't be at a loss for
things to do :)
http://apac-2013.pycon.jp/venue/index.html

...Or if you would just like to come and participate we welcome that too!
Conference registration is currently open:

Early Bird Registration: http://connpass.com/event/2703/
Patron Sponsor Registration: http://connpass.com/event/2704/

Thanks! If anyone has questions I'll do my best to answer them.
Hope to see you in Tokyo!

-- 
Ian

http://www.ianlewis.org/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: internal server error not sending message notification

2013-05-04 Thread Ian Lewis
Hi,

Did you set your LOGGING configuration in your settings.py? If you happened
to upgrade to Django 1.5 then the default LOGGING configuration went away
and it will no longer sent emails to the admins without some configuration.
This is described at the following url where it says "Prior to Django 1.5":
https://docs.djangoproject.com/en/dev/topics/logging/#configuring-logging

You need to set up something like the following for admin error mails to
work:

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'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}

Hope that helps,
Ian


On Sat, May 4, 2013 at 8:01 AM, ?manu* <emanuele.paol...@gmail.com> wrote:

> I suddenly realized that my server is no more sending email notifications
> when an internal error occurs. I'm not sure which could be the modification
> that caused this behavior. I have the following information:
>
> 1. on internal errors the server gives an error not founding template file
> 500.html.
>
> 2. if I put my 500.html template then django does not complain anymore,
> shows the page but does not send the email message.
>
> 3. from manage.py shell the command django.core.mail.mail_admins works
> fine (email arrives to the admins)
>
> Any clue?
>
> Thanks,
> E.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Ian

http://www.ianlewis.org/

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




Re: FW:

2013-05-04 Thread Ian Foote
Sorry for this everyone. My password wasn't strong enough. I've updated 
it now.


Ian

On 04/05/13 03:36, Kurtis Mullins wrote:

Phishing Web Site (SPAM)


On Sat, Apr 6, 2013 at 9:10 PM, Ian Foote <i...@feete.org
<mailto:i...@feete.org>> wrote:

Snip

--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to django-users+unsubscr...@googlegroups.com
<mailto:django-users%2bunsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



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




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




FW:

2013-05-03 Thread Ian Foote
http://kyokushin-aoki.sakura.ne.jp/www/tvojdi.php

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




Re: Oracle database TextField limitations and Django admin interface queries

2013-04-13 Thread Ian
On Saturday, April 13, 2013 10:40:10 AM UTC-6, Ian wrote:
>
> On Friday, April 12, 2013 7:43:32 AM UTC-6, Lauri Savolainen wrote:
>>
>> Thank you for the reply,
>>
>> The field is defined in the Django model as:
>> location_description = models.TextField(_('additional route 
>> information'), blank=True)
>>
>> Data length for the corresponding column in the database seems to be 4000 
>> and the type is NCLOB. The database is created by Django's syncdb and is 
>> not a legacy one.
>>
>> This is the raw SQL query the Django admin interface produces:
>>
>> SELECT DISTINCT "app_route"."id", 
>> "app_route"."route_no", 
>> "app_route"."owner_no", 
>> "app_route"."municipality_code", 
>> "app_route"."location_description", 
>> "app_route"."latitude", 
>> "app_route"."longitude" 
>> FROM   "app_route" 
>>inner join "app_observationevent" 
>>ON ( "app_route"."id" = 
>> "app_observationevent"."route_id" ) 
>> WHERE  "app_observationevent"."observation_date" >= :arg0 
>> ORDER  BY "app_route"."id" DESC 
>>
>> Executing it via the Django management shell django.db.connection 
>> produces the same error (ORA-00932: inconsistent datatypes: expected - got 
>> NCLOB) but when I remove the "app_route"."location_description" field 
>> from the SELECT projection the query executes successfully.
>>
>>
> Yes, this is caused by the use of a SELECT DISTINCT over a LOB column, 
> which Oracle does not allow.  The DISTINCT was added to admin queries over 
> joined fields as a result of ticket #15819.  As for workarounds -- I'm 
> afraid I don't have any suggestions for you.
>

Actually, one suggestion: you could try removing the field from the 
list_display option on the ModelAdmin.  I think you would also need to 
override the get_queryset method on the ModelAdmin to .defer() the field, 
as it doesn't look like the admin would do that automatically.

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




Re: Oracle database TextField limitations and Django admin interface queries

2013-04-13 Thread Ian
On Friday, April 12, 2013 7:43:32 AM UTC-6, Lauri Savolainen wrote:
>
> Thank you for the reply,
>
> The field is defined in the Django model as:
> location_description = models.TextField(_('additional route information'), 
> blank=True)
>
> Data length for the corresponding column in the database seems to be 4000 
> and the type is NCLOB. The database is created by Django's syncdb and is 
> not a legacy one.
>
> This is the raw SQL query the Django admin interface produces:
>
> SELECT DISTINCT "app_route"."id", 
> "app_route"."route_no", 
> "app_route"."owner_no", 
> "app_route"."municipality_code", 
> "app_route"."location_description", 
> "app_route"."latitude", 
> "app_route"."longitude" 
> FROM   "app_route" 
>inner join "app_observationevent" 
>ON ( "app_route"."id" = 
> "app_observationevent"."route_id" ) 
> WHERE  "app_observationevent"."observation_date" >= :arg0 
> ORDER  BY "app_route"."id" DESC 
>
> Executing it via the Django management shell django.db.connection produces 
> the same error (ORA-00932: inconsistent datatypes: expected - got NCLOB) 
> but when I remove the "app_route"."location_description" field from the 
> SELECT projection the query executes successfully.
>
>
Yes, this is caused by the use of a SELECT DISTINCT over a LOB column, 
which Oracle does not allow.  The DISTINCT was added to admin queries over 
joined fields as a result of ticket #15819.  As for workarounds -- I'm 
afraid I don't have any suggestions for you.

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




Re: Setting Django to not quote table names

2013-03-06 Thread Ian Kelly
On Wed, Mar 6, 2013 at 1:38 AM, Ian <ian.g.ke...@gmail.com> wrote:
> In the meanwhile, the commonly used workaround for this is to include the
> schema in the db_table declaration like so:

The other workaround which is mentioned in the ticket I linked but
which I completely neglected to include in my reply, and which I
heartily recommend, is to create private synonyms within the Django
schema to the tables in other schemas.  This works perfectly fine
(it's what we do at my work) and allows you to avoid having
ugly-looking db_table names or having to patch Django.  The only real
issue again is that syncdb will not recognize the synonyms and will
try to create the tables if run.

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




Re: Setting Django to not quote table names

2013-03-06 Thread Ian
On Tuesday, March 5, 2013 2:14:04 PM UTC-7, Steven Githens wrote:
>
> Hello Django Users,
>
> I have an app that uses Oracle and cx_Oracle for the db, and I've made the 
> models from an existing schema with inspectdb.
>
> The database schema also contains a number of sub-schemas, so they must be 
> accessed with schema dot table name.  Looking at the SQL used for model 
> access, I believe Django's automatic quoting of table names in the SQL is 
> causing issues with table name lookup.
>
> I can verify using cursor.execute in the shell, that if I leave off the 
> quotes, the queries work fine.  Is there an easy way to disable table name 
> quoting? (or other facility that gets around this? )
>
>
There is a long-standing ticket to add explicit schema declarations to 
models -- see https://code.djangoproject.com/ticket/6148
Unfortunately the most recent patch is almost a year old at this point, so 
I have no idea how well it would work.

In the meanwhile, the commonly used workaround for this is to include the 
schema in the db_table declaration like so:

db_table = 'my_schema"."my_table'

Note that quotes are included at the end of the schema name and the start 
of the table name, but not at the extremities of the string, since they 
will be added by the backend.  A couple of warnings about this approach:

1) This will break syncdb.  If you're not using syncdb, then this probably 
doesn't matter to you.

2) The oracle backend performs automatic name mangling on table names 
longer than 30 characters.  Since it considers the above to be all one 
table name, this effectively reduces the allowed table name length before 
name manging is applied by the number of extra characters.



On Tuesday, March 5, 2013 3:45:36 PM UTC-7, Shawn Milochik wrote:On Tue, 
Mar 5, 2013 at 5:41 PM, Johan ter Beest  wrote: 
>> Not an Oracle expert at all but maybe this SO answer explains some 
things?: 
>> 
>> 
http://stackoverflow.com/questions/563090/oracle-what-exactly-do-quotation-marks-around-the-table-name-do
 
>> 
>
> So if it's down to case-sensitivity then everything should be fine, 
> because all the queries are generated by the ORM and aren't going to 
> mix case. 

It's not just about case sensitivity.  The quotes are also required for 
names that happen to be Oracle keywords.  If you're controlling all the 
names though, then this is fairly easy to avoid.

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




Re: blank and null with Oracle

2013-02-28 Thread Ian
On Wednesday, February 27, 2013 3:31:20 PM UTC-7, Skylar Saveland wrote:
>
> Some odd behavior with Oracle involving blank and null.
>
> blank is True on this field:
> my_auto = models.AutoField(blank=False, null=False, primary_key=True)
>
> null is True on this field:
> uncles = models.ManyToManyField(Uncle, blank=False, null=False)
>

These two have nothing to do with Oracle specifically.  AutoFields are 
coerced to blank=True regardless of backend.  You can see that here:

https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L534

I don't know exactly why this is done, but I would guess it is because the 
point of the AutoField is that it can be left blank and automatically be 
filled in.  If you don't want that, then you probably want an IntegerField 
instead.

I'm not sure where null=True is getting set on the ManyToManyField, but I 
guess that the reason for this is that null=False represents a database 
constraint, and there is no way to actually set that constraint because the 
field does not map to an actual column in the model table; it maps to an 
intermediate relational table instead.

null is True on this field:
> photo = models.ImageField(upload_to="uploads/") 
>

This one is due to Oracle, because ImageField is a string-based field (it 
stores the filename where the image is stored).  A null value here in 
Oracle is equivalent to an empty filename in another backend.
 

> And, then, as documented null=True on CharFields.
>

Note that the docs say, "fields that have the empty string as a possible 
value", not specifically CharFields.  This is because it also includes 
things like FileField, ImageField, CommaSeparatedIntegerField, 
GenericIPAddressField, etc.

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




Re: charField null=false not enforced for table creation in oracle

2013-02-23 Thread Ian
On Friday, February 22, 2013 11:27:59 PM UTC-7, Skylar Saveland wrote:
>
> This is still a good question :)
>

The answer is that there is no way to instruct Django that you really, 
truly want this CharField to be NOT NULL even on Oracle, and that is 
unlikely to change.  Part of the philosophy in the development of the 
Oracle backend was that Oracle DBAs would not likely be running syncdb 
directly, but that devs would be more likely to run sqlall and hand-edit 
the scripts as needed (e.g. to add storage clauses) before handing them off 
to the DBA.  As a result of this thinking, not every possible Oracle 
idiosyncrasy is directly addressable via model options, and we are 
reluctant to add general features that are only useful for Oracle.

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




Re: Pluggable Q Django App

2013-01-10 Thread ian
Hi Natasha,

I'm looking for the same thing you are, that's how I found your post! Did 
you find anything that can be plugged or wrote your own?

On Tuesday, August 7, 2012 1:53:03 PM UTC-4, natash...@utoronto.ca wrote:
>
> Hi All,
>
> I'm looking to implement a Stack Overflow style Q feed on my site.
>
> I have looked into the following solutions:
> 1) OSQA
> 2) Askbot
> 3) Soclone
>
> The problem with these is that they don't really seem to be standalone 
> apps, and more like fully featured sites.
>
> Any thoughts on a standalone pluggable app with the ability to ask/answer 
> questions, upvoting and downvoting, tagging, etc.? Would rather not 
> re-invent the wheel if it has been done before.
>
> Cheers,
> Natasha
>

-- 
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/-/AN_2jddat9YJ.
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: ORM, Oracle and UTF-8 encoding problem.

2013-01-09 Thread Ian Kelly
On Wed, Jan 9, 2013 at 11:40 PM, Jani Tiainen  wrote:
> If we just force using force_unicode everything works except in older
> versions of cx_Oracle (our server had 5.0.4 or something) connection strings
> can't be unicode for some reason.

Sure, that's why the check exists in the first place.  Prior to 5.1
cx_Oracle could be built either with Unicode or without.  If the
former, it would accept only unicode strings and would raise an
exception on byte strings.  If the latter, it would be exactly the
opposite.

Does it work for you using force_bytes with 5.0.4?

-- 
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: ORM, Oracle and UTF-8 encoding problem.

2013-01-09 Thread Ian Kelly
On Wed, Jan 9, 2013 at 3:55 AM, Jani Tiainen  wrote:
> Server is running Oracle Database 10g Release 10.2.0.5.0 - 64bit Production.
> (EE edition)
>
> and charset info:
> NLS_CHARACTERSETWE8ISO8859P1
> NLS_NCHAR_CHARACTERSET  AL16UTF16

Sorry, I meant your web server setup.

-- 
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: ORM, Oracle and UTF-8 encoding problem.

2013-01-09 Thread Ian
On Wednesday, January 9, 2013 12:38:28 AM UTC-7, Jani Tiainen wrote:
>
> Tested against latest master. Same behaviour. 
>
> In Oracle backend base.py is following piece of code: 
>
> # Check whether cx_Oracle was compiled with the WITH_UNICODE option. 
> This will 
> # also be True in Python 3.0. 
> if int(Database.version.split('.', 1)[0]) >= 5 and not hasattr(Database, 
> 'UNICODE'): 
>  convert_unicode = force_text 
> else: 
>  convert_unicode = force_bytes 
>
> Which was added in  
>
> Thing is that my cx_Oracle is version 5.1.2, it has cx_Oracle.UNICODE 
> definition. 
>

That sounds correct.  The cx_Oracle.UNICODE type constant is present when 
cx_Oracle is compiled *without* the WITH_UNICODE option (which no longer 
exists in 5.1 anyway).

 

> And Django uses smart_str / force_bytes. 
>
> If I remove that and use convert_unicode as force_text / force_unicode 
> everything works as expected. 
>

Strange, in 5.1 it shouldn't make any difference which is used, as long as 
your NLS_LANG is getting set properly in the backend.  What is your server 
setup?  It seems that sometimes that can get interfered with if you have 
other services using Oracle in the same process.  It shouldn't hurt 
anything though for us to do an additional check for cx_Oracle 5.1+ and 
always use force_text in that case. 

-- 
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/-/CIo27txyz84J.
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: Stuck

2012-12-26 Thread Ian Foote

Others have commented on your indentation. You also have a typo:


 votes = models.IntergerField()


should be:

votes = models.IntegerField()

Regards,
Ian

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



Re: Authenticate User with Django 1.5

2012-12-15 Thread Ian Foote

On 15/12/12 11:18, sebastien.mor...@gmail.com wrote:

Hi, i've an authenticate problem with Django 1.5
All informations are
herehttp://stackoverflow.com/questions/13883539/authenticate-with-django-1-5
but i'll resume the situation :

I've a custum user model which looks like :

class User(AbstractBaseUser):
 email = models.EmailField(unique=True)
 activation_key = models.CharField(max_length=255)
 is_active = models.BooleanField(default=False)
 is_admin = models.BooleanField(default=False)

 objects = UserManager()

 USERNAME_FIELD = 'username'






The probleme is that user = authenticate(username=email,
password=password) gives me None as return.
According to the doc, authenticate takes an usersname, not an email as
arg. But how can i use authenticate because my User model desn't support
Username.
Is there a solution with Django 1.5 ?



Have you tried changing USERNAME_FIELD to 'email'?

Ian

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



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

2012-12-13 Thread Ian
On Thursday, December 13, 2012 4:29:30 AM UTC-7, Michał Nowotka wrote:
>
> Does anyone knows the reason why IntegerField and SmallIntegerFields both 
> map to NUMBER(11,0) in Orcale?
> I would expect SmallIntegerFiled map to something smaller ;)
>

Beats me.  Although note that Oracle itself equates both INTEGER and 
SMALLINT to NUMBER(38), so at least there's precedent.  I expect NUMBER(11) 
was picked as a reasonable-looking compromise. 

-- 
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/-/jD_JSd3IbUgJ.
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 1.6.0 over python 3: mysql?

2012-12-06 Thread Ian Clelland
On Fri, Nov 23, 2012 at 6:02 AM, ajendrex <hurbi...@gmail.com> wrote:

> Hello,
>
> I'm new to django and I'm going directly to use it over python 3 (I have
> been using python 3 for mor than one year). However, the MySQLdb library
> doesn't support python 3 yet. Is there a way of connecting django to mysql
> over python3? If not, any plan to get it in the near future?
>
>
I'm sorry I didn't see this when you asked (two weeks ago now).

I wholeheartedly support your move to PostgreSQL, but if anyone else on the
list is stuck in the same situation, about a year ago I adapted the Django
MySQL backend to use PyMySQL[1], which is a pure python interface to MySQL,
is essentially a drop-in replacement for MySQLdb, and *is* Python
3-compatible.

You can just easy_install (or pip install) django-mysql-pymysql, and use
'mysql_pymysql' as your database backend, and you should be set.

If it breaks, feel free to submit improvements at
https://github.com/clelland/django-mysql-pymysql :)

Alternately, you could wait a bit; Andy Dustman mentioned on his blog a
couple of months ago that a soon-upcoming version of MySQLdb could be
released with Python 3 support [2]

[1] https://github.com/petehunt/PyMySQL

[2] http://mysql-python.blogspot.ca/2012/09/a-brief-history-of-mysqldb.html

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

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



Re: reading raw binary data from clob columns using oracle backend

2012-11-08 Thread Ian
On Wednesday, November 7, 2012 6:16:23 AM UTC-7, Michał Nowotka wrote:
>
> Hello,
> I'm working with oracle legacy DB and need to read and write binary data 
> (png images, and and MDL *Molfiles*).
> Django's inspectdb command generated text fields for these columns, saying 
> that's only a guess.
> Now, when I'm trying to retrieve a value from this class fields i get:
> DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0x89 in position 
> 0: invalid start byte.
> error. 
>
> Is there any way to read and write these columns?
> Any help would be appreciated.
>

Django has no built-in field type for BLOB columns.  You might try using 
the custom field type given in one of the answers here:

http://stackoverflow.com/questions/5581466/django-models-blob-field

I haven't used this myself, so I can't vouch for how well it will work.

-- 
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/-/4EzQIAYCLjQJ.
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 registration custom backend

2012-10-27 Thread Ian Foote

Hi,

I'm trying to write a custom backend for django registration. 
(http://docs.b-list.org/django-registration/0.8/backend-api.html)

I'm using python 2.7 and django 1.4.

What I want is for an existing user with suitable permissions to be able 
to register accounts for new users. The new user will get an email with 
an activation link, which will redirect the new user to a form where 
they set a password for their account.


I do not want the existing user to be required to set a password 
manually for the new user to change once they first log in.


This is what I have so far:

from django.conf import settings
from django.contrib.sites.models import RequestSite
from django.contrib.sites.models import Site
from django.contrib.auth import login

from registration import signals
from registration.models import RegistrationProfile
from registration.backends.default import DefaultBackend

class CustomBackend(DefaultBackend):
def register(self, request, **kwargs):
username, email = kwargs['email'], kwargs['email']
# username is email address
password = '' # User will have no password set.
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
new_user = RegistrationProfile.objects.create_inactive_user(
username,
email,
password,
site)
signals.user_registered.send(sender=self.__class__,
 user=new_user,
 request=request)
return new_user

def activate(self, request, activation_key):
activated = RegistrationProfile.objects.activate_user(
activation_key)
if activated:
login(request, activated)
signals.user_activated.send(sender=self.__class__,
user=activated,
request=request)
return activated

def post_activation_redirect(self, request, user):
return ('set_password', (), {})

Unfortunately, when I try to log the new user in during account 
activation, I get an AttributeError: 'User' object has no attribute 
'backend'


I know this is because I'm not calling authenticate before login, but 
authenticate 
(https://docs.djangoproject.com/en/1.4/topics/auth/#django.contrib.auth.authenticate) 
requires a password, which I don't want to set at this stage. I want the 
user to be logged in when they are redirected to the set_password form.


Advice would be appreciated.

Regards,
Ian

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



Email new users account details

2012-10-09 Thread Ian Foote
I'm working on a small website for a small walking/mountaineering club. 
We would like to create accounts for our members using the admin site, 
and automatically email their details. I've googled a bit, but it isn't 
obvious to me if I can do this. Ideally, we would add a username (email 
address) and email the user a random password which they change when 
they first log in.


Is this a sensible approach, and how can I do this?

Thanks,
Ian

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



Re: Disabling CSRF is not working.

2012-10-05 Thread Ian Clelland
On Friday, October 5, 2012, Bill Freeman wrote:

> I believe that I read somewhere that newer Djangos force the CSRF
> middleware even if it's not listed in MIDDLEWARE_CLASSES.


You might be thinking of the CSRF context processor, which is always
enabled, no matter what is in settings. Even the most recent docs don't say
anything about forcing the middleware.

>
> You could dive into the middleware code to see how this happens, and
> come up with a stable strategy to circumvent it.  Or you could just
> fix the necessary views and templates.  There is, after all, a chance
> that you will want to be able to upgrade this site without jumping
> through hoops.
>
> On Thu, Oct 4, 2012 at 4:56 AM, Laxmikant Gurnalkar
> <laxmikant.gurnal...@gmail.com <javascript:;>> wrote:
> > Hi, Guys
> >
> > Disabling CSRF is not working.
> > These are my midlewares., Removed {% csrf_token %} all templates.
> >
> > MIDDLEWARE_CLASSES = (
> > 'django.middleware.common.CommonMiddleware',
> > 'django.contrib.sessions.middleware.SessionMiddleware',
> ># 'django.middleware.csrf.CsrfViewMiddleware',
> > 'django.contrib.auth.middleware.AuthenticationMiddleware',
> > #'django.contrib.messages.middleware.MessageMiddleware',
> > #'django.middleware.csrf.CsrfResponseMiddleware',
> > # 'igp_acfs.acfs.disablecsrf.DisableCSRF',
> > )
> >
> >
> > Also tried by writing disablecsrf.py like this :
> >
> > class DisableCSRF(object):
> > def process_request(self, request):
> > """
> > """
> > setattr(request, '_dont_enforce_csrf_checks', True)
> >
> >
> > Thanks in Advance!!!
> >
> > Laxmikant
> >
> > --
> > 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<javascript:;>
> .
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com <javascript:;>.
> > 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<javascript:;>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com <javascript:;>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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

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



Re: Django on legacy Postgres database with encoding WIN1252

2012-10-04 Thread Ian Clelland
What is that character supposed to be?

According to the Wikipedia page on CP1252, 0x81 is an unused character
position. There is a mention that it might map to some ISO-2022 control
code with no unicode equivalent.

I'm not sure where the error message is coming from, though -- if it was in
the python layer, you would see something like:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position
0: character maps to 

Possibly the postgresql interface is trying to convert it to UTF8 for
transfer, and failing, or maybe the psycopg2 layer can't decode it. Is
there any other info you can provide about the error message?

It may end up that you just have to clean the data in the database to be
able to use it.

Ian

On Thu, Oct 4, 2012 at 9:57 AM, Janeskil1525 <janeskil1...@gmail.com> wrote:

> Hi all
>
> I'm new Django user. I have a legacy system based on a Postgres 9.1
> database that is using encoding WIN1252. When i try to retrie data from one
> table I get the following error
>
> >>character 0x81 of encoding "WIN1252" has no equivalent in "UTF8"<< ,
> does that mean i cant use Django together with this database or is there
> some setting i need to change ?
>
> All help appreciated
>
> Thank you in advance!
>
>
> Jan Eskilsson
>
> --
> 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/-/EXpvuuttJ64J.
> 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.
>



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

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



Re: Can't Find libclntsh.so.11.1 With Oracle Backend

2012-09-10 Thread Ian
On Sunday, September 9, 2012 10:41:00 PM UTC-6, Jon Blake wrote:
>
> It looks like I have to tell my app what my path to libclntsh.so.11.1 is. 
> I have added:
>
> os.environ['LD_LIBRARY_PATH'] = '/oracle/product/11.1.0/db_1/lib'
>>
>
> to my app's wsgi.py file, but this does resolve my problem.
>
>
LD_LIBRARY_PATH has to be set before the process starts to be honored.  So 
it's not sufficient to set it in the wsgi file with os.environ; you need to 
use an Apache SetEnv directive, or use a script to export it in the Apache 
process's environment variables when Apache is started.  Or as a third 
option, use ldconfig to make the Oracle library path globally visible.

Cheers,
Ian

-- 
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/-/z8aKjhUtm3QJ.
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: Syncdb Error With Oracle Database - IntegrityError Exception

2012-08-31 Thread Ian Kelly
On Fri, Aug 31, 2012 at 10:03 PM, Jon Blake  wrote:
> Querying column timestamp of view user_objects for tables, sequences and
> triggers appears to confirm my understanding of what base.py does. I'll drop
> and recreate my user account, and try again. I'll advise how this goes. Does
> the Django doco have any specific documentation for the Oracle back end? If
> so, I missed it! I'm happy to provide specific doco for the Oracle back end
> if that would assist...

Yes, please see:

https://docs.djangoproject.com/en/1.4/ref/databases/#oracle-notes

-- 
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: Syncdb Error With Oracle Database - IntegrityError Exception

2012-08-31 Thread Ian
On Friday, August 31, 2012 12:10:54 AM UTC-6, Amyth wrote:
>
> Hey Jon,
>
> I guess this is because of a bug in django. Django already has a open 
> ticket for this bug. Check it out 
> here
> . 
>
>
As described in that ticket, the reason for the problem is probably just 
that the Django user does not have the CREATE TRIGGER privilege, which it 
needs.  The bug in Django is just that this condition is not detected and 
reported at the time the table is created, instead of getting a rather more 
obscure error message at the time the table is populated.

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



Catch or raise exception designissue

2012-07-31 Thread Ian Clelland
[sorry for the late response; this got lost in drafts, but it's enough of a
sore point for me to want to post it]

On Sun, Jul 15, 2012 at 12:30 PM, Jani Tiainen
<rede...@gmail.com<javascript:_e({}, 'cvml', 'rede...@gmail.com');>
> wrote:

> I think "letting to explode" is all about coloring the bike shed. It all
> depends on a API contract - if parameter is required (thus meaning missing
> it is a critical error) it should explode.
>
> In case of incorrect request I prefer to raise 400 (Bad Request) with some
> explanation what went wrong. Since 500 is usually meant for "catch all"
> unexpected errors that happened in web server and server can't be more
> precise what happened. I've done that according to RFC 2616 (HTTP 1.1
> Specification) where is said that 4xx codes are meant for "client side
> error" (Section 10.4), and 5xx which means "server error" (Section 10.5)
>
> But I think all of that is matter of taste...
>
>
I wouldn't call it a matter of taste; this is the spec for communicating
over HTTP.

Certainly, if you have full and complete control over the server, and over
every client, then by all means use 500 errors to mean whatever you want.
You could also signal an error with a 200 OK message, or just make up your
own status codes.

Status codes have meaning though, which is important as soon as you want to
open up your interface to any other clients. A 400-series code means that
the client request had a problem, and the specific code tells the client
whether there is anything that can be done about it.

A 500 error, on the other hand, means that there is an error (read: bug) in
the web server code. Something happened (almost certainly in response to a
client request) that the server was not properly coded to handle, and the
result was an unexpected exception.

The distinction is important: it communicates who has the responsibility
(or at least the capability) to fix the error.

As developers, we should be reporting 400-series errors every time we can
detect an issue with a request, as a courtesy to clients. We should never
deliberately be creating 500 errors. The only responsible thing to do when
a 500 is seen in the logs is to track down the source of it and fix the bug.

-- 
Regards,
Ian Clelland
<clell...@gmail.com <javascript:_e({}, 'cvml', 'clell...@gmail.com');>>


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

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



Re: Ignore apostrophes using django-postgresql

2012-07-20 Thread Ian Clelland
The queryset's extra() method can help you with that:

MyModel.objects.extra(where=["replace(db_column_name, , '') = %s"],
params=["rockn burger"])

(Be careful if you're typing that in manually -- there are lots of
single-quotes in it)

Ian

On Fri, Jul 20, 2012 at 4:02 PM, Ada Pineda <elizethpin...@gmail.com> wrote:

> Hello
>
> I'm asking for your help because I need to do a query on a table that has
> a field that contains apostrophes, but I need to ignore them (apostrophes)
> when I'm doing the query. I have to save the data as it is, so I can't just
> take away those apostrophes before saving to the database. I mean, if the
> database has "rock'n burger" and a user types "rockn burger", I need to get
> the value with apostrophe from the database.
>
> Can anyone help me?
>
> Thanks a lot!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/lxGzVjrwQgMJ.
> 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.
>



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

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



Re: Oracle error when filtering on one2many related TextField (nclob)

2012-07-13 Thread Ian
On Thursday, July 12, 2012 9:27:30 AM UTC-6, The Bear wrote:
>
> I get this error:
>
> *** DatabaseError: ORA-06502: PL/SQL: numeric or value error: character 
> string buffer too small 
> ORA-06512: at line 1
>
> This is a database encoding issue; see:

https://code.djangoproject.com/ticket/11580

As I understand it, the DBMS_LOB.SUBSTR call is trying to take the first 
4000 characters of some NCLOB and pack them into a 4000-byte buffer.  The 
problem arises when you're using an encoding where those 4000 characters 
take up more than 4000 bytes.  You might try the code patch in that ticket 
and see if it clears up the error.

Ian

-- 
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/-/f0pTxq1QBwkJ.
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 translationissue

2012-07-12 Thread Ian Clelland
On Thursday, July 12, 2012, Phil wrote:

> Hi,
>
> I'm trying to translate form names from a model. I have a working contact
> form for example and have the following code
>
> 
>
> from django import forms
> from django.core.mail import mail_managers
> from django.utils.translation import ugettext_lazy as _
>
> class ContactForm(forms.Form):
> name = forms.CharField(_('name'), max_length=100)
>
>
> ==
>
> It adds it to my .po file ok, but when I run it in the browser I get the
> following error...
>


> Exception Type: TypeError at /contact/
> Exception Value: __init__() got multiple values for keyword argument
> 'max_length'
>
>
>
max_length is the first argument to the CharField constructor. You provided
it twice (accidentally, I'm sure): once as the first argument, and again as
a named parameter.

If the argument "_('name')" is supposed to be the field label, then you
should pass it explicitly as that keyword art, like this:

name = forms.CharField(label=_('name'), max_length=100)

Ian


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

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



Re: Catching Oracle Errors

2012-07-11 Thread Ian
On Tuesday, July 10, 2012 7:45:58 AM UTC-6, Dan Gentry wrote:
>
> My Django app runs on an Oracle database.
>
> A few times a year, the database is unavailable because of a scheduled 
> process or unplanned downtime. However, I can't see how to catch the error 
> and give a useful message back to the requester. Instead, a 500 error is 
> triggered, and I get an email (or hundreds) showing the exception. One 
> example is:
>
>   File 
> "/opt/UDO/env/events/lib/python2.6/site-packages/django/db/backends/oracle/base.py",
>  line 447, in _cursor
> self.connection = Database.connect(conn_string, **conn_params)
>
> DatabaseError: ORA-01035: ORACLE only available to users with RESTRICTED 
> SESSION privilege
>
> I see a similar error with a different ORA number when the DB is down.
>
> Because the exception is thrown deep within the Django libraries, and can 
> be triggered by any of my views or the built in admin views, I don't know 
> where any exception trapping code would go.
>
> Any suggestions?
>
There's nothing specific to Oracle about this.  First, make sure you've 
read:

https://docs.djangoproject.com/en/1.4/howto/error-reporting/

In your case you might do any of the following:

1) Customize the 500.html server error template to provide a more 
user-friendly message.

2) Customize the server error view, which by default just renders the 
500.html template:
https://docs.djangoproject.com/en/1.4/topics/http/views/#the-500-server-error-view

3) Use a middleware to customize completely how otherwise unhandled errors 
are processed.  You can create a customized 500 (or 503) response and do 
whatever admin notification and other processing you want.

-- 
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/-/r5lfeWa1iAgJ.
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: 'CSRF verification failed." from django.contrib.comments. can you help solve it? django 1.3

2012-06-28 Thread Ian Clelland
On Thu, Jun 28, 2012 at 9:14 AM, brycenesbitt <digitalbitstr...@gmail.com>
 wrote:

> I'm using django.contrib.comments and get 'CSRF token missing or
> incorrect.' when previewing or submitting a comment.  I have:

...



The HTML looks like it has the csrf security_hash in the proper place:
> 
>  />
> 
> 
> ...



The "security_hash" field that you see is part of the comments app, and is
not the CSRF token. That needs to be output by a {% csrf_token %} tag (or
its equivalent). If it's working, you should see another hidden input
field, which looks like this:





The comments app normally does that automatically -- it's part of
django/contrib/comments/templates/form.html -- Are you overriding the
comment form in your own app? If so, you need to include the call to {%
csrf_token %} yourself.

@csrf_protect  #does not matter if this is here or not
>

No, if you have the CSRFViewMiddleware installed, then you don't need this
line at all.

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

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



Re: Oracle: blank, null, and empty_strings_allowed

2012-06-21 Thread Ian
On Thursday, June 21, 2012 4:37:35 AM UTC-6, Melvyn Sopacua wrote:
>
> Which is /exactly/ why I mention it. If the default value is inserted 
> instead of an empty string, you can pre-insert the default value and 
> have it linked to an invalid entry. Any attempts to insert the default 
> value on the primary key of the linked model will trigger an integrity 
> error. Any models referencing the pre-inserted "invalid key" can now be 
> identified and relinked properly. 
>

Then all your application logic and views have to be written to ignore the 
invalid entry.  It seems a lot simpler and less error-prone to just tweak 
the DDL to add a "NOT NULL" constraint.

-- 
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/-/9dWmb4ori3EJ.
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: Oracle: blank, null, and empty_strings_allowed

2012-06-21 Thread Ian
On Wednesday, June 20, 2012 1:38:45 PM UTC-6, André Pang wrote:
>
> 1. In Oracle's case, what if you have a model with a primary key that's 
> a CharField?  I suspect that Oracle backend will coerce that to be 
> null=True, so now you have a primary key field that could have NULL. 
>

Primary keys are an exceptions.  The backend doesn't try to make them 
nullable, and the database wouldn't accept that as valid DDL anyway. 

-- 
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/-/iw79PrC-CZsJ.
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: Oracle: blank, null, and empty_strings_allowed

2012-06-20 Thread Ian Kelly
On Wed, Jun 20, 2012 at 12:31 PM, André Pang <andre.p...@gmail.com> wrote:
> I honestly don't mind whether Django decides to do this or not, since I can
> always hack our local tree to enforce this at the database level, but I
> thought it's an idea worth discussing. In my case, I found a couple of stray
> records with empty strings in columns where that wasn't supposed to happen,
> so enforcing it at the database level for me is a worthwhile safety concern.

Sure.  And bear in mind that there is absolutely no requirement to use
syncdb at all.  When we wrote the Oracle backend we had in mind that
most users would probably want to have Django generate the DDL scripts
and then tweak them to their liking before handing them off to the DBA
-- due to process concerns or Oracle DBAs who often want to see things
like storage declarations that are way out of scope for Django.  At my
workplace, many of the tables that Django deals with are actually
updatable views, which are obviously not produced by syncdb.

Cheers,
Ian

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



Re: Oracle: blank, null, and empty_strings_allowed

2012-06-19 Thread Ian
On Monday, June 18, 2012 5:59:27 PM UTC-6, André Pang wrote:
>
> What I'd like to do is (1) disallow NULLs, and (2) disallow empty strings. 
>  It looks like there's no current way to do this with Oracle since the 
> backend overrides null to always be True, and blank is an admin validation 
> thing only. 
>

There's also no current way* to do this AFAIK with postgresql, mysql, or 
sqlite.  I'm not opposed to the feature request, but if we're going to do 
it, then I think it should be universal, not just for Oracle.  For the 
other backends I suppose a CHECK constraint would be required.

Cheers,
Ian
 
* Of course with any backend there is the option of writing custom DDL and 
running it instead of or in addition to syncdb.

-- 
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/-/GbrE1zMU3N4J.
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: Oracle: blank, null, and empty_strings_allowed

2012-06-18 Thread Ian


On Monday, June 18, 2012 2:17:26 PM UTC-6, André Pang wrote:
>
> Hi all,
>
> The Django Oracle documentation has the following to say about NULL and 
> empty 
> strings<https://docs.djangoproject.com/en/1.1/ref/databases/#null-and-empty-strings>
>  (emphasis 
> mine):
>
> Django generally prefers to use the empty string ('') rather than NULL, 
>> but Oracle treats both identically. To get around this, the Oracle backend 
>> coerces the null=True option *on fields that have the empty string as a 
>> possible value*.
>
>
> However, I've found that the Oracle schema that Django generates *always 
> *allows 
> NULLs on all string-like fields (CharField, TextField, FilePathField, etc).
>

Because those are all "fields that have the empty string as a possible 
value".

 

> I'd assume that Django would only generate schemas where NULL is allowed 
> for fields where blank=True, and that fields where blank=False would have 
> "NOT NULL" included in the Oracle DDL.
>

blank=True is a validation option, not a database option.  A field with 
blank=False can still have the empty string as a possible value, and it can 
be stored like that in any of the other backends; it's just not accepted by 
the admin site.  In this case it's mainly a cross-compatibility issue -- if 
an app stores the empty string on a blank=False field in Postgres, it 
should be able to do that when the backend is Oracle as well.

Cheers,
Ian

-- 
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/-/OQ1fVBapZSoJ.
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 at Oracle ROWID

2012-06-13 Thread Ian
On Wednesday, June 13, 2012 5:48:07 AM UTC-6, rahajiyev wrote:
>
> DatabaseError at / 
>
> ORA-01446: cannot select ROWID from, or sample, a view with DISTINCT, GROUP 
> BY, etc.
>
>
> Unfortunately Django doesn't show the precise statement that caused the 
> error.
>

The query it generates is:

SELECT * FROM (SELECT ROWNUM AS "_RN", "_SUB".* FROM (SELECT 
"CREF_TAB"."ROWID", "CREF_TAB"."CREF_NO" FROM "CREF_TAB") "_SUB" WHERE 
ROWNUM <= 5) WHERE "_RN" > 0

(You can find this using str(queryset.query) in a Django shell.)

The error appears to be caused by the outermost SELECT *, since the query 
runs all right if you remove it.  It also works if you add an alias to the 
rowid column, e.g. "SELECT CREF_TAB.ROWID AS FOOBEAR".  You might be able 
to finagle the Field into adding a column alias, but then you will likely 
break something else.  I think we're back to using extra().

-- 
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/-/US4jxwn9mc4J.
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: more than 1 level of belongsTo

2012-06-12 Thread Ian
On Tuesday, June 12, 2012 1:05:16 AM UTC-6, rahajiyev wrote:
>
> You can keep laughing all you want, but I at least could get CakePHP 
> to work with an existing Oracle database lacking primary keys for a 
> backend app involving role permissions, forms, pagination and other 
> usual web stuff, as opposed to designing a new app and database from 
> scratch. I worked around the lack of primary keys using Oracle's ROWID 
> and Cake's $virtualFields. From then on $rowid was as good as a usual 
> field for the purposes of data retrieval and updating. 
> Then I thought I'd rewrite this simple app in Django while learning it 
> at the same time. But Django doesn't really allow me to use such 
> virtual fields easily. Ian gave me a solution to my problem here: 
>
> http://groups.google.com/group/django-users/browse_thread/thread/77f8353da1bcca53
>  
>
> but it doesn't seem to be what I'm looking for. Maybe someone here has 
> an idea?


Sorry, I saw your response in that thread but got distracted and forgot to 
post a followup. I've done so now.

-- 
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/-/VBhUgZpzm68J.
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 at Oracle ROWID

2012-06-12 Thread Ian
On Thursday, June 7, 2012 11:22:56 PM UTC-6, rahajiyev wrote:
>
>
> > MyModel.objects.extra(select={'rowid': "rowid || ''"}) 
> > 
> Thanks. I don't think extra() takes primary_key=True, does it? 
> I wouldn't want Django to auto-add column id otherwise. 
>
> Assuming I have: 
> MyModel.objects.extra(select={'id': "rowid || ''"}) 
> OK, that's fine for fetching the ID itself, suitable for creating 
> forms. But what if I want to fetch an item by this virtual PK, or 
> update by PK with or without prior fetching?


I haven't tried it, but for those you should be able to use an extra where, 
similar to the extra select above.

MyModel.objects.extra(where=["rowid = 
whatever_syntax_you_need"]).update(cake="lie")

If using .extra() on all your queries isn't acceptable, you should be able 
to write a custom Field class for rowids and add that to your models with 
primary_key=True.  It will probably break syncdb (but I assume this is a 
pre-existing table anyway if you need to use rowids).

https://docs.djangoproject.com/en/dev/howto/custom-model-fields/

Cheers,
Ian

-- 
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/-/0EGkINIYbYUJ.
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 at Oracle ROWID

2012-06-07 Thread Ian
On Thursday, June 7, 2012 3:55:37 AM UTC-6, rahajiyev wrote:
>
> There's an existing Oracle database I want to hook Django up with. The 
> problem is, the table I need lacks single-key primary keys. Oracle 
> does provide its unique table-wide ROWID which can normally be used as 
> a PK with a few restrictions. But it's a LOB, so a cast to string is 
> normally required to fetch it: SELECT ROWID || '' 
> Writing this expression a piece of cake for CakePHP and its 
> virtualFields. Can Django do the same?


MyModel.objects.extra(select={'rowid': "rowid || ''"})

Cheers,
Ian

 

-- 
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/-/XXV9rBzhhwwJ.
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: Oracle schema not working

2012-06-04 Thread Ian
On Monday, June 4, 2012 5:36:32 AM UTC-6, rahajiyev wrote:
>
> Why is Django strangely quoting column and table names? It gives 
> Oracle syntax errors. 
>
> DatabaseError at / 
>
> relation "foo" does not exist 
> LINE 1: ...ty", "foo"."address_country" FROM "foo"."... 
>
> Of course it exists as foo, not as "foo". 
>
> I already did the CREATE SYNONYM trick to avoid messing with schemas.


What does the db_table in your model definition look like?  It should just 
be:

db_table = 'foo'  # Django will take foo and change it to "FOO", which 
is how Oracle interprets foo

not:

db_table = '"foo"'  # Since this is already quoted, I think Django 
won't change it, and then Oracle won't be able to find the table because it 
is explicitly the wrong case.

Cheers,
Ian

-- 
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/-/GJh1mmeq6KMJ.
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: What is Django's behavior when a request is interrupted?

2012-05-29 Thread Ian Clelland
On Tuesday, May 29, 2012, John Boxall wrote:

> Consider the following code:
>
> def view(request):
>> import pdb;pdb.set_trace()
>> # Make a bunch of databases updates
>> return HttpResponse('OKAY')
>
>
> I boot up the Django devserver and make a request from my browser. It is
> routed by Django to `view`. When the debugger launches, I cancel the
> request in my browser.
>
> It seems as though Django continues executing the code in the request
> path. Is this the expected behavior?
>

As a WSGI application, Django should have no
idea that the connection has been closed. The connection to the client is
just another resource, like a database connection or a memcache server.
Nothing will happen asynchronously to raise an exception; you'll only see
an exception at the point where you try to use the resource.


> If the connection has 'gone away' are there any circumstances where Django
> will raise an exception in the regular request path?
>

You're only going to see an exception at the point where you try to write
out to the http response object, and your wsgi server fails because the
other end of the connection is closed.

In django 1.4, http response is lazy, as well, so even writing directly to
it will probably not raise an exception until the view has returned, anyway.

Ian


> Cheers,
>
> John
>
> --
> 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/-/M-mNNXY3vbQJ.
> To post to this group, send email to 
> django-users@googlegroups.com<javascript:_e({}, 'cvml', 
> 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com <javascript:_e({}, 'cvml',
> 'django-users%2bunsubscr...@googlegroups.com');>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>


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

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



django-ical - iCalendar generation

2012-05-06 Thread Ian Lewis
Hey all,

I just released a simple library for generating iCalendar feeds based
on the syndication framework. For folks familiar
with the syndication framework and how it works you should be able to
get up and running with django-ical
pretty quickly. Most people seem to be doing iCalendar feeds and
exports in a one off manner and I hoped
with this project to create something a kind of defacto app that
Django folks could use for iCalendar.

It's pretty simple currently so if anyone has any feature requests you
can create issues or send me pull
requests at the link below.

pypi: django-ical
Code: https://bitbucket.org/IanLewis/django-ical/overview
Docs: http://readthedocs.org/docs/django-ics/en/latest/

Thanks,
Ian

--
Ian

http://www.ianlewis.org/

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



Re: HELP with unicode!!!!!

2012-05-01 Thread Ian Clelland
On Tuesday, May 1, 2012, dizzydoc wrote:

> Hi ,
>
> i have lost a lot of time looking for a solution.
>
> My problem is, while i a reading csv in python using
>
> csv_file  = open(path_file, "rb")
> reader = csv.reader(csv_file)
>
> whenever i perform any operation on the string returned in each cell i
> get this error
>
> *** UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0'
> in position 34: ordinal not in range(128)


It's a long-standing limitation with the python csv module that it does not
handle Unicode well. In fact, it's one of the first things mentioned in the
docs:

 http://docs.python.org/library/csv.html

Further down that page, though, is a snippet of code that you should be
able to use (search the page for "unicode_csv_reader")

If that doesn't work, come back here with some code that you've tried and
hopefully we can find a solution

Ian


> i tried decoding the value as
>
> val.decode('utf-8')
>
> ...this helped to reduce a few encodings but gets stuck for
> the encoding "\xa0"
> Please HELP!
>
>
>
>

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

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



Re: HttpResponse_is_string is removed Django 1.4

2012-04-06 Thread Ian Clelland
On Thu, Apr 5, 2012 at 6:07 PM, Rajat Jain <rajat...@gmail.com> wrote:

> Hi,
>
> I have noticed that the class variable HttpReponse._is_string (in
> django/http/__init__.py) is removed in Django 1.4. I was setting this
> variable in a couple of places in my code, so that piece of code is
> breaking in Django 1.4. Do you know if this field is required at all? If
> not, is it just safe to remove this field altogether from my code?
>

Were you setting it to True or False?

If your code sets it to True, then this should be safe to remove -- in
Django 1.4, HttpResponse always renders its output as a string, converts
its contents to a string, regardless of what type of data it has been given.

If you were setting it to False, for some reason, then you'll have to come
up with a different way of accomplish whatever you're trying to do.

(The original ticket was https://code.djangoproject.com/ticket/16494, and
you can see the changes that were made for 1.4 here:
https://code.djangoproject.com/changeset/16829)




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

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



Re: Questions about UnicodeDecodeError

2012-04-04 Thread Ian Clelland
On Monday, April 2, 2012, Ali Mesdaq wrote:

> I did have UTF-8 in the db before but then when I was inserting(done by a
> script) values in I would get errors. I really want to avoid doing
> conversions before I insert the data so I can maintain the data in the
> exact format as it was seen in.


This, in general, isn't going to be possible. Even if you get it to the
point where it looks like its working, you may still end up with silent
data corruption, and not be able to retrieve your data when you need it.

If your database column only supports ASCII, and you cant change the
database, then your best option is probably going to be to use a strict
ASCII encoding, like base64 or base85. If you are pretty sure that the data
is *mostly* ASCII, then you could go with something like quoted-printable.
The point, though, is that you need to do *something* to your data to
coerce it into the ASCII range before you put it in the database.

As long as you remember to encode the data on save, and decode it (once!)
before displaying it, you should be able to get it to work.

Ian


>  I may be forced into doing that it seems
> to make django even work. I tried to get my app to work by creating the
> __unicode__ method return a string of "blah" and it still dies on me.
>
> Thanks,
> Ali Mesdaq
> Security Researcher
> Cell:  +1 (619) 952-8488  |  Fax:  +1 (408) 321-9818
> Email:  ali.mes...@fireeye.com
>
>
> Next Generation Threat Protection
> http://www.FireEye.com <http://www.fireeye.com/>
>
>
>
>
>
>
>
> On 4/1/12 3:04 PM, "Bill Freeman" <ke1g...@gmail.com> wrote:
>
> >If you can, switch to UTF-8 in the db.  Web traffic can arrive in a
> >variety of
> >encodings, and while the headers tell the server how to make unicode out
> >of it, but by having the db set for ASCII, you limit what you can store
> >(since
> >not all unicode characters can be converted to ASCII.
> >
> >On Fri, Mar 30, 2012 at 7:45 PM, Ali Mesdaq <ali.mes...@fireeye.com>
> >wrote:
> >> I have a situation where I am reading data that I have no control over
> >>and
> >> inserting it into a db. The data is http headers. I am storing them in
> >> postgres db in a text field and the db encoding is SQL_ASCII. Since the
> >> data can be anything even non compliant http headers with anything for
> >>its
> >> values I don't want to modify the data before I store it in the db.
> >> However this is causing issues with certain values causing the
> >> UnicodeDecodeError. For example I have a specific case where the user
> >> agent is set to 'KC\xd4\xda\xcf\xdf\xc9\xfd\xbc\xb6'. I have been trying
> >> to look for a way to deal with these cases gracefully in the models
> >> __unicode__ method but nothing I have tried has worked.
> >>
> >> Thanks,
> >> Ali Mesdaq
> >> Security Researcher
> >> Cell:  +1 (619) 952-8488  |  Fax:  +1 (408) 321-9818
> >> Email:  ali.mes...@fireeye.com
> >>
> >>
> >> Next Generation Threat Protection
> >> http://www.FireEye.com <http://www.fireeye.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.
> >
>
> --
> 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: Storing many to many fields

2012-03-18 Thread Ian Lewis
Hi,

facebook_session.books_name is a RelatedManager on the Books model class.

You need to add books to the list with the add() method.

book = Books(book_name="name", book_category="category")
book.save()
facebook_session.books_name.add(book)

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

On Sun, Mar 18, 2012 at 4:41 PM, dummyman dummyman <tempo...@gmail.com> wrote:
> Hi
>
> I ve to models
>
> class FacebookSession(models.Model):
>
>     access_token = models.CharField(max_length = 250,unique=True)
>     expires = models.IntegerField(null=True)
>
>     user = models.ForeignKey(User, null=True)
>     uid = models.BigIntegerField(unique=True, null=True)
>
>     birthday = models.DateField(blank=True,null=True)
>     name = models.CharField(max_length=100,blank=True,null=True)
>
>     books_name = models.ManyToManyField(Books,blank=True,null=True)
>
>
> lass Books(models.Model):
>
>      book_name = models.CharField(max_length=100)
>      book_category = models.CharField(max_length=100,blank=True,null=True)
>
>      def __unicode__(self):
>          return self.book_name
>
>
>
> now i want to have a list of books in a list called books_list
>
> How to store those in the database
>
> I understood how to store basic_fields
>
>
> database_obj = FacebookSession.objects.get(uid=123444)
> database_obj.name="ss"
>
> database_obj.save()
>
> How do i do the same thing for books_name which is a many to many field in
> FacebookSession class
>
> --
> 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.



-- 
Ian

http://www.ianlewis.org/

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



Re: internationalization makemessage don't work

2012-02-27 Thread Ian Clelland
On Mon, Feb 27, 2012 at 1:36 PM, nicolas HERSOG <n.her...@gmail.com> wrote:

> Fun fact, I tried the command manage.py compilemessages, it takes
> loong time to finish and parse all of my workspace in order to create
> translation file xD.
> All my home except my project :| ...
>
>
Does your INSTALLED_APPS setting contain the apps that should be translated?

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

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



Re: Using query set in views.py

2012-02-26 Thread Ian Clelland
On Sunday, February 26, 2012, Stanwin Siow wrote:

> Ok disregard my previous question.
>
> Here's the latest one.
>
>
> I have the following form in my HTML:
> * *
> * Keyword: *
> * *
>

Your immediate problem here is that your  element has an id, but no
name attribute. That is why you are getting None when you try to retrieve
it from the POST dictionary -- the browser never sent it to the server.

I'm certain that you have additional issues with your view function, but
this is the reason for the error that you are seeing right now.

Ian




> * *
> * *
> * *
>
> when the user presses the submit button, it will go to the method
> keyword_subscribe in views.py
>
>
> The method is as shown:
>
> *def keyword_subscribe(request):*
> *if request.POST:*
> * username = UserProfile.objects.all()*
> * #userid = username.objects.all()*
> *subscription_days = "7"*
> * new_keyword = request.POST.get('myTextField')*
> * print new_keyword*
> *new_keyword_subscribed =
> subscribe_keyword(username,subscription_days,new_keyword)*
> **
> *response = simplejson.dumps({'new_keyword':
> new_keyword_subscribed})   *
> * print new_keyword_subscribed  *
> *else:*
> *   # html = form.errors.as_ul()*
> *response = simplejson.dumps({'success':'False'})*
> * return HttpResponseRedirect("/accounts/login/")*
> *#if request.is_ajax():*
> * #   return HttpResponse(response, mimetype='application/json')*
> *#else:*
> * #   return HttpResponseRedirect("/")*
>
> Once in this method, i'm supposed to extract the word which the user
> entered in the textfield and store it in a variable called new_keyword
>
> However, i've been getting NONE which means there's something wrong
> somewhere and i do hope someone can help me.
>
> In addition, i would like to get the username which is stored in the
> UserProfile table in my database to be passed as a parameter to the next
> function too.
>
> How then do i implement the queryset needed?
>
> This should be clearer.
>
> Thank you.
>
>
> Best Regards,
>
> Stanwin Siow
>
>
>
> On Feb 26, 2012, at 6:25 PM, Daniel Roseman wrote:
>
> Your question is not at all clear. You can use whatever you like in your
> view. What problem are you having?
> --
> DR.
>
> --
> 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/-/1N2Cz2nv9wQJ.
> To post to this group, send email to 
> django-users@googlegroups.com<javascript:_e({}, 'cvml', 
> 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com <javascript:_e({}, 'cvml',
> '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<javascript:_e({}, 'cvml', 
> 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com <javascript:_e({}, 'cvml',
> 'django-users%2bunsubscr...@googlegroups.com');>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>


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

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



Re: internationalization makemessage don't work

2012-02-26 Thread Ian Clelland
On Sunday, February 26, 2012, nicolas HERSOG wrote:

> Hi folks !
>
> I'm trying for hours to internationalize my django website.
>
> I added to my settings.py this few lines :
>
> TIME_ZONE = 'Europe/Paris'
> LANGUAGE_CODE = 'fr-FR'
>
> I added to all templates i want to translate the tag trans for the
> sentence I want to  internationalize exemple :
>
> {% trans "article écrit :"%}
> {% trans "Nom :"%}
>
> And then at my root project i run django-admin.py makemessages -l en


Why are you running django-admin.py, rather than manage.py? manage.py knows
how to fund your settings files, and import all of your apps and check all
of your template dirs.

Try first running "manage.py makemessages -l fr" (since I suspect that your
site is already in French, you won't have to actually do anything with that
po file right now, but it's good to have)

Ian


> This command created a django.po file which contains the translations key
> for django debug tool bar, but none key of my webapp.
>
> Did I do something wrong, or miss something ?
>
> Thank you :)
>
> Nicolas
>
>
>
>  --
> 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<javascript:_e({}, 'cvml', 
> 'django-users@googlegroups.com');>
> .
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com <javascript:_e({}, 'cvml',
> 'django-users%2bunsubscr...@googlegroups.com');>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>


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

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



Re: django 1.1: nonexistent URLs display 500.html instead of 404.html

2012-02-22 Thread Ian Clelland
On Tue, Feb 21, 2012 at 5:33 PM, rabousha <ramiaboushaw...@gmail.com> wrote:

> Yes, only for TEMPLATE_CONTEXT_PROCESSORS, the commas aren't added by
> default after the strings. I suspect it's an old bug.
>
> TEMPLATE_CONTEXT_PROCESSORS = (
>'django.core.context_processors.auth'
>'django.core.context_processors.debug'
>'django.core.context_processors.i18n'
>'django.core.context_processors.media'
> )
>

Interesting... my mistake for thinking that this was a syntax error -- this
is equivalent to the declaration

TEMPLATE_CONTEXT_PROCESSORS = (

'django.core.context_processors.authdjango.core.context_processors.debugdjango.core.context_processors.i18ndjango.core.context_processors.media'
)

since the Python interpreter will concatenate string literals.

Either way, this should raise an error -- an ImproperlyConfiguredError, to
be precise. I don't know of any bugs in Django 1.1 that would cause this to
raise a 404 instead -- there is likely a problem with your particular
settings.

I'm pretty sure that, even if there was a legitimate bug here, it would not
get fixed. The last update to the 1.1 series was over a year ago, and even
at that time, only security-related issues were being addressed.

If this is a serious issue for you (and it shouldn't be, if the 'fix' is to
correct the errors in your settings.py), then the recommended solution is
almost certainly going to be to upgrade. Django 1.3 is almost a year old,
and is still the current version -- if you can wait a couple of weeks,
you'll see 1.4 released as well.


> With the commas missing, all requests to nonexistent URLs returned a
> 500 error.
>
>
> On Feb 22, 12:31 am, Ian Clelland <clell...@gmail.com> wrote:
> > By 'missing commas', do you mean that there are *syntax errors* in your
> > settings.py file?
> >
> > That will definitely cause a 500 error, and I would be surprised if it
> > didn't do it on *every* request.
> > It seems odd that you would get a 404 when Debug is turned on, but that
> may
> > be related to the handling of the 500 error template, or possibly
> indicates
> > another error in your application settings.
> >
> > Ian
> >
> > On Tue, Feb 21, 2012 at 10:36 AM, rabousha <ramiaboushaw...@gmail.com
> >wrote:
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > > I am using django 1.1, with DEBUG = False, and
> > > TEMPLATE_CONTEXT_PROCESSORS is missing commas, all nonexistent URLs
> > > display 500.html instead of 404.html. If I set DEBUG to True, it
> > > displays the default 404 page. if I add the commas to
> > > TEMPLATE_CONTEXT_PROCESSORS, then it displays the 404 page. The commas
> > > are not added by default. All pages do exist, so I am not missing
> > > anything.
> >
> > > Is this a known bug?
> >
> > > --
> > > 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.
> >
> > --
> > Regards,
> > Ian Clelland
> > <clell...@gmail.com>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


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

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



Re: django 1.1: nonexistent URLs display 500.html instead of 404.html

2012-02-21 Thread Ian Clelland
By 'missing commas', do you mean that there are *syntax errors* in your
settings.py file?

That will definitely cause a 500 error, and I would be surprised if it
didn't do it on *every* request.
It seems odd that you would get a 404 when Debug is turned on, but that may
be related to the handling of the 500 error template, or possibly indicates
another error in your application settings.

Ian

On Tue, Feb 21, 2012 at 10:36 AM, rabousha <ramiaboushaw...@gmail.com>wrote:

> I am using django 1.1, with DEBUG = False, and
> TEMPLATE_CONTEXT_PROCESSORS is missing commas, all nonexistent URLs
> display 500.html instead of 404.html. If I set DEBUG to True, it
> displays the default 404 page. if I add the commas to
> TEMPLATE_CONTEXT_PROCESSORS, then it displays the 404 page. The commas
> are not added by default. All pages do exist, so I am not missing
> anything.
>
> Is this a known bug?
>
> --
> 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.
>
>


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

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



Re: django get value from oracle function

2012-01-27 Thread Ian
On Jan 20, 3:05 pm, citos88 <cito...@gmail.com> wrote:
> I use Django and Oracle, and I want call oracle's function and catch
> and save to django's variable this what return that function. How can
> I do this?

You'll need to get a database cursor and use its callfunc method,
something like this:

from django.db import connection
import cx_Oracle

cursor = connection.cursor()
result = cursor.callfunc('degrees_to_celsius', cx_Oracle.NUMBER,
[212])
print(result)

For more information, see:

https://docs.djangoproject.com/en/1.3/topics/db/sql/#executing-custom-sql-directly
http://cx-oracle.sourceforge.net/html/cursor.html#Cursor.callfunc

Cheers,
Ian

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



Re: saving in a view

2012-01-27 Thread Ian Clelland
On Fri, Jan 27, 2012 at 9:26 AM, MikeKJ <mike.jo...@paston.co.uk> wrote:

> I have 2 models Count is purely an incremental counter a model called Sale,
> the reason for the Count models is to increment a reference for Sale and
> other models
>
> In a view I get the latest sale and count then I want to save the
> incemented
> count (number) to Count also save number to Sale
>
>
First off, the instances of "0" at the end of the first two lines should be
[0] (surrounded by square brackets), but I'm assuming that that's an
artifact of the email transport.

Past that, your code doesn't actually *do* anything, other than pull two
objects out of the database, and save them again, unmodified. Let's look at
the method you've pasted, line by line:

customer
> = Sale.objects.all().order_by('-id').filter(email_address=email).distinct()[0]
> this = Count.objects.all().order_by('-id')[0]


This part retrieves two objects from the database. You may want to guard
these two lines with an exception handler -- if there are no matching Sale
objects, or if the Count table is empty, either of these lines could raise
a KeyError.

number = this.number + 1


This line creates a new local variable called number, and assigns it the
value of this.number + 1. It doesn't do anything to the 'this' object at
all.

a = this.save(force_insert=True)


So this line forces 'this' to be re-saved (remember, though, that it hasn't
been modified, so the save doesn't really do anything). Model.save()
doesn't return anything, so 'a' is assigned the value None.

ref = number
> reference = number
> name = customer.name
> salutation = customer.salutation


Again, these just create some new local variables, but they don't actually
change your customer object at all, so this line:

b = customer.save(force_update=True)


Just forces a re-save of the unmodified customer object.

I"m not sure exactly what it is that you're trying to do with this view,
but I think that you are going to need some lines that actually update the
'this' and 'customer' object. You would do that like this:

this.number = this.number + 1

or
customer.reference = number

Then, when you save the objects (and just use "customer.save()", the
force_update=True isn't really necessary), then the new values you have
assigned will be saved in the database.

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

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



Re: Please help with complex aggregation/annotation issue

2012-01-19 Thread Ian Clelland
On Wed, Jan 18, 2012 at 1:03 AM, Salvatore Iovene <
salvatore.iov...@gmail.com> wrote:

> Hi,
> I apologize for the lousy title, but I really didn't know how to summarize
> the problem I'm facing. I have the following model:
>
> class MessierMarathon(models.Model):
> messier_number = models.IntegerField()
> image = models.ForeignKey(Image)
> nominations = models.IntegerField(default = 0)
> nominators = models.ManyToManyField(User, null=True)
>
> def __unicode__(self):
> return 'M %i' % self.messier_number
>
> class Meta:
> unique_together = ('messier_number', 'image')
> ordering = ('messier_number', 'nominations')
>
>
> A typical content for this model would be:
>
>Image A: 5 nominations for messier_number 1
>Image B: 4 nominations for messier_number 1
>Image C: 6 nominations for messier_number 2
>...and so on.
>
> I would like to formulate a query that returns me one image for each
> messier_number, picking the one with the most nominations. So, in the
> previous example, the query would return images A and C. The image B would
> not be returned because image A has more nominations for messier_number 1.
>
> The images returned must be sorted by messier_number, and of course may
> repeat. (An image might contain more that one Messier object, and get
> highest nomination counts for both).
>


The other edge case that you need to consider (and this is the one that
makes this more than a simple aggregation query) -- what should be returned
if two images have the same number of nominations for a given
messier_number? Are both of them returned, or is there another tie-breaking
criterion?

It's easy to get the highest nomination count for each messier number:


MessierMarathon.objects.values('messier_number').annotate(Max('nominations'))

What is harder is getting a unique image attached to each messier_number,
given that value for nominations.

A simple solution, which unfortunately requires a database hit for each
messier_number, would be:

highest_counts =
MessierMarathon.objects.values('messier_number').annotate(Max('nominations'))
top_images = dict((x['messier_number'],
MessierMarathon.objects.filter(messier_number=x['messier_number'],
nominations=x['nominations'])[0].image) for x in highest_counts)

You might be better off writing raw SQL for it, though; you could probably
get it all with one (convoluted) query.

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

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



Re: Django orm and no primary key

2012-01-10 Thread Ian Clelland
On Tue, Jan 10, 2012 at 9:04 AM, webonomic <webono...@gmail.com> wrote:

> The Django Book alludes to this, and maybe the comments there will
> help you.
>
> Go to http://www.djangobook.com/en/1.0/chapter05/
> and search for this paragraph:
>
> "Finally, note we haven’t explicitly defined a primary key in any of
> these models. Unless you instruct it otherwise, Django automatically
> gives every model an auto-incrementing integer primary key field
> called id. Each Django model is required to have a single-column
> primary key."
>

This is referring to an implicit primary key, which Django will create if
you do not specify one. The question was regarding using an existing table
with no PK in Django.

> I am wondering if it is possible to still use the django orm without
> > having a primary key at all, I currently got a table holding 61 million
> > entries soon gonna expand to hold 600 million entries, that table never
> > need to identify one entry alone its only to pull off statistics based
> > on other fields, so far I  dropped the primary key index in the database
> > and all works fine, but I know the orm always want a primary key, would
> > it still work if I for example claim one of the fields which aren't
> > unique as the primary key?
> >
> > Or is the only way to do it, use the cursor or even mysqldb directly?
>

This is possible -- there was some discussion on this list about it just a
few days ago. If you tell Django that another field is the actual primary
key, then it will not assume that there is an 'id' column (which is good,
because otherwise it will try to include that in any SELECT statements that
it issues).

As long as you consider this table to be essentially read-only, and you
don't try to use the ORM to create any records in it, then you shouldn't
have any problems with this. As specific measures:

- Don't try to create records with Model.objects.create() or
Model.objects.get_or_create()
- If you have to retrieve records, use filter() rather than get, if you
can't ever assume uniqueness
- Similarly, if you have to update records, use update() rather than save().

It sounds like you want to use aggregate queries on this table anyway, so
you (hopefully) shouldn't run into any issues.

Oh, and don't register this model with the admin; most of that framework is
built around the idea of rows uniquely addressable by their primary key.

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

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



Re: Can I escape or delimit the "{{ }}" template braces?

2011-12-19 Thread Ian Clelland
On Monday, December 19, 2011, J. Marc Edwards <
marc.edwa...@nimbisservices.com> wrote:
> I'd like to write a paragraph on my page that describes the {{ }} syntax,
but the template interpreter is interpreting the braces.

I think what you need is the {% templatetag %} tag -- it outputs template
tag start and end markers.

https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#templatetag

It can get a bit wordy, though, if your page has a lot of tags on it. If
you search online, you will find that a number of people have written {%
verbatim %} tags to solve just this problem.

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



Re: Django 1.2.1 strange problem

2011-12-15 Thread Ian Clelland
On Thu, Dec 15, 2011 at 5:56 AM, Sells, Fred
<fred.se...@adventistcare.org>wrote:

> I’ve got an older app that’s been running in production for about 2 years
> on RedHat 4, MySQL 5.0.77 with MyISAM tables, Django 1.2.1 and Python 2.4.
> 
>
> ** **
>
> This app is used heavily by internal users, which is a relatively light
> load compared to public sites.  I actually use Flex for the client side and
> save each field when the user changes it.
>
> ** **
>
> About once a month one field in particular will have its value cleared, or
> perhaps the save operation did not complete before the next user input hits
> the server.  I’ve searched my code for an unexpected reference to this
> field name with no results.  As I understand it, Django is single threaded
> so I don’t know how this can happen.
>

The Django code itself is not multithreaded -- it spawns no threads of its
own -- but that doesn't mean that your setup is single-threaded. That
depends entirely on how your web server is configured. Every production
environment I have seen uses processes or threads to serve multiple
requests simultaneously, which means that multiple instances of the Django
code are running at any given time.

Django tries to be thread-safe, which is slightly different -- the code is
written such that multiple threads can co-exist without stomping all over
each other's data, at least at the Python level.

At the database level, things are different again. This is probably where
your problems are coming from. If your database doesn't support isolation
through transactions (if you're using MyISAM tables on MySQL, basically),
then you are susceptible to problems like this. Database operations can and
will be interleaved, depending on when and how your web server decides to
schedule its threads.


> 
>
> ** **
>
> Has anyone seen similar behavior?  I plan to upgrade next month anyway,
> but could this be an artifact of the older Django or of MyISAM tables?
>

I doubt that upgrading Django will solve anything, but I would recommend
upgrading your tables to InnoDB. The only reasons I know for sticking with
MyISAM are a requirement for speed over all else (including data
integrity), and to use the MySQL "full-text-search" feature.

  I’m not using transactions since I’m not an experienced DBA, but should I?
>

Happily, Django will take care of all of this for you; you don't have to be
a DBA, or even think about transactions most of the time. As long as your
database supports it, Django will automatically isolate each request in its
own transaction. If the view returns a response, the transaction will be
committed to the database, and if the view raises error, the transaction
will be rolled back automatically. In almost every case, this behaviour
will be exactly what you want.


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

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



Re: Can a template extend a template?

2011-12-13 Thread Ian Clelland
On Tue, Dec 13, 2011 at 2:21 PM, Jason <1jason.whatf...@gmail.com> wrote:

> Hi there,
>
> I love the concept of DRY, and django's enthusiasm for this concept. In
> light of this I have tried to have a template extend a template, but it
> doesn't seem to work. Is there a better way than what I'm currently doing?
>
> The current way
>
> index.html
>
> {% if current_user %}
> {% extends "_logged_out_template.html" %}
>
> {% else %}
> {% extends "_logged_in_template.html" %}
> {% endif %}
>
> contact.html
>
> {% if current_user %}
>
> {% extends "_logged_out_template.html" %}
>
> {% else %}
>
> {% extends "_logged_in_template.html" %}
>
> {% endif %}
>
>
>
> The way I would like it to be (but it didn't work)
>
> index.html
> {% extends "_base_template.html" %}
>
> _base_script.html
>
> {% if current_user %}
>
> {% extends "_logged_out_template.html" %}
>
> {% else %}
>
> {% extends "_logged_in_template.html" %}
>
> {% endif %}
>
>  --
> 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/-/8j1xs23yjnAJ.
> 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.
>


Honestly, I never even realized that you *could* put an {% extends %} node
inside of an {% if %} node like that.

What I find works, if you really do have to dynamically change the base
template that you are inheriting from, is to set a context variable in your
view, and use it in the template. Nobody ever said that the argument to
'extends' has to be a literal string:

View:
def my_view(request):
if request.user.is_authenticated:
base_template = "_logged_in_template.html"
else:
base_template = "_logged_out_template.html"

   ...
   return render("my_template.html", RequestContext({"base_template":
base_template...}))


Template: (my_template.html)

{% extends base_template %}


(In a real app, I would use a base class for the view which would set the
base template for every request automatically, or I would do it in a
context processor, rather than putting those four lines at the top of every
single view)


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

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



Re: Query with no-correspondence results

2011-12-08 Thread Ian Clelland
On Thu, Dec 8, 2011 at 12:45 PM, wgis <alpha.sh...@gmail.com> wrote:

> Ian Clelland, it worked! Thanks a lot for your perseverance
>
> Tom's secret sauce it's not working, unfortunately =(
> Just (Carrots, Flavour, 3.0)
> I guess since some 'contexts' don't have an associated thing-vote, the
> filter will cut them off.
> It would be more neat with the ORM, but I must be looking for a golden
> a pot.
>
> Don't want to seem ungrateful but I realized that I should have not
> just an individual vote by context but also an average vote by
> context. Can you still pull it of? I'm sorry, I know it's not django
> anymore but I have to ask.
>

I would give this a shot:

select thing, name, avg(vote) from mydatabase_votecontext left
join mydatabase_vote on (mydatabase_vote.context_id =
mydatabase_votecontext.id and thing='Carrots') group by thing, name;

Ian

Thanks for your help.
>
> --
> 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.
>
>


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

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



Re: Django E-Commerce Framework

2011-12-08 Thread Ian Clelland
On Wednesday, December 7, 2011, bobhaugen <bob.hau...@gmail.com> wrote:
> I'm guessing that the OP wanted to develop a "standard" e-commerce
> site for a single company, in which case I agree with Stuart and Andre
> that the way to go is a well-tested e-commerce framework.
>
> I had to roll my own because I was doing something very different: B2B
> e-commerce with an efficient order form (order from a grid combining
> many products, not one-product-per-page adding to a shopping cart one
> at a time) and order line items from many producers where the payment
> from the customer needs to get allocated to each producer.  But had a
> well-tested framework for that kind of thing been available, I would
> have grabbed it.

I think the OP's phrase "e-commerce framework" is a bit vague, as well --
there are a lot of different components that could all get tagged with that
label: payment processing, recurring billing, shopping cart, fulfillment,
inventory management -- it's probably not too much of a stretch for some
people to add accounting and customer service to that list, too.

You say you had to roll your own, but really you just didn't need the
shopping cart functionality. Even with your requirements, I'm sure you are
better off using a well-tested payment gateway rather than writing your own
interface to Paypal.

At some level, everybody is going to have to do *some* customization;
whether that's just overriding some templates, or building the whole site
down to the payment provider interface. We could probably provide a survey
of all related packages in this thread, but the OP might also have to do
some more thinking about what their actual requirements are.

The good thing is that the Django community has build lots of high-quality
modules that cover just about every corner of this space, so any specific
needs can almost certainly be addresses here. "What can I use for
e-commerce" is a very open-ended question, though.


>
> As it is, I did use django-paypal with some customizations, which is
> its own kind of pain in the butt.  (Not django-paypal, the
> customizations, because now I am stuck with the version of django-
> paypal that I customized...)  Eventually I'll take another look at
> payment apps and some of the newer e-commerce frameworks that are more
> modular.
>
> --
> 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.
>
>

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

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



Re: Django E-Commerce Framework

2011-12-08 Thread Ian Clelland
On Wednesday, December 7, 2011, bobhaugen <bob.hau...@gmail.com> wrote:
> I'm guessing that the OP wanted to develop a "standard" e-commerce
> site for a single company, in which case I agree with Stuart and Andre
> that the way to go is a well-tested e-commerce framework.
>
> I had to roll my own because I was doing something very different: B2B
> e-commerce with an efficient order form (order from a grid combining
> many products, not one-product-per-page adding to a shopping cart one
> at a time) and order line items from many producers where the payment
> from the customer needs to get allocated to each producer.  But had a
> well-tested framework for that kind of thing been available, I would
> have grabbed it.

I think the OP's phrase "e-commerce framework" is a bit vague, as well --
there are a lot of different components that could all get tagged with that
label: payment processing, recurring billing, shopping cart, fulfillment,
inventory management -- it's probably not too much of a stretch for some
people to add accounting and customer service to that list, too.

You say you had to roll your own, but really you just didn't need the
shopping cart functionality. Even with your requirements, I'm sure you are
better off using a well-tested payment gateway rather than writing your own
interface to Paypal.

At some level, everybody is going to have to do *some* customization;
whether that's just overriding some templates, or building the whole site
down to the payment provider interface. We could probably provide a survey
of all related packages in this thread, but the OP might also have to do
some more thinking about what their actual requirements are.

The good thing is that the Django community has build lots of high-quality
modules that cover just about every corner of this space, so any specific
needs can almost certainly be addresses here. "What can I use for
e-commerce" is a very open-ended question, though.


>
> As it is, I did use django-paypal with some customizations, which is
> its own kind of pain in the butt.  (Not django-paypal, the
> customizations, because now I am stuck with the version of django-
> paypal that I customized...)  Eventually I'll take another look at
> payment apps and some of the newer e-commerce frameworks that are more
> modular.
>
> --
> 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.
>
>

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

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



Re: Query with no-correspondence results

2011-12-07 Thread Ian Clelland
On Wed, Dec 7, 2011 at 7:54 AM, wgis <alpha.sh...@gmail.com> wrote:

> First, thank you both for your answers. I'm now realizing that doing
> this with the ORM is not so easy as I thought it would be to others
> django fellows (it's my first django project, but I'm nailing it =P).
> I saw your RAW SQL solution and it looked genius-simple. I have short
> experience with the JOIN operation but that make sense to me. Yet, I
> tested, and I still get
> (Carrot, Flavour, 2.0)
> and just
> (Cars, Smell, 4.2) (Cars, Usability, 4.9)without the other contexts.
> If I remove the WHEREs (not filtering by user or thing), it still
> presents without nulls (or 0.0)
> Is there other way you can see?
> Again, thanks
> On 6 Dez, 21:48, Ian Clelland <clell...@gmail.com> wrote:
> > On Tue, Dec 6, 2011 at 1:35 PM, Reinout van Rees <rein...@vanrees.org
> >wrote:
> >
> > > Ah! Now I get your point. You also want the "empty" results for which
> > > there's no SQL data. Sorry, but I don't see a way in which you can do
> that
> > > with an SQL query (and so also not with a Django query).
> >
> > > In case you want all contexts, you'll have to query for those
> > > specifically. And afterwards grab the results belonging to that
> context. So
> > > you won't escape a for loop and some manual work, I'm afraid.
> >
> > Raw SQL:
> > select thing, name, vote from mydatabase_votecontext left join
> > mydatabase_vote on (mydatabase_vote.context_id =
> mydatabase_votecontext.id)
> > where thing='Carrot' and user='Me'
> >
> > That should return null if there is no vote. If you'd rather have zeros,
> > then use this:
> >
> > select thing, name, ifnull(vote, 0.0) from mydatabase_votecontext left
> join
> > mydatabase_vote on (mydatabase_vote.context_id =
> mydatabase_votecontext.id)
> > where thing='Carrot' and user='Me'
> >
> > There still might be a way to do it with the ORM; but you can definitely
> > use raw sql for this.
> >
> > --
> > Regards,
> > Ian Clelland
> > <clell...@gmail.com>
>
>
You're right -- it's the 'and user='Me' bit that is messing it up. I know
you left the id columns out to simplify the problem, but without a full
table structure, it's harder for me to visualize the join and the rows that
are getting selected.

Try this:
select thing, name, vote from mydatabase_votecontext left
join mydatabase_vote on (mydatabase_vote.context_id =
mydatabase_votecontext.id and thing='Carrots' and user='me')

With that statement, the left join should produce:
(votecontext.id, name, vote.id, thing, context_id, user, vote)
(1, Flavour, 4, Carrots, 1, Me, 3.0)
(2, Smell, NULL, NULL, NULL, NULL)
(3, Usability, NULL, NULL, NULL, NULL)
(4, Size, NULL, NULL, NULL, NULL)

And the select columns should reduce the width, to this:
(thing, name, vote)
(Carrots, Flavour, 3.0)
(NULL, Smell, NULL)
(NULL, Usability, NULL)
(NULL, Size, NULL)

If you absolutely need 'Carrots' in the first column (and you might not;
you should have it in the template context anyway, when you need to display
it), then you would have to duplicate it in the query, and use another
ifnull, like this:

select ifnull(thing, 'Carrots'), name, vote from mydatabase_votecontext
left join mydatabase_vote on (mydatabase_vote.context_id =
mydatabase_votecontext.id and thing='Carrots' and user='me')

(Or try Tom's secret sauce, and see if that works :) )


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

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



Re: Query with no-correspondence results

2011-12-06 Thread Ian Clelland
On Tue, Dec 6, 2011 at 1:35 PM, Reinout van Rees <rein...@vanrees.org>wrote:

> Ah! Now I get your point. You also want the "empty" results for which
> there's no SQL data. Sorry, but I don't see a way in which you can do that
> with an SQL query (and so also not with a Django query).
>
> In case you want all contexts, you'll have to query for those
> specifically. And afterwards grab the results belonging to that context. So
> you won't escape a for loop and some manual work, I'm afraid.
>
>
Raw SQL:
select thing, name, vote from mydatabase_votecontext left join
mydatabase_vote on (mydatabase_vote.context_id = mydatabase_votecontext.id)
where thing='Carrot' and user='Me'

That should return null if there is no vote. If you'd rather have zeros,
then use this:

select thing, name, ifnull(vote, 0.0) from mydatabase_votecontext left join
mydatabase_vote on (mydatabase_vote.context_id = mydatabase_votecontext.id)
where thing='Carrot' and user='Me'

There still might be a way to do it with the ORM; but you can definitely
use raw sql for this.


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

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



Re: models.Q raising exception

2011-12-01 Thread Ian Clelland
On Thu, Dec 1, 2011 at 12:58 PM, Martin Tiršel <dja...@blackpage.eu> wrote:

> Hello,
>
> why this is not working?
>
> from django.db import models
>
> ...
>GameProfile.objects.get(
>models.Q(nick=nick) | models.Q(user=self.user),
>world=self.world,
>)
>
>
A shot in the dark here, but if you are getting "'module' object has no
attribute 'Q'" here, have you imported something else called 'models'? Or
redefined it somehow above this code?

Try:
from django.db import models as django_models
...
GameProfile.objects.get(
   django_models.Q(nick=nick) | django_models.Q(user=self.user),
   world=self.world,
   )

to see if the problem goes away. If it does, it's almost definitely a
redefined name.

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

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



Re: unit tests and 'system' tests with history

2011-11-30 Thread Ian Clelland
On Wed, Nov 30, 2011 at 2:48 AM, Gelonida N <gelon...@gmail.com> wrote:

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

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


>
> I'd also like to do some other tests, where I work on a system and where
> I am able to suffer from my history.
>
> Example (the example is perhaps too simple to see what I'm aiming it)
> - I create an entry
> - I rename an entry
> - I remove an entry
>
> If I had three independent tests I would never find out if I had a weird
> bug, which would make the system fail if I tried to remove an entry
> which has been renamed before.
>

As an aside, I'm not sure that I would use this sort of test framework for
these kinds of bugs -- there are just too many ways for the system to fail
if you start thinking this way:

   - What if it only fails when the entry has been renamed?
   - What if it only fails when the entry has been renamed to something
   longer?
   - What if it only fails when the entry has been renamed while someone
   else was editing it?
   - What if it only fails when the entry has a name with no vowels in it,
   which was also used as another user's password, but not in the last six
   weeks? :)

You can only simulate so many conditions, and lots of bugs can lurk
undetected even with a whole suite of such tests. Even worse, if the code
changes, then the exact bug that you were testing for might appear to be
fixed, but actually changes very slightly, and doesn't get picked up any
more.

In a case like this, I would normally wait to find out that there was a
problem in the first place, and then institute a 'regression test' --
figure out the cause of the original bug (say, renaming the entry put the
record into an inconsistent state) and then set up a test which:

   1. instantiates a correct record directly
   2. performs the rename operation that was failing
   3. checks that the record is still consistent under every constraint.

And I would do all of these at the lowest level that makes sense --
certainly not by starting at the HTTP level.


> What would be a recommended way to run such system tests?
>
> 'just create a unit test, which is just calling sunb tests explicitely
> in the required order?)
>

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

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


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

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

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

Ian


>
>
> As you can see from my previous questions I'm used to 'non-atomic'
> testing (This was for systems which needed a very huge startup time
> and where taking snapshots was virtually impossible)
>
> Thus I often combined unit tests / system tests.
>
> These stress tests shall be able to run for several hours / days,
> whereas unit tests would run in a few minutes.
>
>
> Thanks for any suggestions
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


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

-- 
You received this mess

Re: Retrieve object model admin userid & password?

2011-11-30 Thread Ian Clelland
On Wed, Nov 30, 2011 at 10:22 AM, Tim Sawyer <list.dja...@calidris.co.uk>wrote:

> You can't retrieve the password, as that would be a security flaw.  The
> security works by hashing the password entered into the login form, and
> comparing the hashed version with the one stored on the database.  Hash
> functions are quick to run one way, but difficult to reverse, hence it's
> difficult to get back the password used.
>
> You can reset a users password in the admin site - login to admin, open
> the user up, then use the change password link next to the user's password
> field.
>
> This, of course, supposes that the password you've forgotten isn't the
> only admin password.  If it is, then you could delete the row from the
> auth_user database table and do a syncdb - that should prompt you to create
> a superuser, if I recall correctly.
>

Yes, yes and yes.

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

manage.py changepassword username_goes_here

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

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

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



Re: Boolean test on queryset

2011-11-28 Thread Ian Clelland
On Monday, November 28, 2011, Adam Nelson <a...@yipit.com> wrote:
> Jirka,
> That doesn't solve the problem.  That will still do a very expensive
count() operation on the queryset.  In fact, examples.count() is what
happens when you do bool(examples) anyway.

I'm confused here -- examples.count() is definitely not the same as
examples.__len__(), which is what you originally claimed that bool() was
doing. examples.count() should issue a SELECT COUNT query, while len()
iterates through the rows in the result set.

If you just need to know whether at least one row exists in the result, use
examples.exists() -- that's what it's for.

https://docs.djangoproject.com/en/1.3/ref/models/querysets/#exists

>From the (linked) docs:

> Returns True if the QuerySet contains any results, and False if not. This
tries to perform the query in the simplest and fastest way possible, but it
does execute nearly the same query. This means that calling
QuerySet.exists() is faster than bool(some_query_set), but not by a large
degree.


> Thanks,
> Adam
>
> On Mon, Nov 28, 2011 at 8:11 PM, Jirka Vejrazka <jirka.vejra...@gmail.com>
wrote:
>>
>> Hi Adam,
>>
>>  I tend to use:
>>
>>  if examples.count():
>>
>>...something...
>>
>>  HTH
>>
>>Jirka
>>
>> --
>> 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.
>

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

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



Re: django.conf.urls import question

2011-11-28 Thread Ian Clelland
On Fri, Nov 25, 2011 at 6:39 PM, Chet <ccor...@gmail.com> wrote:

> Hello,
>
> I just finished to tutorial and for in both my urls.py files, if I
> use:
>
> from django.conf.urls import patterns, include, url
>
> I get an http500 error: TemplateDoesNotExist: 500.html
>

This message is from Django, trying to tell you that there is a
configuration error, but it can't display that error to you because it is
missing the template for the "500" server error page. (Do you have DEBUG
disabled in your settings? Set it to True, and Django should use its
built-in technical error page, which will show you all of the details of
the underlying error.)

The error itself is very likely an import error, because that line in your
urls.py shouldn't work. Specifically, 'patterns', 'include', and 'url'
aren't defined directly inside of the django.conf.urls module, but as part
of django.conf.urls.defaults. (at least, until Django 1.4)

>
> before I had it as:
>
> from django.conf.urls.defaults import patterns, include, url
>

This line is correct for all released versions of Django.

>
> and when I change this statement to be default, everything works fine.
> I don't know why. In the tutorial it says to do it the first way
>
>
What Django version are you using to run through the tutorial?

It sounds to me like you are have a released version of Django (1.2, 1.3,
etc) installed, but you are following the tutorial for the development
version. (There used to be a big warning about this at the top of all every
page in the development docs, but it seems to have disappeared.)

Try following the tutorial starting at
https://docs.djangoproject.com/en/1.3/intro/tutorial01/
instead, and see how far you can get.


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

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



Re: string indices must be integers, not str

2011-11-21 Thread Ian Clelland
On Mon, Nov 21, 2011 at 9:37 AM, MikeKJ <mike.jo...@paston.co.uk> wrote:

>
> Traceback
>
> string indices must be integers, not str
>
> Request Method: POST
> Request URL:http://newrutherford.paston2.webfactional.com/question/
> Django Version: 1.3.1
> Exception Type: TypeError
> Exception Value:
>
> string indices must be integers, not str
>
> Exception Location:
> /home/paston2/webapps/newrutherford/newrutherford/question/views.py in
> question, line 31
>

Line 31 is the problem --- and we can't tell which one is line 31 from the
code you've posted here.

This line looks wrong to me:

send_mail(settings.EMAIL_SUBJECT_PREFIX +"Email from the

question form", msg_header+msg_middle, settings.DEFAULT_FROM_EMAIL

[settings.CONTACT_EMAIL_TO], fail_silently=False)


Maybe it's a word-wrapping issue, but
"settings.DEFAULT_FROM_EMAIL[settings.CONTACT_EMAIL_TO]"
looks like you're trying to use a string to index into another string
variable.

Ian

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

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



Re: Forbiden 403 error

2011-11-16 Thread Ian Clelland
On Wed, Nov 16, 2011 at 10:36 AM, Djano_newb <zamboni_...@yahoo.com> wrote:

>
> I am new to both python and Django but I have been programming for more
> than
> 20 years so I am teaching myself this stuff.  I came across an old training
> video that I have been going through.  This training has you develop a
> website that can create web pages.  I got everything right so far but I
> just
> got to the point where you are to save off your changes to create a new
> file
> and I am getting the 403 Forbidden error associated with a POST to my
> connection.  The error specifically states "CSRF token missing or
> incorrect."
>
>
It certainly does sound like your tutorial video is old; probably
pre-dating the built-in CSRF protection in Django.

The most relevant documentation is here:
https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/


> Now I am currently reading through this stuff on the Django web site and I
> find that you must have it at the top of your "views" but can someone
> explain in more plain language why this isn't on by default and what the
> problem really is here?  In reading the info on the Django site it seems
> backwards so I must be missing something.  When I read it, it sounds like
> you have to add this to "gain" the protection not remove it.  What I think
> I
> am seeing is my system is not allowing my browser to write new files so I
> have the protection by default and I need to add this stuff in order to
> remove the protection.  That makes sense to me but seems backwards from
> what
> I read on the Django site.  I am very confused by this.  Any help would be
> appreciated.
>

It certainly is quite confusing to say the the CSRF token has to go "at the
top of your views". Let me see if I can explain it better:

Django's CSRF protection is built-in; that is, it's on by default, and you,
as the site developer, have to specifically opt out to get around it (more
about that below). What you are seeing is the correct response to a form
submission that is missing the CSRF token. Any POST to your application
that doesn't include that token will be rejected, and Django will generate
a "403 Forbidden" error.

To get past these checks, you need to include the CSRF token in your forms.
The simplest way to do this is to include the template tag somewhere in
your HTML  element. (People seem to do it at the top, but it could go
anywhere). It's as simple as adding

{% csrf_token %}

in your template.

That tag will generate a hidden form element which will be submitted with
your form, and Django will accept the form submission and pass it along to
your view.

There are other, more complicated methods, if you are using JavaScript to
submit your forms, or if you need to access the actual token value, for
some reason, but this tag works for almost all cases.

Now, if you can't supply the token for some reason, and you need to opt out
(perhaps your code is part of an unauthenticated HTTP API, and you want to
accept POST requests from user agents that won't handle cookies), you can
use the @csrf_exempt decorator at the top of any of your views.

If you want to opt your whole application out of CSRF protection, then you
can do that too -- it's not baked into Django that deeply. You will need to
change your settings, and remove the CSRF middleware from
MIDDLEWARE_CLASSES. That will completely remove this feature from your
project. (and, of course, remove all of the security benefits that it comes
with)

Hope this helps,
Ian

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

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



Re: How can I serve static files while requiring Django-based access permissions?

2011-11-08 Thread Ian Clelland
On Tue, Nov 8, 2011 at 2:11 PM, zak2011 <zak2...@m.allo.ws> wrote:

> Dear Django Users,
>
> tl;dr: Please tell me what strategies I might use to serve a large
> static file from within Django, from views.py.
>
> If I want to limit access to a particular page in a Django app, I can
> do something like this in views.py:
>
> (Note: I will use four periods to indent, because spaces or tabs might
> not display properly.)
>
> def private_page(request):
> if special_permissions_checking_function(request.user):
> return render_to_response('private_page_template.html')
> else:
> return render_to_response('access_denied.html')
>
> What if I want to limit access to a large static file, instead of a
> dynamically generated HTML template?
>
>
The fastest way to do this is to tell the web server to serve the file from
a protected location. Apache and nginx both have ways to signal from python
code that a file should be read from disk and streamed to the user. This
file doesn't have to be in a location which is accessible through a normal
web request; ideally all access to it would be through your app, and you
can do whatever access checks that you want to before serving it.

Look up X-SENDFILE for Apache, or X-Accel-Redirect for nginx for the
details.

Ian


> Ideally the resulting website will be fast, but I also want to hear
> options that might be low performance.
>
> Thank you,
>
> Zak
>
> --
> 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.
>
>


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

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



Using the same storage backend for media and static files.

2011-11-05 Thread Ian Lewis
Hi,

I'm a developer for django-storages who maintains the AWS S3 boto
backend. I get a lot of requests and questions about how to use s3boto
as a backend for both media and for the staticfiles contrib app but
with different settings.

The issue is that the storage backends are created without any keyword
arguments in Django and the settings that the backend supports apply
globally. This makes it impossible to have media and static files
stored in different buckets for instance. I'm curious what the authors
of Django and staticfiles had in mind for this kind of situation? What
is the recommended thing to do?

Currently I often get pull requests for hack changes to s3boto to
allow users to set up multiple backends using just settings. I would
like to allow users to do something like that but I'm curious if there
is a recommended way for users to set up multiple backends using the
same class but with different settings.

-- 
Ian

http://www.ianlewis.org/

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



Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Ian Clelland
On Wed, Nov 2, 2011 at 10:46 AM, Tom Evans <tevans...@googlemail.com> wrote:

> OK, take this example. I have a django model table with 70 million
> rows in it. Doing any kind of query on this table is slow, and
> typically the query is date restrained - which mysql will use as the
> optimum key, meaning any further filtering is a table scan on the
> filtered rows.
>
> Pulling a large query (say, all logins in a month, ~1 million rows)
> takes only a few seconds longer than counting the number of rows the
> query would find - after all, the database still has to do precisely
> the same amount of work, it just doesn't have to deliver the data.
>
> Say I have a n entries I want to test are in that resultset, and I
> also want to iterate through the list, calculating some data and
> printing out the row, I can do the existence tests either in python or
> in the database. If I do it in the database, I have n+1 expensive
> queries to perform. If I do it in python, I have 1 expensive query to
> perform, and (worst case) n+1 full scans of the data retrieved (and I
> avoid locking the table for n+1 expensive queries).
>
> Depending on the size of the data set, as the developer I have the
> choice of which will be more appropriate for my needs. Sometimes I
> need "if qs.filter(pk=obj.pk).exists()", sometimes I need "if obj in
> qs".
>
>
Just looking at the source to QuerySet (finally), and it looks like the
__contains__ method actually does something different than this: It
evaluates the whole QuerySet in bulk at the database level, and starts
creating model instances based on that, but only until it finds a matching
one. So, after running "if obj in qs", you might end up with one object
created, or you might end up with 70M objects, or anywhere in between.

Again: odd, undocumented, and potentially surprising behaviour, and I'd
recommend explicit over implicit, especially in this case.



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

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



Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Ian Clelland
On Wed, Nov 2, 2011 at 10:46 AM, Tom Evans <tevans...@googlemail.com> wrote:

> On Wed, Nov 2, 2011 at 5:30 PM, Ian Clelland <clell...@gmail.com> wrote:
> > On Wed, Nov 2, 2011 at 8:25 AM, Thomas Guettler <h...@tbz-pariv.de> wrote:
> >>
> >> # This is my current solution
> >> if get_special_objects().filter(pk=obj.pk).count():
> >># yes, it is special
> >>
> >
> > I can't speak to the "why" of this situation; it seems to me that this
> could
> > always be converted into a more efficient database query without any
> > unexpected side-effects (and if I really wanted the side effects, I would
> > just write "if obj in list(qs)" instead). In this case, though, I would
> > usually write something like this:
> > if get_special_objects().filter(pk=obj.pk).exists():
> ># yes, it is special
> > I believe that in some cases, the exists() query can be optimized to
> return
> > faster than a count() aggregation, and I think that the intent of the
> code
> > appears more clearly.
> > Ian
>
> OK, take this example. I have a django model table with 70 million
> rows in it. Doing any kind of query on this table is slow, and
> typically the query is date restrained - which mysql will use as the
> optimum key, meaning any further filtering is a table scan on the
> filtered rows.
>
> Pulling a large query (say, all logins in a month, ~1 million rows)
> takes only a few seconds longer than counting the number of rows the
> query would find - after all, the database still has to do precisely
> the same amount of work, it just doesn't have to deliver the data.
>
> Say I have a n entries I want to test are in that resultset, and I
> also want to iterate through the list, calculating some data and
> printing out the row, I can do the existence tests either in python or
> in the database. If I do it in the database, I have n+1 expensive
> queries to perform. If I do it in python, I have 1 expensive query to
> perform, and (worst case) n+1 full scans of the data retrieved (and I
> avoid locking the table for n+1 expensive queries).
>
> Depending on the size of the data set, as the developer I have the
> choice of which will be more appropriate for my needs. Sometimes I
> need "if qs.filter(pk=obj.pk).exists()", sometimes I need "if obj in
> qs".
>

I agree that there are situations where you want, or need, to pull the data
in to Python for processing, to avoid a lot of database overhead. That's
why we have select_related, as well: sometimes you really do need to just
grab as much as possible all at once.

The trouble is that querysets are *supposed* to be lazy; just evaluating as
much as necessary, as late as possible, to do the job. I think that this
behaviour violates the principle of least surprise, by instantiating a
(potentially very large) queryset as a side-effect of a simple inclusion
test.

Any other time that you want a queryset instantiated, the idiomatic way to
do it is to construct a Python list based on it:

# Get all objects at once from database
objs = list(qs)
# Now use that list multiple times in a method

or

for obj in list(qs):
  # qs is evaluated once, list members may be manipulated as needed in
Python

or, by extension,

if obj in list(qs):
  # stuff

I wouldn't rely on the behaviour of the in operator to evaluate the
queryset for me; it doesn't look right to me, it's not obvious to anyone
else looking at the code, and I don't think it's documented behaviour.

I would prefer that in did an exists query, but since there are explicit
ways to force either behavior, in practise I use one of those explicit
ways, rather than leave the code looking ambiguous.

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

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



Re: QuerySet: "if obj in queryset" can be very slow

2011-11-02 Thread Ian Clelland
On Wed, Nov 2, 2011 at 8:25 AM, Thomas Guettler <h...@tbz-pariv.de> wrote:

> # This is my current solution
> if get_special_objects().filter(pk=obj.pk).count():
># yes, it is special
>
>
I can't speak to the "why" of this situation; it seems to me that this
could always be converted into a more efficient database query without any
unexpected side-effects (and if I really wanted the side effects, I would
just write "if obj in list(qs)" instead). In this case, though, I would
usually write something like this:

if get_special_objects().filter(pk=obj.pk).*exists*():
   # yes, it is special

I believe that in some cases, the exists() query can be optimized to return
faster than a count() aggregation, and I think that the intent of the code
appears more clearly.

Ian

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

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



Re: Long usernames in auth_user?

2011-10-28 Thread Ian Clelland
On Wed, Oct 26, 2011 at 3:00 PM, Kurtis Mullins <kurtis.mull...@gmail.com>wrote:

> Check out userena as well. But a custom authentication back-end was the
> approach I originally took. And to answer your question, yes -- your chances
> of finding people w/ email addresses longer than 75 chars are less than
> finding people w/ 30 chars -- but still a limitation none-the-less as there
> is no limitation on how long an email address can be.
>
>
Not quite correct -- from RFC-3696:

   In addition to restrictions on syntax, there is a length limit on
   email addresses.  That limit is a maximum of 64 characters (octets)
   in the "local part" (before the "@") and a maximum of 255 characters
   (octets) in the domain part (after the "@") for a total length of 320
   characters.  Systems that handle email should be prepared to process
   addresses which are that long, even though they are rarely
   encountered.

320 characters suffices for any valid email address.


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

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



Re: Database management commands

2011-10-28 Thread Ian Clelland
On Fri, Oct 28, 2011 at 2:35 AM, Daniele Procida <dani...@vurt.org> wrote:

> COuld it still be the case that the issue is the result of the older Django
> database having used one engine by default, and the new one the other?
>
>
That is possible -- in a MySQL shell, run "SHOW TABLE STATUS", and you can
see the engine used by all of your tables.


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

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



Re: Using .filter() on a constant expression

2011-10-21 Thread Ian Clelland
On Sat, Oct 15, 2011 at 9:52 PM, Tim Chase
<django.us...@tim.thechases.com>wrote:

> I have some gnarly AND/OR logic combining Q() objects but deep
> within the logic, I need to do a comparison of two constants.  In an ideal
> world, the logic would look something like
>
>   def age(self, age):
> ... & Q(12=as_of.month) & ...
>
> but that's invalid python.
>
> I *can* break out this rats' nest of logic into individual
> queries, evaluate the constant expression, conditionally OR the
> logic into the tree, then reassemble all the parts.  However,
> that gets even uglier.

...

> Is there any way to include a constant comparison in a Q()?


Q objects are definitely not meant to handle that -- they have to operate on
some field in the database.

Besides, if you need to compare two constants, and you have both of them
available in python before you construct your query, then why would you want
to compare them in SQL? If the point is to include or exclude some other
conditions based on the calling parameters, then I would just use those
parameters to construct the right query to begin with.

I would think that breaking it into smaller, manageable pieces would make
the code easier to understand, rather than uglier, but that's a matter of
aesthetics, I suppose.

If you don't want to do that, then just use python to selectively include or
exclude the other Q objects (that you wanted to depend on your comparison):

Using your code as a base, I would do something like this: (I don't know if
this is correct; I get a headache trying to count all of the parentheses :)
)

 alive_q = use_as_of & (
# dob1 >= y1
Q(dob_year_min__gt=alive_y1) | (
Q(dob_year_min=alive_y1) & (
  Q(dob_month=None) |
  Q(dob_month__gt=as_of.month) | (
  Q(dob_month=as_of.month) & (
Q(dob_day=None) |
Q(dob_day__gte=as_of.day)
))
  )) | (

*# MAGIC HAPPENS HERE*
* ( Q(dob_month=1, dob_day=None) if as_of.month==12 else Q() )  |*
* ( Q(dob_day=1) if as_of_day==31 else Q())*
*# END MAGIC*

))
) & (
# dob2 < y2
Q(dob_year_max__lt=alive_y2) | (
Q(dob_year_max=alive_y2) & (
  Q(dob_month=None) |
  Q(dob_month__lt=as_of.month) | (
  Q(dob_month=as_of.month) & (
Q(dob_day=None) |
Q(dob_day__lt=as_of.day)
))
  )) | (
Q(dob_year_max=alive_y2+1) & (
  Q(dob_month=1) & (
Q(dob_day=None) |
Q(dob_day__lt=1)
  ))
 ))

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

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



Re: django.db.models import Q help!

2011-10-21 Thread Ian Clelland
On Fri, Oct 21, 2011 at 11:06 AM, Kayode Odeyemi <drey...@gmail.com> wrote:

> Hello,
>
> Please I need help with django.db.models.Q. I have the query below which is
> returning empty
>
> qs =
> Q(financial_institution=request.user.get_profile().financial_institution)
> txn = Transaction.objects.extra(
> where=['(tpin=%s or teller_no=%s or identifier=%s) AND
> financial_institution_id=%s'],
> params=[value, str(value), value, str(qs)])
>
> If I substitute the line params=[value, str(value), value, str(qs)]) with
> params=[value, str(value), value, 1),
> I get real results from the database, meaning the problem lies with Q.
>
>
Why are you trying to use a Q object for this? Q objects are meant to be
passed into .filter(), not coerced into extra SQL.

If what you need for the params is the ID of another object, then just use
that!

Try something like

fi = request.user.get_profile().financial_institution
txn = Transaction.objects.extra(
where=['(tpin=%s or teller_no=%s or identifier=%s) AND
financial_institution_id=%s'],
    params=[value, str(value), value, fi.id])

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

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



Re: PUNTARE CON DJANGO SU BILANCIATORE ORACLE ATTRAVERSO IL TSNAME

2011-10-18 Thread Ian
On Oct 18, 5:17 am, Maksymus007  wrote:
> englishoo speakino list only.

That was rude and uncalled for.

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



  1   2   3   4   5   6   7   >