Exemplo n.º 1
0
def create_default_ranks(apps, schema_editor):
    Rank = apps.get_model('misago_users', 'Rank')

    team = Rank.objects.create(
        name=_("Forum team"),
        slug=slugify(_("Forum team")),
        title=_("Team"),
        css_class='team',
        is_tab=True,
        is_on_index=True,
        order=0)

    member = Rank.objects.create(
        name=_("Members"),
        slug=slugify(_("Members")),
        is_default=True,
        order=1)

    Role = apps.get_model('misago_acl', 'Role')

    team.roles.add(Role.objects.get(name=_("Moderator")))
    team.roles.add(Role.objects.get(name=_("Private threads moderator")))
    team.roles.add(Role.objects.get(name=_("Deleting users")))

    member.roles.add(Role.objects.get(name=_("Private threads")))
Exemplo n.º 2
0
def create_default_ranks(apps, schema_editor):
    Rank = apps.get_model('misago_users', 'Rank')

    team = Rank.objects.create(
        name=gettext("Forum team"),
        slug=slugify(gettext("Forum team")),
        title=gettext("Team"),
        css_class='primary',
        is_tab=True,
        order=0,
    )

    member = Rank.objects.create(
        name=gettext("Members"),
        slug=slugify(gettext("Members")),
        is_default=True,
        order=1,
    )

    Role = apps.get_model('misago_acl', 'Role')

    team.roles.add(Role.objects.get(name=_("Moderator")))
    team.roles.add(Role.objects.get(name=_("Private threads")))
    team.roles.add(Role.objects.get(name=_("Private threads moderator")))
    team.roles.add(Role.objects.get(name=_("Deleting users")))

    member.roles.add(Role.objects.get(name=_("Private threads")))
Exemplo n.º 3
0
def post_thread(
        category,
        title='Test thread',
        poster='Tester',
        is_global=False,
        is_pinned=False,
        is_unapproved=False,
        is_hidden=False,
        is_closed=False,
        started_on=None
):
    started_on = started_on or timezone.now()

    kwargs = {
        'category': category,
        'title': title,
        'slug': slugify(title),
        'started_on': started_on,
        'last_post_on': started_on,
        'is_unapproved': is_unapproved,
        'is_hidden': is_hidden,
        'is_closed': is_closed,
    }

    if is_global:
        kwargs['weight'] = 2
    elif is_pinned:
        kwargs['weight'] = 1

    try:
        kwargs.update({
            'starter': poster,
            'starter_name': poster.username,
            'starter_slug': poster.slug,
            'last_poster': poster,
            'last_poster_name': poster.username,
            'last_poster_slug': poster.slug,
        })
    except AttributeError:
        kwargs.update({
            'starter_name': poster,
            'starter_slug': slugify(poster),
            'last_poster_name': poster,
            'last_poster_slug': slugify(poster),
        })

    thread = Thread.objects.create(**kwargs)
    reply_thread(
        thread,
        poster=poster,
        posted_on=started_on,
        is_hidden=is_hidden,
        is_unapproved=is_unapproved,
    )

    return thread
Exemplo n.º 4
0
def post_thread(category,
                title='Test thread',
                poster='Tester',
                is_global=False,
                is_pinned=False,
                is_unapproved=False,
                is_hidden=False,
                is_closed=False,
                started_on=None):
    started_on = started_on or timezone.now()

    kwargs = {
        'category': category,
        'title': title,
        'slug': slugify(title),
        'started_on': started_on,
        'last_post_on': started_on,
        'is_unapproved': is_unapproved,
        'is_hidden': is_hidden,
        'is_closed': is_closed,
    }

    if is_global:
        kwargs['weight'] = 2
    elif is_pinned:
        kwargs['weight'] = 1

    try:
        kwargs.update({
            'starter': poster,
            'starter_name': poster.username,
            'starter_slug': poster.slug,
            'last_poster': poster,
            'last_poster_name': poster.username,
            'last_poster_slug': poster.slug,
        })
    except AttributeError:
        kwargs.update({
            'starter_name': poster,
            'starter_slug': slugify(poster),
            'last_poster_name': poster,
            'last_poster_slug': slugify(poster),
        })

    thread = Thread.objects.create(**kwargs)
    reply_thread(
        thread,
        poster=poster,
        posted_on=thread.last_post_on,
        is_hidden=is_hidden,
        is_unapproved=is_unapproved,
    )

    return thread
def create_default_categories_tree(apps, schema_editor):
    Category = apps.get_model('misago_categories', 'Category')

    Category.objects.create(
        special_role='private_threads',
        name='Private',
        slug='private',
        lft=1,
        rght=2,
        tree_id=0,
        level=0,
    )

    root = Category.objects.create(
        special_role='root_category',
        name='Root',
        slug='root',
        lft=3,
        rght=6,
        tree_id=1,
        level=0,
    )

    category_name = _("First category")

    Category.objects.create(
        parent=root,
        lft=4,
        rght=5,
        tree_id=1,
        level=1,
        name=category_name,
        slug=slugify(category_name),
    )
 def add_text(self, name, value, date=None, directory=None):
     clean_filename = slugify(str(name))
     file_dir_path = self.make_final_path(date=date, directory=directory)
     file_path = os.path.join(file_dir_path, '{}.txt'.format(clean_filename))
     with open(file_path, 'w') as fp:
         fp.write(str(value))
         return file_path
Exemplo n.º 7
0
    def test_anonymize_data(self):
        """anonymize_data sets username and slug to one defined in settings"""
        user = User.objects.create_user('Bob', '*****@*****.**', 'Pass.123')

        user.anonymize_data()
        self.assertEqual(user.username, settings.MISAGO_ANONYMOUS_USERNAME)
        self.assertEqual(user.slug, slugify(settings.MISAGO_ANONYMOUS_USERNAME))
Exemplo n.º 8
0
def create_default_categories_tree(apps, schema_editor):
    Category = apps.get_model('misago_categories', 'Category')

    Category.objects.create(
        special_role='private_threads',
        name='Private',
        slug='private',
        lft=1,
        rght=2,
        tree_id=0,
        level=0,
    )

    root = Category.objects.create(
        special_role='root_category',
        name='Root',
        slug='root',
        lft=3,
        rght=6,
        tree_id=1,
        level=0,
    )

    category_name = _("First category")

    category = Category.objects.create(
        parent=root,
        lft=4,
        rght=5,
        tree_id=1,
        level=1,
        name=category_name,
        slug=slugify(category_name),
        css_class='accent'
    )
def like_post(post, liker=None, username=None):
    if not post.last_likes:
        post.last_likes = []

    if liker:
        like = post.postlike_set.create(
            category=post.category,
            thread=post.thread,
            liker=liker,
            liker_name=liker.username,
            liker_slug=liker.slug,
        )

        post.last_likes = [{
            'id': liker.id,
            'username': liker.username,
        }] + post.last_likes
    else:
        like = post.postlike_set.create(
            category=post.category,
            thread=post.thread,
            liker_name=username,
            liker_slug=slugify(username),
        )

        post.last_likes = [{
            'id': None,
            'username': username,
        }] + post.last_likes

    post.likes += 1
    post.save()

    return like
Exemplo n.º 10
0
    def anonymize_content(self):
        # Replace username on associated items with anonymous one
        self.username = settings.MISAGO_ANONYMOUS_USERNAME
        self.slug = slugify(self.username)

        from misago.users.signals import anonymize_user_content
        anonymize_user_content.send(sender=self)
Exemplo n.º 11
0
    def __call__(self, value):
        slug = slugify(value)

        if not slug.replace('-', ''):
            raise ValidationError(self.error_short)

        if len(slug) > 255:
            raise ValidationError(self.error_long)
Exemplo n.º 12
0
def post_thread(forum,
                title='Test thread',
                poster='Tester',
                is_pinned=False,
                is_moderated=False,
                is_hidden=False,
                is_closed=False,
                started_on=None):
    started_on = started_on or timezone.now()

    kwargs = {
        'forum': forum,
        'title': title,
        'slug': slugify(title),
        'started_on': started_on,
        'last_post_on': started_on,
        'is_pinned': is_pinned,
        'is_moderated': is_moderated,
        'is_hidden': is_hidden,
        'is_closed': is_closed,
    }

    try:
        kwargs.update({
            'starter': poster,
            'starter_name': poster.username,
            'starter_slug': poster.slug,
            'last_poster': poster,
            'last_poster_name': poster.username,
            'last_poster_slug': poster.slug,
        })
    except AttributeError:
        kwargs.update({
            'starter_name': poster,
            'starter_slug': slugify(poster),
            'last_poster_name': poster,
            'last_poster_slug': slugify(poster),
        })

    thread = Thread.objects.create(**kwargs)
    reply_thread(thread,
                 poster=poster,
                 posted_on=thread.last_post_on,
                 is_moderated=is_moderated)

    return thread
Exemplo n.º 13
0
 def set_last_post(self, post):
     self.last_post_on = post.posted_on
     self.last_post = post
     self.last_poster = post.poster
     self.last_poster_name = post.poster_name
     if post.poster:
         self.last_poster_slug = post.poster.slug
     else:
         self.last_poster_slug = slugify(post.poster_name)
Exemplo n.º 14
0
    def set_username(self, new_username, changed_by=None):
        if new_username != self.username:
            old_username = self.username
            self.username = new_username
            self.slug = slugify(new_username)

            if self.pk:
                changed_by = changed_by or self
                self.record_name_change(changed_by, new_username, old_username)
                username_changed.send(sender=self)
Exemplo n.º 15
0
def create_default_forums_tree(apps, schema_editor):
    Forum = apps.get_model("misago_forums", "Forum")

    Forum.objects.create(
        special_role="private_threads", role="forum", name="Private", slug="private", lft=1, rght=2, tree_id=0, level=0
    )

    root = Forum.objects.create(
        special_role="root_category", role="category", name="Root", slug="root", lft=3, rght=10, tree_id=1, level=0
    )

    category_name = _("First category")
    forum_name = _("First forum")
    redirect_name = _("Misago support forums")
    redirect_link = _("http://misago-project.org")

    category = Forum.objects.create(
        parent=root,
        lft=4,
        rght=9,
        tree_id=1,
        level=1,
        role="category",
        name=category_name,
        slug=slugify(category_name),
        css_class="accent",
    )

    Forum.objects.create(
        parent=category, lft=5, rght=6, tree_id=1, level=2, role="forum", name=forum_name, slug=slugify(forum_name)
    )

    Forum.objects.create(
        parent=category,
        lft=7,
        rght=8,
        tree_id=1,
        level=2,
        role="redirect",
        name=redirect_name,
        slug=slugify(redirect_name),
        redirect_url=redirect_link,
    )
Exemplo n.º 16
0
    def set_username(self, new_username, changed_by=None):
        if new_username != self.username:
            old_username = self.username
            self.username = new_username
            self.slug = slugify(new_username)

            if self.pk:
                changed_by = changed_by or self
                self.record_name_change(changed_by, new_username, old_username)
                username_changed.send(sender=self)
Exemplo n.º 17
0
    def anonymize_content(self):
        """Replaces username with anonymized one, then send anonymization signal.

        Items associated with this user then anonymize their user-specific data
        like username or IP addresses.
        """
        self.username = settings.MISAGO_ANONYMOUS_USERNAME
        self.slug = slugify(self.username)

        from misago.users.signals import anonymize_user_content
        anonymize_user_content.send(sender=self)
Exemplo n.º 18
0
def post_thread(forum, title='Test thread', poster='Tester', is_pinned=False,
                is_moderated=False, is_hidden=False, is_closed=False,
                started_on=None):
    started_on = started_on or timezone.now()

    kwargs = {
        'forum': forum,
        'title': title,
        'slug': slugify(title),
        'started_on': started_on,
        'last_post_on': started_on,
        'is_pinned': is_pinned,
        'is_moderated': is_moderated,
        'is_hidden': is_hidden,
        'is_closed': is_closed,
    }

    try:
        kwargs.update({
            'starter': poster,
            'starter_name': poster.username,
            'starter_slug': poster.slug,
            'last_poster': poster,
            'last_poster_name': poster.username,
            'last_poster_slug': poster.slug,
            })
    except AttributeError:
        kwargs.update({
            'starter_name': poster,
            'starter_slug': slugify(poster),
            'last_poster_name': poster,
            'last_poster_slug': slugify(poster),
        })

    thread = Thread.objects.create(**kwargs)
    reply_thread(thread,
        poster=poster,
        posted_on=thread.last_post_on,
        is_moderated=is_moderated)

    return thread
Exemplo n.º 19
0
    def set_first_post(self, post):
        self.started_on = post.posted_on
        self.first_post = post
        self.starter = post.poster
        self.starter_name = post.poster_name
        if post.poster:
            self.starter_slug = post.poster.slug
        else:
            self.starter_slug = slugify(post.poster_name)

        self.is_moderated = post.is_moderated
        self.is_hidden = post.is_hidden
Exemplo n.º 20
0
def create_default_ranks(apps, schema_editor):
    Rank = apps.get_model('misago_users', 'Rank')

    team = Rank.objects.create(
        name=_("Forum team"),
        slug=slugify(_("Forum team")),
        title=_("Team"),
        css_class='team',
        is_tab=True,
        is_on_index=True,
        order=0)

    member = Rank.objects.create(
        name=_("Members"),
        slug=slugify(_("Members")),
        is_default=True,
        order=1)

    Role = apps.get_model('misago_acl', 'Role')
    team.roles.add(Role.objects.get(name=_("Moderator")))
    team.roles.add(Role.objects.get(name=_("Deleting users")))
Exemplo n.º 21
0
    def set_username(self, new_username, changed_by=None):
        if new_username != self.username:
            old_username = self.username
            self.username = new_username
            self.slug = slugify(new_username)

            if self.pk:
                changed_by = changed_by or self
                self.record_name_change(
                    changed_by, new_username, old_username)

                from misago.users.signals import username_changed
                username_changed.send(sender=self)
Exemplo n.º 22
0
    def set_username(self, new_username, changed_by=None):
        new_username = self.normalize_username(new_username)
        if new_username != self.username:
            old_username = self.username
            self.username = new_username
            self.slug = slugify(new_username)

            if self.pk:
                changed_by = changed_by or self
                self.record_name_change(changed_by, new_username, old_username)

                from misago.users.signals import username_changed
                username_changed.send(sender=self)
Exemplo n.º 23
0
def post_thread(forum, title='Test thread', weight=0, poster='Tester',
                is_moderated=False, is_hidden=False, is_closed=False,
                started_on=None):
    started_on = started_on or timezone.now()

    kwargs = {
        'forum': forum,
        'weight': weight,
        'title': title,
        'slug': slugify(title),
        'started_on': started_on,
        'last_post_on': started_on,
        'is_moderated': is_moderated,
        'is_hidden': is_hidden,
        'is_closed': is_closed,
    }

    try:
        kwargs.update({
            'starter': poster,
            'starter_name': poster.username,
            'starter_slug': poster.slug,
            'last_poster': poster,
            'last_poster_name': poster.username,
            'last_poster_slug': poster.slug,
            })
    except AttributeError:
        kwargs.update({
            'starter_name': poster,
            'starter_slug': slugify(poster),
            'last_poster_name': poster,
            'last_poster_slug': slugify(poster),
        })

    thread = Thread.objects.create(**kwargs)
    forum.synchronize()
    forum.save()
    return thread
Exemplo n.º 24
0
    def test_valid_slugify_output(self):
        """Misago's slugify correctly slugifies string"""
        test_cases = (
            ('Bob', 'bob'),
            ('Eric The Fish', 'eric-the-fish'),
            ('John   Snow', 'john-snow'),
            ('J0n', 'j0n'),
            ('An###ne', 'anne'),
            ('S**t', 'st'),
            ('Łók', 'lok'),
        )

        for original, slug in test_cases:
            self.assertEqual(slugify(original), slug)
def upload_to(instance, filename):
    spread_path = md5(str(instance.secret[:16]).encode()).hexdigest()
    secret = Attachment.generate_new_secret()

    filename_lowered = filename.lower().strip()
    for extension in instance.filetype.extensions_list:
        if filename_lowered.endswith(extension):
            break

    filename_clean = '.'.join(
        (slugify(filename[:(len(extension) + 1) * -1])[:16], extension))

    return os.path.join('attachments', spread_path[:2], spread_path[2:4],
                        secret, filename_clean)
Exemplo n.º 26
0
    def test_valid_slugify_output(self):
        """Misago's slugify correctly slugifies string"""
        test_cases = (
            (u'Bob', u'bob'),
            (u'Eric The Fish', u'eric-the-fish'),
            (u'John   Snow', u'john-snow'),
            (u'J0n', u'j0n'),
            (u'An###ne', u'anne'),
            (u'S**t', u'st'),
            (u'Łók', u'lok'),
        )

        for original, slug in test_cases:
            self.assertEqual(slugify(original), slug)
Exemplo n.º 27
0
def upload_to(instance, filename):
    spread_path = md5(str(instance.secret[:16]).encode()).hexdigest()
    secret = Attachment.generate_new_secret()

    filename_lowered = filename.lower().strip()
    for extension in instance.filetype.extensions_list:
        if filename_lowered.endswith(extension):
            break

    filename_clean = u'.'.join((
        slugify(filename[:(len(extension) + 1) * -1])[:16],
        extension
    ))

    return os.path.join('attachments', spread_path[:2], spread_path[2:4], secret, filename_clean)
Exemplo n.º 28
0
def like_post(post, user=None, username=None):
    if not post.last_likes:
        post.last_likes = []

    if user:
        like = post.postlike_set.create(
            category=post.category,
            thread=post.thread,
            user=user,
            user_name=user.username,
            user_slug=user.slug,
            user_ip='127.0.0.1'
        )

        post.last_likes = [
            {
                'id': user.id,
                'username': user.username
            }
        ] + post.last_likes
    else:
        like = post.postlike_set.create(
            category=post.category,
            thread=post.thread,
            user_name=username,
            user_slug=slugify(username),
            user_ip='127.0.0.1'
        )

        post.last_likes = [
            {
                'id': None,
                'username': username
            }
        ] + post.last_likes

    post.likes += 1
    post.save()

    return like
Exemplo n.º 29
0
 def get_by_username_or_email(self, login):
     queryset = models.Q(slug=slugify(login))
     queryset = queryset | models.Q(email_hash=hash_email(login))
     return self.get(queryset)
Exemplo n.º 30
0
 def get_by_username(self, username):
     return self.get(slug=slugify(username))
Exemplo n.º 31
0
 def set_name(self, name):
     self.name = name
     self.slug = slugify(name)
Exemplo n.º 32
0
 def get_by_username_or_email(self, login):
     if '@' in login:
         return self.get(email_hash=hash_email(login))
     return self.get(slug=slugify(login))
Exemplo n.º 33
0
 def set_title(self, title):
     self.title = title
     self.slug = slugify(title)
Exemplo n.º 34
0
 def set_name(self, name):
     self.name = name
     self.slug = slugify(name)
Exemplo n.º 35
0
def create_default_forums_tree(apps, schema_editor):
    Forum = apps.get_model('misago_forums', 'Forum')

    Forum.objects.create(
        special_role='private_threads',
        role='forum',
        name='Private',
        slug='private',
        lft=1,
        rght=2,
        tree_id=0,
        level=0,
    )

    root = Forum.objects.create(
        special_role='root_category',
        role='category',
        name='Root',
        slug='root',
        lft=3,
        rght=10,
        tree_id=1,
        level=0,
    )

    category_name = _("First category")
    forum_name = _("First forum")
    redirect_name = _("Misago support forums")
    redirect_link = _("http://misago-project.org")

    category = Forum.objects.create(
        parent=root,
        lft=4,
        rght=9,
        tree_id=1,
        level=1,
        role='category',
        name=category_name,
        slug=slugify(category_name),
        css_class='accent')

    Forum.objects.create(
        parent=category,
        lft=5,
        rght=6,
        tree_id=1,
        level=2,
        role='forum',
        name=forum_name,
        slug=slugify(forum_name))

    Forum.objects.create(
        parent=category,
        lft=7,
        rght=8,
        tree_id=1,
        level=2,
        role='redirect',
        name=redirect_name,
        slug=slugify(redirect_name),
        redirect_url=redirect_link)
Exemplo n.º 36
0
 def get_by_username_or_email(self, login):
     queryset = models.Q(slug=slugify(login))
     queryset = queryset | models.Q(email_hash=hash_email(login))
     return self.get(queryset)
Exemplo n.º 37
0
 def get_by_username(self, username):
     return self.get(slug=slugify(username))