Created
October 14, 2012 03:36
-
-
Save artursapek/3887162 to your computer and use it in GitHub Desktop.
Example of Ants logging usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ants.views import log_event | |
def ant_log(request, eventname, data={}): | |
# Sample wrapper using ants.log_event which always includes logged-in users' name and email, for instance... | |
if not request.user.is_anonymous(): | |
data['user'] = '%s %s (%s)' % (request.user.first_name, request.user.last_name, request.user.email) | |
log_event(request, eventname, 'mysite', data) | |
def my_view(request): | |
# Your code... | |
# Example usage of our new ant_log wrapper to log this view: | |
ant_log(request, 'my_view', { 'some_more_data': request.POST['some_more_data'] }) | |
# Return value, etc... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
urlpatterns = patterns( | |
# Your urls... | |
(r'/ants/?', 'ants.views.visual', {'group': 'mysite'}), | |
(r'/ants/update/?', 'ants.views.ajax', {'group': 'mysite'}), | |
# etc... | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample view that serves the timeline | |
# Uses ants.views.visual with same groupname argument as used in ant_log | |
# Point a url to this and you've installed Ants | |
def show_ants(request): | |
return visual(request, 'mysite') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment