Ticket #3995: 3995.django.contrib.auth.diff
File 3995.django.contrib.auth.diff, 3.8 KB (added by , 17 years ago) |
---|
-
django/contrib/auth/models.py
277 277 def get_and_delete_messages(self): 278 278 messages = [] 279 279 for m in self.message_set.all(): 280 messages.append(m .message)280 messages.append(m) 281 281 m.delete() 282 282 return messages 283 283 … … 308 308 The message system is a lightweight way to queue messages for given 309 309 users. A message is associated with a User instance (so it is only 310 310 applicable for registered users). There's no concept of expiration or 311 timestamps. Messages are created by the Django admin after successful 312 actions. For example, "The poll Foo was created successfully." is a 313 message. 311 timestamps. A message consists of the actual message text and an optional 312 30 characters or fewer category string. Messages are created by the Django 313 admin after successful actions. For example, "The poll Foo was created 314 successfully." is a message. 314 315 """ 315 316 user = models.ForeignKey(User) 316 317 message = models.TextField(_('message')) 318 category = models.CharField(_('category'), max_length=30, blank=True) 317 319 318 320 def __unicode__(self): 319 321 return self.message -
tests/regressiontests/auth_backends/tests.py
69 69 True 70 70 >>> user.has_perms(['auth.test3', 'auth.test_group']) 71 71 True 72 73 >>> user = User.objects.create_user('test2', 'test2@example.com', 'test') 74 >>> message = user.message_set.create(message="uncategorised message") 75 >>> messages = user.get_and_delete_messages() 76 >>> messages[0] 77 <Message: uncategorised message> 78 >>> messages[0].category 79 u'' 80 >>> message = user.message_set.create(message="Categorised message", category="test") 81 >>> messages = user.get_and_delete_messages() 82 >>> messages[0].category 83 u'test' 72 84 """} -
docs/authentication.txt
959 959 The message system is a lightweight way to queue messages for given users. 960 960 961 961 A message is associated with a ``User``. There's no concept of expiration or 962 timestamps. 962 timestamps. A message consists of the actual ``message`` text and an optional 963 30 characters or fewer ``category`` string. 963 964 964 965 Messages are used by the Django admin after successful actions. For example, 965 966 ``"The poll Foo was created successfully."`` is a message. … … 967 968 The API is simple: 968 969 969 970 * To create a new message, use 970 ``user_obj.message_set.create(message='message_text')``. 971 ``user_obj.message_set.create(message='message_text', 972 category='message_category')``. 971 973 * To retrieve/delete messages, use ``user_obj.get_and_delete_messages()``, 972 974 which returns a list of ``Message`` objects in the user's queue (if any) 973 975 and deletes the messages from the queue. … … 978 980 def create_playlist(request, songs): 979 981 # Create the playlist with the given songs. 980 982 # ... 981 request.user.message_set.create(message="Your playlist was added successfully.") 983 request.user.message_set.create(message="Your playlist was added successfully.", 984 category="information") 982 985 return render_to_response("playlists/create.html", 983 986 context_instance=RequestContext(request)) 984 987 … … 989 992 {% if messages %} 990 993 <ul> 991 994 {% for message in messages %} 992 <li >{{ message }}</li>995 <li class="{{ message.category }}">{{ message }}</li> 993 996 {% endfor %} 994 997 </ul> 995 998 {% endif %}