#NEWLINE# def increment_user_activity_counters( user_id , action , date , db = None ) : #NEWLINE# #INDENT# db = ( db or database ) #NEWLINE# collection = database [ 'useractivitycounters' ] #NEWLINE# date = date . strftime ( '%Y/%m/%d' ) #NEWLINE# query = { #NEWLINE# #INDENT# '$inc' : { #NEWLINE# #INDENT# 'total' : 1 , #NEWLINE# 'date.{0}.total' . format ( date ) : 1 , #NEWLINE# 'action.{0}.total' . format ( action ) : 1 , #NEWLINE# 'action.{0}.date.{1}' . format ( action , date ) : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# collection . update ( { #NEWLINE# #INDENT# '_id' : user_id , #NEWLINE# #UNINDENT# } , query , upsert = True , manipulate = False ) #NEWLINE# return True