Ticket #3995: 3995.diff
File 3995.diff, 5.2 KB (added by , 15 years ago) |
---|
-
django/contrib/auth/models.py
261 261 def get_and_delete_messages(self): 262 262 messages = [] 263 263 for m in self.message_set.all(): 264 messages.append(m .message)264 messages.append(m) 265 265 m.delete() 266 266 return messages 267 267 … … 293 293 The message system is a lightweight way to queue messages for given 294 294 users. A message is associated with a User instance (so it is only 295 295 applicable for registered users). There's no concept of expiration or 296 timestamps. Messages are created by the Django admin after successful 297 actions. For example, "The poll Foo was created successfully." is a 298 message. 296 timestamps. A message consists of the actual message text and an optional 297 30 characters or fewer category string. Messages are created by the Django 298 admin after successful actions. For example, "The poll Foo was created 299 successfully." is a message. 299 300 """ 300 301 user = models.ForeignKey(User) 301 302 message = models.TextField(_('message')) 303 category = models.CharField(_('category'), max_length=30, blank=True) 302 304 303 305 def __unicode__(self): 304 306 return self.message -
django/contrib/auth/management/__init__.py
4 4 5 5 from django.db.models import get_models, signals 6 6 from django.contrib.auth import models as auth_app 7 from django.contrib.auth.models import Message 7 8 8 9 def _get_permission_codename(action, opts): 9 10 return u'%s_%s' % (action, opts.object_name.lower()) … … 44 45 call_command("createsuperuser", interactive=True) 45 46 break 46 47 48 def add_category_field(app, created_models, verbosity, **kwargs): 49 from django.db import connection 50 cursor = connection.cursor() 51 data_type = connection.creation.data_types['CharField'] % {'max_length': 30} 52 alter = 'ALTER TABLE %s ADD COLUMN `category` %s NOT NULL;' % (Message._meta.db_table, data_type) 53 try: 54 cursor.execute(alter) 55 except: 56 # column may already exist 57 pass 58 47 59 signals.post_syncdb.connect(create_permissions, 48 60 dispatch_uid = "django.contrib.auth.management.create_permissions") 49 61 signals.post_syncdb.connect(create_superuser, 50 62 sender=auth_app, dispatch_uid = "django.contrib.auth.management.create_superuser") 63 signals.post_syncdb.connect(add_category_field, sender=auth_app) -
docs/topics/auth.txt
1278 1278 The message system is a lightweight way to queue messages for given users. 1279 1279 1280 1280 A message is associated with a :class:`~django.contrib.auth.models.User`. 1281 There's no concept of expiration or timestamps. 1281 There's no concept of expiration or timestamps. A message consists of the actual 1282 ``message`` text and an optional 30 characters or fewer ``category`` string. 1282 1283 1283 1284 Messages are used by the Django admin after successful actions. For example, 1284 1285 ``"The poll Foo was created successfully."`` is a message. … … 1288 1289 .. method:: models.User.message_set.create(message) 1289 1290 1290 1291 To create a new message, use 1291 ``user_obj.message_set.create(message='message_text')``. 1292 ``user_obj.message_set.create(message='message_text', 1293 category='message_category')``. )``. 1292 1294 1293 1295 To retrieve/delete messages, use 1294 1296 :meth:`user_obj.get_and_delete_messages() <django.contrib.auth.models.User.get_and_delete_messages>`, … … 1301 1303 def create_playlist(request, songs): 1302 1304 # Create the playlist with the given songs. 1303 1305 # ... 1304 request.user.message_set.create(message="Your playlist was added successfully.") 1306 request.user.message_set.create(message="Your playlist was added successfully.", 1307 category="information") 1305 1308 return render_to_response("playlists/create.html", 1306 1309 context_instance=RequestContext(request)) 1307 1310 … … 1315 1318 {% if messages %} 1316 1319 <ul> 1317 1320 {% for message in messages %} 1318 <li >{{ message }}</li>1321 <li class="{{ message.category }}">{{ message }}</li> 1319 1322 {% endfor %} 1320 1323 </ul> 1321 1324 {% endif %} -
tests/regressiontests/auth_backends/tests.py
75 75 False 76 76 >>> user.has_perms(['auth.test2', 'auth.test3']) 77 77 False 78 79 >>> user = User.objects.create_user('test2', 'test2@example.com', 'test') 80 >>> message = user.message_set.create(message="uncategorized message") 81 >>> messages = user.get_and_delete_messages() 82 >>> messages[0] 83 <Message: uncategorized message> 84 >>> messages[0].category 85 u'' 86 >>> message = user.message_set.create(message="Categorized message", category="test") 87 >>> messages = user.get_and_delete_messages() 88 >>> messages[0].category 89 u'test' 78 90 """}