示例#1
0
def view_save_note(request):
    if request.POST:
        y = request.POST['y-location']
        x = request.POST['x-location']
        description = request.POST['description']
        note_id = request.POST['note_id']
        url = request.META['HTTP_REFERER']

        if note_id and note_id != 'new' :
            note = Note.objects.get(id=note_id)
        else:        
            note = Note()

        note.x_location = x
        note.y_location = y
        note.url  = url
        note.description = description
        note.is_ticket_shown = True
        note.is_active = True

        note_category = NoteCategory.objects.get(id=1)
        note.note_category = note_category
        note.save()
        
    return HttpResponse('Success')
示例#2
0
文件: views.py 项目: sadyng/noty50
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)
示例#3
0
 def add_note_to_client(self, author=None):
     note = Note(
         note=self,
         author=author,
         client=self.client,
     )
     note.save()
示例#4
0
def addnote(request):
    setting = Setting.objects.get(pk=1)
    if request.method == 'POST':
        form = NoteForm(request.POST, request.FILES)
        if form.is_valid():
            current_user = request.user
            data = Note()  # model ile bağlantı kur
            data.user_id = current_user.id
            data.category = form.cleaned_data['category']
            data.title = form.cleaned_data['title']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.image = form.cleaned_data['image']
            data.detail = form.cleaned_data['detail']
            data.slug = form.cleaned_data['slug']
            data.status = 'False'
            data.save()  # veritabanına kaydet
            messages.success(request, 'Your Content Insterted Successfuly')
            return HttpResponseRedirect('/user/notes')
        else:
            messages.success(request, 'Note Form Error:' + str(form.errors))
            return HttpResponseRedirect('/user/addnote')
    else:
        category = Category.objects.all()
        form = NoteForm()
        context = {
            'category': category,
            'form': form,
            'setting': setting,
        }
        return render(request, 'user_addnote.html', context)
示例#5
0
 def add_note_to_client(self, author=None):
     note = Note(
         note=self,
         author=author,
         client=self.client,
     )
     note.save()
示例#6
0
def add_note(request):
    args = {}
    args.update(csrf(request))
    if request.user.is_authenticated():
        user = auth.get_user(request)
        if request.POST and 'submit_new_note_button' in request.POST:
            new_note_related_labels = request.POST.getlist('new_related_labels')
            new_note_related_categories = request.POST.getlist('new_related_categories')
            new_note_related_labels_int = list()
            new_note_related_categories_int = list()
            for item in new_note_related_labels:
                new_note_related_labels_int.append(int(item))
            for item in new_note_related_categories:
                new_note_related_categories_int.append(int(item))
            new_note = Note()
            if not request.POST['new_title']:
                new_note.note_title = "untitled"
            else:
                new_note.note_title = request.POST['new_title']
            new_note.note_text = request.POST['new_text']
            new_note.note_owner = user
            new_note.save()
            print new_note_related_labels_int
            for item in new_note_related_labels_int:
                new_note.note_labels.add(item)
            for item in new_note_related_categories_int:
                new_note.note_category.add(item)
            new_note.save()
            unsorted_notes = None
            notes_category = None
            notes_label = None
            if "label" in request.session:
                notes_label = request.session['label']
            if "unsorted" in request.session:
                unsorted_notes = request.session['unsorted']
            if "category" in request.session:
                notes_category = request.session['category']
            return all_notes(request, unsorted_notes, notes_category, notes_label)
        elif request.POST and 'cancel_new_note_button' in request.POST:
            unsorted_notes = None
            notes_category = None
            notes_label = None
            if "label" in request.session:
                notes_label = request.session['label']
            if "unsorted" in request.session:
                unsorted_notes = request.session['unsorted']
            if "category" in request.session:
                notes_category = request.session['category']
            return all_notes(request, unsorted_notes, notes_category, notes_label)
        else:
            categories_and_labels = create_labels_categories_lists(user.id)
            args['username'] = user.username
            args['labels_list'] = categories_and_labels['labels']
            args['categories_list'] = categories_and_labels['categories']
            args['new_label_form'] = NewLabelForm()
            return render_to_response('add_note.html', args)
    return render_to_response('start.html', args)
示例#7
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()
示例#8
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/')
示例#9
0
 def post(self, request, *args, **kwargs):
     """
     Adding a new note
     """
     serializer = self.get_serializer(data=request.data)
     if not serializer.is_valid():
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
     else:
         data = serializer.data
         note = Note(owner=request.user,
                     title=data['title'],
                     content=data['content'])
         note.save()
         data['id'] = note.pk
         return Response(data, status=status.HTTP_201_CREATED)
示例#10
0
文件: views.py 项目: milypoint/dnote
    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
            })
示例#11
0
	def form_valid(self, form):
		try:
			note = Note.objects.get(pk=self.kwargs['pk'])
			data = form.cleaned_data
			note.title = data['title']
			note.short_text = data['short_text']
			note.tags = form.cleaned_data['tags']
			note.date = timezone.now()
			note.save()
			note.save_users_and_groups(data['users'], data['groups'])
		except KeyError:
			data = form.cleaned_data
			note = Note(owner=self.request.user, title=data['title'], short_text=data['short_text'])
			note.save()
			note.save_users_and_groups(data['users'], data['groups'])
		return HttpResponseRedirect(reverse('note:index'))
示例#12
0
文件: views.py 项目: pjkui/notepad
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:
示例#13
0
文件: views.py 项目: yyy20119/django
def add(request):
    if request.method=='GET':
        return render(request,'note/add_note.html')
    elif request.method=='POST':
        #处理数据
        #考虑登录状态
        uid=request.session.get('uid')
        if not uid:
            return HttpResponse('请先登录')
        user=User.objects.filter(id=uid)
        #todo 检查用户是否可以发表言论
        user=user[0]
        title=request.POST.get('title')
        content=request.POST.get('content')
        #todo 检查 title content 是否提交
        note=Note(title=title,content=content,user=user)
        note.save()
        return HttpResponseRedirect('/note/')
示例#14
0
def register(request):
    form = UserCreationForm()
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        email = request.POST.get('email')
        username = request.POST.get('username')
        fullname = request.POST.get('fullname')
        if form.is_valid():

            note = Note(title="Dummy note title",
                        description="Dummy note description",
                        username=username,
                        active=True)
            note.save()
            form.save()

            messages.success(request, 'Your account has been created')
            return redirect('login')

    return render(request, 'register.html', {'form': form})
示例#15
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'})
示例#16
0
def save_note(request):
    note_content = str.strip(request.POST['note_content'])
    note_id = request.POST['note_id']
    if 3 < len(note_content) < 1000:
        try:
            if note_id:
                note = Note.objects.get(pk=note_id)
            else:
                note = Note()
            note.note = note_content
            note.save()
            return HttpResponseRedirect(reverse('home'))
        except:
            return render(
                request, 'add.html', {
                    'error_message': 'Internal server error',
                    'note_content': note_content
                })
    else:
        return render(
            request, 'add.html', {
                'error_message': 'Note length is invalid',
                'note_content': note_content
            })
示例#17
0
文件: views.py 项目: olivaq/notes
def dopost(request, url):
	n = Note(url = url, note = request.POST['note'])
	n.save()
	return HttpResponse("This is a post")
示例#18
0
def addNote(uid, tag, title, content, isPublic):
	user = User.objects.get(id = uid)
	now = time.strftime('%Y-%m-%d',time.localtime(time.time()))
	newNote = Note(uid = user, tag = tag, title = title, content = content, date = now, isPublic = isPublic)
	newNote.save()