Exemplo n.º 1
0
def courses_list(request):

    user = LoginUser.get_login_user(request)
    if request.method == 'POST':
        params = request.POST
    else:
        params = request.GET

    TestContentLogic.check_lesson_status(user.id)
    course_id = params.get('course_id', '')
    if course_id != '':
        course_id = int(course_id)
    levels = None
    courses = None
    if course_id != '':
        levels = CourseListLogic.get_lesson_dict(user.id, course_id)
    else:
        user_courses_id = CourseListLogic.get_user_courses_ids(user.id)
        courses = CourseListLogic.get_user_courses_dict(user.id)

    context = {
        'user': user,
        'screen_name': ScreenName.Course,
        'levels': levels,
        'courses': courses,
    }

    return render(request, 'courses_list.html', context)
Exemplo n.º 2
0
    def get_term_import_history_list(term_number):
        """
        Retrieve data from table by term_number:
            1. import_history: user_id, owner_id, memo, last_import_date
            2. user_filter: meta_type by user_id
            3. auth_meta_type: 
            4. base_data_auth_meta_rel: 
            5. biz_prospect: target_id, type, opportunity_stage by owner_id
        @param term_number: fiscal term
        @type term_number: int
        @return: 
        """
        user = LoginUser.get_login_user()
        in_query = user.get_filtered_query_string(
            ModuleName.BizProspect, AuthMetaTypeDefine.Department.code)
        results_map = dict()
        # len > 0
        if in_query is not None and len(in_query) > 0:
            query = "select ih.*, lt.meta_id as department_id from import_history ih " \
                    "inner join (select import_history_id, meta_id from biz_prospect bp " \
                    "inner join base_data_auth_meta_rel bd on bd.meta_type_id=%s " \
                    "and bd.base_data_name=%s and bp.id=bd.base_data_id and bd.meta_id in ({0})" \
                    "group by import_history_id, meta_id) lt " \
                    "on ih.id = lt.import_history_id " \
                    "where ih.target_term=%s and ih.data_type=%s " \
                    "order by lt.meta_id,imported_datetime desc".format(in_query)
        # config_role is None
        elif in_query is None:
            query = "select ih.*, lt.meta_id as department_id from import_history ih " \
                    "inner join (select import_history_id, meta_id from biz_prospect bp " \
                    "inner join base_data_auth_meta_rel bd on bd.meta_type_id=%s " \
                    "and bd.base_data_name=%s and bp.id=bd.base_data_id " \
                    "group by import_history_id, meta_id) lt " \
                    "on ih.id = lt.import_history_id " \
                    "where ih.target_term=%s and ih.data_type=%s " \
                    "order by lt.meta_id,imported_datetime desc"
        # len = 0
        else:
            return {}

        results = DbAgent.get_record_set(query, [
            AuthMetaTypeDefine.Department.code,
            AuthBaseDataName.BizProspect.value,
            int(term_number), ImportDataType.BizProspect.value
        ])
        # map results to view in template
        for result in results:
            department_id = result['department_id']
            if department_id in results_map:
                results_map[department_id].append(result)
            else:
                department_value = []
                results_map[department_id] = department_value
                results_map[department_id].append(result)
        return results_map
Exemplo n.º 3
0
    def import_scheduled(import_file=None):
        from default.logic.userlogic import LoginUser
        user = LoginUser.get_login_user()

        if import_file is None:
            import_file = os.path.join(settings.BASE_DIR, 'sampledata',
                                       'scheduled.xlsx')

        data = ImportSample.load_data("scheduled_import_adapter", import_file)
        if not data:
            return

        from default.models.models2 import ScheduledJournal
        l = list()
        start_date = None
        end_date = None
        for rec in data:
            o = ScheduledJournal()
            o.owner_id = user.id
            o.type = rec['type']
            o.accrual_date = rec['accrual_date']
            o.settlement_date = rec['settlement_date']
            if end_date is None or end_date < o.settlement_date:
                end_date = o.settlement_date
            if start_date is None or start_date > o.settlement_date:
                start_date = o.settlement_date

            o.account_id = rec['account_id']
            o.opposite_account_id = rec['opposite_account_id']
            o.amount = rec['amount']
            o.tax = rec['tax']
            o.reference = rec['reference']
            o.definition_type = rec['definition_type']
            o.definition_id = rec['definition_id']
            o.tax_class = rec['tax_class']
            o.tax_rate_id = rec['tax_rate_id']
            l.append(o)

        # Delete old data first
        if start_date is not None and end_date is not None:
            DbAgent.execute_query(
                "delete from scheduled_journal where "
                "owner_id=%s and settlement_date >= %s and settlement_date <=%s",
                [user.id, start_date, end_date])

        ScheduledJournal.objects.bulk_create(l)
Exemplo n.º 4
0
 def log(log_module,
         log_type,
         log_result,
         operation_object=None,
         error_message=None):
     """
     LogOperation.log( LogModule.User, LogType.Insert, LogResult.Success, user_id)
     LogOperation.log( LogModule.User, LogType.Delete, LogResult.Fail, user_id, "Fail to delete")
     @type log_module: LogModule
     @param log_module:
     @type log_type: LogType
     @param log_type:
     @type log_result: LogResult
     @param log_result:
     @param operation_object:
     @param error_message:
     @return:
     """
     user = LoginUser.get_login_user()
     if user is None:
         return
Exemplo n.º 5
0
def video_content(request):

    params = request.GET
    part_id = params.get('part_id', '')
    if part_id != '':
        part_id = int(part_id)
    lag_form = LagForm()
    user = LoginUser.get_login_user(request)
    video_path = CourseListLogic.get_video_path(part_id)
    lag_form.set_image_course(video_path, "Watching this video")
    part = Part.objects.get(pk=part_id)
    part_name = part.name
    summary_path = '/static/courses/{0}/summary/{1}'.format(
        str(part_id), part.summary)
    context = {
        'lag_form': lag_form,
        'video_path': video_path,
        'lesson_name': part_name,
        'summary_file_url': summary_path,
        'part_id': part_id,
    }

    return render(request, 'video_content.html', context)
Exemplo n.º 6
0
    def import_budget(term_number, import_file=None):
        if import_file is None:
            import_file = os.path.join(settings.BASE_DIR, 'sampledata',
                                       'budget.xlsx')

        data = ImportSample.load_data("budget_import_adapter", import_file)
        if not data:
            return

        from default.logic.fiscaltermlogic import FiscalTermLogic
        from default.models.models2 import Budget
        from default.logic.userlogic import LoginUser
        from helper.util import Util
        user = LoginUser.get_login_user()

        budgets = []
        periods = FiscalTermLogic.get_term_period_list(term_number)
        periods = list(periods)
        for rec in data:
            for i in range(12):
                if i < len(periods):
                    budget = Budget()
                    budget.owner_id = user.id
                    budget.plan_type = rec['plan_type']
                    budget.account_id = rec['account_id']
                    budget.fiscal_period_id = periods[i].id
                    budget.comment = rec['comment']
                    budget.amount = rec['amount{0}'.format(i + 1)]
                    budgets.append(budget)

        DbAgent.execute_query(
            "delete from budget where owner_id=%s and fiscal_period_id in ({0})"
            .format(", ".join(map(str,
                                  Util.model_list_to_list(periods,
                                                          "id")))), [user.id])

        Budget.objects.bulk_create(budgets)
Exemplo n.º 7
0
    def create_budget_performance_data(start_date, end_date, fields_dict,
                                       target_data):
        """
        Create list of budget performance data dict base on arguments  
        @type start_date: datetime
        @param start_date: 
        @type end_date: datetime
        @param end_date: 
        @type fields_dict: dict 
        @param fields_dict: 
        @type target_data: lists
        @param target_data: 
        @return: 
        """
        data_list = []
        field_keys = []
        # user field keys
        for key, value in fields_dict.items():
            field_keys.append(key)

        meta_types = MetaType.objects.values('id', 'meta_type', 'disp')
        meta_types_key = []
        for meta_type in meta_types:
            meta_dict = {meta_type['meta_type']: meta_type['disp']}
            field_keys.append(meta_type['meta_type'])
            meta_types_key.append(meta_type['meta_type'])
            fields_dict.update(meta_dict)

        # Filter data
        user = LoginUser.get_login_user()
        filters = user.get_filters(ModuleName.BudgetPerformance)
        # Biz Budget
        base_id_biz_budget = user.get_filtered_base_data_ids(
            filters, AuthBaseDataName.BizBudget.value)
        if BPDownloadTarget.BizBudget.code in target_data:
            biz_budget = DownloadFileLogic.create_biz_budget_data(
                start_date, end_date, field_keys, meta_types_key,
                base_id_biz_budget, user.id)
            data_list.extend(biz_budget)

        # Budget
        if BPDownloadTarget.Budget.code in target_data:
            budget = DownloadFileLogic.create_budget_data(
                start_date, end_date, field_keys, meta_types_key)
            data_list.extend(budget)

        # Prospect
        past = False
        if BPDownloadTarget.PastProspect.code in target_data:
            past = True

        # Result
        if BPDownloadTarget.ResultAndProspect.code in target_data:
            base_id_prospect = user.get_filtered_base_data_ids(
                filters, AuthBaseDataName.BizProspect.value)

            # Get prospect data
            prospect = DownloadFileLogic.create_prospect_data(
                start_date, end_date, field_keys, meta_types_key,
                base_id_prospect, user.id, past)
            data_list.extend(prospect)

            # Get schedule data
            schedule = DownloadFileLogic.create_schedule_data(
                start_date, end_date, field_keys, meta_types_key, past)
            data_list.extend(schedule)

            # Get result data (journal voucher )
            result = DownloadFileLogic.create_result_data(
                start_date, end_date, field_keys, meta_types_key)
            data_list.extend(result)

        return data_list, fields_dict, field_keys
Exemplo n.º 8
0
def courses(request):
    """
    Global variable:
        1. checkbox_values: used to store source meta_type records
        2. his_info_id: load info_form after merging
    Create form:
        1. type_form [main_tab]: meta_type table
        2. info_form [detail_tab]: meta_info table
        3. merge_form: merging meta_type
    Form action:
        1. Insert/Update/Delete: using QuerySet
        2. Merge: using QuerySet
    Return:
        Context format (JSON)
    @param request:
    @return:
    """

    user = LoginUser.get_login_user(request)

    if request.method == 'POST':
        params = request.POST
    else:
        params = request.GET

    meta_type_id = params.get('meta_type_id', '')

    course_video = 'https://www.youtube.com/embed/m6TXPNybrmk'
    course_title = 'Kodaline - Brother'
    keu_form = LagForm()
    keu_form.set_image_course(course_video, course_title)

    is_json = params.get("is_json", '')
    current_lesson = params.get("current_lesson", '')
    next_question = params.get("next_question", '')
    correct_question = params.get("correct_question", '')
    state = params.get("state", '')
    # total_question = 11 Helper.get_total_question(current_lesson)
    total_question = 11
    if is_json == "true":
        ret = dict()
        if int(next_question) > total_question:
            if int(state) == 1:
                correct_question = str(int(correct_question) + 1)
            ret['error'] = True
            if int(correct_question) < 1:
                question = 'question'
            else:
                question = 'questions'
            ret['error_message'] = "You are correct {0}/{1} {2}! ".format(
                correct_question, total_question, question)
            return JsonResponse(ret, safe=False)

        ret = dict()
        ret['error'] = False
        ret['error_message'] = "a hihi"
        if int(state) == 1:
            ret['correct_question'] = int(correct_question) + 1
        else:
            ret['correct_question'] = int(correct_question)

        # ret['images'] = Helper.create_image_urls(current_lesson, next_question, 6)
        # ret['audio_url'] = Helper.create_audio_url(current_lesson, next_question)
        ret['current_lesson'] = int(current_lesson)
        ret['next_question'] = int(next_question) + 1
        return JsonResponse(ret, safe=False)

    part = int(params.get("part", ""))
    video_done = params.get("video_done", "")
    if video_done == "true":
        base_user_part = BaseUserPart.objects.get(
            Q(part=part) & Q(user_id=user.id))
        base_user_part.video = TestResult.Done.code
        base_user_part.save()
        TestContentLogic.check_lesson_status(user.id, part)

    part_content_dict = CourseListLogic.get_part_content_dict(part, user.id)
    lesson_id = Part.objects.get(pk=part).lesson_id
    level_id = Lesson.objects.get(pk=lesson_id).level_id
    course_id = Level.objects.get(pk=level_id).course_id

    context = {
        'user': user,
        'current_lesson': 1,
        'next_question': 1,
        'correct_question': 0,
        'keu_form': keu_form,
        'screen_name': ScreenName.Course,
        'total_question': total_question,
        'lesson_contents': part_content_dict,
        'course_id': course_id,
    }
    return render(request, 'courses.html', context)
Exemplo n.º 9
0
def courses_list(request):
    """
    Global variable:
        1. checkbox_values: used to store source meta_type records
        2. his_info_id: load info_form after merging
    Create form:
        1. type_form [main_tab]: meta_type table
        2. info_form [detail_tab]: meta_info table
        3. merge_form: merging meta_type
    Form action:
        1. Insert/Update/Delete: using QuerySet
        2. Merge: using QuerySet
    Return:
        Context format (JSON)
    @param request:
    @return:
    """
    user = LoginUser.get_login_user(request)
    if request.method == 'POST':
        params = request.POST
    else:
        params = request.GET

    meta_type_id = params.get('meta_type_id', '')

    if meta_type_id and meta_type_id.isdigit():
        meta_type_id = int(meta_type_id)
    else:
        meta_type_id = -1

    type_form = GacoiForm("type_form", "/meta/", "POST")
    type_form.set_view("id, meta_type, disp, created_datetime"
                       )  # , grouping_target, restriction
    type_form.set_key("id")
    if user.is_update_right():
        type_form.set_update("meta_type, disp")
    if user.is_add_right():
        type_form.set_insert("meta_type, disp")
    if user.is_delete_right():
        type_form.set_option_deletable(True)
    type_form.set_hidden("meta_type_id", meta_type_id)
    type_form.set_required("meta_type, disp")
    type_form.get_field("id").set_link("?meta_type_id=[id]&tab_index=1")
    type_form.set_type("created_datetime", GacoiFormFieldType.Date)
    type_form.set_order(
        'id, meta_type, disp, created_datetime, grouping_target, restriction')
    type_form.set_caption({
        'id': 'ID',
        'meta_type': 'メタデータ種別',
        'disp': 'メタデータ名',
        'created_datetime': '登録日'
    })
    type_form.init(request)

    course_data = {
        'video_link': 'https://www.youtube.com/embed/m6TXPNybrmk',
    }

    context = {
        'course_data': course_data,
        'user': user,
        'screen_name': ScreenName.Course,
    }

    return render(request, 'courses_list.html', context)
Exemplo n.º 10
0
    def get_current_data(term_number):
        """
        Retrieve data from table by term_number.
        @param term_number: fiscal term
        @type term_number: int
        @return: 
        """
        user = LoginUser.get_login_user()

        fiscal = FiscalTerm.objects.get(term_number=int(term_number))
        periods = FiscalTermLogic.get_term_period_list(int(term_number))
        auth_meta_types = AuthMetaType.objects.all().order_by("meta_type")

        from helper.util import StringBuilder
        query = StringBuilder()
        query_from = StringBuilder()
        query_group_by = StringBuilder()
        query_order_by = StringBuilder()

        main_fields = "target_id, type, opportunity_stage"  # target_id

        query_from.append("\nfrom biz_prospect bz")
        query_group_by.append("\ngroup by {0}".format(main_fields))
        query.append("select {0}".format(main_fields))

        # Auth meta
        for meta_type in auth_meta_types:
            # Only department
            if meta_type.meta_type == AuthMetaTypeDefine.Department.title:
                in_query = user.get_filtered_query_string(
                    ModuleName.BizProspect, AuthMetaTypeDefine.Department.code)
                # len > 0
                if in_query is not None and len(in_query) > 0:
                    query.append(", {0}.meta_id as {0}".format(
                        meta_type.meta_type))
                    query_from.append(
                        " inner join base_data_auth_meta_rel {0} on {0}.base_data_name='{1}' "
                        "and bz.id={0}.base_data_id and {0}.meta_type_id={2} and {0}.meta_id in ({3})"
                        .format(meta_type.meta_type,
                                AuthBaseDataName.BizProspect.value,
                                meta_type.id, in_query))
                    query_group_by.append(", {0}.meta_id".format(
                        meta_type.meta_type))
                    query_order_by.append(", {0}.meta_id".format(
                        meta_type.meta_type))
                # config_role is None
                elif in_query is None:
                    query.append(", {0}.meta_id as {0}".format(
                        meta_type.meta_type))
                    query_from.append(
                        " inner join base_data_auth_meta_rel {0} on {0}.base_data_name='{1}' "
                        "and bz.id={0}.base_data_id and {0}.meta_type_id={2} ".
                        format(meta_type.meta_type,
                               AuthBaseDataName.BizProspect.value,
                               meta_type.id))
                    query_group_by.append(", {0}.meta_id".format(
                        meta_type.meta_type))
                    query_order_by.append(", {0}.meta_id".format(
                        meta_type.meta_type))
                # len = 0
                else:
                    return []

        # Sum by 12 month
        for i in range(periods.count()):
            query.append(
                ", sum(case when accrual_date >= '{0}' and accrual_date <= '{1}' "
                "then amount else 0 end) as '{2}'".format(
                    periods[i].start_date, periods[i].end_date,
                    periods[i].start_date.month))

        query.append(", sum(amount) as summary")

        query_order_by.append(", {0}".format(main_fields))
        query.append(query_from)
        query.append(
            " \nwhere accrual_date >= '{0}' and accrual_date <= '{1}' ".format(
                fiscal.start_date, fiscal.end_date))
        query.append(query_group_by)
        query.append(" \norder by {0}".format(str(query_order_by)[1:]))

        results = DbAgent.get_record_set(str(query))

        return results
Exemplo n.º 11
0
def ace_menu_generate(screen_name):
    """
    Create top menu. Check roles and show only valid menu
    @type screen_name: ScreenName
    @param screen_name: 
    @type user: LoginUser
    @param user: 
    @return: 
    """
    sb = StringBuilder()
    sidebars = []

    user = LoginUser.get_login_user()

    menu_idx = 0
    active_menu_idx = ""
    for menu_info in config_menus:
        if 'screen_name' in menu_info and not user.is_menu_available(
                menu_info['screen_name']):
            continue
        menu_idx += 1
        sub_menu_idx = 0
        if 'screen_name' in menu_info and screen_name == menu_info[
                'screen_name']:
            active_menu_idx = str(menu_idx)
        menu = create_menu(menu_info['icon'], menu_info['url'],
                           menu_info['name'])
        sidebars.append(menu)
        if 'sub_menu' not in menu_info:
            continue
        for sub_menu_info in menu_info['sub_menu']:
            if 'screen_name' in sub_menu_info and not user.is_menu_available(
                    sub_menu_info['screen_name']):
                continue
            sub_menu_idx += 1
            if 'screen_name' in sub_menu_info and screen_name == sub_menu_info[
                    'screen_name']:
                active_menu_idx = str(menu_idx) + "." + str(sub_menu_idx)
            append_submenu(
                menu,
                create_menu(sub_menu_info['icon'], sub_menu_info['url'],
                            sub_menu_info['name']))

    sb.append('<ul class="nav nav-list">\n')
    menu_idx = 0
    for menu in sidebars:
        menu_idx += 1
        sb.append(render_menu(menu, active_menu_idx, "{0}".format(menu_idx)))

    # sb.append('     <li class="">\n')
    # sb.append('        <a href="/course_list">\n')
    # sb.append('        <i class="menu-icon fa fa-caret-right"></i>\n')
    # sb.append('        <span class="menu-text">\n')
    # sb.append('             <div class="center">\n')
    # sb.append('	                <img src="/static/images/msmy/MsMy.jpg" style="height: 10vh"/>\n')
    # sb.append('	                <h6><span class="red">REMI ENGLISH</span><span class="white" id="id-text2"></span></h6>\n')
    # sb.append('	                <h6 class="blue" id="id-company-text"><i class="fa fa-mobile"></i> 0873.099.599</h6>\n')
    # sb.append('	                <h6 class="blue" id="id-company-text"><i class="fa fa-mobile"></i> 09.03.03.2014</h6>\n')
    # sb.append('	                <h6 class="blue" id="id-company-text"><i class=""></i> http://remienglish.com</h6>\n')
    # sb.append('             </div>\n')
    # sb.append('         </span>\n')
    # sb.append('         </a>\n')
    # sb.append('         <b class="arrow"></b>\n')
    # sb.append('     </li>\n')
    sb.append('</ul><!-- /.nav-list -->\n')

    return str(sb)
Exemplo n.º 12
0
def test_content(request):
    params = request.GET
    test_id = params.get('test_id', '')
    if test_id != '':
        test_id = int(test_id)
    lag_form = LagForm()
    user = LoginUser.get_login_user(request)
    current_test = Test.objects.get(pk=test_id)
    current_test_type = current_test.type
    current_lesson = current_test.part_id
    percent_goal = current_test.question_percent_goal
    question_goal = current_test.question_number_goal
    current_question = params.get('current_question', '')
    if current_question != '':
        current_question = int(current_question)
    else:
        current_question = 0
    options_dict = TestContentLogic.create_options_dict(
        current_test_type, test_id, current_question)
    # lag_form.render_question(current_test_type, current_test_type, test_id)
    is_json = params.get('is_json', '')
    if is_json == 'true':
        ret = dict()
        ret['data'] = options_dict[0]
        ret['options_number'] = options_dict[1]
        ret['current_question'] = options_dict[2]
        return JsonResponse(ret, safe=False)
    total_question = params.get('total_question', '')
    if total_question == '':
        total_question = 0
    else:
        total_question = int(total_question)
    correct_question = params.get('correct_question', '')
    if correct_question == '':
        correct_question = 0
    else:
        correct_question = int(correct_question)

    finished = params.get('finished', '')
    if finished == 'true':
        right_question = int(params.get('right_question', ''))
        total_question = int(params.get('total_question', ''))
        test_id = int(params.get('test_id', ''))
        current_part = int(params.get('current_lesson', ''))
        if total_question == 0:
            current_percent = 0
        else:
            current_percent = round(right_question / total_question * 100, 2)

        base_user_test = BaseUserStep()
        ret = dict()
        ret['result'] = False
        ret['right_number'] = right_question
        ret['percent'] = current_percent
        base_user_test.is_done = TestResult.Failed.code
        percent_goal = int(params.get('percent_goal', ''))
        question_goal = int(params.get('question_goal', ''))
        if current_percent >= percent_goal and right_question >= question_goal:
            ret['result'] = True
            base_user_test.is_done = TestResult.Done.code

        base_user_test.test_id = test_id
        base_user_test.part_id = current_part
        base_user_test.right_percent = current_percent
        base_user_test.right_number_question = right_question
        base_user_test.user_id = user.id
        base_user_test.save()
        # Get user test list
        # If all done -> set is_done in base_student_lesson table to 1
        # Create new record in base_student_lesson for next order lesson
        TestContentLogic.check_lesson_status(user.id, current_part)
        return JsonResponse(ret, safe=True)

    context = {
        'lag_form': lag_form,
        'test_id': test_id,
        'questions': options_dict[1],
        'correct_question': correct_question,
        'total_question': total_question,
        'options_dict': options_dict[0],
        'current_lesson': current_lesson,
        'percent_goal': percent_goal,
        'question_goal': question_goal,
        'current_test_type': current_test_type
    }

    return render(request, 'test_content.html', context)
Exemplo n.º 13
0
def password(request):
    """
    Change password 
    @param request: 
    @return: 
    """
    user = LoginUser.get_login_user(request)
    target_user = None
    if request.method == 'POST':
        params = request.POST
    else:
        params = request.GET

    # Check if change for own
    user_id = params.get("user_id", "")

    password_form = GacoiForm("password_form", "/password/", "POST")
    if user_id == "":
        password_form.set_view("old_password")
        password_form.set_insert("old_password")
        password_form.set_required("old_password")
    else:
        # Check if have right
        if not user.is_right(ModuleName.User, UserRightType.Update):
            return redirect('/')
        target_user = User.objects.get(pk=int(user_id))
        # password_form.set_info_message("{0}さんのパスワードを変更します。".format(target_user.user_name))

    password_form.set_view("new_password,confirm_password")
    password_form.set_insert("new_password,confirm_password")
    password_form.set_required("new_password,confirm_password")

    password_form.set_type("old_password,new_password,confirm_password",
                           GacoiFormFieldType.Password)
    password_form.set_view_type(GacoiFormViewType.FormView)
    password_form.set_hidden("password_change", "")
    password_form.set_hidden("user_id", user_id)
    password_form.add_user_button(
        UserButton("Change password", "do_change_password();", True))
    password_form.add_user_button(
        UserButton("Cancel", "do_close_form();", False))
    password_form.init(request)
    password_form.set_action(GacoiFormAction.InsertStart)
    password_form.set_option_form_label_col(3)
    password_form.set_caption({
        "old_password": "******",
        "new_password": "******",
        "confirm_password": "******"
    })
    changed = False
    if params.get("password_change") == "true":
        old_password = params.get('old_password', None)
        new_password = params.get('new_password', None)
        confirm_password = params.get('confirm_password', None)

        if new_password != confirm_password:
            password_form.set_error_message("Confirm password is not correct")
        else:
            if user_id != "":
                changed_user = User.objects.get(id=int(user_id))
                changed_user.password = UserLogic.hash_password(new_password)
                changed_user.save()
                changed = True
            else:
                changed_user = User.objects.get(id=user.id)
                if UserLogic.is_password_match(old_password,
                                               changed_user.password):
                    changed_user.password = UserLogic.hash_password(
                        new_password)
                    changed_user.save()
                    changed = True
                else:
                    password_form.set_error_message("旧パスワードが一致しません。")

    context = {
        'changed': changed,
        'password_form': password_form,
        'target_user': target_user,
    }

    return render(request, 'password.html', context)