Exemplo n.º 1
0
def add_user_work(request):
    """
        Add a record for User Work Experience
    """
    user = request.user
    fullname = user.get_full_name()
    form = AddWorkForm(request.POST)

    if (form.is_valid() and
        (form.cleaned_data["end_date"] is None
         or form.cleaned_data["end_date"] > form.cleaned_data["start_date"])):
        user_company = form.cleaned_data["company"]
        company = Company.objects.filter(company=user_company)
        if (len(company) == 0):
            company = Company()
            company.company = user_company
            company.save()
            user_company = company
        else:
            user_company = company[0]

        user_position = form.cleaned_data["position"]
        user_description = form.cleaned_data["description"]

        user_work = Work(user=user)
        user_work.company = user_company
        user_work.position = user_position
        user_work.description = user_description
        user_work.start_date = form.cleaned_data["start_date"]
        user_work.end_date = form.cleaned_data["end_date"]
        user_work.save()

        info = True
        info_message = "Added Work Experience !"
        parameters = {'info': info, 'info_message': info_message}
    else:
        error = True
        error_list = True
        error_message = []
        if form.cleaned_data["start_date"] is None:
            error_message.append("Start Date is required")
        if form.cleaned_data["company"] is None:
            error_message.append("Company is required")
        if form.cleaned_data["position"] is None:
            error_message.append("Position is required")
        if (form.cleaned_data["end_date"] is not None and
            (form.cleaned_data["end_date"] < form.cleaned_data["start_date"])):
            error_message.append("End Date has to be later than Start Date")
        parameters = {
            'error': error,
            'error_list': error_list,
            'error_message': error_message
        }

    user_profile = UserProfile.objects.filter(user=user)
    if len(user_profile) != 0:
        profile_exists = True
        current_user_profile = user_profile[0]
        user_profile_dictionary = json.loads(current_user_profile.toJson())
        parameters.update(user_profile_dictionary)
    else:
        profile_exists = False
    default_image = "/static/elearning_academy/img/default/user.jpg"
    parameters.update({
        'user_name': fullname,
        'default_image': default_image,
        'profile_exists': profile_exists
    })
    form = get_update_form(user)
    parameters.update(form)
    return render(request, 'user_profile/profile.html', parameters)
Exemplo n.º 2
0
    def create(self, request):
        data = request.DATA
        username = data.get('username', None)
        password = data.get('password', None)
        email = data.get('email', None)
        first_name = data.get('first_name', None)
        last_name = data.get('last_name', None)
        try:
            user = User(username=username,
                        first_name=first_name,
                        last_name=last_name,
                        email=email,
                        is_active=True)
            user.set_password(password)
            user.save()
        except Exception as e:
            message = {'error': str(e), 'error_message': "Error saving model"}
            return Response(message, status=status.HTTP_400_BAD_REQUEST)
        try:
            mobile = data.get('mobile', None)
            city = data.get('city', None)
            user_profile = UserProfile(user=user)
            user_profile.mobile = mobile
            user_profile.city = city
            user_profile.save()
        except Exception as e:
            user.delete()
            message = {'error': str(e), 'error_message': "Error saving model"}
            return Response(message, status=status.HTTP_400_BAD_REQUEST)
        request.user = user
        user_lst = User.objects.filter(username=username, email=email)
        if len(user_lst) == 0:
            error = True
            error_message = "Please enter valid user details"
            errors = {'error': error, 'error_message': error_message}
            return Response(errors, status=status.HTTP_400_BAD_REQUEST)
        else:
            user = user_lst[0]
            fp_object_lst = ForgotPassword.objects.filter(user=user)
            if len(fp_object_lst) == 0:
                fp_object = ForgotPassword(user=user)
                fp_object.generate_key(request)
            else:
                fp_object = fp_object_lst[0]
                fp_object.generate_key(request)
            fp_object.save()
            user_company = data.get('remoteid', None)
            user_company_desc = data.get('remotecentrename', None)
            if user_company is None:
                user.delete()
                error_message = "Remote ID Missing"
                errors = {'error': True, 'error_message': error_message}
                return Response(errors, status=status.HTTP_400_BAD_REQUEST)
            company = Company.objects.filter(company=user_company)
            if (len(company) == 0):
                company = Company()
                company.company = user_company
                company.save()
                user_company = company
            else:
                user_company = company[0]
            user_work = Work(user=user)
            user_work.company = user_company
            user_work.company_description = user_company_desc
            user_work.save()

            return Response({"alldone": "All"}, status=status.HTTP_201_CREATED)
Exemplo n.º 3
0
def add_user_work(request):
    """
        Add a record for User Work Experience
    """
    user = request.user
    fullname = user.get_full_name()
    form = AddWorkForm(request.POST)

    if (form.is_valid() and
        (form.cleaned_data["end_date"] is None or
            form.cleaned_data["end_date"] > form.cleaned_data["start_date"])):
        user_company = form.cleaned_data["company"]
        company = Company.objects.filter(company=user_company)
        if (len(company) == 0):
            company = Company()
            company.company = user_company
            company.save()
            user_company = company
        else:
            user_company = company[0]

        user_position = form.cleaned_data["position"]
        user_description = form.cleaned_data["description"]

        user_work = Work(user=user)
        user_work.company = user_company
        user_work.position = user_position
        user_work.description = user_description
        user_work.start_date = form.cleaned_data["start_date"]
        user_work.end_date = form.cleaned_data["end_date"]
        user_work.save()

        info = True
        info_message = "Added Work Experience !"
        parameters = {'info': info, 'info_message': info_message}
    else:
        error = True
        error_list = True
        error_message = []
        if form.cleaned_data["start_date"] is None:
            error_message.append("Start Date is required")
        if form.cleaned_data["company"] is None:
            error_message.append("Company is required")
        if form.cleaned_data["position"] is None:
            error_message.append("Position is required")
        if (form.cleaned_data["end_date"] is not None and
                (form.cleaned_data["end_date"] < form.cleaned_data["start_date"])):
            error_message.append("End Date has to be later than Start Date")
        parameters = {'error': error, 'error_list': error_list, 'error_message': error_message}

    user_profile = UserProfile.objects.filter(user=user)
    if len(user_profile) != 0:
        profile_exists = True
        current_user_profile = user_profile[0]
        user_profile_dictionary = json.loads(current_user_profile.toJson())
        parameters.update(user_profile_dictionary)
    else:
        profile_exists = False
    default_image = "/static/elearning_academy/img/default/user.jpg"
    parameters.update({'user_name': fullname,
                      'default_image': default_image,
                      'profile_exists': profile_exists})
    form = get_update_form(user)
    parameters.update(form)
    return render(request, 'user_profile/profile.html', parameters)
Exemplo n.º 4
0
    def create(self, request):
        data = request.DATA
        username = data.get('username', None)
        password = data.get('password', None)
        email = data.get('email', None)
        first_name = data.get('first_name', None)
        last_name = data.get('last_name', None)
        try:
            user = User(username=username,
                        first_name=first_name,
                        last_name=last_name,
                        email=email,
                        is_active=True
                        )
            user.set_password(password)
            user.save()
        except Exception as e:
            message = {'error': str(e), 'error_message': "Error saving model"}
            return Response(message, status=status.HTTP_400_BAD_REQUEST)
        try:
            mobile = data.get('mobile', None)
            city = data.get('city', None)
            user_profile = UserProfile(user=user)
            user_profile.mobile = mobile
            user_profile.city = city
            user_profile.save()
        except Exception as e:
            user.delete()
            message = {'error': str(e), 'error_message': "Error saving model"}
            return Response(message, status=status.HTTP_400_BAD_REQUEST)
        request.user = user
        user_lst = User.objects.filter(username=username, email=email)
        if len(user_lst) == 0:
            error = True
            error_message = "Please enter valid user details"
            errors = {'error': error, 'error_message': error_message}
            return Response(errors, status=status.HTTP_400_BAD_REQUEST)
        else:
            user = user_lst[0]
            fp_object_lst = ForgotPassword.objects.filter(user=user)
            if len(fp_object_lst) == 0:
                fp_object = ForgotPassword(user=user)
                fp_object.generate_key(request)
            else:
                fp_object = fp_object_lst[0]
                fp_object.generate_key(request)
            fp_object.save()
            user_company = data.get('remoteid', None)
            user_company_desc = data.get('remotecentrename', None)
            if user_company is None:
                user.delete()
                error_message = "Remote ID Missing"
                errors = {'error': True, 'error_message': error_message}
                return Response(errors, status=status.HTTP_400_BAD_REQUEST)
            company = Company.objects.filter(company=user_company)
            if (len(company) == 0):
                company = Company()
                company.company = user_company
                company.save()
                user_company = company
            else:
                user_company = company[0]
            user_work = Work(user=user)
            user_work.company = user_company
            user_work.company_description = user_company_desc
            user_work.save()

            return Response({"alldone": "All"}, status=status.HTTP_201_CREATED)