Beispiel #1
0
def board_write(request):
    if not request.session.get('user'):
        return redirect('/scum/login/')

    if request.method == 'POST':
        form = BoardForm(request.POST)
        if form.is_valid():
            user_id = request.session.get('user')
            scumuser = scumUser.objects.get(pk=user_id)

            tags = form.cleaned_data['tags'].split(',')

            board = Board()
            board.title = form.cleaned_data['title']
            board.contents = form.cleaned_data['contents']
            board.writer = scumuser
            board.save()

            for tag in tags:
                if not tag:
                    continue
                _tag, _= Tag.objects.get_or_create(name=tag)
                board.tags.add(_tag)



            return redirect('/board/list/')

    else:
        form = BoardForm
    return render(request, 'board_write.html', {'form': form})
Beispiel #2
0
def create_board(request):

    if request.POST:
        form = BoardForm(request.POST)

        if form.is_valid():

            new_board = Board()
            new_board.save()

            welcomePostit = PostIt(text=_("Welcome! Move me! Edit me! Delete me!"),x=120,y=50, board=new_board, width=100,
                                   height=100)
            sharePostit = PostIt(text=_("Share this board and work together in realtime!")+ "\n\nhttp://www.boardino.com/"+new_board.hash,
                            x=200,
                            y=300,
                            board=new_board,
                            width=220,
                            height=100,
                            back_color='#FF69B4')
            comeBackPostit = PostIt(text=_("Come back to check new features!"),x=550,y=50, board=new_board,
                                    width=150,
                                    height=100,
                                    back_color='#ADFF2F')
            welcomePostit.save()
            sharePostit.save()
            comeBackPostit.save()

            return HttpResponseRedirect("/"+new_board.hash)

    return HttpResponseRedirect("/")
Beispiel #3
0
 def create_board(cls, request):
     # DZIALA
     if request.method == 'POST':
         board_form = BoardForm(request.POST)
         if board_form.is_valid():
             new_board = board_form.save()
             return HttpResponseRedirect("/forum/" + str(new_board.pk))
     else:
         board_form = BoardForm()
     return render_to_response('new_board.html', 
                               {'board_form': board_form}, 
                               context_instance=RequestContext(request)) 
Beispiel #4
0
def new_board(request):
	form = BoardForm()
	if request.method == 'POST':
		form = BoardForm(request.POST)
		if form.is_valid():
			title = form.cleaned_data['title']
			desc = form.cleaned_data['description']
			board = Board(title=title, desc=desc)
			board.save()
			return HttpResponseRedirect('/board')

	context = {
		'form': form
	}
	return render(request, 'board_new.html', context)
Beispiel #5
0
def add_board(request, house_slug):
    house = get_object_or_404(House, slug=house_slug)

    if request.method == 'POST':
        form = BoardForm(request.POST)

        if form.is_valid():
            board = form.save(commit=False)
            board.house = house
            board.save()
            house.updated()
            return HttpResponseRedirect(reverse('boards', args=[house_slug]))
    else:
        form = BoardForm()

    return render(request, 'board/add_board.html', {'house': house,
        'form': form})
Beispiel #6
0
def edit_board(request, house_slug, board_id):
    try:
        board = Board.objects.select_related('house').get(pk=board_id,
            house__slug=house_slug)
    except:
        raise Http404()

    if request.method == 'POST':
        board_form = BoardForm(request.POST, instance=board)

        if board_form.is_valid():
            board.save()
            board.house.updated()
            return HttpResponseRedirect(reverse('boards', args=[board.house.slug]))
    else:
        board_form = BoardForm(instance=board)

    return render(request, 'board/add_board.html', {'house': board.house,
        'form': board_form})
Beispiel #7
0
def board_write(request):
    if not request.session.get('user'):
        return redirect('login')

    if request.method == "GET":
        form = BoardForm()

    elif request.method == "POST":
        form = BoardForm(request.POST)
        if form.is_valid():
            user_id = request.session.get('user')
            user = Users.objects.get(pk=user_id)
            new_board = Board(
                title=form.cleaned_data['title'],
                contents=form.cleaned_data['contents'],
                writer=user
            )
            new_board.save()
            return redirect('/board/list')

    return render(request, 'board/board_write.html', {'form': form})
Beispiel #8
0
def post_new(request):

    if request.method == 'POST':
        form = BoardForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.save()

            upfls = request.FILES.getlist('file')
            for upfl in upfls:
                file = File()
                file.file = upfl
                file.post = post
                file.save()

            upimgs = request.FILES.getlist('image')
            for upimg in upimgs:
                img = Image()
                img.image = upimg
                img.post = post
                img.save()

            return redirect('board:post_detail', pk=post.pk)
    else:
        form = BoardForm()
        file = FileForm()
        image = ImageForm()

    return render(request, 'board/post_edit.html', {
        'form': form,
        'file': file,
        'image': image
    })
def board_edit(request, board_id=None):

    user = request.user.pk
    user_type = request.user.profile.type

    if board_id:
        board = get_object_or_404(Board, pk=board_id)
    else:
        board = Board()

    if request.method == "POST":
        # POST 된 request 데이터를 가지고 Form 생성
        form = BoardForm(request.POST, instance=board)
        if form.is_valid():
            board = form.save(commit=False)
            board.board_id = Board(board_id)
            board.writer = User(user)
            if not board_id:
                board.category = user_type
            board.save()
            # request 없이 페이지 이동만 한다.
        return redirect('board:list')
    else:
        # book instance에서 Form 생성
        form = BoardForm(instance=board)
        # 사용자의 request를 가지고 이동한다.
        return render(request, 'board/board_edit.html',
                      dict(form=form, board=board))
Beispiel #10
0
def edit_board(request, house_slug, board_id):
    try:
        board = Board.objects.select_related('house').get(
            pk=board_id, house__slug=house_slug)
    except:
        raise Http404()

    if request.method == 'POST':
        board_form = BoardForm(request.POST, instance=board)

        if board_form.is_valid():
            board.save()
            board.house.updated()
            return HttpResponseRedirect(
                reverse('boards', args=[board.house.slug]))
    else:
        board_form = BoardForm(instance=board)

    return render(request, 'board/add_board.html', {
        'house': board.house,
        'form': board_form
    })
Beispiel #11
0
def update_board(request, board_id):
    board = get_object_or_404(Board, id=board_id)
    template = 'board/create_update_board.html'
    if request.method == "GET":
        form = BoardForm(instance=board)
        return render(request, template, {'form': form})

    # POST
    form = BoardForm(request.POST, instance=board)
    if not form.is_valid():
        return render(request, template, {'form': form})
    form.save()
    messages.success(request, '公告已修改')
    return redirect('board:board')
Beispiel #12
0
 def create_board(cls, request):
     # DZIALA
     if request.method == 'POST':
         board_form = BoardForm(request.POST)
         if board_form.is_valid():
             new_board = board_form.save()
             return HttpResponseRedirect("/forum/" + str(new_board.pk))
     else:
         board_form = BoardForm()
     return render_to_response('new_board.html', {'board_form': board_form},
                               context_instance=RequestContext(request))
Beispiel #13
0
def post_new(request):
    if request.method == 'POST':
        form = BoardForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.save()
            return redirect('board:post_detail', pk=post.pk)
    else:
        form = BoardForm()

    return render(request, 'board/post_edit.html', {'form': form})
Beispiel #14
0
def post_edit(request, pk):
    cat = Category.objects.all()
    post = get_object_or_404(Board, pk=pk)
    if request.method == 'POST':
        form = BoardForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            # post.published_date = timezone.now()
            post.save()
            return redirect('blog:post_detail', pk=post.pk)
    else:
        form = BoardForm(instance=post)
    return render(request, 'blog/post_edit.html', {'form': form, 'cat': cat})
Beispiel #15
0
def post_edit(request, pk):

    post = get_object_or_404(Board, pk=pk)
    if request.method == 'POST':
        form = BoardForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.save()
            return redirect('board:post_detail', pk=post.pk)
    else:
        form = BoardForm(instance=post)

    return render(request, 'board/post_edit.html', {'form': form})
Beispiel #16
0
def add_board(request, house_slug):
    house = get_object_or_404(House, slug=house_slug)

    if request.method == 'POST':
        form = BoardForm(request.POST)

        if form.is_valid():
            board = form.save(commit=False)
            board.house = house
            board.save()
            return HttpResponseRedirect(reverse('boards', args=[house_slug]))
    else:
        form = BoardForm()

    return render(request, 'board/add_board.html', {'house': house,
        'form': form})
Beispiel #17
0
def create_board(request):
    '''
    Create a new board instance
        1. If method is GET, render an empty form
        2. If method is POST, perform form validation and display error messages if the form is invalid
        3. Save the form to the model and redirect the user to the board page
    '''
    template = 'board/create_update_board.html'
    if request.method == "GET":
        return render(request, template, {'form': BoardForm()})

    # POST
    form = BoardForm(request.POST)
    if not form.is_valid():
        return render(request, template, {'form': form})
    form.save()
    messages.success(request, '公告已新增')
    return redirect('board:board')
Beispiel #18
0
def post_edit(request, pk):
    categories = Category.objects.all()
    post = get_object_or_404(Board, pk=pk)
    getfile = post.file_set.all()
    getimage = post.image_set.all()

    if request.method == 'POST':
        form = BoardForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.save()

            upfls = request.FILES.getlist('file')
            for upfls in upfls:
                file = File()
                file.file = upfls
                file.post = post
                file.save()

            upimgs = request.FILES.getlist('image')
            for upimgs in upimgs:
                image = Image()
                image.image = upimgs
                image.post = post
                image.save()

            return redirect('board:post_detail', pk=post.pk)
    else:
        form = BoardForm(instance=post)
        file = FileForm(instance=getfile)
        image = ImageForm(instance=getimage)

    return render(request, 'board/post_edit.html', {
        'form': form,
        'categories': categories,
        'file': file,
        'image': image
    })