Beispiel #1
0
 def test_UserForm_valid(self):
     form = NoteForm(
         data={
             'person': "user",
             'title': 'title',
             'note': 'description',
             'coordinates': '55.3234, 52.23434'
         })
     self.assertTrue(form.is_valid())
Beispiel #2
0
def edit_task(request, task_id):
    task = request.user.tasks.with_hashid(task_id)
    # 'tasks' is the related name of the owner field in the Task model
    # hashid?
    if task is None:
        raise Http404('No task matches the given query.')

    if request.method == 'POST':
        # if user is submitting a form
        form = EditTaskForm(instance=task, data=request.POST)
        if form.is_valid():
            form.save()
            return redirect('task-list')
    else:
        # else make a new form
        form = EditTaskForm(instance=task)

    ### statements below run when none of the if statements above hit due to errors/invalid input ###

    note_form = NoteForm()

    return render(
        request, 'core/edit_task.html', {
            'form': form,
            'note_form': note_form,
            'task': task,
            'notes': task.notes.order_by('created_at')
        })
Beispiel #3
0
def new_note(request, task_id):
    task = request.user.tasks.with_hashid(task_id)
    if task is None:
        raise Http404('No task matches the given query.')

    form = NoteForm(request.POST)

    if form.is_valid():
        note = form.save(commit=False)
        # don't actually save to the database yet
        note.task = task
        note.save()
    else:
        messages.error(request, 'We have a problem saving your note.')

    redirect_url = resolve_url(to='edit_task', task_id=task.pk)
    # redirect_url = resolve_url(to='edit_task', task_id=task.hashid)

    return redirect(to=f'{redirect_url}#note-{note.pk}')
Beispiel #4
0
def addnote(request):
    if request.method == "GET":
        notes_list = Note.objects.all()
        return render(request,
                      "home.html",
                      context={
                          "notes_list": notes_list,
                      })
    if request.method == "POST":
        form = NoteForm(request.POST)
        # import pdb; pdb.set_trace()
        if form.is_valid():
            title = form.cleaned_data["title"]
            description = form.cleaned_data["description"]
            note = Note.objects.create(title=title, description=description)
            note.save()
            messages.success(request, 'Note Is Added!')
            return redirect("core:note", id=note.id)
        else:
            messages.info(request, str(form.errors))
            return redirect("core:addnote")
Beispiel #5
0
def uploadfile(request):
    if request.method == 'POST':
        form = NoteForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.INFO,
                                 'File Upload Successful !')
            return render(request, 'upload.html', {'form': form})

    else:
        form = NoteForm()
        return render(request, 'upload.html', {'form': form})
Beispiel #6
0
def notelist(request, id):
    if request.method == "GET":
        note = get_object_or_404(Note, id=id)
        notes_list = Note.objects.all()
        return render(request,
                      "home.html",
                      context={
                          "notes_list": notes_list,
                          "note": note,
                      })
    if request.method == "POST":
        form = NoteForm(request.POST)
        # import pdb; pdb.set_trace()
        if form.is_valid():
            note = get_object_or_404(Note, id=id)
            note.title = form.cleaned_data["title"]
            note.description = form.cleaned_data["description"]
            note.save()
            messages.success(request, 'Note Is Updated!')
            return redirect("core:note", id=note.id)
        else:
            messages.info(request, str(form.errors))
            return redirect("core:addnote")
Beispiel #7
0
def get_or_create_task_notes(request, task_id):
    task = request.user.tasks.with_hashid(task_id)
    if task is None:
        raise Http404('No task matches the given query.')

    # If this is a GET request, we're calling it via Ajax and
    # should return JSON.
    if request.method == "GET":
        notes = [note.to_dict() for note in task.notes.all()]
        return JsonResponse({"notes": notes})

    form = NoteForm(request.POST)

    if form.is_valid():
        note = form.save(commit=False)
        note.task = task
        note.save()
    else:
        messages.error(request, 'We had a problem saving your note.')

    redirect_url = resolve_url(to='edit_task', task_id=task.hashid)

    return redirect(to=f"{redirect_url}#note-{note.pk}")
Beispiel #8
0
def add_note(req, id):
    contact = get_object_or_404(Contact, pk=int(id))
    company = contact.company
    old_notes = contact.notes.all().order_by('-date')
    if req.method == 'POST':
        form = NoteForm(req.POST)
        if form.is_valid():
            note = Note(subject=form.cleaned_data['subject'],
                        text=form.cleaned_data['text'])
            note.user = req.user
            note.contact = contact
            note.save()
            messages.success(req, u'Neue Bemerkung gespeichert.')
            return redirect('/core/companies/addnote/{0}/'.format(id))
        else:
            messages.error(req, u'Bitte Betreff und Text eingeben.')
    else:
        form = NoteForm()
    title = u'Neue Bemerkung: {name} ({company})'.format(
        name=contact.shortname(), company=company.short_name or company.name)
    ctx = dict(page_title=title, menus=menus, form=form,
               contact=contact, company=company, notes=old_notes)
    return render(req, 'companies/add_note.html', ctx)
Beispiel #9
0
 def dispatch(self, request, *args, **kwargs):
     self.task = request.user.tasks.with_hashid(kwargs['task_id'])
     self.note_form = NoteForm()
     if self.task is None:
         raise Http404('No task matches the given query.')
     return super().dispatch(request, *args, **kwargs)