def notify_object_changed(sender, instance, changes, *args, **kwargs): """Generates an activity related to the change of an existing object. """ author = LoggedInUserCache().user title = _("%(class)s %(name)s changed") context = { "class": sender.__name__.lower(), "name": "%s" % instance, "link": instance.get_absolute_url(), "changes": changes } if author: title = _("%(class)s %(name)s changed by %(author)s") context.update({ "author": "%s" % author, "author_link": author.get_absolute_url() }) activity = Activity.objects.create( title=title, signature="%s-changed" % sender.__name__.lower(), template="notifications/activities/object-changed.html", context=json.dumps(context), backlink=instance.get_absolute_url(), source=instance)
def notify_object_created(sender, instance, *args, **kwargs): """Generates an activity related to the creation of a new object. """ if kwargs['created']: author = LoggedInUserCache().user title = _("%(class)s %(name)s created") context = { "class": sender.__name__.lower(), "name": "%s" % instance, "link": instance.get_absolute_url(), } if author: title = _("%(class)s %(name)s created by %(author)s") context.update({ "author": "%s" % author, "author_link": author.get_absolute_url() }) activity = Activity.objects.create( title=title, signature="%s-created" % sender.__name__.lower(), template="notifications/activities/object-created.html", context=json.dumps(context), backlink=instance.get_absolute_url(), source=instance )
def create_bookmarks(instance): """Creates a new bookmarks list for the given object. """ from djangoerp.core.cache import LoggedInUserCache logged_cache = LoggedInUserCache() current_user = logged_cache.user if isinstance(instance, get_user_model()): logged_cache.user = instance kls = instance.__class__ bookmarks, is_new = Menu.objects.get_or_create(slug=get_bookmarks_slug_for(instance), description="Bookmarks for %s:%s" % (kls.__name__, instance.pk)) logged_cache.user = current_user return bookmarks, is_new
def create_dashboard(sender, instance, *args, **kwargs): """Creates a new dashboard for the given object. """ from djangoerp.core.cache import LoggedInUserCache logged_cache = LoggedInUserCache() current_user = logged_cache.user if isinstance(instance, get_user_model()): logged_cache.user = instance model_ct = ContentType.objects.get_for_model(cls) dashboard, is_new = Region.objects.get_or_create( slug="%s_%d_dashboard" % (model_ct.model, instance.pk), title=default_title, content_type=model_ct, object_id=instance.pk) logged_cache.user = current_user
def create_dashboard(sender, instance, *args, **kwargs): """Creates a new dashboard for the given object. """ from djangoerp.core.cache import LoggedInUserCache logged_cache = LoggedInUserCache() current_user = logged_cache.user if isinstance(instance, get_user_model()): logged_cache.user = instance model_ct = ContentType.objects.get_for_model(cls) dashboard, is_new = Region.objects.get_or_create( slug="%s_%d_dashboard" % (model_ct.model, instance.pk), title=default_title, content_type=model_ct, object_id=instance.pk ) logged_cache.user = current_user
# -*- coding: utf-8 -*- from __future__ import unicode_literals """This file is part of the django ERP project. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ __author__ = 'Emanuele Bertoldi <*****@*****.**>' __copyright__ = 'Copyright (c) 2013-2015, django ERP Team' __version__ = '0.0.5' from djangoerp.core.backends import ObjectPermissionBackend from djangoerp.core.cache import LoggedInUserCache ob = ObjectPermissionBackend() logged_cache = LoggedInUserCache() class FakeRequest(object): def __init__(self): self.META = { 'HTTP_HOST': "myhost.com", 'HTTP_REFERER': "http://myhost.com/bookmarks/" }