Exemplo n.º 1
0
    def index(self):
        counts = {
            'forums': Forum.count(),
            'sections': Section.count(),
            'threads': Thread.count(),
            'labels': ThreadLabel.count(),
            'answers': Answer.count(),
            'users': User.count(),
        }
        for item, count in counts.items():
            counts[item] = '{:,}'.format(counts[item])

        date = datetime.now().strftime('%d.%m.%Y %H:%M')

        return self.render(
            'admin/statistics.html',
            date=date,
            counts=counts,
        )
Exemplo n.º 2
0
                'created_by': admin.id,
            })

        for subsection_title in section_data['subsections']:
            Section.create(
                **{
                    'forum': forum.id,
                    'parent': section.id,
                    'title': subsection_title,
                    'created_at': datetime.datetime.now(),
                    'created_by': admin.id,
                })

# Create threads
print('Create threads...')
current_threads_count = Thread.count()
if current_threads_count < THREADS_COUNT:
    forums = Forum.all()
    users = User.all()

    for i in range(THREADS_COUNT - current_threads_count):
        if i and (i % 100000 == 0):
            print(f' - Created {i} threads')

        user = random.choice(users)
        forum = random.choice(forums)
        section = random.choice(Section.filter(forum=forum.id))

        ThreadFactory.create(
            author_id=user.id,
            forum_id=forum.id,