Ejemplo n.º 1
0
def create_note(request):
    """create note"""
    # if user is in bppp group
    if not from_group(request.user, 'bppp'):
        notes = Note.objects.all()
        return redirect('/notes/')
    if request.method == "GET":
        form = NoteForm()
        return render_to_response(
            'notes/create.html',
            {'form': form},
            context_instance=RequestContext(request)
        )
    elif request.method == "POST":
        form = NoteForm(request.POST)
        if form.is_valid():
            note = Note.objects.create(
                name=form.cleaned_data['name'],
                content=form.cleaned_data['content'],
                public=form.cleaned_data['public'],
                on_top=form.cleaned_data['on_top'],
                author=request.user
            )
            note.save()
            return redirect('/notes/' + str(note.id) + "/")
        else:
            return render_to_response(
                'notes/create.html',
                {'form': form},
                context_instance=RequestContext(request))
        return redirect('/notes/')
Ejemplo n.º 2
0
def edit_note(request, id):
    """edit note"""
    note = Note.objects.get(id=id)
    # check if user is the author
    if request.user != note.author:
        return redirect('/notes/' + id + "/")
    # work with the author
    if request.method == "GET":
        form = NoteForm(instance=note)
        return render_to_response(
            'notes/edit.html',
            {'note': note, 'form': form},
            context_instance=RequestContext(request))
        return redirect('/notes/' + id + "/")
    elif request.method == "POST":
        if request.user != note.author:
            return redirect('/notes/' + id + "/")
        form = NoteForm(request.POST)
        if form.is_valid():
            note.name = form.cleaned_data['name']
            note.content = form.cleaned_data['content']
            note.public = form.cleaned_data['public']
            note.on_top = form.cleaned_data['on_top']
            note.save()
            message = u"Редактирование" + note.name + \
                u" успешно завершено! ;)"
            messages.success(request, message)
            return redirect('/notes/' + id + "/")
Ejemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     template = "notes/close_modal.html"
     form = NoteForm(request.POST)
     item = Item.objects.get(pk=request.POST["item"])
     note = Note.objects.filter(item=item).first() if item else None
     if "delete" in request.POST:
         note.delete()
         note = None
     elif form.is_valid():
         title = form.cleaned_data["title"]
         content = form.cleaned_data["content"]
         if not title and not content:
             if note:
                 note.delete()
                 note = None
         else:
             if not title:
                 title = item.ref
             if note:
                 note.title = title
                 note.content = content
                 note.user = request.user
                 note.save()
             else:
                 note = Note.objects.create(
                     title=title, content=content, item=item, user=request.user
                 )
     context = {"note": note, "item": item}
     return render(request, template, context)
Ejemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        form = NoteForm(request.POST)
        context = self.get_context_data()

        if (form.is_valid()):
            form.save()
        return render(request, self.template_name, context)
Ejemplo n.º 5
0
    def post(self, request, *args, **kwargs):
        context = self.get_context_data(**kwargs)
        form = NoteForm(request.POST, instance=context.get('note'))

        if (form.is_valid()):
            form.save()
        return render(request, self.template_name, context)
Ejemplo n.º 6
0
def add_note(request):
    id = request.GET.get('id', None)
    if id is not None:
        note = get_object_or_404(Notes, id=id)
    else:
        note = None

    if request.method == 'POST':
        if request.POST.get('control') == 'delete':
            note.delete()
            messages.add_message(request, messages.INFO, 'Note Deleted!')
            return HttpResponseRedirect(reverse('notes:index'))

        form = NoteForm(request.POST, instance=note)
        if form.is_valid():

            obj = form.save(commit=False)
            obj.owner = request.user
            obj.save()
            messages.add_message(request, messages.INFO, 'Note Added!')
            return HttpResponseRedirect(reverse('notes:index'))

    else:
        form = NoteForm(instance=note)

    return render(request, 'addNote.html', {'form': form, 'note': note})
Ejemplo n.º 7
0
 def test_form_save(self):
     data = {'title': 'Note Title', 'body': 'Note body', 'tags': ''}
     form = NoteForm(data=data)
     self.assertTrue(form.is_valid())
     user = User.objects.create_user(email='*****@*****.**', password='******')
     form.instance.owner = user
     note = form.save()
     self.assertEqual(note, Note.objects.first())
Ejemplo n.º 8
0
def add_note(request):
	if request.method == 'POST':
		form = NoteForm(request.POST)
		if form.is_valid():
			form.save()
			return redirect('home')
	else:
		form = NoteForm()
	return render(request, 'notes/add_note.html', {'form': form})
Ejemplo n.º 9
0
def add_note(request):
    if request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('home')
    else:
        form = NoteForm()
    return render(request, 'notes/add_note.html', {'form': form})
Ejemplo n.º 10
0
def add_new_note(request):
    if request.method == 'POST':
        noteform = NoteForm(request.POST)
        if noteform.is_valid():
            title = request.POST['title']
            description = request.POST['description']
            note = Note(user=request.user, title=title, description=description)
            note.save()
            return redirect('notes:index')
Ejemplo n.º 11
0
def note_edit(request, note_id):
	note = get_object_or_404(Note, pk=note_id)
	if request.method=='POST':
		form = NoteForm(request.POST, instance=note)
		if form.is_valid():
			form.save()
			return redirect('note_detail', note_id)
	else:
		form = NoteForm(instance=note)
	return render_to_response('notes/note_edit.html', {'form': form}, context_instance=RequestContext(request))
Ejemplo n.º 12
0
def process_add_note_form(request):
    form = NoteForm(request.POST or None)
    form.fields['venue'].queryset = Venue.objects.filter(customer=request.user.userprofile.customer)
    if form.is_valid():
        form.create_daterange_notes(request.user)
        return {
            'success': True,
        }
    form_html = render_crispy_form(form)
    return {'success': False, 'form_html': form_html}
Ejemplo n.º 13
0
def note_edit(request, note_id):
    note = get_object_or_404(Note, pk=note_id)
    if request.method == 'POST':
        form = NoteForm(request.POST, instance=note)
        if form.is_valid():
            form.save()
            return redirect('note_detail', note_id)
    else:
        form = NoteForm(instance=note)
    return render_to_response('notes/note_edit.html', {'form': form},
                              context_instance=RequestContext(request))
Ejemplo n.º 14
0
def process_add_note_form(request):
    form = NoteForm(request.POST or None)
    form.fields['venue'].queryset = Venue.objects.filter(
        customer=request.user.userprofile.customer)
    if form.is_valid():
        form.create_daterange_notes(request.user)
        return {
            'success': True,
        }
    form_html = render_crispy_form(form)
    return {'success': False, 'form_html': form_html}
Ejemplo n.º 15
0
def note_edit(request, id=None):
    instance = Notes.objects.get(id=id, author=auth.get_user(request).id)
    form = NoteForm(request.POST or None, instance=instance)
    if form.is_valid():
        form.save()
        return redirect('/')
    args = {
        'title': instance.title,
        'instance': instance,
        'form': form,
        'category_all': Category.objects.all(),
    }
    return render(request, "note_edit.html", args)
Ejemplo n.º 16
0
def add_book(request):
    template_name = 'books/create_note.html'
    book = get_or_create_book(request)
    form = NoteForm(request.POST)
    if request.method == 'POST' and form.is_valid():
        note = form.save(commit=False)
        note.user = request.user
        note.save()
        book.notes.add(note.pk)
        return redirect('books:book')
    return render(request, template_name, {
        'form': form,
    })
Ejemplo n.º 17
0
def add_note(request):
    """Shows form to add note and processes its POST product."""
    if request.method == "POST":
        form = NoteForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            form.save()
            if request.is_ajax():
                return render(request, "ajax_success.html", {"form": NoteForm()})
            return HttpResponseRedirect(reverse("index"))
        if request.is_ajax():
            return render(request, "ajax_fail.html", {"form": form})
        return render(request, "add_note.html", {"form": form})
    form = NoteForm()
    return render(request, "add_note.html", {"form": form})
Ejemplo n.º 18
0
def note_create(request):
    args = {
        'username':  auth.get_user(request).username,
        'category_all': Category.objects.all(),
        'form': NoteForm(initial={'category': Category.objects.get(name=u'Заметка')}),
    }
    args.update(csrf(request))
    if request.POST:
        new_form = NoteForm(request.POST)
        if new_form.is_valid():
            note = new_form.save(commit=False)
            note.author = request.user
            note.save()
            return redirect('/')
        else:
            args['form'] = new_form
    return render_to_response('create.html', args)
Ejemplo n.º 19
0
def addnote(request):
    if request.method == 'POST':
        form = NoteForm(request.POST)
        error = None
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('viewnotes'))
        else:
            return render(request, 'notes/addnote.html', {
                'form': form,
                'error': error
            })
    else:
        form = NoteForm()
    return render(request, 'notes/addnote.html', {
        'form': form,
    })
Ejemplo n.º 20
0
 def test_filter(self):
     print(self.title)
     self.assertEqual(print(Notes.objects.get(title=self.title)),
                      print(self.title))
     self.assertEqual(print(Category.objects.get(name=self.category_name)),
                      print(self.category_name))
     form = NoteForm({
         'title': self.title,
         'text': self.text,
         'publish': True,
     })
     self.assertTrue(form.is_valid())
     comment = form.save()
     self.assertEqual(comment.title, self.title)
     self.assertEqual(comment.text, self.text)
     self.assertEqual(print(Notes.objects.get(publish=True)),
                      print(self.title))
Ejemplo n.º 21
0
def index(request):
	all_notes = Note.all_notes.all()
	unresolved_notes = Note.unresolved_notes.all()
	urgent_notes = Note.urgent_notes.all()
	queued_invoices = Invoice.queued_invoices.all()
	running_invoices = Invoice.running_invoices.all()
	note_form = NoteForm(request.POST)
	is_admin = request.user.groups.filter(name='Admin')
	updates = Update.objects.all()
	if note_form.is_valid():
		note_form.save()
		return note_form
	form = InvoiceForm(request.POST)
	if form.is_valid():
		form.save()
		return form
	#return render(request, 'invoices/add_job.html', {'form': form})
	return render_to_response('index.html', {'all_notes': all_notes, 'unresolved_notes': unresolved_notes, 'urgent_notes': urgent_notes, 'queued_invoices': queued_invoices, 'running_invoices': running_invoices, 'note_form': note_form, 'is_admin': is_admin, 'updates': updates, 'form': form}, context_instance=RequestContext(request))
Ejemplo n.º 22
0
def note_create(request):
    if not request.user:   # todo должно быть and
        raise Http404
    args = {
        'category_all': Category.objects.all(),
        'form': NoteForm(initial={'category': Category.objects.get(name=u'Заметка')}),
    }
    args.update(csrf(request))
    if request.POST:
        new_form = NoteForm(request.POST)
        if new_form.is_valid():
            note = new_form.save(commit=False)
            note.author = request.user
            note.save()
            return redirect('/')
        else:
            args['form'] = new_form
    return render(request, 'create.html', args)
Ejemplo n.º 23
0
def edit_note(request, note_id):
    """Edit a note. This creates a new revision and bump the head to this new one"""
    # get the old note
    old_note = get_object_or_404(Note, note_id)

    if request.method == "POST":
        # get the new one from the form
        form = NoteForm(data=request.POST)
        if form.is_valid():
            new_note = form.save(commit=False)
            new_note.save_as_revision_of(old_note)
            return redirect("notes:list")
    else:        
        form = NoteForm(initial=old_note)
    
    return render("edit_note.html", {
        "form": form,
    }, request)
Ejemplo n.º 24
0
def add_note(request):
    note = None
    if request.POST:
        form = NoteForm(request.POST)
        if form.is_valid():
            # get the new instance from the model, and save it as a new one.
            try:
                note = form.save(commit=False)
                note.save_as_new()
                return redirect('notes:list')
            except ResourceConflict:
                form.errors['title'] = _("The title must be unique. Please choose another one")
    else:
        form = NoteForm()

    return render("add_note.html", {
        "form": form,
        "note": note
    }, request)
Ejemplo n.º 25
0
def add_note(request):
    """Add a note
    - GET request display the form
    - POST request create the note and redirect if the add is successful
    
    """
    note = None
    
    if request.POST:
        form = NoteForm(request.POST)
        if form.is_valid():
            note = form.save()
    else:
        form = NoteForm()

    return render("add_note.html", {
        "form": form,
        "note": note,
    })
Ejemplo n.º 26
0
def edit_n(request, Note_id):
	
	if request.POST:
		form = NoteForm(request.POST, instance=Note.objects.get(pk=Note_id))
		if form.is_valid():
			form.save()
			return HttpResponseRedirect('/notes/'+ Note_id +'/open_n')
	else:
		notebook_list = Notebook.objects.order_by('-name')
		STATIC_URL = 'https://mynotes.muddyoutnback.com/static/notes/'
		n = Note.objects.get(pk=Note_id)
		form = NoteForm(request.POST)
		args = {'n': n,
				'notebook_list': notebook_list,
				'notes_count': Ncount(request.user.id),
				'all_notebook_count': aNBcount(request.user.id),
				'STATIC_URL': STATIC_URL}
		args.update(csrf(request))
		args['form'] = form
		return render_to_response('notes/edit_n.html', args)
Ejemplo n.º 27
0
def new(request, slug):
    employee = get_object_or_404(Employee, slug=slug)
    if request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            note = form.save(commit=False)
            note.employee = employee
            note.user = request.user
            note.updated = timezone.now()
            note.save()
            messages.success(request, 'Note created')
            return HttpResponseRedirect(reverse('employees.views.notes', 
                args=[employee.slug]))
    form = NoteForm()
    d = {
        'employee': employee,
        'form'    : form,
        'title'   : 'New Note',
    }
    return render_to_response('shared/new.html', add_csrf(request, d), 
        context_instance=RequestContext(request))
Ejemplo n.º 28
0
def add_note(request):
	#fetch note by id to manipulate posted notes and pass the instance of posted note to form
	id = request.GET.get('id', None)
	if id is not None:
		note = get_object_or_404(Note, id=id)
	else:
		note = None

	# get the logged in user
	author = request.user

	if request.method == 'POST':
		# delete note
		# is there a variable named delete in html file
		if request.POST.get('control') == 'delete':
			note.delete()
			messages.add_message(request, messages.INFO, 'Note Deleted!')
			return HttpResponseRedirect(reverse('notes:index'))

		# new note
		form = NoteForm(request.POST, instance=note)
		if form.is_valid():
			# create, but don't save instance
			new_author = form.save(commit=False)
			# add author
			new_author.author = author
			# save instance
			new_author.save()
			# save many-to-many-data for the form
			form.save_m2m()
			messages.add_message(request, messages.INFO, 'Note Added')
			return HttpResponseRedirect(reverse('notes:index'))
	else:
		form = NoteForm(instance=note)
		context = {
			'form': form,
		 	'note': note
		 	}

	return render(request, 'notes/addnote.html', context)
Ejemplo n.º 29
0
def edit_n(request, Note_id):

    if request.POST:
        form = NoteForm(request.POST, instance=Note.objects.get(pk=Note_id))
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/notes/' + Note_id + '/open_n')
    else:
        notebook_list = Notebook.objects.order_by('-name')
        STATIC_URL = 'https://mynotes.muddyoutnback.com/static/notes/'
        n = Note.objects.get(pk=Note_id)
        form = NoteForm(request.POST)
        args = {
            'n': n,
            'notebook_list': notebook_list,
            'notes_count': Ncount(request.user.id),
            'all_notebook_count': aNBcount(request.user.id),
            'STATIC_URL': STATIC_URL
        }
        args.update(csrf(request))
        args['form'] = form
        return render_to_response('notes/edit_n.html', args)
Ejemplo n.º 30
0
def station(request, slug):
    """Add a note for a station."""
    station = get_object_or_404(Station, slug=slug)
    if request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            note = form.save(commit=False)
            note.station = station
            note.user    = request.user
            note.updated = timezone.now()
            note.save()
            messages.success(request, 'Note created')
            return HttpResponseRedirect(reverse('stations.views.detail',
                args=[station.slug]))
    form = NoteForm()
    d = {
        'form': form,
        'station': station,
        'title': 'New Note',
    }
    return render_to_response('shared/new.html', add_csrf(request, d), 
        context_instance=RequestContext(request))
Ejemplo n.º 31
0
def new_n(request):
	notebook_list = Notebook.objects.order_by('-name')
	STATIC_URL = 'https://mynotes.muddyoutnback.com/static/notes/'
	if request.POST:
		form = NoteForm(request.POST)
		if form.is_valid():
			newnote = form.save(commit=False)
			newnote.owner = request.user.id
			newnote.save()
		return HttpResponseRedirect('/notes/')
	else:
		form = NoteForm()
		args = {'notebook_list': notebook_list,
				'notes_count': Ncount(request.user.id),
				'user_username': request.user.username,
				'user_id': request.user.id,
				'all_notebook_count': aNBcount(request.user.id),
				'STATIC_URL': STATIC_URL
				}
			
		args.update(csrf(request))
		args['form'] = form
		return render_to_response('notes/new_n.html', args)
Ejemplo n.º 32
0
def new_n(request):
    notebook_list = Notebook.objects.order_by('-name')
    STATIC_URL = 'https://mynotes.muddyoutnback.com/static/notes/'
    if request.POST:
        form = NoteForm(request.POST)
        if form.is_valid():
            newnote = form.save(commit=False)
            newnote.owner = request.user.id
            newnote.save()
        return HttpResponseRedirect('/notes/')
    else:
        form = NoteForm()
        args = {
            'notebook_list': notebook_list,
            'notes_count': Ncount(request.user.id),
            'user_username': request.user.username,
            'user_id': request.user.id,
            'all_notebook_count': aNBcount(request.user.id),
            'STATIC_URL': STATIC_URL
        }

        args.update(csrf(request))
        args['form'] = form
        return render_to_response('notes/new_n.html', args)
Ejemplo n.º 33
0
def add_note(request):

	id = request.GET.get('id', None)
	if id is not None:
		note = get_object_or_404(Note, id=id)
	else:
		note = None

	if request.method == 'POST':
		if request.POST.get('control') == 'delete':
			note.delete()
			messages.add_message(request, messages.INFO, 'Note Deleted!')
			return HttpResponseRedirect(reverse('notes:index'))

		form = NoteForm(request.POST, instance=note)
		if form.is_valid():
			form.save()
			messages.add_message(request, messages.INFO, 'Note Added!')
			return HttpResponseRedirect(reverse('notes:index'))

	else:
			form = NoteForm(instance=note)

	return render(request, 'notes/addnote.html', {'form':form, 'note':note})	
Ejemplo n.º 34
0
def edit(request, pk):
    note = get_object_or_404(Note, pk=pk)
    if request.method == 'POST':
        form = NoteForm(request.POST, instance=note)
        if form.is_valid():
            note = form.save(commit=False)
            note.updated = timezone.now()
            note.save()
            messages.success(request, 'Note updated')
            if note.employee:
                return HttpResponseRedirect(reverse('employees.views.notes', 
                    args=[note.employee.slug]))
            elif note.station:
                return(HttpResponseRedirect(reverse('stations.views.detail',
                    args=[note.station.slug])))
    form = NoteForm(instance=note)
    d = {
        'employee': note.employee,
        'form'    : form,
        'station' : note.station,
        'title'   : 'Edit Note',
    }
    return render_to_response('shared/new.html', add_csrf(request, d),
        context_instance=RequestContext(request))
Ejemplo n.º 35
0
 def test_empty_title(self):
     form = NoteForm(data={'title': '', 'text': 'some text'})
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['title'], ['This field is required.'])
Ejemplo n.º 36
0
def save_note(request):
    if request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            Note.objects.create_note(form.cleaned_data['title'], form.cleaned_data['text'], request.user)
    return redirect('/')