Ejemplo n.º 1
0
def private_message(request, uid):
    "General moderation function"
    user   = request.user
    target = models.User.objects.get(id=uid)

    # TODO allow users to opt out from getting messages

    # get the message from the body
    text  = request.POST.get("message","").strip()[:1500]
    text  = html.generate(text)
    text  = html.sanitize(text)
    if not text:
        messages.error(request, 'Empty message')
    else:
        content = "PM to %s: %s" % (notegen.userlink(target), text)
        models.send_note(target=user, content=content, sender=user, both=False, unread=False, type=NOTE_PRIVATE, url=user.profile.get_absolute_url() )

        content = "PM from %s: %s" % (notegen.userlink(user), text)
        models.send_note(target=target, content=content, sender=user, both=False, type=NOTE_PRIVATE, url=user.profile.get_absolute_url() )

        tasks.send_test_email()

        messages.info(request, 'Your private message to <b>%s</b> has been sent!' % target.profile.display_name)

    return html.redirect( target.profile.get_absolute_url() )
Ejemplo n.º 2
0
def verify_post(sender, instance, *args, **kwargs):
    "Pre save post information that needs to be applied"

    # change type to integer
    instance.type = int(instance.type)

    if not hasattr(instance, "lastedit_user"):
        instance.lastedit_user = instance.author

    # these types must have valid parents
    if instance.type not in POST_TOPLEVEL:
        assert instance.root and instance.parent, "Instance must have parent/root"

    now = datetime.now()

    instance.creation_date = instance.creation_date or now
    if instance.lastedit_date is None:
        instance.lastedit_date = instance.creation_date
    instance.lastedit_date = instance.lastedit_date or now

    # assings the rank of the instance
    instance.set_rank()

    # generate a slug for the instance
    instance.slug = slugify(instance.title)

    # generate the HTML from the content
    instance.html = html.generate(instance.content)

    # lower case the tags
    instance.tag_val = instance.tag_val.lower()

    # post gets flagged as changed on saving
    instance.changed = True
Ejemplo n.º 3
0
def verify_post(sender, instance, *args, **kwargs):
    "Pre save post information that needs to be applied"
    
    # change type to integer
    instance.type = int(instance.type)

    if not hasattr(instance, 'lastedit_user'):
        instance.lastedit_user = instance.author
    
    # these types must have valid parents
    if instance.type not in POST_TOPLEVEL:
        assert instance.root and instance.parent, "Instance must have parent/root"

    now = datetime.now()
    
    instance.creation_date = instance.creation_date or now
    if instance.lastedit_date is None:
        instance.lastedit_date = instance.creation_date
    instance.lastedit_date = instance.lastedit_date or now
    
    # assings the rank of the instance
    instance.set_rank()

    # generate the HTML from the content
    instance.html = html.generate(instance.content)

    # lower case the tags
    instance.tag_val = instance.tag_val.lower()

    # post gets flagged as changed on saving
    instance.changed = True
Ejemplo n.º 4
0
def preview(request):
    "This runs the markdown preview functionality"
    content = request.POST.get('content','no input')[:5000]

    try:
        output = html.generate(content)
    except KeyError, exc:
        # return more userfriendly errors, used for debugging
        output = 'Error: %s' % str(exc)
Ejemplo n.º 5
0
def private_message(request, uid):
    "General moderation function"
    user   = request.user
    target = models.User.objects.get(id=uid)

    # TODO allow users to opt out from getting messages

    # get the message from the body
    text  = request.POST.get("message","").strip()[:1500]
    text  = html.generate(text)
    text  = html.sanitize(text)
    if not text:
        messages.error(request, 'Empty message')
    else:
        content = "PM to %s: %s" % (notegen.userlink(target), text)
        models.send_note(target=user, content=content, sender=user, both=False, unread=False, type=NOTE_PRIVATE, url=user.profile.get_absolute_url() )

        content = "PM from %s: %s" % (notegen.userlink(user), text)
        models.send_note(target=target, content=content, sender=user, both=False, type=NOTE_PRIVATE, url=user.profile.get_absolute_url() )

        messages.info(request, 'Your private message to <b>%s</b> has been sent!' % target.profile.display_name)

    return html.redirect( target.profile.get_absolute_url() )
Ejemplo n.º 6
0
def verify_post(sender, instance, *args, **kwargs):
    "Pre save post information that needs to be applied"
    
    # change type to integer
    instance.type = int(instance.type)

    if not hasattr(instance, 'lastedit_user'):
        instance.lastedit_user = instance.author
    
    # these types must have valid parents
    if instance.type not in POST_TOPLEVEL:
        assert instance.root and instance.parent, "Instance must have parent/root"

    now = datetime.now()
    
    instance.creation_date = instance.creation_date or now
    if instance.lastedit_date is None:
        instance.lastedit_date = instance.creation_date
    instance.lastedit_date = instance.lastedit_date or now
    
    # attempts to create a rank that is no more than 5 levels lower than the highest ranked post
    def get_rank(post):
        now = time.mktime(post.creation_date.timetuple())
        ranks = list(Post.objects.filter(type=post.type).values_list('rank', flat=True).order_by('-rank')[:1]) + [ now ]
        ranks = sorted(ranks, reverse=True)
        return ranks[0]
            
    instance.rank = instance.rank or get_rank(instance)
    
    # generate a slug for the instance        
    instance.slug = slugify(instance.title)
        
    # generate the HTML from the content
    instance.html = html.generate(instance.content.strip())

    # post gets flagged as changed on saving
    instance.changed = True
Ejemplo n.º 7
0
def verify_note(sender, instance, *args, **kwargs):
    "Pre save notice function"
    instance.date = instance.date or datetime.now()
    instance.html = html.generate(instance.content)
Ejemplo n.º 8
0
def update_profile(sender, instance, *args, **kwargs):
    "Pre save hook for profiles"
    instance.about_me_html = html.generate(instance.about_me)
Ejemplo n.º 9
0
 def html(self):
     """We won't cache the HTML in the DB because revisions are viewed fairly infrequently """
     return html.generate(self.content)
Ejemplo n.º 10
0
def verify_note(sender, instance, *args, **kwargs):
    "Pre save notice function"
    instance.date = instance.date or datetime.now()
    instance.html = html.generate(instance.content)
Ejemplo n.º 11
0
def update_profile(sender, instance, *args, **kwargs):
    "Pre save hook for profiles"
    instance.about_me_html = html.generate(instance.about_me)
Ejemplo n.º 12
0
 def html(self):
     '''We won't cache the HTML in the DB because revisions are viewed fairly infrequently '''
     return html.generate(self.content)