Exemple #1
0
    def post(request, lang, title_id):

        sid = transaction.savepoint()

        if lang == 'ja':
            form = TitleForm(request.POST)
            title_model = Title()
            introduction_model = Introduction()
        else:
            form = TitleEnForm(request.POST)
            title_model = TitleEn()
            introduction_model = IntroductionEn()

        title_post = title_model.get_by_id(title_id)
        if title_post is None:
            return HttpResponseRedirect('/{}/admin/titles'.format(lang))

        if form.errors:
            messages.add_message(request, messages.INFO,
                                 dict(form.errors.items()))

        if form.is_valid():
            try:
                title_model.edit_title(title_id, {
                    'title': form.cleaned_data.get('title'),
                })
                add_introductions = form.cleaned_data.get('introductions')
                if add_introductions:
                    Introduction.add_introduction_from_title(
                        title_id, add_introductions)
                else:
                    Introduction.remove_introduction_from_title(title_id)

                transaction.savepoint_commit(sid)

                return HttpResponseRedirect('/{}/admin/titles'.format(lang))

            except:

                transaction.savepoint_rollback(sid)
                pass

        if form.cleaned_data.get('introductions'):
            introductions_ids = list(
                map(int, form.cleaned_data.get('introductions')))
            use_introductions = introduction_model.get_by_ids(
                introductions_ids)
        else:
            use_introductions = title_post.introduction_set.all()

        return TemplateResponse(
            request, 'title.html', {
                'title': '新規投稿 | タイトル | FEED App 管理',
                'title_post': title_post,
                'use_introductions': use_introductions,
                'form_data': form.cleaned_data,
                'error_messages': get_error_message(request),
                'lang': lang,
            })
Exemple #2
0
    def post(request, lang):

        sid = transaction.savepoint()

        if lang == 'ja':
            form = TitleForm(request.POST)
            title_model = Title()
            introduction_model = Introduction()
        else:
            form = TitleEnForm(request.POST)
            title_model = TitleEn()
            introduction_model = IntroductionEn()

        if form.errors:
            messages.add_message(request, messages.INFO,
                                 dict(form.errors.items()))

        if form.is_valid():
            try:
                res_title = title_model.create_title({
                    'title':
                    form.cleaned_data.get('title'),
                })
                add_introductions = form.cleaned_data.get('introductions')
                if add_introductions:
                    introduction_model.add_title(res_title.id,
                                                 add_introductions)

                transaction.savepoint_commit(sid)

                return HttpResponseRedirect('/{}/admin/titles'.format(lang))

            except:

                transaction.savepoint_rollback(sid)
                pass

        select_introductions = []
        if form.cleaned_data.get('introductions'):
            introductions_ids = list(
                map(int, form.cleaned_data.get('introductions')))
            select_introductions = introduction_model.get_by_ids(
                introductions_ids)

        return TemplateResponse(
            request, 'title_create.html', {
                'title': '新規投稿 | タイトル | FEED App 管理',
                'select_introductions': select_introductions,
                'form_data': form.cleaned_data,
                'error_messages': get_error_message(request),
                'lang': lang,
            })
Exemple #3
0
    def post(request, lang):

        sid = transaction.savepoint()

        if lang == 'ja':
            form = VideoForm(request.POST)
            video_model = Video()
        else:
            form = VideoEnForm(request.POST)
            video_model = VideoEn()
        if form.errors:
            messages.add_message(request, messages.INFO,
                                 dict(form.errors.items()))

        if form.is_valid():
            try:
                res_video = video_model.create_video({
                    'published_at':
                    form.cleaned_data.get('published_at'),
                    'title':
                    form.cleaned_data.get('title'),
                    'text':
                    form.cleaned_data.get('text'),
                    'youtube_id':
                    form.cleaned_data.get('youtube_id'),
                })
                add_introductions = form.cleaned_data.get('introductions')
                if add_introductions:
                    video_model.add_introduction(res_video.id,
                                                 add_introductions)
                add_categories = form.cleaned_data.get('categories')
                if add_categories:
                    video_model.add_category(res_video.id, add_categories)
                add_topics = form.cleaned_data.get('topics')
                if add_topics:
                    video_model.add_topic(res_video.id, add_topics)

                transaction.savepoint_commit(sid)

                return HttpResponseRedirect('/{}/admin/videos'.format(lang))

            except:
                transaction.savepoint_rollback(sid)
                pass

        if lang == 'ja':
            topic_model = Topic()
            introduction_model = Introduction()
        else:
            topic_model = TopicEn()
            introduction_model = IntroductionEn()

        select_categories = []
        if form.cleaned_data.get('categories'):
            category_ids = list(map(int, form.cleaned_data.get('categories')))
            select_categories = Category.get_by_ids(category_ids)

        select_introductions = []
        if form.cleaned_data.get('introductions'):
            title_ids = list(map(int, form.cleaned_data.get('introductions')))
            select_introductions = introduction_model.get_by_ids(title_ids)

        select_topics = []
        if form.cleaned_data.get('topics'):
            topic_ids = list(map(int, form.cleaned_data.get('topics')))
            select_topics = topic_model.get_by_ids(topic_ids)

        select_videos = []
        if form.cleaned_data.get('videos'):
            video_ids = list(map(int, form.cleaned_data.get('videos')))
            select_videos = video_model.get_by_ids(video_ids)

        groups = Group.get_all()

        return TemplateResponse(
            request, 'video_create.html', {
                'title': '新規投稿 | 動画 | FEED App 管理',
                'select_categories': select_categories,
                'select_introductions': select_introductions,
                'select_topics': select_topics,
                'select_videos': select_videos,
                'groups': groups,
                'form_data': form.cleaned_data,
                'error_messages': get_error_message(request),
                'lang': lang,
            })