Ejemplo n.º 1
0
from openPLM.plmapp.models.plmobject import *
from openPLM.plmapp.models.part import *
from openPLM.plmapp.models.document import *
from openPLM.plmapp.models.history import *
from openPLM.plmapp.models.link import *

# monkey patch Comment models to select related fields
from django.contrib.comments.models import Comment
from django.contrib.comments.managers import CommentManager

class CommentManager(CommentManager):
    def get_query_set(self):
        return (super(CommentManager, self)
            .get_query_set()
            .select_related('user', 'user__profile'))
Comment.add_to_class('objects', CommentManager())

# import_models should be the last function

def import_models(force_reload=False):
    u"""
    Imports recursively all modules in directory *plmapp/customized_models*
    """

    MODELS_DIR = "customized_models"
    IMPORT_ROOT = "openPLM.plmapp.%s" % MODELS_DIR
    if __name__ != "openPLM.plmapp.models":
        # this avoids to import models twice
        return
    if force_reload or not hasattr(import_models, "done"):
        import_models.done = True
Ejemplo n.º 2
0
from openPLM.plmapp.models.document import *
from openPLM.plmapp.models.history import *
from openPLM.plmapp.models.link import *

# monkey patch Comment models to select related fields
from django.contrib.comments.models import Comment
from django.contrib.comments.managers import CommentManager


class CommentManager(CommentManager):
    def get_query_set(self):
        return (super(CommentManager, self).get_query_set().select_related(
            'user', 'user__profile'))


Comment.add_to_class('objects', CommentManager())

# import_models should be the last function


def import_models(force_reload=False):
    u"""
    Imports recursively all modules in directory *plmapp/customized_models*
    """

    MODELS_DIR = "customized_models"
    IMPORT_ROOT = "openPLM.plmapp.%s" % MODELS_DIR
    if __name__ != "openPLM.plmapp.models":
        # this avoids to import models twice
        return
    if force_reload or not hasattr(import_models, "done"):
Ejemplo n.º 3
0
        to count these vs doing a count db call
        """
        comments = []
        for comment in self.get_query_set():
            if getattr(settings, 'COMMENTS_HIDE_REMOVED', True):
                if not comment.is_removed and comment.is_public:
                    comments.append(comment)
            elif comment.is_public:
                comments.append(comment)

        return len(comments)

    

# add additional fields onto the comment model
Comment.add_to_class('uuid', UUIDField())
Comment.add_to_class('created', models.DateTimeField(auto_now_add=True, editable = False, blank = True, null = True))
Comment.add_to_class('modified', models.DateTimeField(auto_now=True, blank = True, null = True))
Comment.add_to_class('parent', models.ForeignKey('self', related_name = 'children', blank = True, null = True))
Comment.add_to_class('type', models.CharField(max_length = 255, blank = True, null = True))
Comment.add_to_class('data', PickleField(blank = True, null = True))

# additional methods
Comment.add_to_class('template', get_comment_template)
Comment.add_to_class('get_css_class', get_css_class)
Comment.add_to_class('set_comment_template_dir', set_comment_template_dir)
Comment.add_to_class('get_reply_form', get_reply_form)
Comment.add_to_class('_default_manager', PrimerCommentManager())


Ejemplo n.º 4
0
    def likes_anonymous(self):
        return len(Like.objects.get_likes_anonymous(self))


tagging.register(Post)

    # TODO: update post last modified date upon new like signal (and remove from views.add_like)
    # TODO: add 'via_service' foreign key


class Like(Tracked, OwnableSometimes, GenericObject):
    """
    User and anonymous likes for objects
    """
    objects = LikeManager()


@property
def get_comment_likes(self):
    return Like.objects.get_likes(self)
Comment.add_to_class('likes', get_comment_likes)

@property
def get_comment_likes_users(self):
    return [like.user for like in Like.objects.get_likes_users(self)]
Comment.add_to_class('likes_users', get_comment_likes_users)


from .signals import *
Ejemplo n.º 5
0
        Since we have a prefetch related cache, it doesnt cost us another db hit
        to count these vs doing a count db call
        """
        comments = []
        for comment in self.get_query_set():
            if getattr(settings, 'COMMENTS_HIDE_REMOVED', True):
                if not comment.is_removed and comment.is_public:
                    comments.append(comment)
            elif comment.is_public:
                comments.append(comment)

        return len(comments)


# add additional fields onto the comment model
Comment.add_to_class('uuid', UUIDField())
Comment.add_to_class(
    'created',
    models.DateTimeField(auto_now_add=True,
                         editable=False,
                         blank=True,
                         null=True))
Comment.add_to_class(
    'modified', models.DateTimeField(auto_now=True, blank=True, null=True))
Comment.add_to_class(
    'parent',
    models.ForeignKey('self', related_name='children', blank=True, null=True))
Comment.add_to_class('type',
                     models.CharField(max_length=255, blank=True, null=True))
Comment.add_to_class('data', PickleField(blank=True, null=True))
Ejemplo n.º 6
0
            'Su comentario sobre el evento') + ' "' + evento.nombre + '" ' + _(
                'ha sido aprobado y publicado en:'
            ) + '\n' + site.domain + '/comentario/' + str(
                evento.id) + '/\n\n' + _('Gracias...')

    else:
        asunto = _(u'Nuevo comentario en lista de moderación')
        para = [evento.email]
        mensaje = _('Un nuevo comentario sobre el evento'
                    ) + ' "' + evento.nombre + '" ' + _(
                        'se encuentra en espera para ser aprobado en:'
                    ) + '\n' + site.domain + '/admin/comments/comment/' + str(
                        instance.id) + '/\n\n' + _('Gracias...')

    try:
        email.enviar_mail(asunto, mensaje, evento.email, para)
    except Exception, error:
        pass


def pp(sender, comment, request, **kwargs):
    global EVENTO
    EVENTO = int(request.POST['instancia_evento'])


comment_will_be_posted.connect(pp)
pre_save.connect(pre_save_comment, sender=Comment)
post_save.connect(post_save_comment, sender=Comment)

Comment.add_to_class('instancia_evento',
                     models.ForeignKey(Evento, verbose_name=_(u'Evento')))