Fakultas Ilmu Komputer UI

removetraffic.py 1.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
from datetime import datetime, timedelta
from math import floor, ceil
from random import randint, choice, choices, sample, uniform, random
from typing import List

from django.core.management.base import BaseCommand
from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils import timezone, lorem_ipsum

from app.models import DummyLike, DummyViewStatistics, DummyDownloadStatistics, DummyComment
11
from app.management.commands.utils import SECONDS_IN_DAY, get_time_before, get_random_datetime, generate_list_of_random_datetime, generate_random_string, get_random_color
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44


class Command(BaseCommand):
    help = 'Remmove dummy data for seeding.'

    def _remove_view(self):
        for item in DummyViewStatistics.objects.all():
            item.item.delete()
            item.delete()

    def _remove_download(self):
        for item in DummyDownloadStatistics.objects.all():
            item.item.delete()
            item.delete()

    def _remove_like(self):
        for item in DummyLike.objects.all():
            item.item.delete()
            item.delete()

    def _remove_comment(self):
        for item in DummyComment.objects.all():
            item.item.delete()
            item.delete()
        

    def handle(self, *args, **options):
        self._remove_view()
        self._remove_download()
        self._remove_like()
        self._remove_comment()
        self.stdout.write(self.style.SUCCESS(
            'Successfully remove all dummy traffic'))