Exemple #1
0
def add_todo(request):
    if request.user.is_authenticated:
        user = request.user
   
        form = TODOForm(request.POST)
        if form.is_valid():
           
            todo = form.save(commit=False)
            todo.user = user
            todo.save()
            return redirect("home")
        else: 
            return render(request , 'index.html' , context={'form' : form})
Exemple #2
0
def add_todo(request):
    if request.user.is_authenticated:
        user = request.user
        print(user)
        form = TODOForm(request.POST)
        if form.is_valid():
            print(form.cleaned_data)
            todo = form.save(commit=False)
            todo.user = user
            todo.save()
            print(todo)
            messages.success(request, "Task added Successfully")
            return redirect("home")
        else:
            return render(request, 'index.html', context={'form': form})
Exemple #3
0
def add_todo(request, team_id):
    if request.user.is_authenticated:
        form = TODOForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['user']
            todo = form.save(commit=False)
            todo.save()
            team = Team.objects.get(pk=team_id)
            team.todos.add(todo)
            team.save()
            user.email_user(
                subject='You have new task',
                message=
                'Hello from todo_app. You have new task assigned. This message is automated, please don\'t reply.',
            )
            return redirect("home")
        else:
            context = {'form': form}
            return render(request, 'index.html', context=context)
Exemple #4
0
def home(request):
    if request.user.is_authenticated:
        user = request.user
        form = TODOForm()
        todos = TODO.objects.filter(user=user).order_by('priority')
        return render(request,
                      'index.html',
                      context={
                          'form': form,
                          'todos': todos
                      })
Exemple #5
0
def stats(request, team_id=0):
    if request.user.is_authenticated:
        user = request.user
        form = TODOForm()
        teams = Team.objects.filter(users=user)
        team = None
        todos = []
        messages = []
        if team_id == 0:
            if len(teams) > 0:
                team = teams.first()
                messages = team.messages.all()
                team_id = team.id
        if team_id != 0:
            try:
                team = teams.get(id=team_id)
                messages = team.messages.all()
            except Team.DoesNotExist:
                team = None
        if team != None:
            todos = team.todos.order_by('-priority')
        stats = {st: 0 for st in ['Done', 'In_progress', 'To_do', 'Expired']}
        priors = {"priority " + str(p): 0 for p in range(1, 11)}
        for status in list(map(lambda t: t.status, todos)):
            stats[status.replace(' ', '_')] += 1
        for p in list(map(lambda t: t.priority, todos)):
            priors["priority " + p] += 1
        # print(list(priors.keys()))
        return render(request,
                      'statistics.html',
                      context={
                          'todos': todos,
                          'stats': stats,
                          'priors': list(priors.values()),
                          'priors_labels': list(priors.keys())
                      })
Exemple #6
0
def home(request, team_id=0):
    if request.user.is_authenticated:
        user = request.user
        form = TODOForm()
        teams = Team.objects.filter(users=user)
        team = None
        todos = []
        messages = []
        if team_id == 0:
            if len(teams) > 0:
                team = teams.first()
                messages = team.messages.all()
                team_id = team.id
        if team_id != 0:
            try:
                team = teams.get(id=team_id)
                messages = team.messages.all()
            except Team.DoesNotExist:
                team = None
        if team != None:
            todos = team.todos.order_by('-priority')
        stats = {st: 0 for st in ['Done', 'In_progress', 'To_do', 'Expired']}
        for status in list(map(lambda t: t.status, todos)):
            stats[status.replace(' ', '_')] += 1
        return render(request,
                      'index.html',
                      context={
                          'form': form,
                          'todos': todos,
                          'stats': stats,
                          'teams': teams,
                          'team': team,
                          'team_id': team_id,
                          'messages': messages,
                          'user': user
                      })