Re: importing users from another db
Russell Keith-Magee wrote: > On 7/8/07, Carl Karsten <[EMAIL PROTECTED]> wrote: >> Russell Keith-Magee wrote: >>> Django users have many skills. Unfortunately, mind reading is >>> generally not one of those skills :-) >>> >> Yeah, I see what you mean. seemed obvious to me :) >> >> does django expose it's ORM so that I can do the above code (connect to >> server, >> execute query) and get results back that I can access using object.fieldname >> notation? (or a dict) > > Well, depends what level you want to deal with it. > > If you want Django to handle the full stack, then you will need to > write a Django model that corresponds to the model you are trying to > import. Usually not that difficult to do, but somewhat excessive > effort for a temporary measure. Ok, not that big a deal. even with "inspectdb will help somewhat," it still seems more trouble than it is worth. > Another alternative is to use the cursor to retrieve a row, then feed > that row directly into the Django object of choice: > > for row in cursor.fetchAll(): >user = User(*row) >user.save() > > This assumes that the field names coming back from the cursor > correspond to the field names in the object you are saving; if this > isn't the case, you may need to do some dictionary munging on the *row > part. Unfortunately, I need to do some mucking, including field names with spaces. geez. > >> This code just bothers me: >>user = User.objects.create_user( member[5], member[4], member[6] ) > > Why? It's just a manager shorthand for: > > now = datetime.datetime.now() > user = self.model(None, username, '', '', email.strip().lower(), > 'placeholder', False, True, False, now, now) > user.set_password(password) > user.save() the User.objects.create_user() part is great. the member[5], member[4], member[6] magic numbers bothers me. I was hoping for user = User.objects.create_user( member.username, member.pw, member.first_name ) > >> Also, django.contrib.auth.models import User needs settings imported, and >> import-users.py is in a util/ dir under the 'home dir' that holds >> settings.py. >> What is a good way to reference ../settings.py? > > Something like: > > from myproject import settings as myproject_settings > like that, only completely different :) When I run my code (below) I get: self._target = Settings(settings_module) File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 83, in __init__ raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e) EnvironmentError: Could not import settings 'settings' (Is it on sys.path? Does it have syntax errors?): No module named settings I am assuming there are a few bad ways to solve this, and I am trying to avoid them. also, (still someone on topic, given my vague subject) Is the profile=... profile.save() look right? I'm not too sure what order the new/new/save/save should be done in. Carl K # migrate.py # migrates data from RidgeMoorJonas.Member to django.auth_user # uses the django user api, # mainly to create the password based on the current one. from django.contrib.auth.models import User import MySQLdb con = MySQLdb.connect(user='u', passwd='v' db='src' ) cur=con.cursor() # reset the tables cur.execute("truncate auth_user") cur.execute("truncate eventcal_event") # Create django Users cSql=""" select MemberNumber, Surname, `Given name`, `Familiar Name`, `Email Address` UserID, UserPassword, Telephone from Member limit 1 """ cur.execute(cSql) members = cur.fetchall() for member in members: # user = User.objects.create_user('john', '[EMAIL PROTECTED]', 'johnpassword') user = User.objects.create_user( member[5], member[4], member[6] ) user.first_name=member[2] user.last_name = member[1] profile = UserProfile.objects.create(user=user) profile.phone_number=member[7] user.save() profile.save() --~--~-~--~~~---~--~~ 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: importing users from another db
On 7/7/07, Russell Keith-Magee <[EMAIL PROTECTED]> wrote: > If you want Django to handle the full stack, then you will need to > write a Django model that corresponds to the model you are trying to > import. Usually not that difficult to do, but somewhat excessive > effort for a temporary measure. Though inspectdb will help somewhat, and may make it easier to write the script which imports into the new model. -- "Bureaucrat Conrad, you are technically correct -- the best kind of correct." --~--~-~--~~~---~--~~ 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: one to many
On 7/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I'm curious about the use of instance._set. If I have models: > > class Foo(models.Model): > # something > > class Bar(models.Model): > myFoo = models.ForeignKey(Foo) > > ...would I be able to say barInstance.myFoo_set.[] ? By default, it would be ``bar_set`` (i.e. the lower-cased version of ``Bar``, plus ``_set``). You can change the name of this attribute by setting the ``related_name`` attribute:: class Bar(models.Model): foo = models.ForeignKey(Foo, related_name="bars") This lets you say:: foo_instance.bars.all() For example. More here: http://www.djangoproject.com/documentation/db-api/#related-objects Jacob --~--~-~--~~~---~--~~ 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: importing users from another db
On 7/8/07, Carl Karsten <[EMAIL PROTECTED]> wrote: > > Russell Keith-Magee wrote: > > Django users have many skills. Unfortunately, mind reading is > > generally not one of those skills :-) > > > > Yeah, I see what you mean. seemed obvious to me :) > > does django expose it's ORM so that I can do the above code (connect to > server, > execute query) and get results back that I can access using object.fieldname > notation? (or a dict) Well, depends what level you want to deal with it. If you want Django to handle the full stack, then you will need to write a Django model that corresponds to the model you are trying to import. Usually not that difficult to do, but somewhat excessive effort for a temporary measure. Another alternative is to use the cursor to retrieve a row, then feed that row directly into the Django object of choice: for row in cursor.fetchAll(): user = User(*row) user.save() This assumes that the field names coming back from the cursor correspond to the field names in the object you are saving; if this isn't the case, you may need to do some dictionary munging on the *row part. > This code just bothers me: >user = User.objects.create_user( member[5], member[4], member[6] ) Why? It's just a manager shorthand for: now = datetime.datetime.now() user = self.model(None, username, '', '', email.strip().lower(), 'placeholder', False, True, False, now, now) user.set_password(password) user.save() > Also, django.contrib.auth.models import User needs settings imported, and > import-users.py is in a util/ dir under the 'home dir' that holds settings.py. > What is a good way to reference ../settings.py? Something like: from myproject import settings as myproject_settings Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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: importing users from another db
Russell Keith-Magee wrote: > On 7/8/07, Carl Karsten <[EMAIL PROTECTED]> wrote: >> I am migrating a site from .net/access to django. the MySql Migration Wizard >> gets the data out of access and into a MySql db nice and easy. There is even >> some provision for scripting it, but don't ask me about that cuz I havn't >> used >> it yet :) >> >> I can write .sql and python easy enough, and I am sure I can 'just do this' >> but >> was hoping to expand my skills a bit. The hickup is passwords.>>> from >> >> >>> django.contrib.auth.models import User >> >>> import MySQLdb >> >>> con=MySQLdb.connect(user='u', passwd='x', db='x' ) >> >>> cur=con.cursor() >> >>> cur.execute( 'select * from Member limit 1' ) >> 1L >> >>> members=cur.fetchall() >> >>> members >> (('', 'Deckard', 'Rick', '[EMAIL PROTECTED]'),) >> >> cur.description >> (('MemberNumber', 253, 4, 255, 255, 0, 0), ('Surname'... >> >> So yeah, I can plow through this and figure it out, but I was thinking maybe >> django's ORM could be used. didn't see anything in the docs. > > In your enthusiasm, you appear to have missed one thing... > > Asking an actual question. > > What is it you want to do? How do you think the Django ORM can help? > Why are passwords a hiccup? > > Django users have many skills. Unfortunately, mind reading is > generally not one of those skills :-) > Yeah, I see what you mean. seemed obvious to me :) does django expose it's ORM so that I can do the above code (connect to server, execute query) and get results back that I can access using object.fieldname notation? (or a dict) This code just bothers me: user = User.objects.create_user( member[5], member[4], member[6] ) Also, django.contrib.auth.models import User needs settings imported, and import-users.py is in a util/ dir under the 'home dir' that holds settings.py. What is a good way to reference ../settings.py? Carl K --~--~-~--~~~---~--~~ 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: importing users from another db
On 7/8/07, Carl Karsten <[EMAIL PROTECTED]> wrote: > > I am migrating a site from .net/access to django. the MySql Migration Wizard > gets the data out of access and into a MySql db nice and easy. There is even > some provision for scripting it, but don't ask me about that cuz I havn't used > it yet :) > > I can write .sql and python easy enough, and I am sure I can 'just do this' > but > was hoping to expand my skills a bit. The hickup is passwords.>>> from > > >>> django.contrib.auth.models import User > >>> import MySQLdb > >>> con=MySQLdb.connect(user='u', passwd='x', db='x' ) > >>> cur=con.cursor() > >>> cur.execute( 'select * from Member limit 1' ) > 1L > >>> members=cur.fetchall() > >>> members > (('', 'Deckard', 'Rick', '[EMAIL PROTECTED]'),) > >> cur.description > (('MemberNumber', 253, 4, 255, 255, 0, 0), ('Surname'... > > So yeah, I can plow through this and figure it out, but I was thinking maybe > django's ORM could be used. didn't see anything in the docs. In your enthusiasm, you appear to have missed one thing... Asking an actual question. What is it you want to do? How do you think the Django ORM can help? Why are passwords a hiccup? Django users have many skills. Unfortunately, mind reading is generally not one of those skills :-) Yours, Russ Magee %-) --~--~-~--~~~---~--~~ 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: Unexpected keyword argument when calling a function
Karen, Thanks...that is exactly what happened. I copied the old function but forgot to delete it Thanks On Jul 7, 7:05 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On 7/7/07, Greg <[EMAIL PROTECTED]> wrote: > > > > > I done this before with just one variable and it's always been (? > > P\d+). Can I change the name from object_id to > > manufacturer_id and collection_id? And can I send two variables > > (three including request)? > > Yes, you can change the names and you can have more than one variable in > addition to request passed into your view function. I can't immediately see > anything wrong with your code (it looks very similar to some of my own, > which does much the same thing and works fine). It almost seems as though > an old showcollection() definition is being found somewhere, one that > doesn't have the collection_id argument. Any way that could be happening? > > Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
importing users from another db
I am migrating a site from .net/access to django. the MySql Migration Wizard gets the data out of access and into a MySql db nice and easy. There is even some provision for scripting it, but don't ask me about that cuz I havn't used it yet :) I can write .sql and python easy enough, and I am sure I can 'just do this' but was hoping to expand my skills a bit. The hickup is passwords.>>> from >>> django.contrib.auth.models import User >>> import MySQLdb >>> con=MySQLdb.connect(user='u', passwd='x', db='x' ) >>> cur=con.cursor() >>> cur.execute( 'select * from Member limit 1' ) 1L >>> members=cur.fetchall() >>> members (('', 'Deckard', 'Rick', '[EMAIL PROTECTED]'),) >> cur.description (('MemberNumber', 253, 4, 255, 255, 0, 0), ('Surname'... So yeah, I can plow through this and figure it out, but I was thinking maybe django's ORM could be used. didn't see anything in the docs. Carl K --~--~-~--~~~---~--~~ 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: Unexpected keyword argument when calling a function
On 7/7/07, Greg <[EMAIL PROTECTED]> wrote: > > I done this before with just one variable and it's always been (? > P\d+). Can I change the name from object_id to > manufacturer_id and collection_id? And can I send two variables > (three including request)? Yes, you can change the names and you can have more than one variable in addition to request passed into your view function. I can't immediately see anything wrong with your code (it looks very similar to some of my own, which does much the same thing and works fine). It almost seems as though an old showcollection() definition is being found somewhere, one that doesn't have the collection_id argument. Any way that could be happening? Karen --~--~-~--~~~---~--~~ 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: Unexpected keyword argument when calling a function
According to the code I have, this should be working. Try changing it to def showcollection(request, manufacturer_id=None, collection_id=None): and see if that makes any difference. On Sat, 2007-07-07 at 16:07 -0700, Greg wrote: > Hello, > I have the following line in my urls.py file > > r'^(?P\d+)/(?P\d+)/styles/$', > 'mysite.rugs.views.showcollection'), > > // > > I have the following function defined in my views.py file > > def showcollection(request, manufacturer_id, collection_id): > s = Style.objects.filter(collection=collection_id) > return render_to_response('thecollectionpage.html', {'coll': s}) > > // > > When I go to that url I get the following error: > > TypeError at /rugs/2/1/styles/ > showcollection() got an unexpected keyword argument 'collection_id' > Request Method: GET > Request URL: http://127.0.0.1:8000/rugs/2/1/styles/ > Exception Type: TypeError > Exception Value: showcollection() got an unexpected keyword argument > 'collection_id' > Exception Location: c:\Python24\lib\site-packages\django\core\handlers > \base.py in get_response, line 77 > > > > I done this before with just one variable and it's always been (? > P\d+). Can I change the name from object_id to > manufacturer_id and collection_id? And can I send two variables > (three including request)? > > Thanks > > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Web Service Startup - Looking for Django partner/developer
Hi all, We are looking for a coder, perhaps a designer, for a new web 2.0 startup service. We have a lot of experience in startups and technology, but we're not coders or designers by profession. We are looking for someone who can code well in languages like PHP, Django or Ruby on Rails and also integrate them with a MySQL backend. The project involves a login page/WYSIWYG editor/control panel and input methods such as SMS/email and IM. We may be looking for someone willing to join us in the long term in the future, although most likely will take in someone at an affordable hourly rate once they've signed a NDA. Email me if you are interested. brandoncolorado via gmail. --~--~-~--~~~---~--~~ 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: using create_update.update_object with formtools.preview
On Wed, 2007-07-04 at 13:52 +, sector119 wrote: > is it possible? or it's possible to use formtools.preview only with > newforms models? Formtools.preview relies on newform Forms, that is correct. Regards, Malcolm -- Many are called, few volunteer. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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: caching and authentication
On 7/7/07, patrick k. <[EMAIL PROTECTED]> wrote: > I don´t understand why the page_cache is keyed by the vary header and > the view_cache is not. is there a reason for this? You mean cache_page rather than page_cache, but what is view_cache? I think I may have spotted the problem: the cache_page decorator runs before the Vary header gets patched for the session access. As a test, just before you return your HttpResponse, try adding this to one of your auth views, and try to use the cache_page decorator: from django.utils.cache import patch_vary_headers patch_vary_headers(response, ('Cookie',)) (Maye sure to dump your cache first, too.) --~--~-~--~~~---~--~~ 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: How to use Admin modules in my application
admin != user Atleast that's my view. As tempting as the pretty admin interface might be, I think you would be better off rolling your own form and view for end users. Then you have complete control. Using the form_for_* functions you could have the whole thing done in a few minutes. fetch user profile. form_for_instance on user profile in the post procesing double check userid then do a form.save() and redirect. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Unexpected keyword argument when calling a function
Hello, I have the following line in my urls.py file r'^(?P\d+)/(?P\d+)/styles/$', 'mysite.rugs.views.showcollection'), // I have the following function defined in my views.py file def showcollection(request, manufacturer_id, collection_id): s = Style.objects.filter(collection=collection_id) return render_to_response('thecollectionpage.html', {'coll': s}) // When I go to that url I get the following error: TypeError at /rugs/2/1/styles/ showcollection() got an unexpected keyword argument 'collection_id' Request Method: GET Request URL:http://127.0.0.1:8000/rugs/2/1/styles/ Exception Type: TypeError Exception Value:showcollection() got an unexpected keyword argument 'collection_id' Exception Location: c:\Python24\lib\site-packages\django\core\handlers \base.py in get_response, line 77 I done this before with just one variable and it's always been (? P\d+). Can I change the name from object_id to manufacturer_id and collection_id? And can I send two variables (three including request)? Thanks --~--~-~--~~~---~--~~ 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: caching and authentication
Am 07.07.2007 um 19:36 schrieb Honza Král: > On 7/7/07, patrick k. <[EMAIL PROTECTED]> wrote: >> >> >> Am 07.07.2007 um 02:13 schrieb Jeremy Dunck: >> >>> >>> On 7/6/07, patrickk <[EMAIL PROTECTED]> wrote: when having a header where the username and a logout-button is displayed, how do you cache this page/view? >>> >>> There's a CACHE_MIDDLEWARE_ANONYMOUS_ONLY setting if you want to >>> only >>> do anonymous caching. >>> >>> But I think you must have your cache middleware in the wrong >>> order if >>> you're seeing this problem. >> >> I�m not using the cache middleware. >> >>> >>> page_cache and the cache middleware both are keyed by the Vary >>> header, >>> and the Vary header will contain 'Cookie' if you've accessed the >>> session object-- which you must have done if you have the >>> request.user >>> in your template. >> >> I�m currently using the per-view cache (well, actually I�m >> using the >> low-level cache because of the mentioned problems). >> >> I�d like to cache individual views - the only thing changing is the >> header (either "username/logout" or "login/register"), everything >> else is the same. > > if its that case, you could write your own middleware that would > rewrite the page - just put some placeholder where this information is > supposed to go, and let the middleware handle it I have to check that ... currently, I´ve no idea how this could be done (but I guess the docs will tell me). > > OR > > do not cache the entire page, but rather some reusable blocks or > data... that was the initial question. when caching part of the page, I have to render the templates twice. first render the cached part and then the dynamic part. this leads to strange templates though (because I´m caching the whole page except for one line of code). I don´t understand why the page_cache is keyed by the vary header and the view_cache is not. is there a reason for this? thanks, patrick > >> >> thanks, >> patrick >> >> >>> >>> Please post your MIDDLEWARE_CLASSES tuple. >>> is this (using the low-level cache) the best way doing this? >>> >>> I'm not convinced you need it. >>> >> >> >>> >> > > > -- > Honza Kr�l > E-Mail: [EMAIL PROTECTED] > ICQ#: 107471613 > Phone: +420 606 678585 > > > --~--~-~--~~~---~--~~ 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: Best location for projects and applications?
I just organize them like I have always organized my projects (before django, not web related, etc...): /projects_root/client/project_ref/files All necesary files are given appropiate permissions and symlinked to some path like /var/www/someproject or so, to be in a "nice best practice-place", so I don't end up with apache reading all over the place, and to know where to look when something goes wrong. In production, I keep everything under /var/www/django, though I rarely use a server for more than 1 site. When it's a dedicated box for "that one site", everything's just fine under the document root. You might want to have a look at the LFS (Linux Filesystem Standard), which describes the folders you usually find on a linux distro and the kind of content they should have. Kind regards, Chris Hoeppner www.pixware.org El Saturday 07 July 2007 21:32:41 J.P. Cummins escribió: > Hey Everyone, > > What is the proper location for projects and applications on a *nix system? > The online documentation creates a 'poll' application in the project > directory. To me, that seems reallybad. Is it the best practice? > > For my projects, I use the following folder structure: > > /home/django/apps >/app1 >/app2 > /home/django/projects >/project1 >/project2 > > Between the documentation, mailing list, and blogs, I've seen many > different configurations. What is the best folder structure and why? --~--~-~--~~~---~--~~ 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: Eroneous error with development server: 'module' object has no attribute 'urlpatterns'
Some additional info. I zapped my django installation and reinstalled from svn from scratch. I still had the problem. I tar'd up my project and moved it to a CentOS 5 box running 5631 and I do *not* experience the problem there. The two salient differences between the machines is that the problematic one is running CentOS 4.4/Python 2.3.4 and the CentOS 5.0 box is running Python 2.4.3 and also happens to be running X86_64. Could this be a Python 2.3.x issue? -Steve --~--~-~--~~~---~--~~ 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: mix in view or template?
Carl Karsten wrote: > I am trying to figure out the best place to matchup Events and Dates when > rendering a 'basic calendar.' > > Events: 0, 1, more per date. > Dates: a list of all the dates in a month, so about 30 - one for each day. > > # views.py > class Event(models.Model): > title = models.CharField(maxlength=255) > eventdate = models.DateField() > description = models.TextField(blank=True) > def __str__(self): > return "%(ed)s %(t)s" % {'t':self.title, 'ed':self.eventdate } > > # models.py > # 6=Week starts on Sunday > c=calendar.Calendar(6) > > # get all the dates that will be displaied, > # including the tail and head of previous/next months. > dates=c.monthdatescalendar(year, month) > > # get Events from the DB that are in the specified month. > object_list = > Event.objects.filter(eventdate__range=(dates[0][0],dates[-1][-1])) > > Now that I have dates and object_list, I can either pass both off to the > template and let it put event on the days as it builds, > > or in my view: create a list of 'day objects', one for each day, and hang the > set of events for that day off each. > > I thought it would be easy enough to do it in the template, but I am starting > to > have 2nd thoughts. I have it working in the template. for each day, I loop though all the Event objects, and ifequal out the ones for the current day. seems inefficient, but low volume site, so fine for now. If someone can give me some code that is better, im all ears. {% for week in dates %} {% for day in week %} {{ day|date:"j" }} {% for obj in object_list %} {% ifequal obj.eventdate day %} {{ obj.title }} {% endifequal %} {% endfor %} {% endfor %} {% endfor %} Thanks for listening. Carl K --~--~-~--~~~---~--~~ 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: trunk, sqlite backend bug with date handlig
Malcolm, Thanks, your answers helped to trace down the problem. It appeared that just sqlite connection was opened without proper 'detect_types' parameter. MT> On Sat, 2007-07-07 at 23:04 +0300, Andrey Khavryuchenko wrote: >> MT> On Sat, 2007-07-07 at 20:57 +0300, Andrey Khavryuchenko wrote: >> >> While I'm digging in sqlite backend sources, may anyone share his >> >> experience? >> MT> I just tried this with some models I have here using sqlite and they all MT> loaded DateTime fields as Python datetime instances. Saving and MT> reloading didn't seem to change the type, either. >> MT> So this doesn't seem to be a universal failure. Would be interesting to MT> know what's going on, though. >> >> I'm observing this in unit tests where I do some black magic to substitute >> usual mysql db backend to temporary pysqlite2 in-memory db. MT> That's almost certainly the problem. In the sqlite backend, we install MT> various converters, including on to create datetime objects. MT> Why not just use a settings file that has DATABASE_ENGINE="sqlite3" and MT> set the name to ":memory:"? Telling Django that the engine is MySQL and MT> then using something else is going to lead to no end of problems, I MT> suspect. Because app in usual mode uses mysql and some tests rely on initial mysql data. And anyway, playing with settings.py file and it's content within unit tests smell me more than substituting db connection in setup and restoring it in teardown. >> So, the question to help to clarify what I've done wrong in that magic: >> >> When the object is created in django.db.models.query there's a call around >> line 205 >> >> obj = self.model(*row[:index_end]) >> >> Should the data be already converted to proper data types or not? MT> Yes, it should already be using the correct Python types at this point MT> (e.g. datetime). Exactly. That solved the issue. Thanks again. -- Andrey V Khavryuchenko Django NewGate - http://www.kds.com.ua/djiggit/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
How to use Admin modules in my application
Hi everybody, I'd like to take advantage of Admin modules to edit some my models e.g. user profile by navigating user to /admin/myapp/// to open change form. 1. I should check, whether is the same as request.user.id to prevent user from editing a foreign user record. But I don't know how to implement this. Perhaps by overriding some model's method or listening for a suitable signal. 2. In the related admin's template I need somehow override tag submit_row to hide all buttons except Save one. As well, I have no idea how to do this. 3. Finally, is my conception of using Admin modules this way feasible per se? Please, could somebody enlighten me on this? Thanks, Angela --~--~-~--~~~---~--~~ 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: Best location for projects and applications?
On Sat, 2007-07-07 at 15:32 -0500, J.P. Cummins wrote: > Hey Everyone, > > What is the proper location for projects and applications on a *nix > system? The online documentation creates a 'poll' application in the > project directory. To me, that seems reallybad. You seem to have hit send too early, because you forgot to include any supporting reasoning for this claim. > Is it the best practice? > > For my projects, I use the following folder structure: > > /home/django/apps >/app1 >/app2 > /home/django/projects >/project1 >/project2 > > Between the documentation, mailing list, and blogs, I've seen many > different configurations. What is the best folder structure and why? Any directory structure that works for you is fine. There's no magical "best practice" (whatever that might mean. The reason you've seen different setups is because they all work. Sometimes you want to put a bunch of application directories all together under one parent directory, which together with settings and a url configuration file you might call a project. Sometimes you want to keep some applications separate. Sometimes you'll have hierarchical directories of applications. It's all good. This is the generic "how should I organise my Python code" question. There is not right answer. Certainly on single right answer. Find something that works for your way of thinking and, above all, be consistent with what you write and flexible in what you are prepared to read and use. Regards, Malcolm -- Plan to be spontaneous - tomorrow. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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: object_list=[] ?
Malcolm Tredinnick wrote: > On Sat, 2007-07-07 at 14:59 -0500, Carl Karsten wrote: >> # views.py >> class Event(models.Model): >> title = models.CharField(maxlength=255) >> eventdate = models.DateField() >> description = models.TextField(blank=True) >> def __str__(self): >> return "%(ed)s %(t)s" % {'t':self.title, 'ed':self.eventdate } >> >> # models.py >> # get Events from the DB that are in the specified month. >> object_list = >> Event.objects.filter(eventdate__range=(dates[0][0],dates[-1][-1])) >> >> >> template: >> month_index.html >> >> object_list: {{ object_list }} object_list.0: {{ object_list.0 }} >> >> >> brows it: >> renders: object_list: [ ] object_list.0: 2007-07-07 up >> >> Why does {{object_list}} render an empty list ? > > The usual way to debug these problems is to work out what is going on at > the command line. heh - I just suggested that to someone having problems on IRC. maybe I need to take my own advice sometime :) > I suspect if you do that, you'll find that the > object_list looks like []. So just dumping it into the HTML > will lead to your browser interpreting the angle brackets as an HTML > element, and just swallowing it up, since it's not a valid element. > > Often, if something isn't rendering as you expect, view the HTML source > to check what has really been returned. yup: object_list: [] object_list.0: 2007-07-07 up Thanks Carl K --~--~-~--~~~---~--~~ 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: Eroneous error with development server: 'module' object has no attribute 'urlpatterns'
This problem seems to occur whenever there is any syntax error in my code *anywhere*. I just introduced one about a hundred lines into my view function and triggered it. Here is a simple test case, complete with sample syntax error: === urls.py: from django.conf.urls.defaults import * from testproj.testapp.views import * urlpatterns = patterns('', (r'^testapp/$', hello), ) === === testapp/views.py: from django.shortcuts import render_to_response def hello(request): x = 5 x ++= 1 return render_to_response('hello.html') === === testapp/hello.html: hello Hello, Syntax Error! === --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Best location for projects and applications?
Hey Everyone, What is the proper location for projects and applications on a *nix system? The online documentation creates a 'poll' application in the project directory. To me, that seems reallybad. Is it the best practice? For my projects, I use the following folder structure: /home/django/apps /app1 /app2 /home/django/projects /project1 /project2 Between the documentation, mailing list, and blogs, I've seen many different configurations. What is the best folder structure and why? -- J.P. Cummins --~--~-~--~~~---~--~~ 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: object_list=[] ?
On Sat, 2007-07-07 at 14:59 -0500, Carl Karsten wrote: > # views.py > class Event(models.Model): > title = models.CharField(maxlength=255) > eventdate = models.DateField() > description = models.TextField(blank=True) > def __str__(self): > return "%(ed)s %(t)s" % {'t':self.title, 'ed':self.eventdate } > > # models.py > # get Events from the DB that are in the specified month. > object_list = > Event.objects.filter(eventdate__range=(dates[0][0],dates[-1][-1])) > > > template: > month_index.html > > object_list: {{ object_list }} object_list.0: {{ object_list.0 }} > > > brows it: > renders: object_list: [ ] object_list.0: 2007-07-07 up > > Why does {{object_list}} render an empty list ? The usual way to debug these problems is to work out what is going on at the command line. I suspect if you do that, you'll find that the object_list looks like []. So just dumping it into the HTML will lead to your browser interpreting the angle brackets as an HTML element, and just swallowing it up, since it's not a valid element. Often, if something isn't rendering as you expect, view the HTML source to check what has really been returned. Regards, Malcolm -- Why can't you be a non-conformist like everyone else? http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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: trunk, sqlite backend bug with date handlig
On Sat, 2007-07-07 at 23:04 +0300, Andrey Khavryuchenko wrote: > > MT> On Sat, 2007-07-07 at 20:57 +0300, Andrey Khavryuchenko wrote: > >> While I'm digging in sqlite backend sources, may anyone share his > >> experience? > > MT> I just tried this with some models I have here using sqlite and they all > MT> loaded DateTime fields as Python datetime instances. Saving and > MT> reloading didn't seem to change the type, either. > > MT> So this doesn't seem to be a universal failure. Would be interesting to > MT> know what's going on, though. > > I'm observing this in unit tests where I do some black magic to substitute > usual mysql db backend to temporary pysqlite2 in-memory db. That's almost certainly the problem. In the sqlite backend, we install various converters, including on to create datetime objects. Why not just use a settings file that has DATABASE_ENGINE="sqlite3" and set the name to ":memory:"? Telling Django that the engine is MySQL and then using something else is going to lead to no end of problems, I suspect. > So, the question to help to clarify what I've done wrong in that magic: > > When the object is created in django.db.models.query there's a call around > line 205 > > obj = self.model(*row[:index_end]) > > Should the data be already converted to proper data types or not? Yes, it should already be using the correct Python types at this point (e.g. datetime). Regards, Malcolm -- Why can't you be a non-conformist like everyone else? http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
mix in view or template?
I am trying to figure out the best place to matchup Events and Dates when rendering a 'basic calendar.' Events: 0, 1, more per date. Dates: a list of all the dates in a month, so about 30 - one for each day. # views.py class Event(models.Model): title = models.CharField(maxlength=255) eventdate = models.DateField() description = models.TextField(blank=True) def __str__(self): return "%(ed)s %(t)s" % {'t':self.title, 'ed':self.eventdate } # models.py # 6=Week starts on Sunday c=calendar.Calendar(6) # get all the dates that will be displaied, # including the tail and head of previous/next months. dates=c.monthdatescalendar(year, month) # get Events from the DB that are in the specified month. object_list = Event.objects.filter(eventdate__range=(dates[0][0],dates[-1][-1])) Now that I have dates and object_list, I can either pass both off to the template and let it put event on the days as it builds, or in my view: create a list of 'day objects', one for each day, and hang the set of events for that day off each. I thought it would be easy enough to do it in the template, but I am starting to have 2nd thoughts. Carl K --~--~-~--~~~---~--~~ 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: trunk, sqlite backend bug with date handlig
MT> On Sat, 2007-07-07 at 20:57 +0300, Andrey Khavryuchenko wrote: >> While I'm digging in sqlite backend sources, may anyone share his >> experience? MT> I just tried this with some models I have here using sqlite and they all MT> loaded DateTime fields as Python datetime instances. Saving and MT> reloading didn't seem to change the type, either. MT> So this doesn't seem to be a universal failure. Would be interesting to MT> know what's going on, though. I'm observing this in unit tests where I do some black magic to substitute usual mysql db backend to temporary pysqlite2 in-memory db. So, the question to help to clarify what I've done wrong in that magic: When the object is created in django.db.models.query there's a call around line 205 obj = self.model(*row[:index_end]) Should the data be already converted to proper data types or not? -- Andrey V Khavryuchenko Django NewGate - http://www.kds.com.ua/djiggit/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
object_list=[] ?
# views.py class Event(models.Model): title = models.CharField(maxlength=255) eventdate = models.DateField() description = models.TextField(blank=True) def __str__(self): return "%(ed)s %(t)s" % {'t':self.title, 'ed':self.eventdate } # models.py # get Events from the DB that are in the specified month. object_list = Event.objects.filter(eventdate__range=(dates[0][0],dates[-1][-1])) template: month_index.html object_list: {{ object_list }} object_list.0: {{ object_list.0 }} brows it: renders: object_list: [ ] object_list.0: 2007-07-07 up Why does {{object_list}} render an empty list ? Carl K --~--~-~--~~~---~--~~ 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: Eroneous error with development server: 'module' object has no attribute 'urlpatterns'
On Sat, 2007-07-07 at 19:51 +, Steve Bergman wrote: > Apologies if I was not clear. Yes, I was expecting that if I had a > syntax error in my code, the development server (./manage.py > runserver) would either abort completely or restart itself. > > Instead, I see the error page directing me to the syntax error, which > I fix, and then reload the page or try to load the main page. That's > when I get the above output. I would prefer that the development > server either restart itself or abort completely so that I could have > a shell script restart it as necessary. Usually the development webserver does restart correctly whenever you change a file. However, if you have a syntax early enough in the code execution path, it is probably possible to get it into a state where it cannot recover cleanly. Not a lot we can do about that, unfortunately. Luckily, restarting the dev server shouldn't be a big deal and you're only going to have a very limited number of syntax errors that early in the code. Regards, Malcolm -- The hardness of butter is directly proportional to the softness of the bread. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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: Eroneous error with development server: 'module' object has no attribute 'urlpatterns'
Apologies if I was not clear. Yes, I was expecting that if I had a syntax error in my code, the development server (./manage.py runserver) would either abort completely or restart itself. Instead, I see the error page directing me to the syntax error, which I fix, and then reload the page or try to load the main page. That's when I get the above output. I would prefer that the development server either restart itself or abort completely so that I could have a shell script restart it as necessary. Thanks, Steve P.S. It also occurs to me that I should have switched to cut and paste view before pasting into my original post. Sorry about that. --~--~-~--~~~---~--~~ 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: one to many
Yes, clear. Thanks. I read that example (found here: http://www.djangoproject.com/documentation/models/many_to_one/ ) right after I posted. I thought this usage made it very clear: # Create an Article via the Reporter object. >>> new_article = r.article_set.create(headline="John's second story", >>> pub_date=datetime(2005, 7, 29)) >>> new_article >>> new_article.reporter.id 1 I'm curious about the use of instance._set. If I have models: class Foo(models.Model): # something class Bar(models.Model): myFoo = models.ForeignKey(Foo) ...would I be able to say barInstance.myFoo_set.[] ? Thanks, Ivan On Jul 6, 11:59 pm, "Jeremy Dunck" <[EMAIL PROTECTED]> wrote: > On 7/6/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > class content(model.Models): > > link = models.URLField(verify_exists=True) > > mods = models.SomeKindOfManyToOne(lotsOfMods) > > Both in the database and in Django's ORM, it's done the other > direction. What you're looking for is called a foreign key > (ForeignKey in Django). > > Let's take the Article / Reporter models as an example. An article > has one reporter, but a reporter can have more than one article. > > To model this in the database, we make a reporter table with a primary > key-- that's a value that uniquely identifies the reporter record. > > In the article table, we make a foreign key to the reporter's primary key. > > reporter table: > id name > 1joe > 2 lisa > > article table > id reporter_id title > 1 1 "spamalot rocks" > 2 2 "sushi sundae" > 3 1 "ratatouille smoothies" > > > > From these records, we see that joe and lisa are reporters, and that > "spamalot rocks" and "ratatouille smoothies" are articles written by > joe, while "sushi sundae" was written by lisa. > > In the Django Model definition, it's like this: > > class Reporter(models.Model): > name = models.CharField(maxlength=50) > > class Article(models.Model): > reporter = models.ForeignKey(Reporter) >title = models.CharField(maxlength=50) > > Clear? --~--~-~--~~~---~--~~ 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: Eroneous error with development server: 'module' object has no attribute 'urlpatterns'
On Sat, 2007-07-07 at 19:15 +, Steve Bergman wrote: > I'm still seeing this with 5631. It is definitely after I hit a > syntax errror in my code that I see the behavior. I'm wondering if I > am the only one seeing this. Or if is perhaps expected behavior. What you do mean by "after you hit a syntax error"? This wasn't clear when I read your first post, either. If your code has syntax errors in it, all bets are off. After fixing the error, you need to remember to restart the webserver (if you aren't using the development server) so that the newly fixed code is re-imported. If you are doing that and still seeing the problem, perhaps you could provide an explicit example of what you are doing. There isn't any consistent error with urlpatterns being missing, so this is something special about the way you are developing, I suspect. Regards, Malcolm -- If at first you don't succeed, destroy all evidence that you tried. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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: Eroneous error with development server: 'module' object has no attribute 'urlpatterns'
I'm still seeing this with 5631. It is definitely after I hit a syntax errror in my code that I see the behavior. I'm wondering if I am the only one seeing this. Or if is perhaps expected behavior. Thanks, Steve Bergman --~--~-~--~~~---~--~~ 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: trunk, sqlite backend bug with date handlig
On Sat, 2007-07-07 at 20:57 +0300, Andrey Khavryuchenko wrote: > Hi! > > Had anyone noticed that loading DateField and DateTimeField from sqlite > in-memory db results in getting plain strings instead of datetime objects? > > Code: > > f = models.Feed(feed_url='no such url', is_active=True) > f.save() > post = models.Post(feed = f, title='test post', link=self.url) > post.save() > > assert models.Feed.objects.count() == 1, 'should be single feed' > assert models.Post.objects.count() == 1, 'should be single post' > > print '!!!', type(post.date_created), \ > models.Post.objects.all()[0].date_created, \ > type(models.Post.objects.all()[0].date_created) > assert type(models.Post.objects.all()[0].date_created) == \ >type(post.date_created) > > It prints the following and fails on last assert: > > >> begin captured stdout << - > !!! 2007-07-07 > > - >> end captured stdout << -- > > While I'm digging in sqlite backend sources, may anyone share his > experience? I just tried this with some models I have here using sqlite and they all loaded DateTime fields as Python datetime instances. Saving and reloading didn't seem to change the type, either. So this doesn't seem to be a universal failure. Would be interesting to know what's going on, though. Regards, Malcolm -- The early bird may get the worm, but the second mouse gets the cheese. http://www.pointy-stick.com/blog/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
trunk, sqlite backend bug with date handlig
Hi! Had anyone noticed that loading DateField and DateTimeField from sqlite in-memory db results in getting plain strings instead of datetime objects? Code: f = models.Feed(feed_url='no such url', is_active=True) f.save() post = models.Post(feed = f, title='test post', link=self.url) post.save() assert models.Feed.objects.count() == 1, 'should be single feed' assert models.Post.objects.count() == 1, 'should be single post' print '!!!', type(post.date_created), \ models.Post.objects.all()[0].date_created, \ type(models.Post.objects.all()[0].date_created) assert type(models.Post.objects.all()[0].date_created) == \ type(post.date_created) It prints the following and fails on last assert: >> begin captured stdout << - !!! 2007-07-07 - >> end captured stdout << -- While I'm digging in sqlite backend sources, may anyone share his experience? -- Andrey V Khavryuchenko Django NewGate - http://www.kds.com.ua/djiggit/ --~--~-~--~~~---~--~~ 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: Building forms by hands
On 7 июл, 20:30, "Bill Fenner" <[EMAIL PROTECTED]> wrote: > I wrote about a helper function that lets you access > individual radio buttons too, since otherwise you get all the > radiobuttons in one clump. > Seehttp://fenron.blogspot.com/2007/06/custom-radio-field-rendering-with > . Thanks! I think this will help a lot! -- Alexander --~--~-~--~~~---~--~~ 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: Building forms by hands
On 7 июл, 20:14, Steve Bergman <[EMAIL PROTECTED]> wrote: > You do know that you can place the fields yourself, right? I know that I can. ;) They want to have all this s in HTML. But, if I can't easily get value from field, they will use {{ form.field }} notation. :D -- Alexander --~--~-~--~~~---~--~~ 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: caching and authentication
On 7/7/07, patrick k. <[EMAIL PROTECTED]> wrote: > > > Am 07.07.2007 um 02:13 schrieb Jeremy Dunck: > > > > > On 7/6/07, patrickk <[EMAIL PROTECTED]> wrote: > >> > >> when having a header where the username and a logout-button is > >> displayed, how do you cache this page/view? > > > > There's a CACHE_MIDDLEWARE_ANONYMOUS_ONLY setting if you want to only > > do anonymous caching. > > > > But I think you must have your cache middleware in the wrong order if > > you're seeing this problem. > > I�m not using the cache middleware. > > > > > page_cache and the cache middleware both are keyed by the Vary header, > > and the Vary header will contain 'Cookie' if you've accessed the > > session object-- which you must have done if you have the request.user > > in your template. > > I�m currently using the per-view cache (well, actually I�m using the > low-level cache because of the mentioned problems). > > I�d like to cache individual views - the only thing changing is the > header (either "username/logout" or "login/register"), everything > else is the same. if its that case, you could write your own middleware that would rewrite the page - just put some placeholder where this information is supposed to go, and let the middleware handle it OR do not cache the entire page, but rather some reusable blocks or data... > > thanks, > patrick > > > > > > Please post your MIDDLEWARE_CLASSES tuple. > > > >> is this (using the low-level cache) the best way doing this? > >> > > > > I'm not convinced you need it. > > > > > > > > > > -- Honza Kr�l E-Mail: [EMAIL PROTECTED] ICQ#: 107471613 Phone: +420 606 678585 --~--~-~--~~~---~--~~ 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: Building forms by hands
On 7/7/07, Alexander Solovyov <[EMAIL PROTECTED]> wrote: > Mmm... I'm using form_for_instance-derived form with many > modifications (Indeed, this is better than using form, written by > hands) - I love automatization. But my colleguaes, who are responsible > for HTML part, doesn't like django-generated forms - they want full > control. Basic django forms give you full control over the placement of all the fields. I wrote about a helper function that lets you access individual radio buttons too, since otherwise you get all the radiobuttons in one clump. See http://fenron.blogspot.com/2007/06/custom-radio-field-rendering-with.html . Bill --~--~-~--~~~---~--~~ 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: Building forms by hands
On Jul 7, 9:48 am, Alexander Solovyov <[EMAIL PROTECTED]> wrote: > But my colleguaes, who are responsible > for HTML part, doesn't like django-generated forms - they want full > control. Yeah. Coworkers are a drag. ;-) You do know that you can place the fields yourself, right? If your form instance is called 'form' and has fields lastname and firstname, you can put something like: {{ form.lastname }},{{ form.firstname }} in your template and have full control over the way the form looks. You don't have to accept the default arrangement that Django gives by default. HTH, Steve --~--~-~--~~~---~--~~ 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: caching and authentication
Am 07.07.2007 um 02:13 schrieb Jeremy Dunck: > > On 7/6/07, patrickk <[EMAIL PROTECTED]> wrote: >> >> when having a header where the username and a logout-button is >> displayed, how do you cache this page/view? > > There's a CACHE_MIDDLEWARE_ANONYMOUS_ONLY setting if you want to only > do anonymous caching. > > But I think you must have your cache middleware in the wrong order if > you're seeing this problem. I´m not using the cache middleware. > > page_cache and the cache middleware both are keyed by the Vary header, > and the Vary header will contain 'Cookie' if you've accessed the > session object-- which you must have done if you have the request.user > in your template. I´m currently using the per-view cache (well, actually I´m using the low-level cache because of the mentioned problems). I´d like to cache individual views - the only thing changing is the header (either "username/logout" or "login/register"), everything else is the same. thanks, patrick > > Please post your MIDDLEWARE_CLASSES tuple. > >> is this (using the low-level cache) the best way doing this? >> > > I'm not convinced you need it. > > > --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
It's "official"...The 7 Figure Code Has Launched!
Hi, don't waste a single second... The most talked about product launch of 2007 just hit the shelves and you need to move *fast* if you expect to get your copy before they're gone! Go Here Now: => https://paydotcom.com/r/15727/pfelicies/ It really doesn't matter what business you're in, or how much experience (i.e. money) you've got, this incredible Home Study Course has exactly what you need to turn-around your business. Some of the biggest names in the marketing industry (and I'm talking multi-millionaires only) were caught on film while shelling out their best- kept secrets for seven figure mega-success -- stuff they've never taught *anywhere* before! This is 100% "meat" - no fluff, zero-pitch content designed to boost your income to seven figures. I give this my absolute highest recommendation. Get it right now: https://paydotcom.com/r/15727/pfelicies/ To your ultimate success, Pete Felicies --~--~-~--~~~---~--~~ 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: Building forms by hands
On 7 июл, 16:08, "Todd O'Bryan" <[EMAIL PROTECTED]> wrote: > On Sat, 2007-07-07 at 12:36 +, Alexander Solovyov wrote: > > On 5 июл, 14:19, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > > > Can you explain your problem another way, possibly with a more > > > complete example? > > > Ok, I'll try. > > > I want to enter HTML by hands, but can't determine which radio must be > > selected. Form is built with form_for_instance, so it contains values. > > > Sorry if my description is unclear. > > If you don't want to use a to output the form HTML that Django gives > you, you'll need to store some kind of value in the context to let you > know which radio button is selected. This is what I was afraid. :) > Can I ask why, if you're using form_for_instance, you don't want to use > the form's HTML output as well? Mmm... I'm using form_for_instance-derived form with many modifications (Indeed, this is better than using form, written by hands) - I love automatization. But my colleguaes, who are responsible for HTML part, doesn't like django-generated forms - they want full control. -- Alexander --~--~-~--~~~---~--~~ 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: Building forms by hands
On Sat, 2007-07-07 at 12:36 +, Alexander Solovyov wrote: > On 5 июл, 14:19, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > > > Can you explain your problem another way, possibly with a more > > complete example? > > Ok, I'll try. > > I want to enter HTML by hands, but can't determine which radio must be > selected. Form is built with form_for_instance, so it contains values. > > Sorry if my description is unclear. If you don't want to use a to output the form HTML that Django gives you, you'll need to store some kind of value in the context to let you know which radio button is selected. Can I ask why, if you're using form_for_instance, you don't want to use the form's HTML output as well? Todd --~--~-~--~~~---~--~~ 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: Adding own auth methods
> I'm trying to figure out whether I can use Django's built in auth > system for my needs. I need to limit access to certain areas > depending on whether the user is member of particular groups. Not > groups as in whether they area admins, moderators etc, but more in a > social network type sense of the word groups. > > How would I go about adding my own methods, something like: > > request.user.is_member_of(group) Yes, Django's built-in auth system will do what you describe. An "auth method" isn't, however, what you want. Django does support additional "auth methods" as I discovered just yesterday when I needed to support one-time hash authentication. It sounds like all you need is to create your own decorator like the login_required or user_passes_test functions found in django/contrib/auth/decorators.py Django already has support for groups and per-user permissions on the User object, so the permission_required decorator (also in the above-mentioned file) may already do what you want. Or, you can copy the permission_required decorator and make your own "group_required" decorator in 2-5 lines of code. -tim --~--~-~--~~~---~--~~ 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: Building forms by hands
On 5 июл, 14:19, "Russell Keith-Magee" <[EMAIL PROTECTED]> wrote: > Can you explain your problem another way, possibly with a more > complete example? Ok, I'll try. I want to enter HTML by hands, but can't determine which radio must be selected. Form is built with form_for_instance, so it contains values. Sorry if my description is unclear. --~--~-~--~~~---~--~~ 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: No module named _md5
On Jul 7, 6:25 pm, e-gor <[EMAIL PROTECTED]> wrote: > Switching off mod_php doesn't help. > > when i import module md5 from command prompt there are no errors: > > # python > Python 2.5.1 (r251:54863, Jun 28 2007, 13:12:40) > [GCC 3.4.6 [FreeBSD] 20060305] on freebsd6 > Type "help", "copyright", "credits" or "license" for more information.>>> > import md5 > >>> import blahblah > > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named blahblah Can you import 'hashlib' on the command line: import hashlib In Python 2.5 how the hash library modules is done was changed. This has caused issues before: http://www.modpython.org/pipermail/mod_python/2007-April/023508.html http://www.modpython.org/pipermail/mod_python/2007-April/023512.html A suitable answer wasn't found as it fixed itself when person recompiled Apache. My suspicion is that in recompiling Apache, Apache was then using the same shared library version of something (probably SSL libraries) as one of the Python hash modules was using. Previous to that it was using different versions and that caused a problem when loading one of the Python modules, thus resulting in it falling back to trying to load _md5 when it shouldn't have. Loading _md5 would fail as in Python 2.5 it doesn't necessarily exist as hashlib modules replace it from memory. Note, in recompiling Apache it may be important to ensure that it finds and uses system SSL libraries, otherwise it will use one from its own source code and that is where the clash may arise because Python will use the system one instead. Graham > On Jul 6, 4:26 pm, Roboto <[EMAIL PROTECTED]> wrote: > > > i'm not great at this, but a shot in the dark - turn off mod_php > > > On Jul 5, 2:59 pm, e-gor <[EMAIL PROTECTED]> wrote: > > > > I have python 2.5.1, django report errors: > > > >Mod_pythonerror: "PythonHandler django.core.handlers.modpython" > > > > Traceback (most recent call last): > > > > File "/usr/local/lib/python2.5/site-packages/mod_python/apache.py", > > > line 193, in Dispatch > > > result = object(req) > > > > File "/usr/local/lib/python2.5/site-packages/django/core/handlers/ > > > modpython.py", line 177, in handler > > > return ModPythonHandler()(req) > > > > File "/usr/local/lib/python2.5/site-packages/django/core/handlers/ > > > modpython.py", line 145, in __call__ > > > self.load_middleware() > > > > File "/usr/local/lib/python2.5/site-packages/django/core/handlers/ > > > base.py", line 31, in load_middleware > > > raise exceptions.ImproperlyConfigured, 'Error importing middleware > > > %s: "%s"' % (mw_module, e) > > > > ImproperlyConfigured: Error importing middleware > > > django.middleware.common: "No module named _md5" > > > > When i write import md5 from python command prompt i have no errors. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Adding own auth methods
Hi all, I'm trying to figure out whether I can use Django's built in auth system for my needs. I need to limit access to certain areas depending on whether the user is member of particular groups. Not groups as in whether they area admins, moderators etc, but more in a social network type sense of the word groups. How would I go about adding my own methods, something like: request.user.is_member_of(group) ? I'm sure I'll need to change the name 'groups' so that it doesn't clash with the built-in stuff, but hopefully you can understand what I mean. --~--~-~--~~~---~--~~ 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: Error log interpretation
Hi guys, I posted this elsewhere but if you're up for an example consider my photo app or image gallery here: https://saschashideout.de/wiki/DjangoGalleryTutorial/ I am currently working on it, but when it's finished I will upload also urls.py and views.py. --- saschashideout.de --~--~-~--~~~---~--~~ 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: making newforms' field as type hidden temporarily
On Jul 7, 10:47 am, Mambaragi <[EMAIL PROTECTED]> wrote: > Hello, > I use Django 0.96, newforms. > > If a form's field is bound, sometimes I need it to be hidden. > I have to use {% if %} for this. > But if it possible to set the form object's field as hidden > temporarily, it will be really nice. > > Regards, > KwonNam. form.fields["field_name"].widget = forms.HiddenInput() --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
making newforms' field as type hidden temporarily
Hello, I use Django 0.96, newforms. If a form's field is bound, sometimes I need it to be hidden. I have to use {% if %} for this. But if it possible to set the form object's field as hidden temporarily, it will be really nice. Regards, KwonNam. --~--~-~--~~~---~--~~ 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: No module named _md5
Switching off mod_php doesn't help. when i import module md5 from command prompt there are no errors: # python Python 2.5.1 (r251:54863, Jun 28 2007, 13:12:40) [GCC 3.4.6 [FreeBSD] 20060305] on freebsd6 Type "help", "copyright", "credits" or "license" for more information. >>> import md5 >>> import blahblah Traceback (most recent call last): File "", line 1, in ImportError: No module named blahblah >>> On Jul 6, 4:26 pm, Roboto <[EMAIL PROTECTED]> wrote: > i'm not great at this, but a shot in the dark - turn off mod_php > > On Jul 5, 2:59 pm, e-gor <[EMAIL PROTECTED]> wrote: > > > I have python 2.5.1, django report errors: > > > Mod_python error: "PythonHandler django.core.handlers.modpython" > > > Traceback (most recent call last): > > > File "/usr/local/lib/python2.5/site-packages/mod_python/apache.py", > > line 193, in Dispatch > > result = object(req) > > > File "/usr/local/lib/python2.5/site-packages/django/core/handlers/ > > modpython.py", line 177, in handler > > return ModPythonHandler()(req) > > > File "/usr/local/lib/python2.5/site-packages/django/core/handlers/ > > modpython.py", line 145, in __call__ > > self.load_middleware() > > > File "/usr/local/lib/python2.5/site-packages/django/core/handlers/ > > base.py", line 31, in load_middleware > > raise exceptions.ImproperlyConfigured, 'Error importing middleware > > %s: "%s"' % (mw_module, e) > > > ImproperlyConfigured: Error importing middleware > > django.middleware.common: "No module named _md5" > > > When i write import md5 from python command prompt i have no errors. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---