Example #1
0
def NoteShow(request, uuid):
    note = Note.objects.get(note_uuid=uuid)
    form = NoteForm(request.POST or None, instance=note)
    if form.is_valid():
        note.save()
        return HttpResponseRedirect('/')
    return render(request, 'note_create.html', {'form': form})
Example #2
0
def NoteShow(request, uuid):
    note = Note.objects.get(note_uuid=uuid)
    form = NoteForm(request.POST or None, instance=note)
    if form.is_valid():
        note.save()
        return HttpResponseRedirect('/')
    return render(request, 'note_create.html', {'form': form})
Example #3
0
def add(request):
    if request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/')
    else:
        form = NoteForm()
    return render_to_response('add.html', {'form' : form}, RequestContext(request, 
    processors=[count_notes]))
Example #4
0
def NoteUpdate(request):
    noteid = request.GET['id']
    note = Note.objects.get(id=noteid)
    form = NoteForm(request.POST or None, instance=note)
    if request.method == 'POST':
        if form.is_valid():
            note.save()
            # return redirect('/')
            return HttpResponseRedirect('/')
    else:
        return render(request, 'note_create.html', {'form': form})
Example #5
0
def NoteUpdate(request):
    noteid = request.GET['id']
    note = Note.objects.get(id=noteid)
    form = NoteForm(request.POST or None, instance=note)
    if request.method == 'POST':
        if form.is_valid():
            note.save()
            # return redirect('/')
            return HttpResponseRedirect('/')
    else:
        return render(request, 'note_create.html', {'form': form})
Example #6
0
def NoteCreate(request):
    if request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            note = form.save(commit=False)
            note.created_by = request.user
            note.save()
            # return redirect('/')
            return HttpResponseRedirect('/')
    else:
        form = NoteForm()

    return render(request, 'note_create.html', {'form': form})
Example #7
0
    def project_notes(self):
        """Get notes and note form for the project."""

        notes = self.object.notes.all().order_by('-creation_date')
        form = NoteForm()

        return {'notes': notes, 'form': form}
Example #8
0
    def post(self, request):
        form = NoteForm(request.POST)

        if form.is_valid():
            text = form.cleaned_data['post']
            print("Add new note:", text)
            note = Note()
            note.text_message = text
            note.save()
            form = NoteForm()  # Clear input field

        return render(
            request, self.tamplate_name, {
                'notes': Note.objects.all().order_by("-unique_word_count"),
                'form': form
            })
Example #9
0
    def get(self, request, *args, **kwards):
        form = NoteForm()

        return render(
            request, self.tamplate_name, {
                'notes': Note.objects.all().order_by("-unique_word_count"),
                'form': form
            })
Example #10
0
def create(request):
    if request.method == "POST":
        note = Note()
        form = NoteForm(request.POST, instance=note)

        if form.is_valid():
            # if note get the authorID then set the ID is -1. because at the
            # first step. we didn't hava build UC system.
            if note.authorID == None:
                note.authorID = 0

            # if user forget to set note's type. we set it as default value 0
            if note.noteType == None:
                note.noteType = 0

            if note.color == None:
                note.color = "#000000"

            # set createtime
            note.createTime = timezone.now()

            try:
                note.save()
                tags = form.cleaned_data["tags"]
                # TODO: not support chinese character
                tags = tags.replace(",", "|").replace(";", "|").replace(" ", "").replace("||", "|")
                tagArr = tags.split("|")
                # 下面虽然实现了tags的插入,但是效率不高
                # for tag in tagArr:
                #     tag_record=Tag(tagName=tag,noteID=note.id)
                #     tag_record.save()
                # Optimizaition way
                insert_list = []
                for tag in tagArr:
                    # 此处逻辑不严,如果tag为空,还会插入的,这样没有意义
                    if tag != "":
                        insert_list.append(Tag(tagName=tag, noteID=note))
                # print insert_list
                Tag.objects.bulk_create(insert_list)

                return HttpResponseRedirect("/view?id=" + str(note.id))

            except Exception, e:
                # return HttpResponseRedirect('/view?id='+str(note.id
                return HttpResponse("data is valid and we store it in the database failed. ")
            finally:
Example #11
0
 def get_context_data(self, pk):
     project = get_object_or_404(Project, pk=pk)
     form = NoteForm()
     notes = project.notes.all().order_by('-creation_date')
     return {
         'project': project,
         'form': form,
         'notes': notes,
     }
Example #12
0
 def get_context_data(self, pk):
     story = get_object_or_404(Story, pk=pk)
     form = NoteForm()
     notes = story.notes.all().order_by('-creation_date')
     return {
         'story': story,
         'form': form,
         'notes': notes,
     }
Example #13
0
def edit(request, note_id):
    if (not request.user.is_authenticated()):
         return redirect('/auth/login')
    else:
        args = {}
        form = NoteForm(instance=Note.objects.get(id = note_id))
        args.update(csrf(request))
        args['form'] = form
        args['username'] = auth.get_user(request).username
        if (request.method == 'GET'):
            return render_to_response('edit.html',args)
        else:
            if (request.POST):
                form = NoteForm(request.POST)
                if form.is_valid():
                    note = form.save(commit=False)
                    note.date = datetime.now()
                    note.user = request.user
                    note.save()
                    return redirect('/note/all')
                else:
                    args['errors'] = form.errors
                return render_to_response('edit.html',args)
Example #14
0
def NoteCreate(request):
    if request.method == 'POST':
        form = NoteForm(request.POST)
        if form.is_valid():
            note = form.save(commit=False)
            note.created_by = request.user
            note.save()
            # return redirect('/')
            return HttpResponseRedirect('/')
    else:
        form = NoteForm()

    return render(request, 'note_create.html', {'form': form})
Example #15
0
def update(request):
    # 现在这个是要进行更新文章的入口
    # 主要的逻辑处理都在这个里面
    # OK
    id = request.GET.get("id", "1")

    note = Note.objects.get(pk=id)
    # 获得本文的所有的标签,因为无论是用户GET还是POST请求都会用到它,所以把它放到前面
    tags = Tag.objects.filter(noteID=note)

    if request.method == "POST":
        # 如果用户要保存数据
        # note = Note()
        form = NoteForm(request.POST, instance=note)
        if form.is_valid():
            # if note get the authorID then set the ID is -1. because at the
            # first step. we didn't hava build UC system.

            # if user forget to set note's type. we set it as default value 0
            if note.noteType == None:
                note.noteType = 0

            if note.color == None:
                note.color = "#000000"

            # set createtime
            note.createTime = timezone.now()

            try:
                note.save()
                # 获得用户提交的新标签
                newTags = form.cleaned_data["tags"]
                # TODO: not support chinese character
                newTags = newTags.replace(",", "|").replace(";", "|").replace(" ", "").replace("||", "|")
                newTags = newTags.split("|")

                oldTags = []
                for _tag in tags:
                    oldTags.append(_tag.tagName)

                # 如果想让一片文章所有的标签tags都变成最新的。需要先求一次
                # oldTags与newTags的差集,然后删除差集中的所有元素
                # 这样就可以删除所有旧的标签
                # 第二步:newTags 和oldTags进行求差集。然后把这些集合插入到数据库
                # 这样两步就可以实现了标签的更改。
                # Start!
                # first step
                print oldTags
                print newTags
                print 156
                oldDiff = list(set(oldTags).difference(set(newTags)))  # oldTags中有而newTags中没有的
                # 批量删除
                # TODO 可能有删除性能瓶颈,查查批量删除
                for tag in oldDiff:
                    tagRecorder = Tag.objects.get(tagName=tag, noteID=note)
                    tagRecorder.delete()

                print 165
                print newTags
                print oldTags

                newDiff = list(set(newTags).difference(set(oldTags)))  # newTags中有而oldTags中没有的
                print 169
                # 批量插入操作
                insert_list = []
                for tag in newDiff:
                    # 此处逻辑不严,如果tag为空,还会插入的,这样没有意义
                    if tag != "":
                        insert_list.append(Tag(tagName=tag, noteID=note))
                # print insert_list
                Tag.objects.bulk_create(insert_list)
                print 178

                # return redirect(reverse('note.views.view',
                # args=['id',note.id]))
                return HttpResponseRedirect("/view?id=" + str(note.id))
                # return HttpResponse(note.content)
                # return HttpResponse("data is valid and we store it in the
                # database. The id of this note is:"+str(note.id))
            except Exception, e:
                # return HttpResponseRedirect('/view?id='+str(note.id
                return HttpResponse("data is valid and we store it in the database failed. %s " % e)
            finally: