The thing is, I don't want to tie the comments signals to a specific application. It's more of a project-wide thing.
So I did put the code into signals.py, stuffed it into my project root (not in an app) and imported it in my project's __init__.py. Now I get this Error if I try to ./manage.py runserver: Traceback (most recent call last): File "./manage.py", line 11, in <module> execute_manager(settings) File "/Library/Python/2.5/site-packages/django/core/management/ __init__.py", line 338, in execute_manager setup_environ(settings_mod) File "/Library/Python/2.5/site-packages/django/core/management/ __init__.py", line 316, in setup_environ project_module = __import__(project_name, {}, {}, ['']) File "/Users/benjamin/Code/django/kassette/../kassette/ __init__.py", line 1, in <module> import signals.py File "/Users/benjamin/Code/django/kassette/../kassette/signals.py", line 1, in <module> from django.contrib.comments.models import Comment File "/Library/Python/2.5/site-packages/django/contrib/comments/ models.py", line 2, in <module> from django.contrib.auth.models import User File "/Library/Python/2.5/site-packages/django/contrib/auth/ models.py", line 6, in <module> from django.db import models File "/Library/Python/2.5/site-packages/django/db/__init__.py", line 9, in <module> if not settings.DATABASE_ENGINE: File "/Library/Python/2.5/site-packages/django/conf/__init__.py", line 28, in __getattr__ self._import_settings() File "/Library/Python/2.5/site-packages/django/conf/__init__.py", line 57, in _import_settings raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE) ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined. Why do I have to set an environment variable for this? Django never complained about this before. @adi: What do you mean by 'whatever pleases you'? I understand that I can create any arbitrary .py-file with code that I want and than import this file, but I'm not quite sure from which file I should import it. As seen above, importing from __init__.py results in quite some trouble. But thanks for the reply! benjamin Am 29.10.2008 um 12:09 schrieb Adi Jörg Sieker: > > Since a django application is a normal python module you > could create a signals.py and import it in your applications > __init__.py > or whatever pleases you. > a django application can contain whatever new files modules you want. > It has to respect somethings so that django recognises it as an > application > but other than that you are free to create whatever you want. > > Gruß > adi > > On 29.10.2008 9:17 Uhr, Benjamin Buch wrote: >> Hi, >> >> short summary for all who didn't follow or don't remember (it's >> been a >> while since the last reply...): >> >> I have signals wired up for comments (email-notification on >> commenting). >> Users are allowed to comment on three different models. >> Where should the code live? >> >> Am 29.09.2008 um 14:36 schrieb Benjamin Buch: >> >>> I should write the code first, and then say something about it I >>> guess... ;-) >>> I'll get back when I did so. >>> benjamin >> >> I wrote the code now. >> Here it is: >> >> from django.contrib.comments.models import Comment >> from django.core.mail import mail_managers >> from django.contrib.comments.signals import comment_was_posted >> >> def mail_on_posted_comment(sender, comment, request, **kwargs): >> name = comment.user_name >> email = comment_user_email >> comment_body = comment.comment >> ct = comment.content_type >> ct_name = ct.name >> ct_object = ct.get_object_for_this_type(pk=comment.object_pk) >> domain = comment.site.domain >> url_read = domain + ct_object.get_absolute_url() >> url_edit = domain + '/admin/comments/comment/' + str(comment.id) >> >> email_body = '''Ein neuer Kommentar wurde erstellt: >> von: %s >> E-mail: %s >> zu: %s %s >> Kommentar: %s >> >> Kommentar lesen: %s >> Kommentar bearbeiten: %s''' % (name, email, ct_name, ct_object, >> comment_body, url_read, url_edit) >> email_subject = 'Neuer Kommentar' >> mail_managers(email_subject, email_body) >> >> comment_was_posted.connect(mail_on_posted_comment, sender=Comment) >> >> So the question is: Where should this code live? >> >> As Erik said, it's more of a project related thing (because you can >> comment on three different models), >> so I think it would be a bad idea to tie the code to one particular >> model and put it in some models.py. >> >> Other places I could think of but considered them as 'not so good': >> __init__.py: Who would think that there are signals here? I guess >> nobody. >> views.py: signals in views? I don't think so. Let's keep things >> separated. >> urls.py: urls.py is for wiring up urls, not signals. >> >> @Erik: >> What exactly do you mean by 'put them somewhere in the project'? >> >> benjamin >> >>>>> >>>>> Am 28.09.2008 um 17:14 schrieb Erik Allik: >>>>> >>>>>> The way I see it is that your comment notification is not tied to >>>>>> any particular application that has commentable models but >>>>>> instead >>>>>> is more like a project related thing. So depending on your source >>>>>> layout, I'd put them somewhere in the project. Basically this >>>>>> relates to the application reuse topic -- when you connect the >>>>>> handler to the comment signal, is it something you want to reuse >>>>>> in the future or it's just a one time thing for the current >>>>>> project? >>>>>> >>>>>> Erik >>>>>> >>>>>> On 28.09.2008, at 14:58, Benjamin Buch wrote: >>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> I'm using the new comments framework, and I'd like to get >>>>>>> notified by mail when someone posts a comment. >>>>>>> How to di it I think I know, but I'm not quite sure where the >>>>>>> code should live. >>>>>>> The website has several kinds of entries where users can comment >>>>>>> on, so it would feel a little odd to put the comments' >>>>>>> signal-code in just one models.py. >>>>>>> As I have even more signals, I thought it would be great to have >>>>>>> a file signals.py, where all signal handling is done. >>>>>>> >>>>>>> But where should signals.py live? >>>>>>> Documentation says to signals: >>>>>>> "Where should this code live? >>>>>>> You can put signal handling and registration code anywhere you >>>>>>> like. However, you'll need to make sure that the module it's in >>>>>>> gets imported early on so that the signal handling gets >>>>>>> registered before any signals need to be sent. This makes your >>>>>>> app's models.py a good place to put registration of signal >>>>>>> handlers." >>>>>>> What means "the module it's in gets imported early"? >>>>>>> I suppose it's not enough to put my signals.py right there in my >>>>>>> projects' root folder? >>>>>>> -benjamin >> >> >>> > > > -- > Adi J. Sieker mobile: +49 - 178 - 88 5 88 13 > Freelance developer web: http://www.sieker.info/profile > SAP-Developer > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---