Ejemplo n.º 1
0
 def test_valid_form_submission(self):
     data = {'name':'My last semister Assignment',
             'short_description':'',
             'content':open("/".join([settings.ROOT_PATH, 'users', 'fixtures', 'assignment.py'])).read(),
             'public':True}
     form = SaveNoteForm(data)
     self.assertTrue(form.is_valid())
     self.assertFalse(form.errors)
     self.assertEquals(data['content'].strip(), form.cleaned_data.get('content'))
Ejemplo n.º 2
0
 def test_empty_content_submission(self):
     data = {'name':'My C Assignment', 'short_description':'', 'content':'', 'public':True}
     form = SaveNoteForm(data)
     self.assertFalse(form.is_valid())
     self.assertTrue(form.errors)
     self.assertFalse(form.errors.has_key('name'))
     self.assertFalse(form.errors.has_key('short_description'))
     self.assertTrue(form.errors.has_key('content'))
     self.assertFalse(form.errors.has_key('public'))
Ejemplo n.º 3
0
def view_notepad(request, notepad_template):
    userprofile = loggedin_userprofile(request)
    all_notes = userprofile.all_notes
    if request.method == 'GET':
        return response(request, notepad_template, {'form':SaveNoteForm(),
                                                    'all_notes':all_notes})
    form = SaveNoteForm(post_data(request))
    userprofile = loggedin_userprofile(request)
    if not form.is_valid():
        return response(request, notepad_template, {'form':form,
                                                    'all_notes':all_notes})
    Note.objects.create_note(userprofile=userprofile,
                             name=form.cleaned_data.get('name'),
                             short_description=form.cleaned_data.get('short_description'),
                             note=form.cleaned_data.get('content'),
                             public=form.cleaned_data.get('public'))
    from users.messages import SAVED_NOTEPAD_SUCCESSFULLY_MESSAGE
    messages.success(request, SAVED_NOTEPAD_SUCCESSFULLY_MESSAGE)
    return response(request, notepad_template, {'form':SaveNoteForm(),
                                                'all_notes':all_notes})
Ejemplo n.º 4
0
def view_edit_note(request, note_id, notepad_template):
    userprofile = loggedin_userprofile(request)
    note = get_object_or_404(Note, id=int(note_id))
    if userprofile.is_my_note(note):
        all_notes = userprofile.all_notes
        if request.method == 'GET':
            form = SaveNoteForm({'name':note.name,
                                 'short_description':note.short_description,
                                 'content':note.note,
                                 'public':note.public})
            return response(request, notepad_template, {'form':form,
                                                        'note':note,
                                                        'all_notes':all_notes})
        form = SaveNoteForm(post_data(request))
        if form.is_valid():
            note.update(name=form.cleaned_data.get('name'),
                        short_description=form.cleaned_data.get('short_description'),
                        note=form.cleaned_data.get('content'),
                        public=form.cleaned_data.get('public'))
            from users.messages import SAVED_NOTEPAD_SUCCESSFULLY_MESSAGE
            messages.success(request, SAVED_NOTEPAD_SUCCESSFULLY_MESSAGE)
        return response(request, notepad_template, {'form':SaveNoteForm(),
                                                    'all_notes':all_notes})
    raise Http404