Ejemplo n.º 1
0
def __get_entity(topic_obj, **kwargs):
    # fail-proof entity retrieval function
    entity = None
    Model = get_topic_model(topic_obj, kwargs.get('type'))
    if Model:
        entity = Model.objects.get(pk=kwargs.get('pk'))
    return entity
Ejemplo n.º 2
0
def __get_entity(topic_obj, **kwargs):
    # fail-proof entity retrieval function
    entity = None
    Model = get_topic_model(topic_obj, kwargs.get('type'))
    if Model:
        entity = Model.objects.get(pk=kwargs.get('pk'))
    return entity
Ejemplo n.º 3
0
def entity_list(request, **kwargs):
    def __entity_type_name(entity_klass):
        type_name           = None
        verbose_name        = getattr(entity_klass, 'verbose_name', None)
        verbose_name_plural = getattr(entity_klass, 'verbose_name_plural', None)
        if verbose_name_plural:
            type_name = verbose_name_plural
        elif verbose_name:
            type_name = verbose_name + 's'
        else:
            type_name = entity_klass.__name__ + 's'
        return type_name

    def __entity_type_description(entity_klass):
        return getattr(entity_klass, 'help_text', None)

    meta_dict = None
    try:
        user      = __get_user(request, **kwargs)
        topic     = __get_topic(request, user, **kwargs)

        if not topic.public:
            return home(request, None, **kwargs)

        if topic.public and user:
            default_meta = default_social_meta(request)
            entity_klass = get_topic_model(topic, kwargs.get('type'))
            if entity_klass:
                pictures = []
                if topic.background:
                    pictures.append(topic.background)


                list_title = u"{name} of {topic} by {owner}".format(
                    name=__entity_type_name(entity_klass),
                    topic=topic.title,
                    owner=user.username
                )
                meta_title = u"{list_title} - {title}".format(
                    list_title=list_title,
                    title=APP_TITLE
                )
                meta_description = __entity_type_description(entity_klass) or \
                                   topic.description or default_meta['description']
                meta_dict = {
                    'title'       : meta_title,
                    'description' : meta_description,
                    'pictures'    : pictures,
                    'url'         : default_meta['url']
        }
        return home(request, meta_dict, **kwargs)

    except ObjectDoesNotExist as e:
        logger.debug("Tried to access a non-existing model %s" % e)
        return home(request, None, **kwargs)
Ejemplo n.º 4
0
def entity_list(request, **kwargs):
    def __entity_type_name(entity_klass):
        type_name = None
        verbose_name = getattr(entity_klass, 'verbose_name', None)
        verbose_name_plural = getattr(entity_klass, 'verbose_name_plural',
                                      None)
        if verbose_name_plural:
            type_name = verbose_name_plural
        elif verbose_name:
            type_name = verbose_name + 's'
        else:
            type_name = entity_klass.__name__ + 's'
        return type_name

    def __entity_type_description(entity_klass):
        return getattr(entity_klass, 'help_text', None)

    meta_dict = None
    try:
        user = __get_user(request, **kwargs)
        topic = __get_topic(request, user, **kwargs)

        if not topic.public:
            return main(request, None, **kwargs)

        if topic.public and user:
            default_meta = default_social_meta(request)
            entity_klass = get_topic_model(topic, kwargs.get('type'))
            if entity_klass:
                pictures = []
                if topic.background:
                    pictures.append(topic.background)

                list_title = u"{name} of {topic} by {owner}".format(
                    name=__entity_type_name(entity_klass),
                    topic=topic.title,
                    owner=user.username)
                meta_title = u"{list_title} - {title}".format(
                    list_title=list_title, title=APP_TITLE)
                meta_description = __entity_type_description(entity_klass) or \
                                   topic.description or default_meta['description']
                meta_dict = {
                    'title': meta_title,
                    'description': meta_description,
                    'pictures': pictures,
                    'url': default_meta['url']
                }
        return main(request, meta_dict, **kwargs)

    except ObjectDoesNotExist as e:
        logger.debug("Tried to access a non-existing model %s" % e)
        return main(request, None, **kwargs)