Issues with setting attrs and Media when creating my own widget
I'm trying to subclass the Select widget, so that I can create an editable scrolling list (done via JavaScript code that I found). My entire class is as follows: --Code-- from django import forms class ComboBox(forms.Select): class Media: js = ("/js/wise/comboBox.js",) def __init__(self, choices=()): # Set up calls to the combo box JavaScript attrs = { "onFocus": "return combo_focus(this);", "onChange": "return combo_change(this);", "onKeyDown":"return combo_keydown(this, event);", "onKeyPress": "return combo_keypress(this, event);", "onKeyUp": "return combo_keyup(this, event);", "onClick": "return combo_click(this, '');" } super(ComboBox, self).__init__(attrs, choices) --Code-- The form that uses it looks like: --Code-- class TestTargetForm(forms.Form): # Family name fname = forms.ModelChoiceField( queryset=TargetFamily.objects.all(), required = False, label = "Family Name", empty_label = "[Match All]", widget = ComboBox ) --Code-- Issue #1: I figured out that I can add HTML attributes by setting the 'attrs' variable. Which means I only need to create __init__() and not render(). That works fine except that I want to call a JavaScript function with a string (the onClick attribute). The single quotes get escaped. How would you pass a string to a JavaScript function using 'attrs'? Issue #2: The 'class Media' definition is being ignored when running through the Django server. I can import my class in python, instantiate the class, and print the media: python manage.py shell >>> from share.widgets import ComboBox >>> print ComboBox().media but when I look at the web page source coming back from the Django server, that text isn't there. Did I need to do anything else? I would appreciate any help either by example or pointers to examples or docs. I looked in the Django source and it looks like the admin stuff sets Media just like I'm doing. The Django doc page for Media also shows an example that looks just like what I'm doing (doesn't mention that I have to do anything else). -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Your IDE of choice
I have omnicomplete working (haven't used it too much yet). I have this in my $HOME/.vimrc file: --.vimrc-- if has("autocmd") autocmd BufRead *.py set smartindent \ cinwords=if,elif,else,for,while,try,except,finally,def,class autocmd FileType python set omnifunc=pythoncomplete#Complete autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS autocmd FileType html set omnifunc=htmlcomplete#CompleteTags autocmd FileType css set omnifunc=csscomplete#CompleteCSS endif " Allow to be used instead of like other IDE's do " for auto-completion inoremap --.vimrc-- All 'autocmd' lines should be single lines. Also, I have vim starting automatically importing the Django db. I have a little script (below) that will automatically find my settings.py file and start vim. I do this by starting at the location of the file on the vim command line and working upwards in the directory structure until I find it: --dvim-- #!/packages/bin/python """ Start vim for Django files """ import os import sys args = sys.argv # Get our starting directory to look for the settings file. If no # filename is given, start in the current directory if len(args) > 1: # If multiple filenames are given on the command line, we assume # the same Django settings apply to all dir = os.path.realpath(os.path.dirname(args[1])) else: dir = os.path.realpath(".") # Start looking for the settings file, going up one directory if we # don't find it until we hit the top of the filesystem while not os.path.exists(dir + "/settings.py"): if dir == "/": # We are as far as we can go and didn't find anything dir = None break # Go up one directory dir = os.path.dirname(dir) if dir != None: # Found the settings file os.putenv("PYTHONPATH", os.path.dirname(dir)) os.putenv("DJANGO_SETTINGS_MODULE", os.path.basename(dir) + ".settings") os.system("/packages/bin/vim '+python from django import db' " + \ " ".join(args[1:])) else: raise IOError("Django settings file not found") sys.exit(0) --dvim-- I'm sure some lines are probably getting wrapped. I only use Django on Unix/Linux so I'm guessing it would need some tweaking for Windows. On Wed, 2009-01-07 at 12:26 +0100, Oscar Carlsson wrote: > Have you been able to make omnicomplete work with Django? > I haven't been able to figure it out myself, and gave up after a few > tries. It would be really sweet to have, since vim otherwise is a really > good editor. > > Oscar > > On Wed, Jan 07, 2009 at 12:15:22PM +1930, Santiago wrote: > > > > i recently switched to screen + vim with omnicomplete for python and html... > > > > komodo edit its pretty good too > > > > 2009/1/7 martyn : > > > > > > Hi > > > > > > http://pyrox.utp.edu.co/ > > > > > > Regards > > > > > > Bye. > > > > > > On Jan 6, 9:34 am, roberto wrote: > > >> I tried them all (almost ... I think... at least the free ones). > > >> - Pyscripter is really nice but it is true, it is only for windows. > > >> (If it is developed with python it should be platform-independent, > > >> shouldn' be ?) (no support for sql queries I think) > > >> - Eclipse + PyDev (no good support for sql queries to relational db) > > >> - Ulipad (open source / excellent / very small / some issues with > > >> svn / no support for sql queries to db - django plugin to highlight > > >> templates, etc) > > >> - Netbeans (ex-NBPython) it is excellent (very good sql support - some > > >> issues with memory consume - I didn't get debugger work 100% with > > >> django) > > >> - Oracle jdeveloper. it is an excellent tool. Its support for python > > >> is still too new and I think that django support is still to come. > > >> - Eric4: screenshots are very beautiful bu I couldn't get to install > > >> it in my ubuntu box (too many precedences and too complicated for a > > >> newbie like me). > > >> > > >> Have a great year 2009 everyone ! > > >> > > >> On Jan 6, 9:02 am, "Trivedi, Apaar" wrote: > > >> > > >> > I use Eclipse with PyDev and PyDev extensions. I really like it, but I > > >> > prefer the eclipse sort of IDE's. > > >> > > >> > ____ > > >> > > >> > From: django-users@googlegroups.com > > >> &g
Re: Your IDE of choice
Glad it was of use. Except for the script which I wrote myself, all the information came from either the following page or a link from that page: http://code.djangoproject.com/wiki/UsingVimWithDjango On Wed, 2009-01-07 at 19:32 +0100, Oscar Carlsson wrote: > Sweet! > > I've been looking (and I'm pretty sure it's not only me who's been > looking) for some good tutorial on how to do this. > > Luckily I use OS X at home, which probably means that I can use this > without any modification... :-D > > Thank you very much! > > Oscar > > On Wed, Jan 07, 2009 at 01:06:43PM +, Adam Stein wrote: > > > > I have omnicomplete working (haven't used it too much yet). I have this > > in my $HOME/.vimrc file: > > > > --.vimrc-- > > if has("autocmd") > > autocmd BufRead *.py set smartindent > > \ cinwords=if,elif,else,for,while,try,except,finally,def,class > > > > autocmd FileType python set omnifunc=pythoncomplete#Complete > > autocmd FileType javascript set > > omnifunc=javascriptcomplete#CompleteJS > > autocmd FileType html set omnifunc=htmlcomplete#CompleteTags > > autocmd FileType css set omnifunc=csscomplete#CompleteCSS > > endif > > > > " Allow to be used instead of like other IDE's do > > " for auto-completion > > inoremap > > --.vimrc-- > > > > All 'autocmd' lines should be single lines. > > > > Also, I have vim starting automatically importing the Django db. I have > > a little script (below) that will automatically find my settings.py file > > and start vim. I do this by starting at the location of the file on the > > vim command line and working upwards in the directory structure until I > > find it: > > > > --dvim-- > > #!/packages/bin/python > > > > """ > > Start vim for Django files > > """ > > > > import os > > import sys > > > > args = sys.argv > > > > # Get our starting directory to look for the settings file. If no > > # filename is given, start in the current directory > > if len(args) > 1: > > # If multiple filenames are given on the command line, we assume > > # the same Django settings apply to all > > dir = os.path.realpath(os.path.dirname(args[1])) > > else: > > dir = os.path.realpath(".") > > > > # Start looking for the settings file, going up one directory if we > > # don't find it until we hit the top of the filesystem > > > > while not os.path.exists(dir + "/settings.py"): > > if dir == "/": > > # We are as far as we can go and didn't find anything > > dir = None > > break > > > > # Go up one directory > > dir = os.path.dirname(dir) > > > > if dir != None: > > # Found the settings file > > os.putenv("PYTHONPATH", os.path.dirname(dir)) > > os.putenv("DJANGO_SETTINGS_MODULE", os.path.basename(dir) + > > ".settings") > > > > os.system("/packages/bin/vim '+python from django import db' " + \ > > " ".join(args[1:])) > > else: > > raise IOError("Django settings file not found") > > > > sys.exit(0) > > --dvim-- > > > > I'm sure some lines are probably getting wrapped. > > > > I only use Django on Unix/Linux so I'm guessing it would need some > > tweaking for Windows. > > > > On Wed, 2009-01-07 at 12:26 +0100, Oscar Carlsson wrote: > > > Have you been able to make omnicomplete work with Django? > > > I haven't been able to figure it out myself, and gave up after a few > > > tries. It would be really sweet to have, since vim otherwise is a really > > > good editor. > > > > > > Oscar > > > > > > On Wed, Jan 07, 2009 at 12:15:22PM +1930, Santiago wrote: > > > > > > > > i recently switched to screen + vim with omnicomplete for python and > > > > html... > > > > > > > > komodo edit its pretty good too > > > > > > > > 2009/1/7 martyn : > > > > > > > > > > Hi > > > > > > > > > > http://pyrox.utp.edu.co/ > > > > > > > > > > Regards > > > > > > > > > > Bye. > > > > > > > > > > On Jan 6, 9:34 am, roberto
Re: What do you use as a build tool (like Ant or make)
I'm not doing unit tests at the moment, but for build and release I use Waf (http://code.google.com/p/waf/), which happens to be written in Python (including the configuration files). On Tue, 2008-09-09 at 01:14 -0700, ristretto.rb wrote: > Hello, > > What do you use to build a Django project? By build I mean, > > * run unit tests > * copy files to a distribution set based on a target (production, > staging, clustered, etc.) > * include config files specific to the target, and not including > source control files and other development > time artifacts. > * transfer distribution > > Perhaps you just hand build python scripts to do it. Or do you use > Ant or make? I'm coming over from Java, and used to use Ant, but I'm > migrating over to Python and would like to use what is generally > considered the Pythonic way. > > cheers > > -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Looking for an example on how to use us.forms.USZipCodeField
Using Django v1.0. One of my models is a standard address table. I knew about us.models.PhoneNumberField, so I used that for a phone number field. It uses us.forms.USPhoneNumberField so that validation works nicely on an Admin form. Same thing for USStateField. While there is are phone number and US state model fields, there doesn't seem to be the equivalent zip code field, even though there is a zip code form element. Not sure why that would be. I've searched around, but the best I get are syntax errors (at least Python/Django complains about a syntax error when I try to set up a form and have my zip code field use USZipCodeField). Given that, how do you actually tell the Admin form to use us.forms.USZipCodeField for a given model field or somehow associate the zip code model field with USZipCodeField? Right now my zip code model is a CharField() for lack of a better choice. Thanks for any links, pointers, examples, etc. -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Looking for an example on how to use us.forms.USZipCodeField
Thanks for the information. I eventually stumbled across a web page that mentioned formfield_for_dbfield(). I wound up doing this: class AddressAdmin(admin.ModelAdmin): def formfield_for_dbfield(self, db_field, **kwargs): if db_field.name == "Zipcode": return USZipCodeField(**kwargs) else: return super(AddressAdmin,self).formfield_for_dbfield(db_field, **kwargs) where my field name is "Zipcode". Since this was the only zipcode field, this seemed like the easiest solution. On Sat, 2008-09-27 at 19:42 +0800, Russell Keith-Magee wrote: > On Fri, Sep 26, 2008 at 9:11 PM, Adam Stein <[EMAIL PROTECTED]> wrote: > > > > While there is are phone number and US state model fields, there doesn't > > seem to be the equivalent zip code field, even though there is a zip > > code form element. Not sure why that would be. > > Mostly an accident of history. The US-centric model fields lived in > the core fields package until very recently - moving those two fields > into localflavor was one of the last backwards-incompatible changes > made before v1.0. These model fields have a history that goes back to > the initial release of Django. > > The form fields were developed independently as part of the broader > 'localflavor' development effort. During that development, form fields > were written for phone numbers, zip codes, states, etc. At some point, > the existing model fields (in core) were linked to the new localflavor > form fields. > > Adding a US Zip code model field would be a reasonable contribution to > the localflavor application. If a suitable patch were to materialize > (i.e., a good implementation with docs and tests), it would probably > find itself in core in short order. > > > Given that, how do you actually tell the Admin form to use > > us.forms.USZipCodeField for a given model field or somehow associate the > > zip code model field with USZipCodeField? Right now my zip code model > > is a CharField() for lack of a better choice. > > That's a reasonable approach. An actual implemention of a > models.USZipCodeField would probably subclass CharField. > > As for getting the admin to use your field - you several options: > > 1) Write a custom modelform, but override the Zip code field. e.g., > > class MyForm(forms.ModelForm): > zip = USZipCodeField() > class Meta: > model = MyModel > > This will do all the default form processing for MyModel, but will > override the field used for the 'zip' field. You can then use this > form in your application, or provide it to a ModelAdmin class as the > form that you want the model to use: > > class MyModelAdmin(ModelAdmin): > form = MyForm > > 2) Override the formfield_for_dbfield method on the ModelAdmin class. > When the admin renders a form, it uses the formfield_for_dbfield > method to determine the widget that should be used for model fields of > a particular type. If you want to use your US ZipCodeField > consistently throughout your admin, it may be a good idea to subclass > the base ModelAdmin providing your own default form field.. I haven't > testing this code specifically, but it will end up something like: > > class MyModelAdmin(ModelAdmin): > def formfield_for_dbfield(self, db_field, **kwargs): > if isinstance(db_field, models.ZipCode): > kwargs['form_class'] = forms.USZipCodeField > return db_field.formfield(**kwargs) > > return super(MyModelAdmin, self).formfield_for_dbfield(db_field, **kwargs) > > 3) Write your own USZipCode model field that specifies > forms.USZipCodeField by default. This would mean that whenever a model > defines a ZipCode, the admin would get the right form element. This is > the code that you could submit for inclusion to the localflavor > application in Django itself. > > Option 3 is the most comprehensive solution, but will also require the > most work (nothing too dramatic, just fiddly, and it's just not > particularly well documented at the moment). > > Yours > Russ Magee %-) > > -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: http links without using URLs.py
Check out: http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs I have Django serve static files during development so that all my links that don't need to go thru Django work. On Tue, 2009-01-27 at 08:42 -0800, May wrote: > Hello, > > I'm converting PHP pages to Django. I'm using base.html for my > formatting. I've included the left-side bar in the base.html, which > includes links that do not require using a database, such as the > "contact us" page. Since I'm using localhost for testing my link > looks something like this: > > http://127.0.0.1/contactus.html/"; >Contact Us > > Since the left-side bar is in base.html when the link is selected > django requires that I place the link in the URL.py and include it in > View.py. I have many links like this and would prefer that the links > go directly to the page ignoring the django requests. > > Is there a simple work around for this, that will allow me to continue > to use the convenience of the base.html inheritance? > > Thanks, > > Ana > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: http links without using URLs.py
I ONLY use it for development with the Django server. I only set up to serve static pages when DEBUG = True (as they show toward the bottom of the page). No need to change links on the production server (apache + mod_python) because the URLs are a different location than what I have set up for mod_python. You set up mod_python using if you are using Apache. This tells apache that ONLY what matches the specified location will use mod_python. An example: SetHandler python-program PythonHandler django.core.handlers.modpython PythonInterpreter my_arbitrary_unique_name_here PythonPath "['/my/django/code'] + sys.path" SetEnv DJANGO_SETTINGS_MODULE WebSite.settings SetEnv PYTHON_EGG_CACHE /tmp/.python-eggs PythonDebug On With this setup, only those URLs that have /my_django_site/ will go to Django (via mod_python). Any other URLs will get serviced by Apache as normal. It is quite discouraged to have Django serve static pages on a production server since it's not meant for that, so it's slow and inefficient. On Tue, 2009-01-27 at 09:06 -0800, May wrote: > Hello, > > The tutorial suggests not serving the static pages with this method on > a permanent basis. Are you using this method for your production > server? I'm using windows/apache/modpython and I've tried using the > IP address and still run into django url requests. Do you know of a > way to get apache to override django? > > Thanks, > > Ana > > On Jan 27, 8:55 am, Adam Stein wrote: > > Check out: > > > > http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs > > > > I have Django serve static files during development so that all my links > > that don't need to go thru Django work. > > > > > > > > On Tue, 2009-01-27 at 08:42 -0800, May wrote: > > > Hello, > > > > > I'm converting PHP pages to Django. I'm using base.html for my > > > formatting. I've included the left-side bar in the base.html, which > > > includes links that do not require using a database, such as the > > > "contact us" page. Since I'm using localhost for testing my link > > > looks something like this: > > > > > http://127.0.0.1/contactus.html/"; >Contact Us > > > > > Since the left-side bar is in base.html when the link is selected > > > django requires that I place the link in the URL.py and include it in > > > View.py. I have many links like this and would prefer that the links > > > go directly to the page ignoring the django requests. > > > > > Is there a simple work around for this, that will allow me to continue > > > to use the convenience of the base.html inheritance? > > > > > Thanks, > > > > > Ana > > > -- > > > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > Disclaimer: Any/All views expressed > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: http links without using URLs.py
Eggs seems to be something related to python packages, not sure exactly what they are used for. I needed the PYTHON_EGG_CACHE because my web server could not write to the default egg cache directory and so I had it use a temp place. Perhaps somebody else can better explain eggs. On Tue, 2009-01-27 at 09:42 -0800, May wrote: > Hello Adam, > > Thanks! I have already set up several sections for the > django site, so I must not have the syntax quite right for apache to > ignore the static links. I will work on it. One last question? What > are eggs? > SetEnv PYTHON_EGG_CACHE /tmp/.python-eggs > > Thanks, > Ana > > On Jan 27, 9:23 am, Adam Stein wrote: > > I ONLY use it for development with the Django server. I only set up to > > serve static pages when DEBUG = True (as they show toward the bottom of > > the page). > > > > No need to change links on the production server (apache + mod_python) > > because the URLs are a different location than what I have set up for > > mod_python. > > > > You set up mod_python using if you are using > > Apache. This tells apache that ONLY what matches the specified location > > will use mod_python. > > > > An example: > > > > > > SetHandler python-program > > PythonHandler django.core.handlers.modpython > > PythonInterpreter my_arbitrary_unique_name_here > > PythonPath "['/my/django/code'] + sys.path" > > SetEnv DJANGO_SETTINGS_MODULE WebSite.settings > > SetEnv PYTHON_EGG_CACHE /tmp/.python-eggs > > PythonDebug On > > > > > > With this setup, only those URLs that have /my_django_site/ will go to > > Django (via mod_python). Any other URLs will get serviced by Apache as > > normal. > > > > It is quite discouraged to have Django serve static pages on a > > production server since it's not meant for that, so it's slow and > > inefficient. > > > > > > > > On Tue, 2009-01-27 at 09:06 -0800, May wrote: > > > Hello, > > > > > The tutorial suggests not serving the static pages with this method on > > > a permanent basis. Are you using this method for your production > > > server? I'm using windows/apache/modpython and I've tried using the > > > IP address and still run into django url requests. Do you know of a > > > way to get apache to override django? > > > > > Thanks, > > > > > Ana > > > > > On Jan 27, 8:55 am, Adam Stein wrote: > > > > Check out: > > > > > >http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs > > > > > > I have Django serve static files during development so that all my links > > > > that don't need to go thru Django work. > > > > > > On Tue, 2009-01-27 at 08:42 -0800, May wrote: > > > > > Hello, > > > > > > > I'm converting PHP pages to Django. I'm using base.html for my > > > > > formatting. I've included the left-side bar in the base.html, which > > > > > includes links that do not require using a database, such as the > > > > > "contact us" page. Since I'm using localhost for testing my link > > > > > looks something like this: > > > > > > > http://127.0.0.1/contactus.html/"; >Contact Us > > > > > > > Since the left-side bar is in base.html when the link is selected > > > > > django requires that I place the link in the URL.py and include it in > > > > > View.py. I have many links like this and would prefer that the links > > > > > go directly to the page ignoring the django requests. > > > > > > > Is there a simple work around for this, that will allow me to continue > > > > > to use the convenience of the base.html inheritance? > > > > > > > Thanks, > > > > > > > Ana > > > > > -- > > > > > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > > > Disclaimer: Any/All views expressed > > > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > > > -- > > > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > Disclaimer: Any/All views expressed > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Any way to NOT escape a percent sign using 'contains'?
According to the docs, when using 'contains' in filter() a percent sign or underscore is automatically escaped. However, in my case I want the resulting SQL to use the percent sign. I know 'contains' will fill in the outside percent signs, but it escapes the percent sign in my string. So that calling: Entry.objects.filter(headline__contains='a%b') will result in: SELECT ... WHERE headline LIKE '%a\%b%'; but I want it to be this instead: SELECT ... WHERE headline LIKE '%a%b%'; This there an easy way to do this? I could use regexp, but I didn't want people to know that they would have to use "a.*b" instead of "a*b", just trying to make it simplier for myself and the people using the system. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Any way to NOT escape a percent sign using 'contains'?
Thanks for the advice. I was kinda thinking I would have to use regex. I hadn't thought of puting the replace() in a custom cleaning method, but I agree that sounds like a good place to put it. On Fri, 2009-01-30 at 13:59 +1100, Malcolm Tredinnick wrote: > On Thu, 2009-01-29 at 18:47 +0000, Adam Stein wrote: > > According to the docs, when using 'contains' in filter() a percent sign > > or underscore is automatically escaped. However, in my case I want the > > resulting SQL to use the percent sign. > > > > I know 'contains' will fill in the outside percent signs, but it escapes > > the percent sign in my string. So that calling: > > > > Entry.objects.filter(headline__contains='a%b') > > > > will result in: > > > > SELECT ... WHERE headline LIKE '%a\%b%'; > > Because the "contains" lookup type is used to look for string > containment, not as a proxy for SQL. We deliberately try to not leak the > underlying SQL abstraction (the storage backend may not even be SQL, > after all). > > > > > but I want it to be this instead: > > > > SELECT ... WHERE headline LIKE '%a%b%'; > > > > This there an easy way to do this? > > > > I could use regexp, but I didn't want people to know that they would > > have to use "a.*b" instead of "a*b", just trying to make it simplier for > > myself and the people using the system. > > Well, the regexp lookup type is for this purpose, so it's the right tool > to use at the code level. The point about the user-interface is well > taken, but it doesn't have to be a transparent pass-through. What I > would suggest is converting your value by doing using > > value = value.replace('%', '.*') > > at some point. If these values are coming in through a form field, a > custom cleaning method for the form field would be a nice level to this > at, for example. > > Regards, > Malcolm > > > > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Changing default app url in development server
Ah yes, not being able to change urls.py would make it more difficult. Somebody is making your job way too hard :-{} On Wed, 2009-02-04 at 15:29 +0100, Ales Zoulek wrote: > > That way, the exact same URL can be used in both places. > Yep. But the urls.py cannot :) > > That was why I suggested the solution with midlleware. Which is > conditionaly loaded > > Example: > > settings.py: > > if DEBUG: >MIDDLEWARE_CLASSES = ['project.mw.InjectUrlPrefix'] + MIDDLEWARE_CLASSES > > > > > > > > On Wed, 2009-02-04 at 15:11 +0100, Ales Zoulek wrote: > >> As I undrestood it is that it's infact *used* on Apache. > >> That's why the django project is on "/peergw" - Apache, but "/" - dev > >> server. > >> > >> > >> And Alex wants to simulate this behaviour on dev server side. > >> > >> Or am I wrong? > >> > >> > >> A. > >> > >> On Wed, Feb 4, 2009 at 3:02 PM, Karen Tracey wrote: > >> > On Wed, Feb 4, 2009 at 4:46 AM, Ales Zoulek > >> > wrote: > >> >> > >> >> That's not as easy as it seams, quick fix/hack would be middleware > >> >> that strips out /pergw from the url. That middleware would be used > >> >> only for dev server, not for apache. > >> >> > >> > > >> > What about simply using the django.root PythonOption when running under > >> > Apache: > >> > > >> > http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#basic-configuration > >> > > >> > Its entire reason for being is, I believe, to handle situations like > >> > this. > >> > > >> > Karen > >> > > >> >> > >> >> A. > >> >> > >> >> > >> >> On Wed, Feb 4, 2009 at 9:39 AM, knight wrote: > >> >> > > >> >> > My production version is running on different computer with apache > >> >> > installed on http:///peergw > >> >> > and development version on my computer is running on http:// >> >> > with port>. > >> >> > I want them both to run on http:///peergw. > >> >> > The port has no difference. > >> >> > > >> >> > Thanks, Alex A. > >> >> > > >> >> > On Feb 4, 9:58 am, Ian Lewis wrote: > >> >> >> What are you trying to do? If your development appserver is > >> >> >> conflicting > >> >> >> with > >> >> >> a locally installed apache then why not just use a different port? > >> >> >> > >> >> >> python manage.py runserver 8001 > >> >> >> > >> >> >> 2009/2/4 knight > >> >> >> > >> >> >> > >> >> >> > >> >> >> > Hi, > >> >> >> > >> >> >> > My question is: > >> >> >> > >> >> >> > Is there a way to change my default app url in development server > >> >> >> > fromhttp://localhost:8000tohttp://localhost:8000/peergw. > >> >> >> > >> >> >> > If it's a problem, maybe someone have a good reference for > >> >> >> > configuring > >> >> >> > apache server on MAC. > >> >> >> > >> >> >> > Regards, > >> >> >> > Arshavski Alexander. > >> >> >> > >> >> >> -- > >> >> >> === > >> >> >> 株式会社ビープラウド イアン・ルイス > >> >> >> 〒150-0012 > >> >> >> 東京都渋谷区広尾1-11-2アイオス広尾ビル604 > >> >> >> email: ianmle...@beproud.jp > >> >> >> TEL:03-5795-2707 > >> >> >> FAX:03-5795-2708http://www.beproud.jp/ > >> >> >> === > >> >> > > > >> >> > > >> >> > >> >> > >> >> > >> >> -- > >> >> -- > >> >> Ales Zoulek > >> >> +420 604 332 515 > >> >> Jabber: a...@jabber.cz > >> >> ICQ: 82647256 > >> >> -- > >> >> > >> >> > >> > > >> > > >> > > > >> > > >> > >> > >> > > -- > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > Disclaimer: Any/All views expressed > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > > > > > > > > > > > > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Changing default app url in development server
I do something similiar where I have an extra item in the url. To get Apache and the Django server to match, I just add the extra part in urls.py that I'm matching. So instead of something like: (r'^admin/(.*)', admin.site.root) in Alex's case, it would be: (r'^peergw/admin/(.*)', admin.site.root) The same would go for any other match, just add the 'peergw' in front. That way, the exact same URL can be used in both places. On Wed, 2009-02-04 at 15:11 +0100, Ales Zoulek wrote: > As I undrestood it is that it's infact *used* on Apache. > That's why the django project is on "/peergw" - Apache, but "/" - dev server. > > > And Alex wants to simulate this behaviour on dev server side. > > Or am I wrong? > > > A. > > On Wed, Feb 4, 2009 at 3:02 PM, Karen Tracey wrote: > > On Wed, Feb 4, 2009 at 4:46 AM, Ales Zoulek wrote: > >> > >> That's not as easy as it seams, quick fix/hack would be middleware > >> that strips out /pergw from the url. That middleware would be used > >> only for dev server, not for apache. > >> > > > > What about simply using the django.root PythonOption when running under > > Apache: > > > > http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#basic-configuration > > > > Its entire reason for being is, I believe, to handle situations like this. > > > > Karen > > > >> > >> A. > >> > >> > >> On Wed, Feb 4, 2009 at 9:39 AM, knight wrote: > >> > > >> > My production version is running on different computer with apache > >> > installed on http:///peergw > >> > and development version on my computer is running on http:// >> > with port>. > >> > I want them both to run on http:///peergw. > >> > The port has no difference. > >> > > >> > Thanks, Alex A. > >> > > >> > On Feb 4, 9:58 am, Ian Lewis wrote: > >> >> What are you trying to do? If your development appserver is conflicting > >> >> with > >> >> a locally installed apache then why not just use a different port? > >> >> > >> >> python manage.py runserver 8001 > >> >> > >> >> 2009/2/4 knight > >> >> > >> >> > >> >> > >> >> > Hi, > >> >> > >> >> > My question is: > >> >> > >> >> > Is there a way to change my default app url in development server > >> >> > fromhttp://localhost:8000tohttp://localhost:8000/peergw. > >> >> > >> >> > If it's a problem, maybe someone have a good reference for > >> >> > configuring > >> >> > apache server on MAC. > >> >> > >> >> > Regards, > >> >> > Arshavski Alexander. > >> >> > >> >> -- > >> >> === > >> >> 株式会社ビープラウド イアン・ルイス > >> >> 〒150-0012 > >> >> 東京都渋谷区広尾1-11-2アイオス広尾ビル604 > >> >> email: ianmle...@beproud.jp > >> >> TEL:03-5795-2707 > >> >> FAX:03-5795-2708http://www.beproud.jp/ > >> >> === > >> > > > >> > > >> > >> > >> > >> -- > >> -- > >> Ales Zoulek > >> +420 604 332 515 > >> Jabber: a...@jabber.cz > >> ICQ: 82647256 > >> -- > >> > >> > > > > > > > > > > > > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Any way to show progress during a short process job?
Maybe somebody can suggest how to get the functionality I'm trying to duplicate. I looked and can't find anything that seemed similiar. I have a form with checkboxes. User selects one or more and submits the form. The processing currently goes like this: 1) Write JavaScript to display moving progress bar 2) Process based on checked boxes (which in my specific example is to copy the specified databases into a sandbox area) 3) Write JavaScript to turn off progress bar The database copying is short, up to about 20 seconds. Short enough to let the user wait, long enough that I want to indicate the computer hasn't frozen :-{} It seems that I can only return HTML to be displayed once from a view. Is there a way to get the functionality described above somehow? -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Any way to show progress during a short process job?
Thanks Kevin and Malcom for responding. Kevin is right in that I don't need AJAX. I came up with a different method that also allows me to change the string above my progress bar to reflect what I'm actually doing at the moment. My method (roughly) involves setting the HTTPResponse content to an iterator and having the iterator split a rendered template. It yields the first part which would load the progress bar and display it. Then it calls a passed in callback function to do the actual processing, then yield the last part of the rendered template which would turn the progress bar off. If anybody is interested, I can post code and go through exactly what I do. Another thing I tried for fun was passing in a reference to a Python function to the template. Had the template call a tag I made myself which then calls the passed in Python function. Turns out, you can do that but the display wasn't updated properly. On Wed, 2009-02-18 at 16:12 -0800, Kevin Audleman wrote: > Ajax would only be necessary if you want a status bar that reflects > accurately the progress. You can probably get by with something > simpler. I would write some Javascript that is triggered on clicking > the submit button that replaces the button with this graphic: > http://yesmagazine.org/store/images/pleasewait.gif > > > Your Javascript looks like this: > > ?> > <!-- > > > function SubmitOrderButton(){ > document.getElementById("submitmain").style.display = "none"; > > if (navigator.appName == "Microsoft Internet Explorer") { > document.getElementById("pleasewait").innerHTML = ""; > document.getElementById("pleasewait").style.display = "block"; > document.getElementById("pleasewait").innerHTML = "<img src='images/ > pleasewait.gif' alt='Please Wait'>"; > } else { > document.getElementById("pleasewait").style.display = "block"; > } > } > > //--> > > And your HTML code looks like this: > > >class="checkout_button" /> > > > >Please wait while your request is being processed... > > > Cheers, > Kevin Audleman > > On Feb 18, 2:52 pm, Malcolm Tredinnick > wrote: > > On Wed, 2009-02-18 at 12:20 +, Adam Stein wrote: > > > Maybe somebody can suggest how to get the functionality I'm trying to > > > duplicate. I looked and can't find anything that seemed similiar. > > > > > I have a form with checkboxes. User selects one or more and submits the > > > form. The processing currently goes like this: > > > > > 1) Write JavaScript to display moving progress bar > > > 2) Process based on checked boxes (which in my specific example is to > > > copy the specified databases into a sandbox area) > > > 3) Write JavaScript to turn off progress bar > > > > > The database copying is short, up to about 20 seconds. Short enough to > > > let the user wait, long enough that I want to indicate the computer > > > hasn't frozen :-{} > > > > > It seems that I can only return HTML to be displayed once from a view. > > > Is there a way to get the functionality described above somehow? > > > > It's called AJAX. You have to keep asking the server for an update and > > then updating the page. > > > > Regards, > > Malcolm > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Any way to show progress during a short process job?
On Thu, 2009-02-19 at 09:54 -0500, Karen Tracey wrote: > You might want to read: > > http://code.djangoproject.com/ticket/6527 > > My sense from that ticket (and other half-remembered discussions of > iterators and HttpResponses) is that, if this is working for you now, > you are just lucky you don't have any middleware consuming your > iterator before it actually gets sent as a response. In the future > when that ticket is fixed I believe the element of luck will go away > and you'll be guaranteed all of your iterator response content will be > sent, but sending the beginning of the response will have to wait > until the full response is generated, so it won't accomplish the > progress display you are attempting to show by using this technique. Darn. I'm looking at the patch and it clearly says: ``HttpResponse.__init__()`` will read and store the iterator's contents. Guess I found a bug to exploit. Too bad they are changing it. Let me take another look at Kevin's suggestion. Maybe I can play around with showing the progress bar (unhiding it) via the JavaScript example. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Can I limit the choices in a ContentType field in admin?
Trying to create a generic FK using ContentType. In admin, the menu lists all the models. Since I only ever need to select 1 of 2 different models, anyway to limit the choice? Setting the choices attribute as Django complains must be a "ContentType" instance ContentType.objects.get() returns an instance of a particular model, not ContentType (as one would expect), so I'm not sure how to create an instance with the particulars I need to point to something specific in the choices list. Here's what I have: from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class GenericFKExample(models.Model): CHOICES = ( (ContentType.objects.get(model="model1"), "Model 1"), (ContentType.objects.get(model="model2"), "Model 2"), ) content_type = models.ForeignKey(ContentType, choices = CHOICES, null = True, ) object_id = models.PositiveIntegerField( null = True, ) content_object = generic.GenericForeignKey( "content_type", "object_id" ) Obviously, if I don't use choices, it works but then I have a very long list of model choices. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Any way to save the output of a template filter to another variable?
Using Django v1.0.2. Didn't see or find anything obvious, so I thought I would ask. In my specific example, I would like to save the output value from the 'length' template filter so that I can send it to the 'expr' tag (expr is a tag that allows you to effectively execute python statements and save the result to another template variable). I could make a specific tag or filter, but I thought it would be more general purpose to be able to save the length value and pass that in to expr to use in an equation (need to multiply the length of a list). Assuming Django native template can't do it (which is what it looks like), anybody know of any tags that can do this? -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Missing Roles (group of groups)
I could certainly use it if available. On Thu, 2009-07-30 at 16:05 +0200, Thomas Guettler wrote: > Hi, > > The models from django.contrib.auth look like unix /etc/passwd and /etc/groups > files. > > But roles are more flexible: A role contains roles. A user is a role. > > Are there any other django coders who miss this? > > I know that this can be implemented with only a few lines. But a reusable > solution would be better. > > Thomas > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Authentication integration with Netegrity SiteMinder?
Using Django v1.1/mod_wgsi v2.5. I'm forced to use CA's Netegrity SiteMinder to authenticate users. I couldn't find anything regardng integration with Django (so that Django can provide authorization). I have integrated Django authentication with an LDAP server, but I need to use SiteMinder instead because of corporate policy. Figure I would ask to see if anybody has already done this before I try to figure this out from scratch. SiteMinder gives me the login name in an environment variable which I can then tie into the Django user system. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 login page AND RemoteUserMiddleware depending on user?
Couldn't find anything regarding this. All authentication schemes seem to assume you are only doing it one way. Using Django v1.1. I need the Django admin to come thru the login page as normal. However, every other account is authenticated by an external authentication source. I can use RemoteUserMiddleware for the external authentication, but then I can't log in as the Django admin (since RemoteUserMiddleware ALWAYS gets the user name from REMOTE_USER). Anybody deal with this before? It's easy enough to subclass RemoteUserMiddleware, but how do I tell when to use REMOTE_USER and when to use what user is already set to? -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 limit the choices in a ContentType field in admin?
Thanks for the info. I also ran across 'limit_choices_to' which also works. On Wed, 2009-04-01 at 08:48 -0700, Lee wrote: > You're close... > > change your method in CHOICES to get_for_model( _model_ ) > > So it should be > CHOICES = ( > (ContentType.objects.get_for_model(My_Model), "Model 1"), > (ContentType.objects.get_for_model(My_Other_Model), "Model > 2"), > ) > > Obviously, make sure you import your model before you try to use it. > > On Mar 23, 3:26 pm, Adam Stein wrote: > > Trying to create a generic FK using ContentType. In admin, the menu > > lists all the models. Since I only ever need to select 1 of 2 different > > models, anyway to limit the choice? > > > > Setting the choices attribute as Django complains > > > > must be a "ContentType" instance > > > > ContentType.objects.get() returns an instance of a particular model, not > > ContentType (as one would expect), so I'm not sure how to create an > > instance with the particulars I need to point to something specific in > > the choices list. Here's what I have: > > > > from django.db import models > > from django.contrib.contenttypes.models import ContentType > > from django.contrib.contenttypes import generic > > > > class GenericFKExample(models.Model): > > CHOICES = ( > > (ContentType.objects.get(model="model1"), "Model 1"), > > (ContentType.objects.get(model="model2"), "Model 2"), > > ) > > > > content_type = models.ForeignKey(ContentType, > > choices = CHOICES, > > null = True, > > ) > > > > object_id = models.PositiveIntegerField( > > null = True, > > ) > > > > content_object = generic.GenericForeignKey( > > "content_type", "object_id" > > ) > > > > Obviously, if I don't use choices, it works but then I have a very long > > list of model choices. > > > > -- > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > Disclaimer: Any/All views expressed > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 limit the choices in a ContentType field in admin?
I wound up doing it that way as well except I used the model name rather than the ID: data_type = models.ForeignKey(ContentType, limit_choices_to = {"model__in": ("model1", "model2")}, ) On Wed, 2009-04-01 at 10:34 -0700, Lee wrote: > Actually I tried to do as I suggested and I couldn't get it to > work... I ended up using the following: > > from MyProject.MyApp.models import MyModel > > CONTENT_TYPE_CHOICES = (ContentType.objects.get_for_model > (MyModel).id,) > > class My_Other_Model(models.Model): > content_type = models.ForeignKey(ContentType, limit_choices_to= > {'id__in': CONTENT_TYPE_CHOICES}) > > > On Apr 1, 11:48 am, Lee wrote: > > You're close... > > > > change your method in CHOICES to get_for_model( _model_ ) > > > > So it should be > > CHOICES = ( > > (ContentType.objects.get_for_model(My_Model), "Model 1"), > > (ContentType.objects.get_for_model(My_Other_Model), "Model > > 2"), > > ) > > > > Obviously, make sure you import your model before you try to use it. > > > > On Mar 23, 3:26 pm, Adam Stein wrote: > > > > > Trying to create a generic FK using ContentType. In admin, the menu > > > lists all the models. Since I only ever need to select 1 of 2 different > > > models, anyway to limit the choice? > > > > > Setting the choices attribute as Django complains > > > > > must be a "ContentType" instance > > > > > ContentType.objects.get() returns an instance of a particular model, not > > > ContentType (as one would expect), so I'm not sure how to create an > > > instance with the particulars I need to point to something specific in > > > the choices list. Here's what I have: > > > > > from django.db import models > > > from django.contrib.contenttypes.models import ContentType > > > from django.contrib.contenttypes import generic > > > > > class GenericFKExample(models.Model): > > > CHOICES = ( > > > (ContentType.objects.get(model="model1"), "Model 1"), > > > (ContentType.objects.get(model="model2"), "Model 2"), > > > ) > > > > > content_type = models.ForeignKey(ContentType, > > > choices = CHOICES, > > > null = True, > > > ) > > > > > object_id = models.PositiveIntegerField( > > > null = True, > > > ) > > > > > content_object = generic.GenericForeignKey( > > > "content_type", "object_id" > > > ) > > > > > Obviously, if I don't use choices, it works but then I have a very long > > > list of model choices. > > > > > -- > > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > > Disclaimer: Any/All views expressed > > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 not get Django admin page
Maybe you need to add "/admin/" (note the 2nd slash). Could be your URL patterns are expecting an ending slash? On Tue, 2009-05-05 at 09:34 -0700, David wrote: > yes, i added "/admin" to the url. > > thanks, > > david > > > On May 5, 9:05 am, Matthias Petermann wrote: > > Did you add /admin to the URL? > > > > Kind regards, > > Matthias > > > > Am Dienstag, den 05.05.2009, 09:03 -0700 schrieb David: > > > > > > > > > ...and I re-started the dev server as the 4th step > > > > > david > > > > > On May 5, 8:57 am, David wrote: > > > > Hello, > > > > > > I am following those steps in django tutorial 2, however I can not > > > > get "django administration: Username and Password" page. I still get > > > > the "Welcome" page. > > > > > > I did these steps twice but I got the same result. > > > > > > 1. Add "django.contrib.admin" to your INSTALLED_APPS setting. > > > > 2. Run python manage.py syncdb. Since you have added a new > > > > application to INSTALLED_APPS, the database tables need to be > > > > updated. > > > > 3. Edit your mysite/urls.py file and uncomment the lines below the > > > > “Uncomment the next two lines...” > > > > > > Can anybody tell me what I should do to fix this? > > > > > > Thanks so much.- Hide quoted text - > > > > - Show quoted text - > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
ValidationError exception message not coming through
Running Django v1.0.2. I have a form with a file field. The file needs to be in PDF format, so I have a clean routine that checks that (modified slightly to NOT wrap lines): def clean_PDF_File(self): """Verify that the content is PDF format""" type = "application/pdf" if self.cleaned_data["PDF_File"].content_type != type: raise forms.ValidationError("File must be in PDF format") return self.cleaned_data["PDF_File"] A simplified view looks like this: if form.is_valid(): else: print "Errors = [", form.errors, "]" I'm expecting form.errors to contain the message I gave to ValidationError(). Instead, this is what prints out: Errors = [ PDF_FileThe submitted file is empty. ] What happened to my error message? I can't pass the correct error message to the form if I don't receive it in the first place. When the field is blank, I get the correct error message that I expect to see: Errors = [ PDF_FileThis field is required. ] Any thoughts on what else I might try or look at? -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: ValidationError exception message not coming through
I did supply a file, just NOT a PDF format file which causes ValidationError to be raised (yea, probably want to make sure that wasn't the problem :-{}) When I don't supply a filename, I do get the correct error message back in form.errors. But you could be correct about the FileField's clean method. If I detect a file isn't PDF format, I raise the exception so no filename is passed back. Could it be that the FileField clean method is called AFTER mine? I know my clean method is being called. On Thu, 2009-05-28 at 13:06 -0700, V wrote: > my guess is that the validation fails before reaching the > clean_PDF_File method, that is it fails at the FileField's clean > method. Perhaps, you haven't supplied a file. :) > > On May 28, 3:02 pm, Adam Stein wrote: > > Running Django v1.0.2. > > > > I have a form with a file field. The file needs to be in PDF format, so > > I have a clean routine that checks that (modified slightly to NOT wrap > > lines): > > > > def clean_PDF_File(self): > > """Verify that the content is PDF format""" > > > > type = "application/pdf" > > if self.cleaned_data["PDF_File"].content_type != type: > > raise forms.ValidationError("File must be in PDF format") > > > > return self.cleaned_data["PDF_File"] > > > > A simplified view looks like this: > > > > if form.is_valid(): > > > > else: > > print "Errors = [", form.errors, "]" > > > > I'm expecting form.errors to contain the message I gave to > > ValidationError(). Instead, this is what prints out: > > > > Errors = [ PDF_File > class="errorlist">The submitted file is empty. ] > > > > What happened to my error message? I can't pass the correct error > > message to the form if I don't receive it in the first place. When the > > field is blank, I get the correct error message that I expect to see: > > > > Errors = [ PDF_File > class="errorlist">This field is required. ] > > > > Any thoughts on what else I might try or look at? > > -- > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > Disclaimer: Any/All views expressed > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 the django orm outside a web system
Django command extensions has 'runjob' and 'runjobs', one of which might do want you want. You can find the extensions at: http://code.google.com/p/django-command-extensions/ On Thu, 2009-06-04 at 10:44 +, Juan Hernandez wrote: > Hey there people: > > I started developing a django application where a user takes a big > text file and loads it into a database. I have been able to do pretty > much everything but I've been having some problems on scheduling tasks > involving the django ORM. > > I know that python manage.py shell loads the python prompt with the > necessary environment settings for me to work with the shell but, what > if I wanted to let's say, schedule a text file to be loaded every > night using the django orm along with all the other python features? > how can I set a script or what settings do I have so set in order to > easily use the ORM automatically for me to be able to work with those > files over the web interface later?? in other words, what settings are > loded everytime I execute python manage.py shell? > > Thanks a lot > jhv > > > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: LDAP support in Django?
Just google django and ldap. That's how I found how to set up Django authentication to use an LDAP server (works great). On Fri, 2009-06-05 at 08:52 -0700, Mike Driscoll wrote: > Hi, > > Can someone tell me if Django has LDAP support builtin or as a plugin > of some sort? Or do I need to write all that myself? I saw references > to LDAP in the svn docs and I've found some snippets of code with the > ldap module and Django 0.96 as well as a blog post or two on rolling > your own LDAP integration. > > Anyway, your advice would be welcome. I'm getting rather fed up with a > certain other Python web framework's poor documentation and unhelpful > community. > > Thanks, > > Mike > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 Django authentication for web pages outside Django?
I'm trying to figure out a way to use Django authentication to control access to web pages (on the same web server) that are NOT under Django. I have found some information regarding setting up Apache for basic authentication using mod_wsgi, but in this case Apache puts up it's own login window. I'm looking for a solution using Django and/or Apache directives that would put up Django's login page. It should look exactly the same as if the URL were under Django control. Has anyone done anything like this? I'm currently using Django v1.0.2 and Apache v2.2 but can upgrade either if necessary. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 Django authentication for web pages outside Django?
Thanks for responding and for the idea. I'm also migrating, but security seems to be a bigger deal than getting the rest migrated at the moment, hence the need to authenticate for the old stuff. On Fri, 2009-06-05 at 16:43 -0700, BenW wrote: > I did something similar while migrating an old app to Django. Since > auth was the first step for me in the migration, I set up the users > and session data in a table accessible by both apps and used Django > for auth while I migrated the rest. This method requires sharing a > secret between three entities though (browser/django/old app) > > On Jun 5, 1:26 pm, Adam Stein wrote: > > I'm trying to figure out a way to use Django authentication to control > > access to web pages (on the same web server) that are NOT under Django. > > > > I have found some information regarding setting up Apache for basic > > authentication using mod_wsgi, but in this case Apache puts up it's own > > login window. > > > > I'm looking for a solution using Django and/or Apache directives that > > would put up Django's login page. It should look exactly the same as if > > the URL were under Django control. > > > > Has anyone done anything like this? I'm currently using Django v1.0.2 > > and Apache v2.2 but can upgrade either if necessary. > > -- > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > Disclaimer: Any/All views expressed > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 Django authentication for web pages outside Django?
Thanks for the link. The description sounds like just what I need. On Fri, 2009-06-05 at 20:46 -0700, Graham Dumpleton wrote: > Have a look at: > > http://www.openfusion.com.au/labs/mod_auth_tkt/ > > Graham > > On Jun 6, 6:26 am, Adam Stein wrote: > > I'm trying to figure out a way to use Django authentication to control > > access to web pages (on the same web server) that are NOT under Django. > > > > I have found some information regarding setting up Apache for basic > > authentication using mod_wsgi, but in this case Apache puts up it's own > > login window. > > > > I'm looking for a solution using Django and/or Apache directives that > > would put up Django's login page. It should look exactly the same as if > > the URL were under Django control. > > > > Has anyone done anything like this? I'm currently using Django v1.0.2 > > and Apache v2.2 but can upgrade either if necessary. > > -- > > Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com > > > > Disclaimer: Any/All views expressed > > here have been proven to be my own. [http://www.csh.rit.edu/~adam/] > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: problem using ajax in django
Don't know if this will help, but when I use AJAX, I don't set the mimetype in HttpResponse(), I just pass simplejson.dumps() to HttpResponse(): return HttpResponse(simplejson.dumps(response)) This approach works with Firefox, IE6, & IE7. On Wed, 2009-06-10 at 02:50 -0700, newbie wrote: > Hi, > > I have written a small javascript ajax code in my django > application. Its working fine in the development environment. But when > i use the same code in the same django application running on apache > and also on a different url(if it matters), it is not working. I have > tried using Firebug debugger. It is showing UnboundLocalError at / > identity/ajax_districts/ > > It says local variable 'state' referenced before assignment > > in urls.py > (r'^identity/ajax_districts/$',ajax_districts), > > I have a funtion ajax_districts defined in my view identity.py > def ajax_districts(request): > from django.utils import simplejson > import logging > logging.error("Came here") > districts = {} > districts[0] = "Nizamabad" > json = simplejson.dumps(districts) > return HttpResponse(json, mimetype="application/json") > > in template: > > > > function getdistricts(state){ > alert("getdistricts"); > $.post("/identity/ajax_districts/", {"state":state}, > function(data){ > alert("getdistrict2s"); > }, "json"); > alert("getdistrict1s"); > } > > $(document).ready(function(){ > // alert($("#id_state").val()); > // getdistricts($("#id_state").val()); > > $("#id_state").change(function(){ > getdistricts($("#id_state").val()); > }); > > // alert($("#id_district").val()); > }); > > > > Here id_state is the id of a select box > > Can someone help me in this regard. > > I hope i made myself clear. Do reply if i havent made myself clear. > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Error loading MySQLdb module: libmysqlclient_r.so.16 - Help please
LD_LIBRARY_PATH variable is the correct one to use when running from your account (not to go into the discussion as to why some people think LD_LIBRARY_PATH is evil), as evidenced when you run python on the command line. In the case of Django running through a web server, the web server is not picking up the LD_LIBRARY_PATH setting you are using in your own personal account. The reason editing ld.so.conf works, is because you are globally setting the library path to search. Since ld.so.conf is a 'global' setting, your Django application (python) picks it up from the system and finds the library. Another way (what I do) is to compile Python with the MySQL lib directory (--with-libs configuration argument) so that Python can find the library whenever it runs (no matter who's running it, me -- or the web server). On Sat, 2009-06-13 at 10:18 -0700, NoCleverName wrote: > > This is the author again. Of course, 10 minutes after I post a question, I > find the solution. (After hours of searching beforehand) > > If anyone else has this problem, the solution for me was: > > edit /etc/ld.so.conf > add the line: /usr/local/mysql/lib > > then run /etc/ldconfig > > Fixed the problem right up. No idea why or how this worked, but everything > is working now. > > > > NoCleverName wrote: > > > > So I'm having an issue getting Django to work with MySQL. After I log > > into my Django site, I get the following error: > > > > ImproperlyConfigured: Error loading MySQLdb module: > > libmysqlclient_r.so.16: cannot open shared object file: No such file or > > directory > > > > The error is being thrown from > > site-packages/django/db/backends/mysql/base.py line 13. > > > > Unlike a lot of similar posts on the message board (I have searched), I > > have MySQLdb installed. The lines in question are just 'import MySQLdb as > > Database' and the associated try/catch throwing the error. When I run > > python from a command line and type 'import MySQLdb' it imports just fine. > > I added to to the root's .bash_profile and the .bashrc of the 'mysql' > > user. The file definitely exists (in /usr/local/mysql/lib) > > > > I used the variable LD_LIBRARY_PATH in the two profiles to make the > > 'import MySQLdb' statement work, is that the correct environment variable? > > > > As a note, I installed mysql from the .tar.gz files and MySQLpython from > > the .tar.gz files as well. I can't use any sort of package manager to > > install this stuff. > > > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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: Moving the .py(c|o) files out of the app?
Another option is to use a build tool. I use waf (http://code.google.com/p/waf/), a Python-based framework for configuring, compiling and installing applications. I have it set up so that it compiles the Python files, copies Python and other types of files to an installed location, then remove the Python source files from that installed location. On Sun, 2009-09-27 at 15:53 -0400, Ned Batchelder wrote: > Python doesn't give you a way to write the .pyc files anywhere except > next to their .py files. But you can compile everything ahead of time, > and then either move the .pyc files somewhere else or just delete the > .py files (assuming you have another copy!) > > The python module compileall is just for this purpose: > > $ python -m compileall . > > will search the tree rooted in the current directory for .py files newer > than their .pyc files, and compile them. > > --Ned. > http://nedbatchelder.com > > Christophe Pettus wrote: > > This is more a deployment question, but: Is there a way of specifying > > a directory other than the app folder hierarchy for the .pyc or .pyo > > files to be written to? In production, I'm not wild about the idea of > > the app folders being writable by the Apache process. Any guidance? > > Thanks? > > > > -- > > -- Christophe Pettus > > x...@thebuild.com > > > > > > > > > > > > > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 to choose web-template
Have you checked out Open Source Web Design (http://www.oswd.org/)? I got all the templates that I use from this site. On Fri, 2009-10-16 at 21:20 +0400, Михаил Лукин wrote: > Not really Django question, so i'm sorry :) > > I'm Python programmer, not a web-designer. I wasted a whole day by > reinventing the wheel. First, I made base template myself. Then I > dumped HTML and CSS from some favorite sites and tried to apply them > to my app. Then I googled for free web-templates and found nothing > good for me. > > The app is neither blog nor company portal. It is front-end for > hardware and software database. So, It must be VERY simple. It should > contain header (for app title), main menu, sidebar (for object context > menu), styles for tables with caption. I'll be happy if there will be > footer and simple search bar (somewhere in header or main menu). > > I appreciate any advice. > > -- > regards, > Mihail > > > > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Trouble setting a form field's value in clean()
Running Django v1.1.1 on Apache v2.2.8 with Firefox v3.5.4. I have a very simplified and unreal example below to demonstrate what's happening. class MyForm(forms.Form): string1 = forms.CharField() string2 = forms.CharField(widget = forms.HiddenInput()) def clean(self): cleaned = self.cleaned_data if not cleaned.has_key("string2") and cleaned.has_key("string1"): cleaned["string2"] = string1 return cleaned As seen, both 'string1' and 'string2' are required. In the clean() method, if string2 isn't defined, I set it to a value. For my simple case, I'm just setting it to the value of another field on the form. What happens is that Django comes back with an error message because 'string2' is required and has no associated value. Is there any way to set a field value that get's POST'd? Even if I make 'string2' not required (so it winds up being an empty string), there still doesn't seem to be a way to change the empty string to have a value. While validation passes, the resulting POST data still shows 'string2' as an empty string. I thought that changing and returning the cleaned data would do it, but apparently not. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: Trouble setting a form field's value in clean()
On Mon, 2009-11-16 at 17:57 +0100, Dennis Kaarsemaker wrote: > On Mon, Nov 16, 2009 at 5:12 PM, Adam Stein wrote: > > Running Django v1.1.1 on Apache v2.2.8 with Firefox v3.5.4. > > > > I have a very simplified and unreal example below to demonstrate what's > > happening. > > > >8 -- > > > >def clean(self): > >cleaned = self.cleaned_data > > > >if not cleaned.has_key("string2") and > > cleaned.has_key("string1"): > >cleaned["string2"] = string1 > > > >return cleaned > >8 -- > > > > What happens is that Django comes back with an error message because > > 'string2' is required and has no associated value. Is there any way to > > set a field value that get's POST'd? > > clean() is run after the built-in validation and per-field validation. > You'll want to copy request.POST, set the value there, and then feed > it to the form. Or make string2 not required and do it in clean the > way you do now. > Thanks for responding. I'll have to look into using POST. The problem with NOT requiring string2 is that I still can't change the value. Instead of checking if it's not there, I check for an empty string: if cleaned["string2"] == "": cleaned["string2"] = string1 which means an empty string goes along with POST, not the value I set. -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
Re: Trouble setting a form field's value in clean()
Ok, thanks for the example. On Mon, 2009-11-16 at 11:27 -0800, pjrhar...@gmail.com wrote: > > if not cleaned.has_key("string2") and > > cleaned.has_key("string1"): > > cleaned["string2"] = string1 > > > > return cleaned > > > I think the problem here is that if string2 is not required it will be > in the cleaned dictionary but an empty string. So instead you might > need: > > if not cleaned.get('string2', ''): > cleaned['string2'] = string1 > > I'd still suggest doing it like this though, not in the POST, as you > would need to do that in every view where you use the form. > > Peter > > -- > > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@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=. > -- Adam Stein @ Xerox Corporation Email: a...@eng.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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=.
{% load %} tag in a base template can't be inherited?
Running Django v0.96. Want to check to see if this behavior is normal. I have a base template that uses {% load %}. I have another template that extends the base template. The {% load %} tag doesn't seem to carry into the extended template. In other words, it looks like I have to use {% load %} in every single extended template, not just declare it once in the base. To give a concrete example: --base.html-- {% load mytags %} {% mytitle "My Title Tag" %} --base.html-- --derived.html-- {% extends "base.html" %} {% mytitle "My Title Tag in the Derived" %} --derived.html-- Using 'base.html' calls 'mytitle' just fine. Using 'derived.html' does not. On a related note, the docs say: If you use {% extends %} in a template, it must be the first template tag in that template. Template inheritance won’t work, otherwise. This isn't true unless {% load %} doesn't count as a template tag. My derived templates work if I put {% extends %} first or {% load %} first. -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: All views expressed here have been proved to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: {% load %} tag in a base template can't be inherited?
On Wed, 2008-02-06 at 11:31 -0800, Daniel Roseman wrote: > >From the same documentation page you quote above (http:// > www.djangoproject.com/documentation/templates/): > > When you load a custom tag or filter library, the tags/filters are > only made available to the current template -- not any parent or child > templates along the template-inheritance path. > For example, if a template foo.html has {% load comments %}, a child > template (e.g., one that has {% extends "foo.html" %}) will not have > access to the comments template tags and filters. The child template > is responsible for its own {% load comments %}. > This is a feature for the sake of maintainability and sanity. Thanks for the info. At least I know I'm not missing something. It does seem to interfere with DRY since I have to repeat {% load %} (in my case, there are 2) in each child template. > RE the extends tag placement, this is a recent change in the trunk > (there's a thread talking about it in django-developers now). You're > looking at the SVN documentation but using 0.96 - you might be better > off following the link at the top of the page to the 0.96 > documentation. I took the quote from the v0.96 doc (http://www.djangoproject.com/documentation/0.96/templates/). -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: All views expressed here have been proved to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: {% load %} tag in a base template can't be inherited?
On Wed, 2008-02-06 at 13:02 -0800, koenb wrote: > BTW, you can add tags to builtins if you need them all the time. > > eg. if you need i18n all over: > > from django.template import add_to_builtins > add_to_builtins('django.templatetags.i18n') Thanks for the info. Where would I put this? -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: All views expressed here have been proved to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting development environment configured
Glad to hear my information was useful. Now all I have to do is finish figuring out how to use WAF to deploy my Django project and I'm all set :-{} On Fri, 2008-02-08 at 11:51 -0800, Brandon Taylor wrote: > FINALLY, it works. > > I guess the entire problem was that I had specified the website > directory itself instead of the PARENT of the website directory in the > PythonPath. Now I just need to tell Apache to not process anything > else with mod_python and I should be good to go. > > Thanks Adam, > b > > On Feb 8, 1:08 pm, Adam Stein <[EMAIL PROTECTED]> wrote: > > Just started with Django myself. Went thru 3 different tutorials. > > Hopefully, what I'm mentioning below hasn't already been covered. > > > > > > > > On Fri, 2008-02-08 at 10:34 -0800, Brandon Taylor wrote: > > > So, chin up, moving on. Here is my website's directory structure: > > > > > /mysite > > > /public > > > /images > > > /css > > > /javascripts > > > > > /templates > > > public.html > > > home_page.html > > > > > views.py > > > settings.py > > > urls.py > > > __init__.py > > >From your directory structure, it looks like views.py, settings.py, > > > > urls.py, and __init__.py are NOT in 'mysite' but at the same level. If > > that's true, that's one reason why mod_python can't find > > "mysite.settings". > > > > I run Apache using virtual servers, so my ... stuff > > is associated with a specific virtual server (in httpd-vhosts.conf). If > > you don't, you can put it into the top-level httpd.conf file. Mine > > looks like this: > > > > > > SetHandler python-program > > PythonHandler django.core.handlers.modpython > > PythonInterpreter wise > > PythonPath "['/home/adam/Src/WISE-2.0'] + sys.path" > > SetEnv DJANGO_SETTINGS_MODULE WebSite.settings > > SetEnv PYTHON_EGG_CACHE /tmp/.python-eggs > > PythonDebug On > > > > > > I have everything athttp://my-server/wise2/and under handled by > > mod_python. The two main things here are PythonPath and > > DJANGO_SETTINGS_MODULE. > > > > Given your structure above, settings.py (along with views.py, urls.py, > > and __init__.py) should be in the 'mysite' directory. Then PythonPath > > would be set to point to the directory 'mysite' is in: > > > > PythonPath "['/my/dir'] + sys.path" > > > > In this case, your 'mysite' directory can be found at "/my/dir/mysite". > > Then DJANGO_SETTINGS_MODULE would point to the settings file via the > > Python import syntax: > > > > SetEnv DJANGO_SETTINGS_MODULE mysite.settings > > > > mod_python would find the settings.py file because it would be in the > > 'mysite' directory. > > > > > > > > > When I start up the dev server using manage.py runserver, my > > > home_page.html template will render, but no images, no css, etc. > > > > > How can I: > > > > > 1. Tell the development server what the root of the website is. > > > 2. Where my images, css and javascript files are. > > > > > I have put: (r'^public/../(?P.*)$', 'django.views.static.serve', > > > {'document_root': '/public/../images'}), > > > > > in my URLconf, but, it's still not happy. > > > > I set up to handle static content if running in DEBUG mode (i.e. theff > > # Set up to server static files if running within the development > > # environment > > if settings.DEBUG == True: > > urlpatterns += patterns('django.views.static', > > (r'^(?P.*)$', "serve", {"document_root": > > "/project/www/htdocs/WISE > > ",}), > > ) > > > > This goes last in urls.py and will pick up anything not matched by a > > real Django pattern match (i.e. everything that's NOT a Django page). > > So if I have a URL like ", the > > dev server will actually serve (given my example) > > "/project/www/htdocs/WISE/img/icons/UnknownPerson.jpg" from the local > > filesystem. > > -- > > Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] > > > > Disclaimer: All views expressed > > here have been proved to be my own. [http://www.csh.rit.edu/~adam/] > > -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: All views expressed here have been proved to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting development environment configured
Just started with Django myself. Went thru 3 different tutorials. Hopefully, what I'm mentioning below hasn't already been covered. On Fri, 2008-02-08 at 10:34 -0800, Brandon Taylor wrote: > So, chin up, moving on. Here is my website's directory structure: > > /mysite > /public > /images > /css > /javascripts > > /templates > public.html > home_page.html > > views.py > settings.py > urls.py > __init__.py >From your directory structure, it looks like views.py, settings.py, urls.py, and __init__.py are NOT in 'mysite' but at the same level. If that's true, that's one reason why mod_python can't find "mysite.settings". I run Apache using virtual servers, so my ... stuff is associated with a specific virtual server (in httpd-vhosts.conf). If you don't, you can put it into the top-level httpd.conf file. Mine looks like this: SetHandler python-program PythonHandler django.core.handlers.modpython PythonInterpreter wise PythonPath "['/home/adam/Src/WISE-2.0'] + sys.path" SetEnv DJANGO_SETTINGS_MODULE WebSite.settings SetEnv PYTHON_EGG_CACHE /tmp/.python-eggs PythonDebug On I have everything at http://my-server/wise2/ and under handled by mod_python. The two main things here are PythonPath and DJANGO_SETTINGS_MODULE. Given your structure above, settings.py (along with views.py, urls.py, and __init__.py) should be in the 'mysite' directory. Then PythonPath would be set to point to the directory 'mysite' is in: PythonPath "['/my/dir'] + sys.path" In this case, your 'mysite' directory can be found at "/my/dir/mysite". Then DJANGO_SETTINGS_MODULE would point to the settings file via the Python import syntax: SetEnv DJANGO_SETTINGS_MODULE mysite.settings mod_python would find the settings.py file because it would be in the 'mysite' directory. > > When I start up the dev server using manage.py runserver, my > home_page.html template will render, but no images, no css, etc. > > How can I: > > 1. Tell the development server what the root of the website is. > 2. Where my images, css and javascript files are. > > I have put: (r'^public/../(?P.*)$', 'django.views.static.serve', > {'document_root': '/public/../images'}), > > in my URLconf, but, it's still not happy. I set up to handle static content if running in DEBUG mode (i.e. theff # Set up to server static files if running within the development # environment if settings.DEBUG == True: urlpatterns += patterns('django.views.static', (r'^(?P.*)$', "serve", {"document_root": "/project/www/htdocs/WISE ",}), ) This goes last in urls.py and will pick up anything not matched by a real Django pattern match (i.e. everything that's NOT a Django page). So if I have a URL like ", the dev server will actually serve (given my example) "/project/www/htdocs/WISE/img/icons/UnknownPerson.jpg" from the local filesystem. -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: All views expressed here have been proved to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Having problems changing the default query set for Admin
To follow up my own post, since I've learned a bit more... The query set works as expected on an Admin form. What I want to change is what's shown on the change list Admin page. I'm currently investigating overriding the change list template and see if I can do it that way. Any other suggestions are welcome. On Mon, 2008-02-11 at 11:17 -0500, Adam Stein wrote: > Using Django v0.96 > > According to what I've been able to find, I can assign my own Manager to > a Model. Setting up my default Manager would then affect the default > query, which includes the one the Admin view would use. For example: > > class OrgManager(models.Manager): > def get_query_set(self): > qs = super(OrgManager, self).get_query_set() > return qs.exclude(OR_Name = "N/A") > > # Organizations > class Org(models.Model): > # Org's name > OR_Name = models.CharField( > maxlength = 50, > help_text = "Name of the organization" > ) > > objects = OrgManager() > > def __str__(self): > return self.OR_Name > > class Admin: > pass > > The idea it to NOT show the "N/A" entry, but to show all the rest. I > create OrgManager.get_query_set() to return everything except "N/A". I > set Org.objects to use this manager, and since it's the only one set, it > should also be the default. Running in the shell works as expected > (Org.objects.all() shows all EXCEPT "N/A"). > > It doesn't look like the Admin view even uses the manager. I even put a > print statement into get_query_set() to see it being called and it never > was. Am I missing something? Can I affect the query the Admin view > uses? -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: All views expressed here have been proved to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Having problems changing the default query set for Admin
Using Django v0.96 According to what I've been able to find, I can assign my own Manager to a Model. Setting up my default Manager would then affect the default query, which includes the one the Admin view would use. For example: class OrgManager(models.Manager): def get_query_set(self): qs = super(OrgManager, self).get_query_set() return qs.exclude(OR_Name = "N/A") # Organizations class Org(models.Model): # Org's name OR_Name = models.CharField( maxlength = 50, help_text = "Name of the organization" ) objects = OrgManager() def __str__(self): return self.OR_Name class Admin: pass The idea it to NOT show the "N/A" entry, but to show all the rest. I create OrgManager.get_query_set() to return everything except "N/A". I set Org.objects to use this manager, and since it's the only one set, it should also be the default. Running in the shell works as expected (Org.objects.all() shows all EXCEPT "N/A"). It doesn't look like the Admin view even uses the manager. I even put a print statement into get_query_set() to see it being called and it never was. Am I missing something? Can I affect the query the Admin view uses? -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: All views expressed here have been proved to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Is there a ModelChoiceField() HTML widget that accepts typing?
Thanks. I'll check it out when I get a chance. On Sat, 2008-03-01 at 06:53 -0800, Zack wrote: > Check this out: http://code.djangoproject.com/wiki/AJAXWidgetComboBox > > If it doesn't suit your needs you can make your own widget and then > tell your form field to render itself using your custom widget. > > Here's an OK example of making a custom widget: > http://code.djangoproject.com/wiki/CustomWidgetsTinyMCE > The main issues I have with this example are 1) you can't use a > javascript function object as an element in the settings, and 2) the > inline HTML. Ick. I think it would be nicer to create a template > containing the HTML for the widget, then pass in a Context with all > the configuration data. Good example of that over here: > http://www.hoboes.com/Mimsy/?ART=609 but it get's a bit complex as he > is deailing specifically with a multiwidget. > > After you've coded up your own, you can tell CharField to use it by > doing something like: > > from django import newforms as forms > class MyForm(forms.Form): > combobox = forms.fields.CharField(widget=MyCustomWidget()) > > On Feb 29, 11:24 am, Adam Stein <[EMAIL PROTECTED]> wrote: > > Want to see if something exists so I don't recreate it. > > > > For years, I've been using a JavaScript utility called "HTML CombBox" by > > CS Wagner. This provided ComboBox functionality for HTML. That is, you > > can have a ... list with the added functionality that > > you can type into the select box (useful if what you want isn't on the > > list). > > > > Now that I'm using Django, I need that functionality again. Does > > anything like this exist already? > > -- > > Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] > > > > Disclaimer: All views expressed > > here have been proved to be my own. [http://www.csh.rit.edu/~adam/] > > -- Adam Stein @ Xerox Corporation Email: [EMAIL PROTECTED] Disclaimer: All views expressed here have been proved to be my own. [http://www.csh.rit.edu/~adam/] --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: displaying images
On Wed, 2011-11-23 at 08:31 -0800, marjenni wrote: > Hi all, >Again, I am sure this is a very common problem for beginners, but > all help appreciated. > > > In a python function I am building a webpage, and trying to add > images to a table like this: > > html += " > " % imageName > > return HttpResponse(html) > > > Now the table is displayed fine, but images are missing. > > The images are present in the directory /home/www/mysite/images/ > > and in settings.py > > MEDIA_URL = '/home/www/mysite/cache/' > > any suggestions? > > many thanks > > Mark Whenever something isn't displaying (image) or available (JavaScript function), I always look at the source of the web page to make sure my paths are what they are suppose to be and that the content I want is at that path. Take a look at the source of your rendered page, make sure the image URL is correct and that there is actually an image there (open the URL in it's own browser window/tab). Hopefully that will lead you to the source of your problem. -- Adam Stein @ HCL America Inc.Email: a...@ppdev.mc.xerox.com Disclaimer: Any/All views expressed here have been proven to be my own. [http://www.csh.rit.edu/~adam/] -- 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: Generating pdf from html using Pisa
In myview(), you are setting "mylist" to results but I don't see results defined in myview() anywhere. On Thu, 2013-02-21 at 00:35 +0530, Satinderpal Singh wrote: > I am trying to produce pdf from html using the following code, but > unable to do so, it gives an error that, global name 'results' is not > defined. Please tell me how to use this view. > > def render_to_pdf(template_src, context_dict): > template = get_template(template_src) > context = Context(context_dict) > html = template.render(context) > result = StringIO.StringIO() > > pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), > result) > if not pdf.err: > return HttpResponse(result.getvalue(), mimetype='application/pdf') > return HttpResponse('We had some errors%s' % escape(html)) > > def myview(request): > #Retrieve data or whatever you need > return render_to_pdf( > 'report/pdf.html', > { > 'pagesize':'A4', > 'mylist': results, > } > ) > > in the report/pdf.html there is: > > > "http://www.w3.org/TR/html4/loose.dtd";> > > > My Title > > @page { > size: {{ pagesize }}; > margin: 1cm; > @frame footer { > -pdf-frame-content: footerContent; > bottom: 0cm; > margin-left: 9cm; > margin-right: 9cm; > height: 1cm; > } > } > > > {% block report %} > > > {% for item in mylist %} > {{item}} > {% endfor %} > > > {%block page_foot%} > Page > > {%endblock%} > > > > > > -- > Satinderpal Singh > http://satindergoraya.blogspot.in/ > http://satindergoraya91.blogspot.in/ > -- Adam (a...@csh.rit.edu) -- 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.
Trouble with STATIC_URL in v1.5.2
Maybe this is something well known. I'm using STATIC_URL in my templates. Worked perfectly in Django 1.4.x. Upgraded to v1.5.2. Now STATIC_URL ONLY works when the DEBUG setting is True. When set to False (For production), STATIC_URL is an empty string in the template. Anybody have any idea why this might be happening or what to look at? Everything that needs to be set for STATIC_URL is set, otherwise it wouldn't have worked in v1.4.x in the first place. -- Adam (a...@csh.rit.edu) -- 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: Trouble with STATIC_URL in v1.5.2
Turns out that I had to use the new {% static %} template tag. It seems that STATIC_URL is only set in the context for template use when in DEBUG mode (didn't look in the code, but it appears that way). {% static %} works for both development and production environments. It was pretty simple for me to switch. All STATIC_ variables were already set correctly. I just needed to add this to the top of my base template file: {% load static %} {% get_static_prefix as STATIC_URL %} and everything else remained the same. On Tue, 2013-09-17 at 02:42 -0700, Kelvin Wong wrote: > Check that your STATIC_URL setting in your template is outputting the > same string as settings.STATIC_URL. Make sure that any included > local_settings.py files are not wiping out those settings. You can > check it using the Django shell: > > > $ python manage.py shell > > > >>> from django.conf import settings > >>> settings.STATIC_URL > '/assets/static/' > > > If not, check that you're using RequestContext to render your views. > You can do this from the Django shell as well. > > > >>> from django.http import HttpRequest > >>> r = HttpRequest() > >>> from django.template import Template > >>> t = Template("{{ STATIC_URL }}") > >>> from django.template import RequestContext > >>> c = RequestContext(r, {}) > >>> t.render(c) > u'/assets/static/' > > > Check that you're including 'django.core.context_processors.static' > in your settings.TEMPLATE_CONTEXT_PROCESSORS tuple. > > > >>> settings.TEMPLATE_CONTEXT_PROCESSORS > ('django.contrib.auth.context_processors.auth', > 'django.core.context_processors.debug', > 'django.core.context_processors.i18n', > 'django.core.context_processors.media', > 'django.core.context_processors.static', > 'django.core.context_processors.tz', > 'django.contrib.messages.context_processors.messages') > > K > > > > On Monday, September 16, 2013 12:43:04 PM UTC-7, Adam wrote: > Maybe this is something well known. > > I'm using STATIC_URL in my templates. Worked perfectly in > Django 1.4.x. > Upgraded to v1.5.2. Now STATIC_URL ONLY works when the DEBUG > setting is > True. When set to False (For production), STATIC_URL is an > empty string > in the template. > > Anybody have any idea why this might be happening or what to > look at? > Everything that needs to be set for STATIC_URL is set, > otherwise it > wouldn't have worked in v1.4.x in the first place. > > -- > Adam (ad...@csh.rit.edu) > > > -- > 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. -- Adam (a...@csh.rit.edu) -- 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: Trouble with STATIC_URL in v1.5.2
I'm not using RequestContext(). The behavior must have changed between v1.4 and v1.5 regarding this. On Tue, 2013-09-17 at 08:27 -0700, Kelvin Wong wrote: > If your software works then I guess it works, but I just ran this in > the shell on Django 1.5.4. > > > $ python manage.py shell > Python 2.7.3 (default, May 4 2012, 11:07:18) > [GCC 4.0.1 (Apple Inc. build 5493)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > (InteractiveConsole) > >>> from django.conf import settings > >>> settings.STATIC_URL > '/static/' > >>> settings.DEBUG > False > >>> from django.http import HttpRequest > >>> r = HttpRequest() > >>> from django.template import Template > >>> t = Template("{{ STATIC_URL }}") > >>> from django.template import RequestContext > >>> c = RequestContext(r, {}) > >>> t.render(c) > u'/static/' > >>> import django > >>> django.get_version() > '1.5.4' > > > If you look at django.core.context_processors you can see that the > STATIC_URL is placed in the RequestContext unconditionally on line 65: > > > https://github.com/django/django/blob/stable/1.5.x/django/core/context_processors.py > > > > K > > > > > > On Tuesday, September 17, 2013 6:09:54 AM UTC-7, Adam wrote: > Turns out that I had to use the new {% static %} template > tag. It seems > that STATIC_URL is only set in the context for template use > when in > DEBUG mode (didn't look in the code, but it appears that > way). > > {% static %} works for both development and production > environments. It > was pretty simple for me to switch. All STATIC_ variables > were already > set correctly. I just needed to add this to the top of my > base template > file: > > {% load static %} > {% get_static_prefix as STATIC_URL %} > > and everything else remained the same. > > On Tue, 2013-09-17 at 02:42 -0700, Kelvin Wong wrote: > > Check that your STATIC_URL setting in your template is > outputting the > > same string as settings.STATIC_URL. Make sure that any > included > > local_settings.py files are not wiping out those settings. > You can > > check it using the Django shell: > > > > > > $ python manage.py shell > > > > > > >>> from django.conf import settings > > >>> settings.STATIC_URL > > '/assets/static/' > > > > > > If not, check that you're using RequestContext to render > your views. > > You can do this from the Django shell as well. > > > > > > >>> from django.http import HttpRequest > > >>> r = HttpRequest() > > >>> from django.template import Template > > >>> t = Template("{{ STATIC_URL }}") > > >>> from django.template import RequestContext > > >>> c = RequestContext(r, {}) > > >>> t.render(c) > > u'/assets/static/' > > > > > > Check that you're including > 'django.core.context_processors.static' > > in your settings.TEMPLATE_CONTEXT_PROCESSORS tuple. > > > > > > >>> settings.TEMPLATE_CONTEXT_PROCESSORS > > ('django.contrib.auth.context_processors.auth', > > 'django.core.context_processors.debug', > > 'django.core.context_processors.i18n', > > 'django.core.context_processors.media', > > 'django.core.context_processors.static', > > 'django.core.context_processors.tz', > > 'django.contrib.messages.context_processors.messages') > > > > K > > > > > > > > On Monday, September 16, 2013 12:43:04 PM UTC-7, Adam > wrote: > > Maybe this is something well known. > > > > I'm using STATIC_URL in my templates. Worked > perfectly in > > Django 1.4.x. > > Upgraded to v1.5.2. Now STATIC_URL ONLY works when > the DEBUG > > setting is > > True. When set to False (For production), > STATIC_URL is an > > empty string > > in the template. > > > > Anybody have any idea why this might be happening or > what to > > look at? > > Everything that needs to be set for STATIC_URL is > set, > > otherwise it > > wouldn't have worked in v1.4.x in the first place. > > > > -- > > Adam (ad...@csh.rit.edu) > > > > > > -- > > You received this message because you are subscribed to the >
Re: Did Ubuntu 14.04 or Linux Mint 17 break your Django project files?
IntegrityError is at the database level (not the OS). Shouldn't have anything to do with the OS specifically. Has the database you are using changed? On Wed, 2014-07-16 at 13:53 -0700, Pepsodent Cola wrote: > Hi, > I have been learning and developing my first Django project in Linux > Mint 14 for about 2 years. This month I moved my Django project files > to Linux Mint 17. > When I run my unit tests then I get this error, which I don't remember > having when I was testing code in Linux Mint 14. > > IntegrityError: NOT NULL constraint failed: > userprofile_userprofile.likes_cheese > > > NOT NULL constraint failed > I try to change the old code from this. > > class UserProfile(models.Model): > user = models.OneToOneField(User) > likes_cheese = models.BooleanField() > favourite_hamster_name = models.CharField(max_length=50) > > To this. > > class UserProfile(models.Model): > user = models.OneToOneField(User) > likes_cheese = models.NullBooleanField() > favourite_hamster_name = models.CharField(max_length=50) > > But then all kinds of different stuff in the project breaks. Which > makes me suspect that nothing was wrong with my code to begin with, > that perhaps the change of operating system has caused this error. > > Did Ubuntu 14.04 or Linux Mint 17 break your Django project files > also? > > > > admin.TabularInline > Also I think Linux Mint 17 broke admin.py's TabularInline function > because now the fields looks stacked instead. I'm not sure if this > has anything to do with my operating system switch. Or if it's > because of my recent experimentations with overriding certain parts of > the admin template. > > class UserProfileInline(admin.TabularInline): > model = UserProfile > extra = 1 > > Did Ubuntu 14.04 or Linux Mint 17 break your Django admin? > > > > > > -- > 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/f0b3c781-e088-4ba1-a251-8e78795fd0f1%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- Adam (a...@csh.rit.edu) -- 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/1405544732.3645.128.camel%40localhost.localdomain. For more options, visit https://groups.google.com/d/optout.
Re: What is *the* django 1.7 IDE which is opensource & multiplattform
Not sure what you are looking for in terms of Django template support. The only difference between pycharm community (free) and commercial in terms of Django support that I've noticed is that Django's development web server won't restart automatically when code changes in the community edition. Haven't used community edition since last year, but I seem to recall, I was still able to have a task to start Django's dev web server (in debug mode so I can trace through my code as you'd expect), so as long as I restarted that after making changes, things were fine. On Wed, 2014-09-24 at 11:36 +0200, anton wrote: > Hi, > > actually I use Aptana Studio 3.4.1 (http://www.aptana.com/) > to develop Django apps (on Windows and Linux). > > What I (personally) need from an ide: > 1. ability to debug (python code) > 2. support for django templates > 3. support for django (start a new project, adding a django app) > 4. support for refactoring (like rename and so on) > 5. support for mercurial > 6. multi plattform (at least windows/linux) > > Starting with *django 1.7*, aptana marks some line > as errors which are not errors (undefined variables from import ..) > > Now I have the following problem: > > - I tried the actual aptana 3.6.0, but it is buggy and does not work >(no idea if and when it will be fixed, the development >speed is actually slow) > > - if I use eclipse + actual pydev 3.7.1 I have >no support for *django templates* > > - all other ides like PyCharm are commercial (the free pycharm does >not support django and django templates, only python) > > Now the question: does somebody know a solution? > > Thanks > > Anton > > -- Adam (a...@csh.rit.edu) -- 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/1411558851.20736.10.camel%40localhost.localdomain. For more options, visit https://groups.google.com/d/optout.
Re: What is *the* django 1.7 IDE which is opensource & multiplattform
On Wed, 2014-09-24 at 12:03 -0700, John Schmitt wrote: > On Wed, Sep 24, 2014 at 07:40:51AM -0400, Adam Stein wrote: > > Not sure what you are looking for in terms of Django template support. > > The only difference between pycharm community (free) and commercial in > > terms of Django support that I've noticed is that Django's development > > web server won't restart automatically when code changes in the > > community edition. Haven't used community edition since last year, but > > I seem to recall, I was still able to have a task to start Django's dev > > web server (in debug mode so I can trace through my code as you'd > > expect), so as long as I restarted that after making changes, things > > were fine. > > I've been hearing about pycharm lately, sounds great. I'm a command line guy > so I normally ssh to my server where I fire up my editor and hack away. > > What do you do with a GUI IDE like pycharm? That is, how does your > edit/run/debug cycle work with a pycharm et al? Can you still edit the > 'live' files for your django project? > > My imagination says that I would sshfs mount the server's file system and > then pretend that the files I'm editing are local. Do I still need to ssh to > the server and manually restart httpd or launch manage.py as needed? > > John > Is your server your production machine? By that, I mean, do you install your files somewhere else once you are done making changes to another server where it's "officially" used? I ask because you really don't want to be editing live files where "live" means what your customers (or yourself) are really using. I develop locally, then deploy to a remove server only when changes are done and tested. Therefore, my edit/run/debug cycle with PyCharm consists of running Django's web server (./manage.py runserver) on my local machine through PyCharm's debugger so that I can step through the code. I also have PyCharm set up to run various unit tests (also useful if I need to step through unit test code). I don't restart httpd, because that is running on the remove server and only needs restarting when my code is deployed. In the case of restarting Django's web server, PyCharm's professional version ($$$) has the ability to restart it for you if you have it running within PyCharm. For the community version, you have to restart it yourself which is as simple as clicking a "restart" button. If your files live somewhere else, you can mount the file system as you've mentioned. Performance might be better if the files were local, but that's true anytime you go across a mounted file system. Hopefully that answers your questions. -- Adam (a...@csh.rit.edu) -- 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/1411587803.20736.49.camel%40localhost.localdomain. For more options, visit https://groups.google.com/d/optout.
Re: What is *the* django 1.7 IDE which is opensource & multiplattform
On Wed, 2014-09-24 at 14:30 -0700, John Schmitt wrote: > I appreciate what you said about deploying and not editing "live" files > directly. Hope the information is of use to you. > However, I have several projects in various stages of development and when I > first start a project, I don't have anything to deploy, I edit everything > "live". When it's in production and users are counting on it being up, then > I would rather not touch the running machine. I do the exact opposite. When I first start out, all I have is my development environment. Once I have "enough" of a project for others to use, then I start deploying. > > When I'm creating a dummy project to test my apache configuration and/or my > management commands, or trying to assemble a complicated query, I do it > "live" on the VM on which I created the playground project. > Currently, I don't need to run apache locally (I used to), but if I did, I would still test it in a development environment. Once everything is good, replicate (deploy) onto the target server. I like to have my development and production match if possible. If not, then a staging/testing area should be the same so I can deploy from development to staging, test like heck, then deploy to production. > Another use-case I have is that my workstation is sometimes far removed from > my development machine. My workstation is either a Linux machine or > sometimes a laptop via VPN over wireless. Tmux and vim/emacs are glorious > workhorses for this scenario and I have a hard time envisioning that same > level of convenience from an IDE. I guess I was hoping that someone had > found something magical that was at least this convenient. > My development machine is in my home in New York, the staging and production servers are in California, I think (not absolutely sure). Doesn't matter the distance. Since development is all local, don't have to worry about anything else until I'm ready to deploy. > In case it isn't obvious, I'm a django nub and probably do not know about > many best practices. While there are certainly lots of Django best practices, I think the use of a development environment and deployment would work equally well for any type of project, not just Django. In fact, anything I've ever worked on C, C++, Python/Django, Perl/CGI, etc., would all start in a local development environment first. If you don't find good answers to your question, maybe you should wonder why. Perhaps most people do things a different way and so your question really doesn't have a good answer. Just a thought. -- Adam (a...@csh.rit.edu) -- 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/1411603125.20736.66.camel%40localhost.localdomain. For more options, visit https://groups.google.com/d/optout.
Looking for a full time Django/Python job (Rochester, NY area OR remote)
As I can't relocate, I'm looking for something either in the Rochester, NY area OR remote. I've been using Django for professional and personal use for about 6 years. Check out my LinkedIn page (www.linkedin.com/in/adamestein/ ) for more details about my skills and work history. A resume is available upon request. I'm currently using Django/Python for my own personal projects. You can see examples at http://stein.alwaysdata.net/. The 'Home Web Apps' is meant to keep track of my monthly bill payments. The 'Shop Owner Web Apps' is meant to keep track of inventory and sales. Just log in with the user name "guest" and password "guest" for either project. These are meant just for me so it's missing functionality that you would see in a commercial project, but it does provide an example of Django and JavaScript (specifically jQuery). Also, they are works in progress. Feel free to try out anything you want. The "guest" account is specifically there so I can show these projects to others. Other Python and/or Django examples can be found at https://github.com/adamestein/. My tic-tac-toe program is a command line program with an option (--humanstart) to allow the human to go first. All other projects were created by someone else, but I added functionality that I needed for home Django projects. You can contact me at 'a...@csh.rit.edu' or through my LinkedIn profile. -- Adam Stein (a...@csh.rit.edu) -- 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/1389020809.2567.42.camel%40zookeeper.steinhome.net. For more options, visit https://groups.google.com/groups/opt_out.
Re: BookMarker Project - Opening local files on localhost through Django generated pages
On Tue, 2014-05-20 at 11:29 -0700, Aseem Bansal wrote: > I am working on a BookMarker project for managing my bookmarks. I was > creating the search page for lisitng bookmarks as per categories. I > hit a snag while testing it. I am unable to open locally stored > webpages. I understand that it is for security purposes but is it > possible (cross-browser way) to grant permissions for a app to open > locally stored files? The app can ask for permissions for this. Are you running with DEBUG=True or did you set ALLOWED_HOSTS? -- Adam (a...@csh.rit.edu) -- 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/1400611202.13850.26.camel%40zookeeper.steinhome.net. For more options, visit https://groups.google.com/d/optout.
Re: Question about moving code to product from local or development server.
I use Fabric (http://www.fabfile.org/), which bills itself as a Python library and command line tool for streamlining the use of SSH for application deployment or systems administration tasks. No need to invent your own. On Sat, 2014-06-07 at 16:50 -0400, Chen Xu wrote: > I am building a django website, and wondering what is an easy way to > move all of my code to production, is there a tool for doing that, or > maybe write my own script? > > > > > > Thanks > > > > -- > ⚡ Chen Xu ⚡ > > -- > 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/CACac-qY8nbj6uiPyvkorvARAqZ%2Bej7rAty_CtdkHnz5bXBKBKQ%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- Adam (a...@csh.rit.edu) -- 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/1402185868.15179.61.camel%40zookeeper.steinhome.net. For more options, visit https://groups.google.com/d/optout.
Re: Storing images in a database using Django.
You can take a look at django-db-file-storage https://readthedocs.org/projects/django-db-file-storage/ In my case, I was making something for myself and the hosting server doesn't allow me access to any kind of file system, so I found this. On Fri, 2016-05-06 at 15:42 -0500, Alex Heyden wrote: > There's an ImageField for use in models, but to really understand it, > start with FileField > > https://docs.djangoproject.com/en/1.9/topics/files/ > https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.mo > dels.FileField > > The general idea is that you have a directory configured by Django's > settings that you can use to hold uploaded files. You can also use > Django to serve these files if you want. (I tend to use nginx > directly for this for performance reasons, but you do what works for > you.) > > I wouldn't go so far as to say that there's no use case for storing > images in databases, but in general, André's advice is solid: store > the path instead. Your OS is good at managing files. Let it do its > job. > > On Fri, May 6, 2016 at 2:53 PM, André Machado > com> wrote: > > NEVER store images in DB, store its path so you can use it in a img > > tag later. =) > > > > > > > > Hi guys, I'm a TOTAL noob when it comes to django and web > > > development for that matter. I have an idea for a web app and I > > > do have a basic understanding of programming. I've gone through a > > > few Django tutorials and I'm confident I can do it, I just need > > > help along the way :) > > > > > > So, my "brilliant" idea is to make an app for cooking for > > > dummies. Basically, I'd have a repository of recipes. Each recipe > > > consists of: recipe_ID, name, and 10 instruction-photo pairs > > > ("now do this" + photo of that). > > > > > > The photos are relatively lightweight (less than 50k each) so I > > > think storing them in a database is the way to go. The only snag > > > - I have absolutely no idea how to do it. I've googled a lot but > > > I'm either too thick or my needs are too specific. > > > > > > I don't actually need to be able to store the images in the > > > database through the web app. I was thinking of creating folders > > > that contain the pertinent photos and "somehow" storing them in > > > the database for further use. The name of the folder would be the > > > same as the recipe_ID, and the photos would be named > > > recipe_ID_01.jpg, recipe_ID_02.jpg, ... > > > > > > Thanks in advance for any help you can give me :) > > > > > > -- Adam (a...@csh.rit.edu) -- 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/1462577175.4828.32.camel%40csh.rit.edu. For more options, visit https://groups.google.com/d/optout.
Re: Test fails when run in whole test suite - but not stand-alone?
When I've had that happen before, it's because some previous test changed something (like a setting value or the site domain) that influenced the test that failed. To narrow it down, I would run all the tests up to and including the failed one. That should fail, then I start taking out half the tests before. If the test still fails, I keep cutting in half until I can determine which previous test is causing issues. If, after cutting out tests, the problem test passes, then I need to put back in what I took out since it was one of those. Once I figure out which previous test it was, I can start removing the individual tests to finally get to the code causing the problem. Usually, it's a case that a test changed something and I just have to add in the teardown function to restore the state of whatever was changed. On Thu, 2016-06-02 at 21:33 +0200, Derek wrote: > I have a test that is failing when the file it is in is run as part > of all the other test files by the test runner. > > If I just run only the file that contains this test - then it > passes. > > (pass/fail refers to the very last assert in the code below.) > > I'd appreciate any ideas or insights from anyone who can spot an > obvious mistake - or suggest some options to explore. > > Thanks > Derek > > > # THIS IS AN EXTRACT OF RELEVANT CODE (not all of it...) > from django.contrib.messages.storage.fallback import FallbackStorage > from django.core.urlresolvers import reverse > from django.test import TestCase, Client > # ... various app-related imports ... > > > class MockRequest(object): > """No code needed.""" > pass > > > REQUEST = MockRequest() > # see: https://stackoverflow.com/queI stions/11938164/why-dont-my- > django-\ > # unittests-know-that-messagemiddleware-is-installed > setattr(REQUEST, 'session', 'session') > MESSAGES = FallbackStorage(REQUEST) > setattr(REQUEST, '_messages', MESSAGES) > setup_test_environment() > > > class PersonAdminTest(TestCase): > > def setUp(self): > self.user, password = utils.user_factory(model=None) > self.client = Client() > login_status = self.client.login(username=self.user.email, > password=password) > self.assertEqual(login_status, True) > > def test_action_persons_make_unreal(self): > try: > change_url = > reverse('admin:persons_realpersons_changelist') > except NoReverseMatch: > change_url = '/admin/persons/realpersons/' > sys.stderr.write('\n WARNING: Unable to reverse URL! > ... ') > response = self.client.get(change_url) > self.assertEqual(response.status_code, 200) > > -- > 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/CAF1Wu3MoGgm_dSToObDX9gH7GQJ%3DTZzGLV7RPOiZk4kvV- > _Nbg%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- Adam (a...@csh.rit.edu) -- 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/1464896791.20313.13.camel%40csh.rit.edu. For more options, visit https://groups.google.com/d/optout.
Re: Mocking date and time in LiveServerTestCase?
When I need to set the date to a known day for tests, I use forbiddenfruit (https://github.com/clarete/forbiddenfruit). On Wed, 2017-01-25 at 20:46 +0100, Carsten Fuchs wrote: > Dear Django fellows, > > I'm using LiveServerTestCase with Selenium. The application code run > by > LiveServerTestCase's live server works well and a view's call to > date.today() > returns the current date. > > For the tests, however, it would be helpful if we could fix the time > and date at > which the test is supposedly run, making date.today() and similar > functions > return a predetermined value. > > Can this be achieved? > > Best regards, > Carsten > -- Adam (a...@csh.rit.edu) -- 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/1485374467.29427.53.camel%40csh.rit.edu. For more options, visit https://groups.google.com/d/optout.
Re: Initial data, tests and migrations
On Wed, 2017-02-22 at 14:22 +, 'Tom Evans' via Django users wrote: > On Wed, Feb 22, 2017 at 12:47 AM, Melvyn Sopacua > om> wrote: > > > > On Tuesday 21 February 2017 19:00:42 'Tom Evans' via Django users > > wrote: > > > > > > > > > > > > Previously, these instances were loaded from a JSON fixtures > > > file, > > > > > > And you can still do that. > > > > > > > > > > > > which used to be the recommended way. For our own tests, we > > > simply > > > > > > load these fixtures in the setUp portion of the test; obviously > > > we > > > > > > can't go around modifying tests in third party libraries. > > > > > > I tried taking them out of the fixtures, and adding them instead > > > in a > > > > > > data migration, but this also had the same effect - the instances > > > were > > > > > > there for the first test ran, and then missing for all the > > > subsequent > > > > > > ones. > > > > > > setUp is run between test methods of a test case. setupTestData is > > a class > > method on the testcase run once per test case. > > > > > > > > > > > > > > > > > > > > What is the "correct" way of ensuring that these instances exist > > > in > > > > > > the test database before any test is run? > > > > > > All explained in the docs. > > > > Either redeclare the same fixtures for different test cases or > > reorganize > > your testcases to share the same fixture(s). > > > I think you have misunderstood: > > 1) The test cases belong to a library and cannot be modified > 2) The initial data is populated from a data migration and not from a > fixture, as that is not recommended [1] > > Data is placed in to the test database using migrations, but after > the > first test has been run the data is flushed out again, causing the > second test to fail. > I would like the all the tests to pass: > * I don't want to put the same data into fixtures as well as > migrations (DRY) > * I don't want to modify the 3rd party library. > > How? > > Cheers > > Tom > > [1] https://docs.djangoproject.com/en/1.10/howto/initial-data/#provid > ing-initial-data-with-migrations > The URL you refer to mentions about loading data for apps. Doesn't mention anything in regards to tests. Why are fixtures bad for tests? In fact, right above the "Providing initial data with migrations" section is a "See also" box that says "Fixtures are also used by the testing framework to help set up a consistent test environment". It would seem to me that the docs are telling you to use fixtures for tests and use migrations for real data. -- Adam (a...@csh.rit.edu) -- 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/1487774504.29637.5.camel%40csh.rit.edu. For more options, visit https://groups.google.com/d/optout.
Re: Initial data, tests and migrations
On Wed, 2017-02-22 at 15:06 +, 'Tom Evans' via Django users wrote: > On Wed, Feb 22, 2017 at 2:41 PM, Adam Stein wrote: > > > > On Wed, 2017-02-22 at 14:22 +, 'Tom Evans' via Django users > > wrote: > > > > The URL you refer to mentions about loading data for apps. Doesn't > > mention > > anything in regards to tests. Why are fixtures bad for tests? In > > fact, right > > above the "Providing initial data with migrations" section is a > > "See also" > > box that says "Fixtures are also used by the testing framework to > > help set > > up a consistent test environment". It would seem to me that the > > docs are > > telling you to use fixtures for tests and use migrations for real > > data. > OK. How do I load that data from a fixture in a TestCase I cannot > modify? Unfortunately, nothing easy comes to mind. My only thought was the possibility of putting your own wrapper around their tests. The idea being is that you call your wrapper which in turns loads the fixtures and calls their tests rather than having Django call their tests directly. This wrapper could be a unit test or be a derivative of the Django test runner. Don't know how feasible either is but I'm guessing neither would be trivial. Maybe I'm wrong, I didn't pursue the thought any more than having a wrapper of some kind. I was originally just going on your statements that fixtures weren't used in the tests because they weren't recommended (which is not really the case). Hope you figure something out. > Cheers > > Tom > > -- Adam (a...@csh.rit.edu) -- 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/1487776952.29637.10.camel%40csh.rit.edu. For more options, visit https://groups.google.com/d/optout.
Re: Django tests and token timeout
Whenever I need to set the date or datetime to something specific for unit tests, I use Forbidden Fruit (https://github.com/clarete/forbidden fruit). id="-x-evo-selection-start-marker"> On Mon, 2018-07-30 at 16:12 +0200, Birger Schacht wrote: > hi, > > i'm using my own PasswordResetTokenGenerator which has a timeout that > is > not given in days but hours, to make the password token timeout more > fine grained. Is there a way to test such a timeout in Django tests, > i.e. something that lets the unit test use a fake time in the future? > > cheers, > Birger > -- Adam (a...@csh.rit.edu) -- 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/1532961455.10313.6.camel%40csh.rit.edu. For more options, visit https://groups.google.com/d/optout.
Re: circular imports error
Since you said 3 separate apps, I assume each of these classes are in a separate file. However, you have the line: from .models import Supplier which would make it seem that Supplier is defined in the same file as Shipment. Shipment should be in ".models" and if Supplier is also defined in the same file, no need to import it. If it's defined in a different file, then the import should reference another place, not ".models". On Fri, 2021-06-11 at 12:22 -0700, frank dilorenzo wrote: > Hello, I have 3 separate app as follow: > from django.db import models > > # Create your models here. > > # Supplier can have many shipments > class Supplier(models.Model): > name = models.CharField(max_length=120, null=True) > phone = models.CharField(max_length=15, null=True) > email = models.CharField(max_length=120, null=True) > created = models.DateTimeField(auto_now_add=True) > updated = models.DateTimeField(auto_now=True) > > def __str__(self): > return self.name > - > from django.db import models > from django.utils import timezone > > # Create your models here. > > # A specie can belong to many shipments > class Specie(models.Model): > name = models.CharField(max_length=120, null=True) > image = models.ImageField(upload_to="species", > default="no_picture.png") > created = models.DateTimeField(default=timezone.now) > > def __str__(self): > return self.name > > from django.db import models > from .models import Supplier > > # from .models import Supplier, Specie > > # Create your models here. > > # A shipment can have many species > class Shipment(models.Model): > > supplier = models.ManyToManyField(Suppliers) > specie = models.ManyToManyField(Species) > > name = models.CharField( > max_length=120, null=True, help_text="enter name from Supplier > above..." > ) > slabel = models.CharField(max_length=10) > received = models.PositiveIntegerField(default=0) > bad = models.PositiveIntegerField(default=0) > non = models.PositiveIntegerField(default=0) > doa = models.PositiveIntegerField(default=0) > para = models.PositiveIntegerField(default=0) > released = models.PositiveIntegerField(default=0) > entered = models.BooleanField(default=False) > created = models.DateTimeField(default=timezone.now) > > def __str__(self): > return f"{self.slabel}" > > === > > when trying to migrate I get this error message: > > ImportError: cannot import name 'Supplier' from partially initialized > module 'shipments.models' (most likely due to a circular import) > (/Users/frankd/django_projects/stlzoo/src/shipments/models.py) > > I am stuck here and cannot seem to resolve this error. I would truly > appreciate any help on this. Thanks. > > Frank > -- > 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/c0aff4c4-651a-43ad-9ac9-42c6452a33f4n%40googlegroups.com > . -- Adam (a...@csh.rit.edu) -- 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/a5c49b5dedd58f28ba9d7039ed8977b626b53a1e.camel%40csh.rit.edu.
Re: circular imports error
Glad to be of help. Sometimes it just takes a fresh pair of eyes. On Fri, 2021-06-11 at 17:33 -0500, frank dilorenzo wrote: > I hate to sound corny but you sir are my hero!. Thanks, it all > works now > > frank- > > > On Fri, Jun 11, 2021 at 2:43 PM Adam Stein wrote: > > Since you said 3 separate apps, I assume each of these classes are > > in a separate file. However, you have the line: > > > > from .models import Supplier > > > > which would make it seem that Supplier is defined in the same file > > as Shipment. Shipment should be in ".models" and if Supplier is > > also defined in the same file, no need to import it. If it's > > defined in a different file, then the import should reference > > another place, not ".models". > > > > On Fri, 2021-06-11 at 12:22 -0700, frank dilorenzo wrote: > > > Hello, I have 3 separate app as follow: > > > from django.db import models > > > > > > # Create your models here. > > > > > > # Supplier can have many shipments > > > class Supplier(models.Model): > > > name = models.CharField(max_length=120, null=True) > > > phone = models.CharField(max_length=15, null=True) > > > email = models.CharField(max_length=120, null=True) > > > created = models.DateTimeField(auto_now_add=True) > > > updated = models.DateTimeField(auto_now=True) > > > > > > def __str__(self): > > > return self.name > > > - > > > from django.db import models > > > from django.utils import timezone > > > > > > # Create your models here. > > > > > > # A specie can belong to many shipments > > > class Specie(models.Model): > > > name = models.CharField(max_length=120, null=True) > > > image = models.ImageField(upload_to="species", > > > default="no_picture.png") > > > created = models.DateTimeField(default=timezone.now) > > > > > > def __str__(self): > > > return self.name > > > > > > from django.db import models > > > from .models import Supplier > > > > > > # from .models import Supplier, Specie > > > > > > # Create your models here. > > > > > > # A shipment can have many species > > > class Shipment(models.Model): > > > > > > supplier = models.ManyToManyField(Suppliers) > > > specie = models.ManyToManyField(Species) > > > > > > name = models.CharField( > > > max_length=120, null=True, help_text="enter name from Supplier > > > above..." > > > ) > > > slabel = models.CharField(max_length=10) > > > received = models.PositiveIntegerField(default=0) > > > bad = models.PositiveIntegerField(default=0) > > > non = models.PositiveIntegerField(default=0) > > > doa = models.PositiveIntegerField(default=0) > > > para = models.PositiveIntegerField(default=0) > > > released = models.PositiveIntegerField(default=0) > > > entered = models.BooleanField(default=False) > > > created = models.DateTimeField(default=timezone.now) > > > > > > def __str__(self): > > > return f"{self.slabel}" > > > > > > === > > > > > > when trying to migrate I get this error message: > > > > > > ImportError: cannot import name 'Supplier' from partially > > > initialized module 'shipments.models' (most likely due to a > > > circular import) > > > (/Users/frankd/django_projects/stlzoo/src/shipments/models.py) > > > > > > I am stuck here and cannot seem to resolve this error. I would > > > truly appreciate any help on this. Thanks. > > > > > > Frank > > > -- > > > 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/c0aff4c4-651a-43ad-9ac9-42c6452a33f4n%40googlegroups.com > > > . > > > > > > -- > > Adam (a...@csh.rit.edu) > > -- Adam (a...@csh.rit.edu) -- 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/34fe18d800ae49957c4a6ababcc80d943bf95295.camel%40csh.rit.edu.
Re: Management command scheduling options
On Wed, 2023-10-25 at 08:24 -0400, Larry Martell wrote: > On Wed, Oct 25, 2023 at 5:35 AM Mike Dewhirst > wrote: > > > > Ahmedrufai > > > > I looked at APScheduler and like Celery it is too much of a > > sledgehammer for my tiny problem. > > > > I ended up using cron to launch the command each day. It works > > perfectly. > > > > My task now is to find a way to automate establishment of that > > crontab entry when the project is migrated to a new server. > > How are new servers deployed? How many new servers will be deployed? > If it's a one off thing you are doing manually, you just have to > remember to do it. If there are many, then you should use a tool like > terraform or octopus, or something similar and have that do it. > I use django-crontab myself for cron jobs. That way, I can add or update easily during deployment. Maybe you can make use of that so you can keep everything in your project. -- Adam (a...@csh.rit.edu) -- 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/6433ead4bf666e3ef52ac742df731e0cf7c66743.camel%40csh.rit.edu.