Ejemplo n.º 1
0
def add_task(request):
    if request.method == "POST":
        desc = request.POST["description"]
        t = TodoItem(description=desc)
        t.save()

    return redirect(reverse("tasks:list"))
Ejemplo n.º 2
0
 def handle(self, *args, **options):
     now = datetime.now(timezone.utc)
     with open("input.txt", encoding='utf-8') as fp:
         for line in fp:
             task = TodoItem(description=line)
             task.save()
             print("Добавленные задачи:", task, task.created)
Ejemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        form = TodoItemImportTrelloForm(request.POST, )

        if form.is_valid():
            data = form.cleaned_data
            board_id = data['trello_id_board']

            try:
                client = TrelloClient(
                    api_key=request.user.profile.trello_api_key,
                    api_secret=request.user.profile.trello_api_secret)
                desc = client.get_board(board_id)
            except:
                return render(
                    request, 'tasks/import_trello.html', {
                        'form': form,
                        'error':
                        'check your api key and api secret and id board'
                    })
            left_list = desc.list_lists()[0]
            cards = left_list.list_cards()
            for card in cards:
                t = TodoItem(description=card.name,
                             trello_id_board=board_id,
                             trello_id_card=card.id)
                t.owner = request.user
                t.save()

        return redirect(reverse('tasks:list'))
Ejemplo n.º 4
0
def task_cats_added(sender, instance, action, model, **kwargs):
    print(action)
    if action != 'post_add':
        return

    todo_by_cat = instance.category.through.objects.filter(
        todoitem_id=instance.id).prefetch_related()
    category = Category.objects.all().select_related()

    for cat_id in todo_by_cat:
        for cat in category:
            if cat.id == cat_id.category_id:
                cat.todos_count += 1

            cat.save()

    #
    # for cat in instance.category.all():
    #     slug = cat.slug
    #     new_count = 0
    #     for task in TodoItem.objects.all():
    #         new_count += task.category.filter(slug=slug).count()
    #
    #     Category.objects.filter(slug=slug).update(todos_count=new_count)
    TodoItem.priority_counter()
Ejemplo n.º 5
0
 def handle(self, *args, **options):
     now = datetime.now(timezone.utc)
     with open(options['input_file'], 'r', encoding='utf-8') as fp:
         for line in fp:
             ss = line.replace("\n", '')
             t = TodoItem(description=ss)
             t.save()
Ejemplo n.º 6
0
def add_tasks_from_trello(request):
    p = request.user.profile
    trello_key = p.trello_api_key
    trello_secret = p.trello_api_secret

    if request.method == "POST":
        form = AddTrelloIdForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            trello_id = cd["board_id"]

            tasks = get_trello_tasks(board_id=trello_id,
                                     api_key=trello_key,
                                     api_secret=trello_secret)

            for task in tasks:
                t = TodoItem(description=task.name,
                             trello_id=task.board_id,
                             task_id=task.id)
                t.owner = request.user
                t.save()
            return redirect(reverse('list'))
    else:
        form = AddTrelloIdForm()

    return render(request, "tasks/AddTrelloId.html", {"form": form})
Ejemplo n.º 7
0
 def handle(self, *args, **options):
     now = datetime.now(timezone.utc)
     file_path = 'C:/Users/admin/Python/PycharmProjects/Django/'
     with open(file_path + options['input_file'], 'r', encoding='utf-8') as file:
         for line in file.readlines():
             t = TodoItem(description=line)
             t.save()
Ejemplo n.º 8
0
def add_task(request):
	if request.method == 'POST':
		desc = request.POST['description']
		t = TodoItem(description=desc)
		t.save()
		messages.success(request,'Задача добавлена')
	return redirect(reverse('tasks:list'))
Ejemplo n.º 9
0
 def handle(self, *args, **options):
     path = os.getcwd() + '/tasks/management/commands/'
     data = options['input_file']
     with open(os.path.join(path, data), 'r') as f:
         for row in f.readlines():
             desc = row.split(sep='\n')[0]
             t = TodoItem(description=desc)
             t.save()
Ejemplo n.º 10
0
 def handle(self, *args, **options):
     if options['input_file'] is not None:
         with open(options['input_file']) as f:
             for line in f:
                 t = TodoItem(description=line)
                 t.save()
         print('Все ништяк')
     else:
         print('Не указан файл')
Ejemplo n.º 11
0
 def handle(self, *args, **options):
     counter = 0
     with open(options['input_file']) as data:
         for line in data:
             if line:
                 t = TodoItem(description=line)
                 t.save()
                 counter += 1
     print(f"{counter} tasks have been imported")
Ejemplo n.º 12
0
def task_cats_removed(sender, instance, action, model, **kwargs):
    if action != "post_remove":
        return

    cat_counter = Counter()
    for t in TodoItem.objects.all():
        for cat in t.category.all():
            cat_counter[cat.slug] += 1
            for category in Category.objects.all():
                if category.slug not in cat_counter:
                    cat_counter[category.slug] = 0
    for slug, new_count in cat_counter.items():
        Category.objects.filter(slug=slug).update(todos_count=new_count)

    TodoItem.priority_counter()
Ejemplo n.º 13
0
	def generate_body(self, user, priorities):
		q = Q()
		if priorities['prio_high']:
			q = q | Q(priority=TodoItem.PRIORITY_HIGH)
		if priorities['prio_med']:
			q = q | Q(priority=TodoItem.PRIORITY_MEDIUM)
		if priorities['prio_low']:
			q = q | Q(priority=TodoItem.PRIORITY_LOW)

		tasks = TodoItem.objects.filter(owner=user).filter(q).all()
		
		if not priorities['group']:
			body = 'Ваши задачи и приоритеты:\n'
			for t in tasks:
				tags = ', '.join([tag.name for tag in t.tags.all()])
				if t.is_completed:
					body += f"[x] {t.description} (тэги: {tags}) ({t.get_priority_display()})\n"
				else:
					body += f"[ ] {t.description} (тэги: {tags}) ({t.get_priority_display()})\n"
		else:
			body = 'Ваши задачи, сгруппированные по приоритетам:\n'
			prio = [TodoItem().PRIORITY_CHOICES[i][1] for i in range(3)]

			for i in range(len(prio)):
				body += '\n' + prio[i] + '\n'
				for t in tasks:
					tags = ', '.join([tag.name for tag in t.tags.all()])
					if t.get_priority_display() == prio[i]:
						if t.is_completed:
							body += f"[x] {t.description} (тэги: {tags})\n"
						else:
							body += f"[ ] {t.description} (тэги: {tags})\n"			
		return body
Ejemplo n.º 14
0
 def import_task_trello(self, user, id):
     client = TrelloClient(api_key=user.profile.api_key,
                           api_secret=user.profile.api_secret)
     tasks_Trello = client.list_boards()[id["id_board"]]
     to_do = tasks_Trello.list_lists()[0]
     cards = to_do.list_cards()
     card = to_do.list_cards()[0]
     tasks = TodoItem.objects.filter(owner=user).all()
     tag = []
     for t in tasks:
         # tag.append(t.tags)
         t.delete()
     # for ta in tag:
     #     count = TodoItem.tags.through.objects.filter(tag_id=ta).aggregate(total_tasks=Count('id'))
     r = 0
     for i in cards:
         t = TodoItem(description=i.name, id_trello=i.id, owner=user)
         t.save()
         r += 1
     return r
Ejemplo n.º 15
0
def tasks_import(request):
    if request.method == "POST":   #если был переход из формы
        board_id = (request.POST['board_id']) #получаем ID борда
        owner = request.user #получаем пользователя
        prof = Profile.objects.get(user=owner) #получаем профайл пользователя
        key = prof.trello_key #из профайла достаем ключ
        token = prof.trello_token #из профайла достаем токен
        delete_all(owner)
        task_list = get_tasks_from_trello(key, token, board_id) #получаем список тасок из Трелло

        for task in task_list: # сохраняем таски из списка в нашу базу
            import_task = TodoItem()
            import_task.description = task[0]
            import_task.trello_id = task[1]
            import_task.trello_board_id = task[2]
            import_task.owner  = owner
            import_task.save()

        return redirect(reverse("tasks:list"))

    else: #если перешли поссылке, то гененрируем форму
        return render(request, "tasks/import.html")
Ejemplo n.º 16
0
 def post(self, request, *args, **kwargs):
     form = TrelloImportForm(request.POST)
     user = request.user
     key = user.profile.trello_key
     secret = user.profile.trello_secret
     if form.is_valid():
         board_id = form.cleaned_data['board_id']
         client = TrelloClient(api_key=key, api_secret=secret)
         board = client.get_board(board_id)
         left_most = board.list_lists()[0]
         # right_most = board.list_lists()[-1]
         todo_tasks = left_most.list_cards()
         for task in todo_tasks:
             t = TodoItem(description=task.name)
             t.owner = user
             t.trello_id = task.id
             t.save()
         messages.success(request, 'Задачи успешно импортированы')
         return redirect(reverse('tasks:list'))
Ejemplo n.º 17
0
 def handle(self, *args, **options):
     now = datetime.now(timezone.utc)
     with open(options['input_file'], encoding='utf-8') as f:
         for desc in f.readlines():
             t = TodoItem(description=desc)
             t.save()
Ejemplo n.º 18
0
 def handle(self, *args, **options):
     with open(options['input_file'], "r", encoding='utf-8') as fp:
         for line in fp:
             t = TodoItem(description=line)
             t.save()
Ejemplo n.º 19
0
 def handle(self, *args, **options):
     with open(options['input_file'], encoding='utf-8') as file:
         for line in file:
             item = TodoItem(description=line)
             item.save()
Ejemplo n.º 20
0
def add_task(request):
    if request.method == 'POST':
        desc = request.POST['description']
        t = TodoItem(description=desc)
        t.save()
    return reverse('tasks:list')
Ejemplo n.º 21
0
 def handle(self, *args, **options):
     with open(options['input_file'], encoding="utf-8") as f:
         for line in f:
             t = TodoItem(description=line.strip())
             t.save()
 def handle(self, *args, **options):
     with open(options['filename']) as file:
         for line in file:
             t = TodoItem(description=line)
             t.save()
Ejemplo n.º 23
0
from tasks.models import TodoItem
all_tasks = ("прочитать книгу", "учиться жонглировать 30 минут",
             "помыть посуду", "поесть")
for desc in all_tasks:
    t = TodoItem(description=desc)
    t.save()
Ejemplo n.º 24
0
 def handle(self, *args, **kwargs):
     with open(kwargs['input_file']) as f:
         for desc in f:
             t = TodoItem(description=desc)
             t.save()
Ejemplo n.º 25
0
 def handle(self, *args, **options):
     now = datetime.now(timezone.utc)
     with open(options['input_file'], 'r', encoding='utf-8') as inf:
         for line in inf:
             t = TodoItem(description=line.strip())
             t.save()