Ejemplo n.º 1
0
def board_update(request, post_id):

    user_name = request.session['userss']
    user_id = request.session['user_id']


    chat = Chat.objects.all()

    post = get_object_or_404(Post, pk=post_id)
    context={'chat': chat,'userss': user_name,'user_id': user_id}
    if request.method == 'POST':
        post_form = PostForm(request.POST, instance=post)

        if post_form.is_valid(): # 입력한 데이터에 문제가 없다면
            post_form.save() # 포스트 폼에 저장한다
            context['post_form']=post_form
            posts = Post.objects.all()
            context['bbspage'] = posts
            return render(request,'bbs.html', context)
            # 네임스페이스가 posts이고 urlpattern에서 name이 list인
            # url로 리다이렉션

    else:
        post_form = PostForm(instance=post)

        # 수정 시 빈 칸이 아니라 instance에 post 데이터를 가져오는 칸을 만들어줌


        return render(request, 'bbs_create.html', {'post_form': post_form, 'userss': user_name, 'user_id': user_id, 'chat': chat})
Ejemplo n.º 2
0
    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form = PostForm(obj=self.object, data=request.POST)

        if form.is_valid():
            form.save()
            return redirect(self.object)

        context = self.get_context_data(object=self.object, form=form)
        return self.render_to_response(context)
Ejemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        self.object = self.get_object()
        form = PostForm(obj=self.object, data=request.POST)

        if form.is_valid():
            form.save()
            return redirect(self.object)

        context = self.get_context_data(object=self.object, form=form)
        return self.render_to_response(context)
Ejemplo n.º 4
0
def edit_post(request, pk):
    post = Post.objects.get(pk=pk)

    if post.approved or request.user != post.author:
        return redirect('/board/')

    tags = Tag.objects.all()
    role = get_role(request.user)
    posttags = post.tags.split(",")
    menu_type = 'general'

    form = PostForm(instance=post)
    if request.method == 'POST':
        form = PostForm(instance=post, data=request.POST, files=request.FILES)
        if form.is_valid():
            post = form.save(commit=False)
            if role == "coordinator" or role == "admin":
                post.status = 1
            else:
                post.status = 3
            post.save()

            short_title = (post.title[:25] +
                           '..') if len(post.title) > 25 else post.title
            details = (post.content[:100] +
                       '..') if len(post.content) > 100 else post.content
            description = u'Board updated - {}'.format(short_title)

            notification = create_notification_from(post)
            notification.type = 4
            notification.creator = request.user
            notification.description = description
            notification.details = details
            notification.save()

            coordinators_ids = (ConsultantProfile.objects.prefetch_related(
                'consultant').get_coordinator_by_market(
                    post.market).is_active().values_list('consultant__id',
                                                         flat=True))

            bulk_receiver_creation(notification, coordinators_ids)

            if role == "coordinator" or role == "admin":
                messages.success(request, 'Post successfully edited.')
            else:
                messages.success(
                    request,
                    'Post successfully edited. An administrator will review it shortly.'
                )

            return redirect('board:board')
        else:
            messages.error(
                request,
                'There was a problem editing the post. Please correct the errors and try again.'
            )

    edit = True

    return render(request, 'board/create.html', locals())
Ejemplo n.º 5
0
def post_edit(request, category_name, pk):
    current_user = UserProfile.objects.get(user=request.user)
    current_post = Post.objects.get(id=pk)

    try:
        cat = Category.objects.get(name=category_name)
    except Category.DoesNotExist:
        cat = None

    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            if cat:
                post = form.save(commit=False)
                current_post.title = post.title
                current_post.content = post.content
                current_post.save()
                return HttpResponseRedirect('/donkey/category/{}/'.format(cat))
        else:
            print(form.errors)
    else:
        form = PostForm()

    context_dict = {'form': form, 'category': cat, 'post': current_post}

    return render(request, 'donkey/edit_post.html', context_dict)
Ejemplo n.º 6
0
def post_edit(request, url_name, category_name, post_pk):
    if request.user.is_anonymous:
        return redirect_with_next('core:accounts:login',
                                  'core:board:post_detail',
                                  params={
                                      'to': [url_name],
                                      'next':
                                      [url_name, category_name, post_pk]
                                  })
    univ = get_object_or_404(Univ, url_name=url_name)
    post = Post.objects.get(pk=post_pk)
    if request.user != post.author:
        return redirect('core:board:post_detail', url_name, category_name,
                        post_pk)

    form = PostForm(request.POST or None, request=request, instance=post)
    if request.method == 'POST':
        if form.is_valid():
            post = form.save(commit=False)
            if post.ctgy.is_anonymous:
                post.is_anonymous = True
            post.save()
            for image in request.FILES.getlist('images'):
                Image.objects.create(post=post, image=image)
            return redirect('core:board:post_detail', url_name, category_name,
                            post_pk)
    return render(request, 'board/post_new.html', {
        'form': form,
        'univ': univ,
        'url_name': url_name
    })
Ejemplo n.º 7
0
def reply_topic(request, pk, topic_pk):
    topic = get_object_or_404(Topic, board__pk=pk, pk=topic_pk)
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.topic = topic
            post.created_by = request.user
            post.save()

            topic.last_updated = timezone.now()
            topic.save()

            topic_url = reverse('topic_posts',
                                kwargs={
                                    'pk': pk,
                                    'topic_pk': topic_pk
                                })
            topic_post_url = '{url}?page={page}#{id}'.format(
                url=topic_url, id=post.pk, page=topic.get_page_count())

            return redirect(topic_post_url)
    else:
        form = PostForm()
    return render(request, 'reply_topic.html', {'topic': topic, 'form': form})
Ejemplo n.º 8
0
def new_post(request, board_slug):
    board = Board.objects.get(slug=board_slug)
    if request.method == 'POST':
        post_form = PostForm(request.POST)
        attachment_form = AttachmentForm(request.POST, request.FILES)
        if post_form.is_valid() and attachment_form.is_valid(
        ) and request.user.is_authenticated:
            post = post_form.save(commit=False)
            post.board = board
            post.ip = get_ip(request)
            try:
                post.account = request.user
            except Post.DoesNotExist:
                post.account = None
            post.save()
            attachment = attachment_form.save(commit=False)
            attachment.post = post
            attachment.save()
            return redirect(board)
    else:
        post_form = PostForm()
        attachment_form = AttachmentForm()

    return render(request, 'new_post.html', {
        'board': board,
        'post_form': post_form,
        'attachment_form': attachment_form
    })
Ejemplo n.º 9
0
def create_post(request):
    role = get_role(request.user)

    tags = Tag.objects.all()
    form = PostForm()
    if request.method == 'POST':
        form = PostForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            market = get_user_market_or_main_market(request.user)

            post = form.save(commit=False)
            post.author = request.user
            post.market = market
            if role == "coordinator" or role == "admin":
                post.status = 1

            post.save()

            short_title = (post.title[:25] +
                           '..') if len(post.title) > 25 else post.title
            details = (post.content[:100] +
                       '..') if len(post.content) > 100 else post.content
            description = u'New board created - {}'.format(short_title)

            notification = create_notification_from(post)
            notification.type = 3
            notification.creator = request.user
            notification.description = description
            notification.details = details
            notification.save()

            coordinators_ids = (
                ConsultantProfile.objects.prefetch_related('consultant').
                get_coordinator_by_market(market).is_active().values_list(
                    'consultant__id', flat=True))

            bulk_receiver_creation(notification, coordinators_ids)

            if role == "coordinator" or role == "admin":
                messages.success(request, 'Post successfully created.')
            else:
                messages.success(
                    request,
                    'Post successfully created. An administrator will review it shortly.'
                )
            return redirect('/board/')
        else:
            messages.error(
                request,
                'There was a problem creating the post. Please correct the errors and try again.'
            )

    if role == 'corporate':
        menu_type = 'general'

    return render(request, 'board/create.html', locals())
Ejemplo n.º 10
0
def new_post(request):
    if request.method == "POST":
        form = PostForm(request.POST)

        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.generate()
            return redirect('board:post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render(request, 'board/form.html', {'form': form})
Ejemplo n.º 11
0
def post_edit(request, pk):
    post = get_object_or_404(Post, pk=pk)
    if post.author == User.objects.get(username=request.user.get_username()):
        if request.method == "POST":
            form = PostForm(request.POST, instance=post)
            if form.is_valid():
                post = form.save(commit=False)
                post.author = request.user
                post.regdate = timezone.now()
                post.generate()
                return redirect('board:post_detail', pk=post.pk)
        else:
            form = PostForm(instance=post)
        return render(request, 'board/form.html', {'form': form})
    else:
        return render(request, 'board/warning.html')
Ejemplo n.º 12
0
def board_create(request):
    print('board_create')
    chat = Chat.objects.all()
    user_name = request.session['userss']
    user_id = request.session['user_id']

    companyNamedict = GetStockCode.Get_CSV_Maching_dict()
    companyName = request.POST.get('machingstock')
    print(companyName)
    xmlDict = GetStockCode.Get_XML_maching_dict()
    match_code = ''


    if companyName is not None:
        match_code = xmlDict[companyName]
        print(match_code)


    if request.method == 'POST':
        post_form = PostForm(request.POST)


        print('포스트로 들오온')
        print(post_form.errors)

        if post_form.is_valid():
            print('폼이상')
            if match_code != '':
                print(post_form)
                # commit=False : db에 넣지말고 객체를 가져와라->post에 넣어줌
                post = post_form.save(commit=False)
                post.maching_code = match_code
                post.stock_name = companyName
                post.author = user_name
                post.save()
            #post_form.save()
            return redirect('board:bbs_main')

    else:
        post_form = PostForm()
        print('get으로 들어온다 ')

    return render(request, 'bbs_create.html', {'post_form': post_form, 'companydict': companyNamedict, 'userss': user_name, 'user_id': user_id, 'chat': chat })
Ejemplo n.º 13
0
def post_create(request, url_name):
    if request.user.is_anonymous:
        return redirect_with_next('core:accounts:login',
                                  'core:board:post_create',
                                  params={
                                      'to': [url_name],
                                      'next': [url_name]
                                  })
    try:
        can_use(request, url_name, ck_univ_url=True, ck_anon=True)
        univ = get_object_or_404(Univ, url_name=url_name)
        form = PostForm(request.POST or None, request=request)
        if request.method == 'POST':
            if form.is_valid():
                post = form.save(commit=False)
                if post.ctgy.is_anonymous:
                    post.is_anonymous = True
                post.save()
                for image in request.FILES.getlist('images'):
                    Image.objects.create(post=post, image=image)
                return redirect(
                    reverse('core:board:main_board', args=[url_name]) +
                    '?state=new')
        return render(request, 'board/post_new.html', {
            'form': form,
            'univ': univ,
            'url_name': url_name,
        })

    except Exception as e:
        if str(e) == 'anon':
            return redirect_with_next("core:accounts:login",
                                      "core:board:main_board",
                                      params={
                                          "to": [url_name],
                                          "next": [url_name]
                                      })
        if str(e) == 'others':
            return redirect("core:board:main_board",
                            url_name=request.user.univ.url_name)

        # return HttpResponseBadRequest(content="Bad request: " + str(e))
        raise SuspiciousOperation
Ejemplo n.º 14
0
def new_post(request, board_slug):
    board = Board.objects.get(slug=board_slug)
    if request.method == 'POST':
        post_form = PostForm(request.POST)
        attachment_form = AttachmentForm(request.POST, request.FILES)
        if post_form.is_valid() and attachment_form.is_valid() and request.user.is_authenticated:
            post = post_form.save(commit=False)
            post.board = board
            post.ip = get_ip(request)
            try:
                post.account = request.user
            except Post.DoesNotExist:
                post.account = None
            post.save()
            attachment = attachment_form.save(commit=False)
            attachment.post = post
            attachment.save()
            return redirect(board)
    else:
        post_form = PostForm()
        attachment_form = AttachmentForm()

    return render(request, 'new_post.html', {'board': board, 'post_form': post_form, 'attachment_form': attachment_form})