Esempio n. 1
0
def upload_pic(request):
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            m = ExampleModel()
            m.model_pic = form.cleaned_data['image']
            m.save()
            return HttpResponse('image upload success')
    return HttpResponseForbidden('allowed only via POST')
Esempio n. 2
0
def update_post_complete(request):
    try:
        entry = Entries.objects.get(id=request.POST['entry_id'])
    except:
        return HttpResponse('Post does not exist anymore %s' %
                            request.POST['entry_id'])
    edit_title = request.POST['title']
    edit_content = request.POST['content']
    edit_category = Categories.objects.get(id=request.POST['category'])

    # 글 꼬리표 처리
    if request.POST.has_key('tags') == True:
        tags = map(lambda str: str.strip(),
                   unicode(request.POST['tags']).split(','))
        tag_list = map(
            lambda tag: TagModel.objects.get_or_create(Title=tag)[0], tags)
    else:
        tag_list = []

    #계정확인   &  이미지 업로드
    if request.method == 'POST':
        entry.Title = edit_title
        entry.Content = edit_content
        entry.Category = edit_category
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            edit_image = request.FILES['image']
            entry.Image = edit_image

    #꼬리표 임시추가
    try:
        entry.save()
    except:
        return HttpResponse('Error: incomplete save for tag')

    # 꼬리표 추가
    entry.Tags = tag_list

    # 최종 저장.
    if len(tag_list) > 0:
        try:
            entry.save()
            return redirect('/')
        except:
            return HttpResponse('Error: incomeplete saving')
    return HttpResponse('Error:nothiung happened')
Esempio n. 3
0
def update_post_complete(request):    
    try:
    	entry = Entries.objects.get(id=request.POST['entry_id'])    
    except:  
        return HttpResponse('Post does not exist anymore %s' %request.POST['entry_id'])
    edit_title = request.POST['title']
    edit_content = request.POST['content']
    edit_category = Categories.objects.get(id=request.POST['category'])

    # 글 꼬리표 처리    
    if request.POST.has_key('tags') == True:
        tags = map(lambda str: str.strip(), unicode(request.POST['tags']).split(','))
        tag_list = map(lambda tag: TagModel.objects.get_or_create(Title=tag)[0], tags)
    else:
        tag_list = []

    #계정확인   &  이미지 업로드
    if request.method == 'POST':
	entry.Title=edit_title
	entry.Content=edit_content
	entry.Category=edit_category
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
	    edit_image=request.FILES['image']
	    entry.Image=edit_image
    
    #꼬리표 임시추가 
    try:
        entry.save()
    except:
        return HttpResponse('Error: incomplete save for tag')
    
    # 꼬리표 추가
    entry.Tags=tag_list

    # 최종 저장.
    if len(tag_list) > 0:
        try:
            entry.save()
	    return redirect('/');
        except:
            return HttpResponse('Error: incomeplete saving')
    return HttpResponse('Error:nothiung happened')
Esempio n. 4
0
def add_post(request):
    
    # 글 제목 처리
    if request.POST.has_key('title') == False:
        return HttpResponse('Missing title of the post')
    else:
        if len(request.POST['title']) == 0:
            return HttpResponse('Title must be longer than one letter')
        else:
            entry_title = request.POST['title']

    # 글 본문 처리
    if request.POST.has_key('content') == False:
        return HttpResponse('Missing content of the post')
    else:
        if len(request.POST['content']) == 0:
            return HttpResponse('Content must be longer than one letter')
        else:
            entry_content = request.POST['content']

    # 글 갈래 처리
    if request.POST.has_key('category') == False:
        return HttpResponse('Must choose category')
    else:
        try:
            entry_category = Categories.objects.get(id=request.POST['category'])
        except:
            return HttpResponse('Invaild category')

    # 글 꼬리표 처리    
    if request.POST.has_key('tags') == True:
        tags = map(lambda str: str.strip(), unicode(request.POST['tags']).split(','))
        tag_list = map(lambda tag: TagModel.objects.get_or_create(Title=tag)[0], tags)
    else:
        tag_list = []

    #계정확인   &  이미지 업로드
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
	    entry_user = request.user
            entry_image=request.FILES['image']
	    new_entry = Entries(User = entry_user, Title=entry_title, Content=entry_content, Category=entry_category, Image=entry_image)
    	else:
	    entry_user = request.user
            new_entry = Entries(User = entry_user, Title=entry_title, Content=entry_content, Category=entry_category)
    
    #꼬리표 임시추가 
    try:
        new_entry.save()
    except:
        return HttpResponse('Error: incomplete save for tag')
    
    # 꼬리표 추가
    for tag in tag_list:
        new_entry.Tags.add(tag)
        
    # 최종 저장.
    if len(tag_list) > 0:
        try:
            new_entry.save()
        except:
            return HttpResponse('Error: incomeplete saving')
    return redirect('/')
Esempio n. 5
0
def add_post(request):

    # 글 제목 처리
    if request.POST.has_key('title') == False:
        return HttpResponse('Missing title of the post')
    else:
        if len(request.POST['title']) == 0:
            return HttpResponse('Title must be longer than one letter')
        else:
            entry_title = request.POST['title']

    # 글 본문 처리
    if request.POST.has_key('content') == False:
        return HttpResponse('Missing content of the post')
    else:
        if len(request.POST['content']) == 0:
            return HttpResponse('Content must be longer than one letter')
        else:
            entry_content = request.POST['content']

    # 글 갈래 처리
    if request.POST.has_key('category') == False:
        return HttpResponse('Must choose category')
    else:
        try:
            entry_category = Categories.objects.get(
                id=request.POST['category'])
        except:
            return HttpResponse('Invaild category')

    # 글 꼬리표 처리
    if request.POST.has_key('tags') == True:
        tags = map(lambda str: str.strip(),
                   unicode(request.POST['tags']).split(','))
        tag_list = map(
            lambda tag: TagModel.objects.get_or_create(Title=tag)[0], tags)
    else:
        tag_list = []

    #계정확인   &  이미지 업로드
    if request.method == 'POST':
        form = ImageUploadForm(request.POST, request.FILES)
        if form.is_valid():
            entry_user = request.user
            entry_image = request.FILES['image']
            new_entry = Entries(User=entry_user,
                                Title=entry_title,
                                Content=entry_content,
                                Category=entry_category,
                                Image=entry_image)
        else:
            entry_user = request.user
            new_entry = Entries(User=entry_user,
                                Title=entry_title,
                                Content=entry_content,
                                Category=entry_category)

    #꼬리표 임시추가
    try:
        new_entry.save()
    except:
        return HttpResponse('Error: incomplete save for tag')

    # 꼬리표 추가
    for tag in tag_list:
        new_entry.Tags.add(tag)

    # 최종 저장.
    if len(tag_list) > 0:
        try:
            new_entry.save()
        except:
            return HttpResponse('Error: incomeplete saving')
    return redirect('/')