def mmessage_save(sender, instance, created, **kwargs): if created is False: # try to get the user user = get_user(instance) if 'name' not in kwargs.keys(): # try to get the object name obj_name = get_object_name(instance, user) else: obj_name = kwargs('name') # try to get the admin url admin_url = get_admin_url(instance) event_str = ' edited' if created: event_str = ' created' event_class = instance.__class__.__name__ + event_str # create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=user, url=get_url(instance), admin_url=admin_url, event_class=event_class, ) return
def mmessage_save(sender, instance, created, **kwargs): #~ try to get the user user = get_user(instance) if 'name' not in kwargs.keys(): #~ try to get the object name obj_name = get_object_name(instance, user) else: obj_name = kwargs('name') #~ try to get the admin url admin_url = get_admin_url(instance) event_str = ' edited' #~ check for object level monitoring if created: event_str = ' created' event_class = instance.__class__.__name__+event_str #~ create event MEvent.objects.create( model = instance.__class__, name = obj_name, obj_pk = instance.pk, user = user, url = get_url(instance), admin_url = admin_url, event_class = event_class, ) if settings.DEBUG: print bcolors.SUCCESS+'Event'+bcolors.ENDC+' : object '+obj_name+event_str return
def mmessage_save(sender, instance, created, **kwargs): # try to get the user user = get_user(instance) if 'name' not in kwargs.keys(): # try to get the object name obj_name = get_object_name(instance, user) else: obj_name = kwargs('name') # try to get the admin url admin_url = get_admin_url(instance) event_str = ' edited' if created: event_str = ' created' event_class = instance.__class__.__name__ + event_str # create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=user, url=get_url(instance), admin_url=admin_url, event_class=event_class, ) if LIVE_FEED is True and STREAM_MODELS is True: data = {"admin_url": admin_url, "site": SITE_NAME} broadcast(message=obj_name, event_class=event_class, channel=CHANNEL, data=data) if len(EXTRA_CHANNELS) > 0: for channel in EXTRA_CHANNELS: broadcast(message=obj_name, event_class=event_class, channel=channel, data=data) if settings.DEBUG: print bcolors.SUCCESS + 'Event' + bcolors.ENDC + ' : object ' + obj_name + event_str return
def mmessage_save(sender, instance, created, **kwargs): #~ try to get the user user = get_user(instance) if 'name' not in kwargs.keys(): #~ try to get the object name obj_name = get_object_name(instance, user) else: obj_name = kwargs('name') #~ try to get the admin url admin_url = get_admin_url(instance) event_str = ' edited' #~ check for object level monitoring if created: event_str = ' created' event_class = instance.__class__.__name__ + event_str #~ create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=user, url=get_url(instance), admin_url=admin_url, event_class=event_class, ) if settings.DEBUG: print bcolors.SUCCESS + 'Event' + bcolors.ENDC + ' : object ' + obj_name + event_str return
def send_msg(objclass, instance, event_str): obj_name = get_object_name(instance, instance) # try to get the admin url admin_url = get_admin_url(instance) event_class = instance.__class__.__name__ + " " + event_str # create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=instance, url=get_url(instance), admin_url=admin_url, event_class=event_class, ) return
def mmessage_create(sender, instance, created, **kwargs): if created is True: # try to get the user user = get_user(instance) # try to get the object name obj_name = get_object_name(instance, user) # try to get the admin url admin_url = get_admin_url(instance) event_class = instance.__class__.__name__ + ' created' # create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=user, url=get_url(instance), admin_url=admin_url, event_class=event_class, ) return
def mmessage_create(sender, instance, created, **kwargs): if created: #~ try to get the user user = get_user(instance) #~ try to get the object name obj_name = get_object_name(instance, user) #~ try to get the admin url admin_url = get_admin_url(instance) #~ check for object level monitoring event_class = instance.__class__.__name__+' created' #~ create event MEvent.objects.create( model = instance.__class__, name = obj_name, obj_pk = instance.pk, user = user, url = get_url(instance), admin_url = admin_url, event_class = event_class, ) if settings.DEBUG: print bcolors.SUCCESS+'Event'+bcolors.ENDC+' : object '+obj_name+' created' return
def mmessage_create(sender, instance, created, **kwargs): if created: #~ try to get the user user = get_user(instance) #~ try to get the object name obj_name = get_object_name(instance, user) #~ try to get the admin url admin_url = get_admin_url(instance) #~ check for object level monitoring event_class = instance.__class__.__name__ + ' created' #~ create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=user, url=get_url(instance), admin_url=admin_url, event_class=event_class, ) if settings.DEBUG: print bcolors.SUCCESS + 'Event' + bcolors.ENDC + ' : object ' + obj_name + ' created' return
def event_admin_url(event): return get_admin_url(event)
def create(self, *args, **kwargs): if not 'name' in kwargs.keys(): raise ValueError( u"You must provide a 'name' argument for the MEvent") else: name = kwargs['name'] obj_pk = None if 'obj_pk' in kwargs.keys() and not 'instance' in kwargs.keys(): obj_pk = kwargs['obj_pk'] content_type = None if 'model' in kwargs.keys() and not 'instance' in kwargs.keys(): content_type = ContentType.objects.get_for_model(kwargs['model']) #~ trying to grab an object instance in order to guess some fields instance = None if obj_pk and content_type and not 'instance' in kwargs.keys(): try: instance = content_type.get_object_for_this_type(pk=obj_pk) except: pass if 'instance' in kwargs.keys(): instance = kwargs['instance'] obj_pk = instance.pk content_type = ContentType.objects.get_for_model( kwargs['instance'].__class__) #~ guessed stuff user = None if 'user' in kwargs.keys(): user = kwargs['user'] else: if instance: user = get_user(instance) url = '' if 'url' in kwargs.keys(): url = kwargs['url'] else: if instance: url = get_url(instance) admin_url = '' if 'admin_url' in kwargs.keys(): admin_url = kwargs['admin_url'] else: if instance: admin_url = get_admin_url(instance) # request save_request = False if 'request' in kwargs.keys(): request = kwargs['request'] formated_request = '' for key in request.META.keys(): formated_request += str(key) + ' : ' + str( request.META[key]) + '\n' save_request = True #~ static stuff event_class = '' if 'event_class' in kwargs.keys(): event_class = kwargs['event_class'] notes = '' if 'notes' in kwargs.keys(): notes = kwargs['notes'] mevent = MEvent(name=name, content_type=content_type, obj_pk=obj_pk, user=user, url=url, admin_url=admin_url, notes=notes, event_class=event_class) if save_request is True: mevent.request = formated_request # save by default unless it is said not to if 'commit' in kwargs.keys(): if kwargs['commit'] is False: return mevent else: mevent.save(force_insert=True) return mevent
def create(self, *args, **kwargs): if 'name' not in kwargs.keys(): raise ValueError( u"You must provide a 'name' argument for the MEvent") else: name = kwargs['name'] obj_pk = None if 'obj_pk' in kwargs.keys() and 'instance' not in kwargs.keys(): obj_pk = kwargs['obj_pk'] content_type = None model = None if 'model' in kwargs.keys() and 'instance' not in kwargs.keys(): model = kwargs['model'] content_type = ContentType.objects.get_for_model(model) # trying to grab an object instance in order to guess some fields instance = None if obj_pk and content_type and 'instance' not in kwargs.keys(): try: instance = content_type.get_object_for_this_type(pk=obj_pk) except Exception: pass if 'instance' in kwargs.keys(): instance = kwargs['instance'] obj_pk = instance.pk content_type = ContentType.objects.get_for_model( kwargs['instance'].__class__) # guessed stuff user = None if 'user' in kwargs.keys(): user = kwargs['user'] else: if instance: user = get_user(instance) url = '' if 'url' in kwargs.keys(): url = kwargs['url'] else: if instance: url = get_url(instance) admin_url = '' if 'admin_url' in kwargs.keys(): admin_url = kwargs['admin_url'] else: if instance: admin_url = get_admin_url(instance) # request formated_request = '' if 'request' in kwargs.keys(): request = kwargs['request'] try: for key in request.META.keys(): formated_request += str(key) + ' : ' + \ str(request.META[key]) + '\n' except Exception: pass # static stuff event_class = '' if 'event_class' in kwargs.keys(): event_class = kwargs['event_class'] notes = '' if 'notes' in kwargs.keys(): notes = kwargs['notes'] if isinstance(user, AnonymousUser): user = None bucket = "" if 'bucket' in kwargs.keys(): bucket = kwargs["bucket"] data = {} if "data" in kwargs.keys(): data = kwargs["data"] # scope scope = "superuser" if "scope" in kwargs.keys(): scope = kwargs["scope"] # test if it is an allowed scope isok = False for s in SCOPE: if s[0] == scope: isok = True break if isok is False: msg = "Unable to create event: wrong scope provided: \ choices are: superuser, staff, users, public" MEvent.objects.create(name=msg, event_class="Error") return None # create te event mevent = MEvent( name=name, content_type=content_type, obj_pk=obj_pk, user=user, url=url, admin_url=admin_url, notes=notes, event_class=event_class, bucket=bucket, data=data, scope=scope, request=formated_request, ) # proceed hooks dispatch(mevent) # print info if settings.DEBUG: print(bcolors.SUCCESS + 'Event' + bcolors.ENDC + ' [' + mevent.event_class + '] : ' + name) # save by default unless it is said not to modelname = None if instance is not None: modelname = instance.__class__.__name__ if model is not None: modelname = model.__name__ if modelname is not None: if modelname in NOSAVE: return mevent if 'commit' in kwargs.keys(): if kwargs['commit'] is False: return mevent mevent.save(force_insert=True) return mevent
def create(self, *args, **kwargs): if not 'name' in kwargs.keys(): raise ValueError(u"You must provide a 'name' argument for the MEvent") else: name = kwargs['name'] obj_pk = None if 'obj_pk' in kwargs.keys() and not 'instance' in kwargs.keys(): obj_pk = kwargs['obj_pk'] content_type = None if 'model' in kwargs.keys() and not 'instance' in kwargs.keys(): content_type = ContentType.objects.get_for_model(kwargs['model']) #~ trying to grab an object instance in order to guess some fields instance = None if obj_pk and content_type and not 'instance' in kwargs.keys(): try: instance = content_type.get_object_for_this_type(pk=obj_pk) except: pass if 'instance' in kwargs.keys(): instance = kwargs['instance'] obj_pk = instance.pk content_type = ContentType.objects.get_for_model(kwargs['instance'].__class__) #~ guessed stuff user = None if 'user' in kwargs.keys(): user = kwargs['user'] else: if instance: user = get_user(instance) url = '' if 'url' in kwargs.keys(): url = kwargs['url'] else: if instance: url = get_url(instance) admin_url = '' if 'admin_url' in kwargs.keys(): admin_url = kwargs['admin_url'] else: if instance: admin_url = get_admin_url(instance) # request save_request = False if 'request' in kwargs.keys(): request = kwargs['request'] formated_request = '' for key in request.META.keys(): formated_request += str(key)+' : '+str(request.META[key])+'\n' save_request = True #~ static stuff event_class = '' if 'event_class' in kwargs.keys(): event_class = kwargs['event_class'] notes = '' if 'notes' in kwargs.keys(): notes = kwargs['notes'] mevent = MEvent(name=name, content_type=content_type, obj_pk=obj_pk, user=user, url=url, admin_url=admin_url, notes=notes, event_class=event_class) if save_request is True: mevent.request = formated_request # save by default unless it is said not to if 'commit' in kwargs.keys(): if kwargs['commit'] is False: return mevent else: mevent.save(force_insert=True) return mevent
def create(self, *args, **kwargs): if 'name' not in kwargs.keys(): raise ValueError( u"You must provide a 'name' argument for the MEvent") else: name = kwargs['name'] obj_pk = None if 'obj_pk' in kwargs.keys() and 'instance' not in kwargs.keys(): obj_pk = kwargs['obj_pk'] content_type = None if 'model' in kwargs.keys() and 'instance' not in kwargs.keys(): content_type = ContentType.objects.get_for_model(kwargs['model']) # trying to grab an object instance in order to guess some fields instance = None if obj_pk and content_type and 'instance' not in kwargs.keys(): try: instance = content_type.get_object_for_this_type(pk=obj_pk) except: pass if 'instance' in kwargs.keys(): instance = kwargs['instance'] obj_pk = instance.pk content_type = ContentType.objects.get_for_model( kwargs['instance'].__class__) # guessed stuff user = None if 'user' in kwargs.keys(): user = kwargs['user'] else: if instance: user = get_user(instance) url = '' if 'url' in kwargs.keys(): url = kwargs['url'] else: if instance: url = get_url(instance) admin_url = '' if 'admin_url' in kwargs.keys(): admin_url = kwargs['admin_url'] else: if instance: admin_url = get_admin_url(instance) # request save_request = False if 'request' in kwargs.keys(): request = kwargs['request'] formated_request = '' try: for key in request.META.keys(): formated_request += str(key) + ' : ' + \ str(request.META[key]) + '\n' save_request = True except: pass # static stuff event_class = '' if 'event_class' in kwargs.keys(): event_class = kwargs['event_class'] notes = '' if 'notes' in kwargs.keys(): notes = kwargs['notes'] if isinstance(user, AnonymousUser): user = None bucket = "" if 'bucket' in kwargs.keys(): bucket = kwargs["bucket"] data = {} if "data" in kwargs.keys(): data = kwargs["data"] # scope scope = "superuser" if "scope" in kwargs.keys(): scope = kwargs["scope"] # test if it is an allowed scope isok = False for s in SCOPE: if s[0] == scope: isok = True break if isok is False: msg = "Unable to create event: wrong scope provided: \ choices are: superuser, staff, users, public" MEvent.objects.create(name=msg, event_class="Error") return None # create te event mevent = MEvent( name=name, content_type=content_type, obj_pk=obj_pk, user=user, url=url, admin_url=admin_url, notes=notes, event_class=event_class, bucket=bucket, data=data, scope=scope, ) if save_request is True: mevent.request = formated_request # proceed hooks dispatch(mevent) # print info if settings.DEBUG: print(bcolors.SUCCESS + 'Event' + bcolors.ENDC + ' [' + mevent.event_class + '] : ' + name) # save by default unless it is said not to modelname = "" if instance is not None: modelname = instance.__class__.__name__ if modelname in NOSAVE: return mevent if 'commit' in kwargs.keys(): if kwargs['commit'] is False: return mevent mevent.save(force_insert=True) return mevent