Exemple #1
0
def index(request):
    user=request.user

    if user.is_authenticated==False:
        user=User.objects.get(username="******")
    context={
        'username': user.username,
        'userid': user.id,
        'notes':user.notes.all() 
    }
    
    #if post,save that note then display all note as normal
    if request.method=="POST":
        title=request.POST['titleinput']
        content=request.POST['noteinput']
        if len(title)==0 or len(content)==0:
            return render(request,"error.html",context={"errormsg": "empty title or note,please check your input"})
        new_note=Note()
        new_note.user=user;
        new_note.level=3;
        new_note.title=request.POST['titleinput']
        new_note.content=request.POST['noteinput']
        new_note.save();
        context['notes']=reversed(context['notes'])
        return render(request,"note/index.html",context=context)        
    

    if 'keyword' in request.GET:
        #filter keyword in two 
        context['notes']=context['notes'].filter(content__contains=request.GET['keyword']) | context['notes'].filter(title__contains=request.GET['keyword'])
    
    context['notes']=reversed(context['notes'])
    return render(request,"note/index.html",context=context)
Exemple #2
0
 def note_save(self, form, commit=True):
     note = Note()
     note.content = form.cleaned_data.get("content")
     note.uid = self.User.id
     note.username = self.User.username
     note.date_create = now()
     note.date_update = now()
     
     if commit:
         note.save()
Exemple #3
0
def add_note(request, **kwargs):
    user_id = request.user.id

    if request.is_ajax():
        new_note = Note()
        new_note.user_id = user_id
        new_note.name = request.POST.get('name', '')
        if new_note.name == '':
            new_note.name = '제목 없음'

        new_note.content = request.POST.get('content', '')
        if new_note.content == '':
            new_note.content = '내용 없음'

        if request.POST.get('isNotPublic') == 'true':
            new_note.isPublic = False

        new_note.save()

        tmp_topic = request.POST.get('topic', '')
        tmp_topic = tmp_topic.split(':$&*:')
        tmp_topic.pop()

        for t in tmp_topic:
            chk_t = Topic.objects.filter(name__exact=t)
            # 동일한 Topic이 아직 없다면
            if chk_t.count() == 0:
                topic = Topic()
                topic.name = t
                topic.save()
                new_note.topic.add(topic.id)

            # 동일한 Topic이 이미 있다면
            else:
                new_note.topic.add(chk_t[0].id)

        return to_json({'status': 'success', 'id': new_note.id})

    else:
        return to_json({'status': 'failed'})
Exemple #4
0
def add_view(request):
    if request.method == 'GET':
        return render(request, 'note/add_note.html')
    elif request.method == 'POST':
        # 处理提交数据
        title = request.POST.get('title')
        content = request.POST.get('content')
        # 存数据
        username = request.session.get('username')
        user = User.objects.get(username=username)
        note = Note(user=user)
        note.title = title
        note.content = content
        note.save()
        return HttpResponseRedirect('/note/')