def test_utils_get_object_name(self): # test unicode method instance, created = MEvent.objects.get_or_create(name="Event name") user = User.objects.create_user('myuser', '*****@*****.**', 'super_password') object_name = get_object_name(instance, user) res = instance.__class__.__name__ + ' ' + instance.__unicode__()[:45] + '...' + ' (' + user.username + ')' self.assertEqual(object_name, res) # test name FakeModel.objects.create(name='123') instance = FakeModel.objects.get(name='123') res = instance.__class__.__name__ + ' ' + instance.name + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res) # test title FakeModelTitle.objects.create(title='123') instance = FakeModelTitle.objects.get(title='123') res = instance.__class__.__name__ + ' ' + instance.title + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res) # test slug FakeModelSlug.objects.create(slug='123') instance = FakeModelSlug.objects.get(slug='123') res = instance.__class__.__name__ + ' ' + instance.slug + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res) # test pk instance, created = FakeModelEmpty.objects.get_or_create() res = instance.__class__.__name__ + ' ' + str(instance.pk) + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res)
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' #~ 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): 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' 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 test_utils_get_object_name(self): self.reset() # test unicode method instance, _ = MEvent.objects.get_or_create(name="Event name") user = self.user object_name = get_object_name(instance, user) res = instance.__class__.__name__ + ' - ' + \ str(instance.date_posted) + ' (' + user.username + ')' self.assertEqual(object_name, res) # test name MEvent.objects.create(name='123') instance = MEvent.objects.get(name='123') res = instance.__class__.__name__ + ' - ' + \ str(instance.date_posted) + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res) self.reset()
def test_utils_get_object_name(self): # test unicode method instance, created = MEvent.objects.get_or_create(name="Event name") user = User.objects.create_user('myuser', '*****@*****.**', 'super_password') object_name = get_object_name(instance, user) res = instance.__class__.__name__ + ' ' + \ instance.__unicode__()[:45] + '...' + ' (' + user.username + ')' self.assertEqual(object_name, res) # test name FakeModel.objects.create(name='123') instance = FakeModel.objects.get(name='123') res = instance.__class__.__name__ + ' ' + \ instance.name + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res) # test title FakeModelTitle.objects.create(title='123') instance = FakeModelTitle.objects.get(title='123') res = instance.__class__.__name__ + ' ' + \ instance.title + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res) # test slug FakeModelSlug.objects.create(slug='123') instance = FakeModelSlug.objects.get(slug='123') res = instance.__class__.__name__ + ' ' + \ instance.slug + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res) # test pk instance, created = FakeModelEmpty.objects.get_or_create() res = instance.__class__.__name__ + ' ' + \ str(instance.pk) + ' (' + user.username + ')' object_name = get_object_name(instance, user) self.assertEqual(object_name, res)
def mmessage_delete(sender, instance, **kwargs): # try to get the user user = get_user(instance) # try to get the object name obj_name = get_object_name(instance, user) event_class = instance.__class__.__name__ + ' deleted' # create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=user, event_class=event_class, ) 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_delete(sender, instance, **kwargs): #~ try to get the user user = get_user(instance) #~ try to get the object name obj_name = get_object_name(instance, user) #~ check for object level monitoring event_class = instance.__class__.__name__+' deleted' #~ create event MEvent.objects.create( model = instance.__class__, name = obj_name, obj_pk = instance.pk, user = user, event_class = event_class, ) if settings.DEBUG: print bcolors.WARNING+'Event'+bcolors.ENDC+' : object '+obj_name+' deleted' return
def mmessage_delete(sender, instance, **kwargs): #~ try to get the user user = get_user(instance) #~ try to get the object name obj_name = get_object_name(instance, user) #~ check for object level monitoring event_class = instance.__class__.__name__ + ' deleted' #~ create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=user, event_class=event_class, ) if settings.DEBUG: print bcolors.WARNING + 'Event' + bcolors.ENDC + ' : object ' + obj_name + ' deleted' 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_delete(sender, instance, **kwargs): # try to get the user user = get_user(instance) # try to get the object name obj_name = get_object_name(instance, user) event_class = instance.__class__.__name__ + ' deleted' # create event MEvent.objects.create( model=instance.__class__, name=obj_name, obj_pk=instance.pk, user=user, event_class=event_class, ) if LIVE_FEED is True and STREAM_MODELS is True: data = {"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.WARNING + 'Event' + bcolors.ENDC + ' : object ' + obj_name + ' deleted' 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