Ejemplo n.º 1
0
def knowledge_post_save(sender, instance, created, **kwargs):
    """
    Gathers all the responses for the sender's parent question
    and shuttles them to the predefined module.
    """
    from knowledge.models import Question, Response

    func = get_module(settings.ALERTS_FUNCTION_PATH)

    if settings.ALERTS and created:
        # pull together the out_dict:
        #    {'*****@*****.**': ('first last', '*****@*****.**') or <User>}
        if isinstance(instance, Response):
            instances = list(instance.question.get_responses())
            instances += [instance.question]

            # dedupe people who want alerts thanks to dict keys...
            out_dict = dict([[i.get_email(), i.get_user_or_pair()]
                            for i in instances if i.alert])

        elif isinstance(instance, Question):
            staffers = get_user_model().objects.filter(is_staff=True)
            out_dict = dict([[user.email, user] for user in staffers
                                if user.has_perm('change_question')])

        # remove the creator...
        if instance.get_email() in out_dict.keys():
            del out_dict[instance.get_email()]

        func(
            target_dict=out_dict,
            response=instance if isinstance(instance, Response) else None,
            question=instance if isinstance(instance, Question) else None
        )
Ejemplo n.º 2
0
def knowledge_post_save(sender, instance, created, **kwargs):
    """
    Gathers all the responses for the sender's parent question
    and shuttles them to the predefined module.
    """
    from knowledge.models import Question, Response
    from django.contrib.auth.models import User

    func = get_module(settings.ALERTS_FUNCTION_PATH)

    if settings.ALERTS and created:
        # pull together the out_dict:
        #    {'*****@*****.**': ('first last', '*****@*****.**') or <User>}
        if isinstance(instance, Response):
            instances = list(instance.question.get_responses())
            instances += [instance.question]

            # dedupe people who want alerts thanks to dict keys...
            out_dict = dict([[i.get_email(),
                              i.get_user_or_pair()] for i in instances
                             if i.alert])

        elif isinstance(instance, Question):
            staffers = User.objects.filter(is_staff=True)
            out_dict = dict([[user.email, user] for user in staffers
                             if user.has_perm('change_question')])

        # remove the creator...
        if instance.get_email() in list(out_dict.keys()):
            del out_dict[instance.get_email()]

        func(target_dict=out_dict,
             response=instance if isinstance(instance, Response) else None,
             question=instance if isinstance(instance, Question) else None)
Ejemplo n.º 3
0
def knowledge_post_save(sender, instance, created, **kwargs):
    """
    Gathers all the responses for the sender's parent question
    and shuttles them to the predefined module.
    """
    from knowledge.models import Question, Response, Category
    from django.contrib.auth.models import User

    func = get_module(settings.ALERTS_FUNCTION_PATH)
    logger.debug('SEND knowledge_post_save')
    if settings.ALERTS and created:
        # pull together the out_dict:
        #    {'*****@*****.**': ('first last', '*****@*****.**') or <User>}
        if isinstance(instance, Response):
            instances = list(instance.question.get_responses())
            instances += [instance.question]

            # dedupe people who want alerts thanks to dict keys...
            out_dict = dict([[i.get_email(),
                              i.get_user_or_pair()] for i in instances
                             if i.alert])

        elif isinstance(instance, Question):
            # TODO: отправка почты всем is_staff переделать на категории
            #staffers = User.objects.filter(is_staff=True)
            #out_dict = dict([[user.email, user] for user in staffers if user.has_perm('change_question')])
            try:
                cat_id = instance.categories.pk
            except:
                cat_id = 1
            logger.debug('>>> categories.id={0}'.format(cat_id))
            staffers = Category.objects.select_related().get(pk=cat_id)
            #staffers =Category.objects.select_related().get(Question.categories)
            out_dict = dict([[user['email'], user['username']]
                             for user in staffers.user.values()])

        # remove the creator...
        if instance.get_email() in out_dict.keys():
            del out_dict[instance.get_email()]

        func(target_dict=out_dict,
             response=instance if isinstance(instance, Response) else None,
             question=instance if isinstance(instance, Question) else None)
Ejemplo n.º 4
0
def knowledge_post_save(sender, instance, created, **kwargs):
    """
    Gathers all the responses for the sender's parent question
    and shuttles them to the predefined module.
    """
    from knowledge.models import Question, Response, Category
    from django.contrib.auth.models import User

    func = get_module(settings.ALERTS_FUNCTION_PATH)
    logger.debug('SEND knowledge_post_save')
    if settings.ALERTS and created:
        # pull together the out_dict:
        #    {'*****@*****.**': ('first last', '*****@*****.**') or <User>}
        if isinstance(instance, Response):
            instances = list(instance.question.get_responses())
            instances += [instance.question]

            # dedupe people who want alerts thanks to dict keys...
            out_dict = dict([[i.get_email(), i.get_user_or_pair()]
                            for i in instances if i.alert])

        elif isinstance(instance, Question):
            # TODO: отправка почты всем is_staff переделать на категории
            #staffers = User.objects.filter(is_staff=True)
            #out_dict = dict([[user.email, user] for user in staffers if user.has_perm('change_question')])
            try:
                cat_id = instance.categories.pk
            except:
                cat_id = 1
            logger.debug('>>> categories.id={0}'.format(cat_id))
            staffers = Category.objects.select_related().get(pk=cat_id)
            #staffers =Category.objects.select_related().get(Question.categories)
            out_dict = dict([[user['email'], user['username']] for user in staffers.user.values()])

        # remove the creator...
        if instance.get_email() in out_dict.keys():
            del out_dict[instance.get_email()]

        func(
            target_dict=out_dict,
            response=instance if isinstance(instance, Response) else None,
            question=instance if isinstance(instance, Question) else None
        )
Ejemplo n.º 5
0
def response_post_save(response, created):
    """
    Gathers all the responses for the sender's parent question
    and shuttles them to the predefined module.

    For some reason I get crazy errors for a standard Django 
    signal. Will revisit.
    """
    func = get_module(settings.ALERTS_FUNCTION_PATH)

    if settings.ALERTS and created:
        # pull together the instances (could be question or response)
        instances = list(response.question.get_responses())
        instances += [response.question]

        # dedupe people who want alerts thanks to dict keys...
        out_dict = dict([[i.get_email(), i.get_user_or_pair()] 
                        for i in instances if i.alert])

        # remove the creator...
        if response.get_email() in out_dict.keys():
            del out_dict[response.get_email()]

        func(out_dict, response)
Ejemplo n.º 6
0
    def test_importer_basic(self):
        from django.template.defaultfilters import slugify
        sluggy = get_module('django.template.defaultfilters.slugify')

        self.assertTrue(slugify is sluggy)
Ejemplo n.º 7
0
    def test_importer_basic(self):
        from django.template.defaultfilters import slugify
        sluggy = get_module('django.template.defaultfilters.slugify')

        self.assertTrue(slugify is sluggy)