Esempio n. 1
0
    def get(self, request, o_id):
        meister = Meister.objects.get(lic_num=o_id)
        try:
            bgimage = BackgroundPhoto.objects.get(
                content_type=ContentType.objects.get(model='meister'),
                object_id=o_id)
        except BackgroundPhoto.DoesNotExist:
            bgimage = None
        #data_source = 'California Contractors State License Board'

        try:
            review = Review.objects.filter(
                content_type=ContentType.objects.get(model='meister'),
                object_id=o_id,
                review_status='A')
        except:
            review = None
        # rating
        RATING_STAR_MAX = 10
        meister_ratings = Rating.objects.filter(
            content_type=ContentType.objects.get(model='meister'),
            object_id=o_id).order_by('ratings_average')
        ratings = {}
        ratings['stars'] = range(RATING_STAR_MAX, 0, -1)
        # TODO:NEED TO CHANGE HERE
        ratings['overall'] = (avg_rating(review, 'Q') + avg_rating(
            review, 'E') + avg_rating(review, 'L')) / 3
        try:
            ratings['rate'] = [(item.average,
                                round(item.average * 1.0 / RATING_STAR_MAX, 2))
                               for item in meister_ratings]
        except:
            pass
        project_photos = Photo.objects.filter(
            content_type=ContentType.objects.get(model='meister'),
            object_id=o_id)
        if request.user.is_anonymous():
            p_lic_num = None
        else:
            try:
                p_lic_num = str(request.user.professional_profiles.first().
                                professional.lic_num)
            except:
                p_lic_num = -1

        # other situation
        user_rating_form = UserRatingForm()
        if request.user.is_authenticated:
            review_form = ReviewForm(
                initial={
                    'first_name': request.user.first_name,
                    'last_name': request.user.last_name,
                    'project_date': datetime.datetime.today().strftime(
                        '%Y-%m-%d')
                })
        else:
            review_form = ReviewForm(initial={
                'project_date':
                datetime.datetime.today().strftime('%Y-%m-%d')
            })
        try:
            overview = Overview.objects.get(
                content_type=ContentType.objects.get(model='meister'),
                object_id=o_id).overview
        except Overview.DoesNotExist:
            overview = _(
                """{lic_name} is a professional located in {full_state_name}. The professional is verified as 
            active when we checked last time. If you would like to know {lic_name} more, please contact us and we will 
            share more information and data about this meister to you."""
            ).format(lic_name=meister.lic_name,
                     full_state_name=get_state_full_name(meister.state))
        overview_form = OverviewForm(initial={'overview': overview})
        info_dict = {
            "meister": meister,
            "bg_image": bgimage,
            "overview": overview,
            'review': review,
            "ratings": ratings,
            'project_photos': project_photos,
            'review_form': review_form,
            "user_rating_form": user_rating_form,
            'p_lic_num': p_lic_num,
            'overview_form': overview_form
        }
        template_name = 'meister/meister.html'
        return render(request, template_name, {"info_dict": info_dict})
Esempio n. 2
0
    def post(self, request, o_id):
        template_name = 'meister/meister.html'
        meister = Meister.objects.get(lic_num=o_id)
        try:
            bgimage = BackgroundPhoto.objects.get(
                content_type=ContentType.objects.get(model='meister'),
                object_id=o_id)
        except BackgroundPhoto.DoesNotExist:
            bgimage = None
        #data_source = 'California Contractors State License Board'

        try:
            review = Review.objects.filter(
                content_type=ContentType.objects.get(model='meister'),
                object_id=o_id,
                review_status='A')
        except:
            review = None
        # rating
        RATING_STAR_MAX = 10
        meister_ratings = Rating.objects.filter(
            content_type=ContentType.objects.get(model='meister'),
            object_id=o_id).order_by('ratings_average')
        ratings = {}
        ratings['stars'] = range(RATING_STAR_MAX, 0, -1)
        # TODO:NEED TO CHANGE HERE
        ratings['overall'] = (avg_rating(review, 'Q') + avg_rating(
            review, 'E') + avg_rating(review, 'L')) / 3
        try:
            ratings['rate'] = [(item.average,
                                round(item.average * 1.0 / RATING_STAR_MAX, 2))
                               for item in meister_ratings]
        except:
            pass
        project_photos = Photo.objects.filter(
            content_type=ContentType.objects.get(model='meister'),
            object_id=o_id)
        if request.user.is_anonymous():
            p_lic_num = None
        else:
            try:
                p_lic_num = str(request.user.professional_profiles.first().
                                professional.lic_num)
            except:
                p_lic_num = -1

        # other situation
        user_rating_form = UserRatingForm()
        if request.user.is_authenticated:
            review_form = ReviewForm(
                initial={
                    'first_name': request.user.first_name,
                    'last_name': request.user.last_name,
                    'project_date': datetime.datetime.today().strftime(
                        '%Y-%m-%d')
                })
        else:
            review_form = ReviewForm(initial={
                'project_date':
                datetime.datetime.today().strftime('%Y-%m-%d')
            })
        try:
            overview = Overview.objects.get(
                content_type=ContentType.objects.get(model='meister'),
                object_id=o_id).overview
        except Overview.DoesNotExist:
            overview = _(
                """{lic_name} is a professional located in {full_state_name}. The professional is verified as 
            active when we checked last time. If you would like to know {lic_name} more, please contact us and we will 
            share more information and data about this meister to you."""
            ).format(lic_name=meister.lic_name,
                     full_state_name=get_state_full_name(meister.state))
        overview_form = OverviewForm(initial={'overview': overview})
        info_dict = {
            "meister": meister,
            "bg_image": bgimage,
            "overview": overview,
            'review': review,
            "ratings": ratings,
            'project_photos': project_photos,
            'review_form': review_form,
            "user_rating_form": user_rating_form,
            'p_lic_num': p_lic_num,
            'overview_form': overview_form
        }

        if request.POST.get('review'):
            user_rating_form = UserRatingForm(request.POST)
            review_form = ReviewForm(request.POST)
            # TODO: assign a random password
            # TODO: validator doesn't work
            if review_form.is_valid() and user_rating_form.is_valid():
                model_type = check_professional_type(request)
                review = review_form.save(commit=False)
                if request.user.is_authenticated():
                    review.user = request.user
                review.content_type = ContentType.objects.get(model=model_type)
                review.object_id = o_id
                review.save()

                for field in user_rating_form.cleaned_data:
                    user_rating = UserRating(
                        review=review,
                        rating_type=field[0].upper(),
                        rating_score=int(user_rating_form.cleaned_data[field]))
                    user_rating.save()
                # direct to the page to upload photos
                # TODO: ADD PHOTOFORM VALIDATION FOR SECURITY
                content_type = ContentType.objects.get(model='review')
                object_id = int(review.id)
                files = request.FILES.getlist('project photos')
                if len(files) > 0:
                    for f in files:
                        instance = Photo.objects.create(
                            img=f,
                            title=f.name,
                            content_type=content_type,
                            object_id=object_id)
                        instance.save()
                else:
                    pass
                # request.session.pop('review_form', None)
                # TODO: redirect the sucess url and add bootstrap messages: success
                return redirect(request.path)
            else:
                # request.session.update({'review_form': review_form.data})
                info_dict['review_form'] = review_form
                info_dict["user_rating_form"] = user_rating_form
                messages.warning(
                    request,
                    _('Submit Failed. Please verify your content is correct.'))
                return render(request, template_name, {"info_dict": info_dict})
        elif request.POST.get('overview'):
            edit_overview(request, o_id)
            return redirect(request.path)
        else:
            raise Http404(_("Error Pages!"))
Esempio n. 3
0
    def get(self, request, designer_id):
        designer = Designer.objects.get(lic_num=str(designer_id))
        o_id = designer.lic_id
        try:
            bgimage = BackgroundPhoto.objects.get(
                content_type=ContentType.objects.get(model='designer'),
                object_id=o_id)
        except:
            bgimage = None

        data_source = 'NCIQ'
        score = None
        rank = None

        full_state_name = get_state_full_name(designer.state)
        # preferred_project_type = 'house remodel'
        # if preferred_project_type:
        #     specialization = 'with many year experiences in ' + preferred_project_type
        # else:
        #     specialization = None
        # Lic Type
        lic_type = designer.lic_type.split('&')
        try:
            review = Review.objects.filter(
                content_type=ContentType.objects.get(model='designer'),
                object_id=o_id,
                review_status='A')
        except:
            review = None

        RATING_STAR_MAX = 10
        contractor_ratings = Rating.objects.filter(
            content_type=ContentType.objects.get(model='designer'),
            object_id=o_id).order_by('ratings_average')
        ratings = {}
        ratings['stars'] = range(RATING_STAR_MAX, 0, -1)

        # TODO:NEED TO CHANGE HERE
        ratings['overall'] = (avg_rating(review, 'Q') + avg_rating(
            review, 'E') + avg_rating(review, 'L')) / 3
        try:
            ratings['rate'] = [(item.average,
                                round(item.average * 1.0 / RATING_STAR_MAX, 2))
                               for item in contractor_ratings]
        except:
            pass

        if request.user.is_anonymous():
            p_lic_num = None
        else:
            try:
                p_lic_num = str(request.user.professional_profiles.first().
                                professional.lic_num)
            except:
                p_lic_num = None

        project_photos = Photo.objects.filter(
            content_type=ContentType.objects.get(model='designer'),
            object_id=o_id)

        user_rating_form = UserRatingForm()
        if request.user.is_authenticated:
            review_form = ReviewForm(
                initial={
                    'first_name': request.user.first_name,
                    'last_name': request.user.last_name,
                    'project_date': datetime.datetime.today().strftime(
                        '%Y-%m-%d')
                })
        else:
            review_form = ReviewForm(initial={
                'project_date':
                datetime.datetime.today().strftime('%Y-%m-%d')
            })

        try:
            overview = Overview.objects.get(
                content_type=ContentType.objects.get(model='designer'),
                object_id=o_id).overview
        except Overview.DoesNotExist:
            overview = _(
                """{bus_name} is a designer based on {city} {state} . The company holds a license number according to {data_source}. 
                The License is verified as active when we checked last time. If you would like to know {bus_name} more, 
                please contact us and we will share more information about this designer to you.
                """).format(bus_name=designer.lic_name,
                            city=designer.city,
                            state=designer.state,
                            data_source=data_source,
                            rank=rank,
                            full_state_name=full_state_name)

        overview_form = OverviewForm(initial={'overview': overview})

        info_dict = {
            "designer": designer,
            "bg_image": bgimage,
            "overview": overview,
            "score": score,
            "lic_type": lic_type,
            'review': review,
            "ratings": ratings,
            'project_photos': project_photos,
            'review_form': review_form,
            "user_rating_form": user_rating_form,
            'overview_form': overview_form,
            'p_lic_num': p_lic_num
        }
        return render(request, 'designer/designer.html',
                      {"info_dict": info_dict})
Esempio n. 4
0
def submit_review(request, o_id):
    template_name = r'review/submit_review.html'
    if request.method == "POST":

        user_rating_form = UserRatingForm(request.POST)
        # sign_up_form = SignUpForm2(request.POST)
        review_form = ReviewForm(request.POST)
        # TODO: assign a random password
        if review_form.is_valid() and user_rating_form.is_valid():
            # User = #ContentType.objects.get_for_model(settings.AUTH_USER_MODEL)
            # TODO: anyone could leave message and add recaptcha.

            # user = User(email=review_form.cleaned_data['email'],
            #             username=review_form.cleaned_data['email'],
            #             last_name=review_form.cleaned_data['last_name'],
            #             first_name=review_form.cleaned_data['first_name'],
            #             password=make_password("aaaaaaa"))
            # user.save()
            model_type = check_professional_type(request)
            review = review_form.save(request, commit=False)
            if request.user.is_authenticated():
                review.user = request.user
            #TODO: add changes here
            review.content_type = ContentType.objects.get(model=model_type)
            instance = review.content_type.model_class().objects.get(
                lic_num=o_id)
            review.object_id = instance.lic_id
            review.save()

            for field in user_rating_form.cleaned_data:
                user_rating = UserRating(
                    review=review,
                    rating_type=field[0].upper(),
                    rating_score=int(user_rating_form.cleaned_data[field]))
                user_rating.save()
            # direct to the page to upload photos
            content_type = ContentType.objects.get(model='review')
            object_id = int(review.id)
            files = request.FILES.getlist('project photos')
            if len(files) > 0:
                for f in files:
                    instance = Photo.objects.create(img=f,
                                                    title=f.name,
                                                    content_type=content_type,
                                                    object_id=object_id)
                    instance.save()
            else:
                pass
            return redirect(request.path)

    # other situation
    user_rating_form = UserRatingForm()
    if request.user.is_authenticated:
        review_form = ReviewForm(
            initial={
                'first_name': request.user.first_name,
                'last_name': request.user.last_name,
                'contractor': Contractor.objects.get(pk=o_id),
                'project_date': datetime.datetime.today().strftime('%Y-%m-%d')
            })
    else:
        review_form = ReviewForm(
            initial={
                'contractor': Contractor.objects.get(pk=o_id),
                'project_date': datetime.datetime.today().strftime('%Y-%m-%d')
            })

    info_dict = {
        'review_form': review_form,
        "user_rating_form": user_rating_form,
    }
    return render(request, template_name, {"info_dict": info_dict})
Esempio n. 5
0
    def get(self, request, contractor_id):
        # contractor info
        contractor = Contractor.objects.get(lic_num=contractor_id)
        # contractor background image
        o_id = contractor.lic_id
        try:
            bgimage = BackgroundPhoto.objects.get(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id)
        except:
            bgimage = None

        bh = BondHistory.objects.filter(
            contractor_id=o_id).order_by('-bond_effective_date').first()
        wh = WorkerCompensationHistory.objects.filter(
            contractor_id=o_id).order_by('-insur_effective_date').first()

        data_source = 'California Contractors State License Board'
        try:
            if contractor_id.startswith('TX'):
                hscore = Hscore.objects.create(contractor=contractor,
                                               score=None,
                                               rank=None,
                                               max=None)
            else:
                hscore = Hscore.objects.get(contractor_id=o_id)
        except:
            hscore = Hscore.objects.create(contractor=contractor,
                                           score=None,
                                           rank=None,
                                           max=None)

        letter_grade = convert_hscore_to_rank(hscore)
        full_state_name = get_state_full_name(contractor.state)
        # Lic Type
        lic_type = contractor.lic_type.split('&')
        # review
        try:

            review = Review.objects.filter(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id,
                review_status='A')
        except:
            review = None
        # rating

        RATING_STAR_MAX = 10
        ratings = {}
        ratings['stars'] = range(RATING_STAR_MAX, 0, -1)
        if contractor_id.startswith('TX'):
            ratings['overall'] = 0
            ratings['rate'] = 0

        else:
            contractor_ratings = Rating.objects.filter(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id).order_by('ratings_average')

            # TODO:NEED TO CHANGE HERE
            ratings['overall'] = (avg_rating(review, 'Q') + avg_rating(
                review, 'E') + avg_rating(review, 'L')) / 3
            try:
                ratings['rate'] = [(item.average,
                                    round(item.average * 1.0 / RATING_STAR_MAX,
                                          2)) for item in contractor_ratings]
            except:
                pass
        try:
            project_photos = Photo.objects.filter(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id)
        except:
            project_photos = None
        try:
            if (contractor.lic_expire_date is not None) and (
                    contractor.lic_expire_date < datetime.date.today()):
                length = int(contractor.lic_expire_date.year -
                             contractor.lic_issue_date.year)
            elif (not contractor.lic_expire_date) and (
                    not contractor.lic_issue_date):
                length = 0
            else:
                length = int(datetime.date.today().year -
                             contractor.lic_issue_date.year)
        except:
            length = "N/A"
        # test issue, won't happen in prod

        try:
            complaint = ComplaintOverall.objects.get(contractor=contractor)
        except:
            complaint = Complaint1
            complaint.case = 0
            complaint.citation = 0
            complaint.arbitration = 0
            complaint.complaint = 0

        if request.user.is_anonymous():
            p_lic_num = None
        else:
            try:
                p_lic_num = str(request.user.professional_profiles.first().
                                professional.lic_num)
            except:
                p_lic_num = None

        # other situation
        user_rating_form = UserRatingForm()
        # review_form = request.session.get('review_form', None)
        # if review_form is None:
        if request.user.is_authenticated:
            review_form = ReviewForm(
                initial={
                    'first_name': request.user.first_name,
                    'last_name': request.user.last_name,
                    'project_date': datetime.datetime.today().strftime(
                        '%Y-%m-%d')
                })
        else:
            review_form = ReviewForm(initial={
                'project_date':
                datetime.datetime.today().strftime('%Y-%m-%d')
            })

        try:
            overview = Overview.objects.get(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id).overview
        except:
            if contractor.license_board:
                data_source = contractor.license_board
            if contractor.csp and contractor.csp != '':
                overview = _(
                    """{lic_name} is a contractor company located in {csp} . The company holds a license number 
                according to {data_source}. According to real-time data analysis, this licensed contractor's hoome score 
                is {score} and is rated as {rank}. The License is verified as active when we checked last time. If you would
                 like to know {lic_name} more, please contact us and we will share more information and data about this
                  contractor to you.""").format(
                        lic_name=contractor.lic_name,
                        csp=contractor.csp,
                        data_source=data_source,
                        score=hscore.score,
                        rank=letter_grade,
                        full_state_name=full_state_name)
            else:
                overview = _(
                    """{lic_name} is a contractor company. The company holds a license number 
                according to {data_source}. According to real-time data analysis, this licensed contractor's hoome score 
                is {score} and is rated as {rank}. The License is verified as active when we checked last time. If you would
                 like to know {lic_name} more, please contact us and we will share more information and data about this
                  contractor to you.""").format(
                        lic_name=contractor.lic_name,
                        data_source=data_source,
                        score=hscore.score,
                        rank=letter_grade,
                        full_state_name=full_state_name)

        overview_form = OverviewForm(initial={'overview': overview})

        info_dict = {
            "contractor": contractor,
            "bg_image": bgimage,
            "overview": overview,
            'review': review,
            "score": hscore.score,
            'bond_history': bh,
            "wc_history": wh,
            "lic_type": lic_type,
            "ratings": ratings,
            'project_photos': project_photos,
            'review_form': review_form,
            "user_rating_form": user_rating_form,
            "complaint": complaint,
            "length": length,
            'p_lic_num': p_lic_num,
            'rank': letter_grade,
            'overview_form': overview_form
        }

        return render(request, 'contractor/contractor.html',
                      {"info_dict": info_dict})
Esempio n. 6
0
    def post(self, request, contractor_id):
        # contractor info
        contractor = Contractor.objects.get(lic_num=contractor_id)
        # contractor background image
        o_id = contractor.lic_id
        try:
            bgimage = BackgroundPhoto.objects.get(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id)
        except:
            bgimage = None

        bh = BondHistory.objects.filter(
            contractor_id=o_id).order_by('-bond_effective_date').first()
        wh = WorkerCompensationHistory.objects.filter(
            contractor_id=o_id).order_by('-insur_effective_date').first()

        data_source = 'California Contractors State License Board'
        try:
            if contractor_id.startswith('TX'):
                hscore = Hscore.objects.create(contractor=contractor,
                                               score=None,
                                               rank=None,
                                               max=None)
            else:
                hscore = Hscore.objects.get(contractor_id=o_id)
        except:
            hscore = Hscore.objects.create(contractor=contractor,
                                           score=None,
                                           rank=None,
                                           max=None)

        letter_grade = convert_hscore_to_rank(hscore)
        full_state_name = get_state_full_name(contractor.state)
        # Lic Type
        lic_type = contractor.lic_type.split('&')
        # review
        try:

            review = Review.objects.filter(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id,
                review_status='A')
        except:
            review = None
        # rating

        RATING_STAR_MAX = 10
        ratings = {}
        ratings['stars'] = range(RATING_STAR_MAX, 0, -1)
        if contractor_id.startswith('TX'):
            ratings['overall'] = 0
            ratings['rate'] = 0

        else:
            contractor_ratings = Rating.objects.filter(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id).order_by('ratings_average')

            # TODO:NEED TO CHANGE HERE
            ratings['overall'] = (avg_rating(review, 'Q') + avg_rating(
                review, 'E') + avg_rating(review, 'L')) / 3
            try:
                ratings['rate'] = [(item.average,
                                    round(item.average * 1.0 / RATING_STAR_MAX,
                                          2)) for item in contractor_ratings]
            except:
                pass
        try:
            project_photos = Photo.objects.filter(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id)
        except:
            project_photos = None
        try:
            if (contractor.lic_expire_date is not None) and (
                    contractor.lic_expire_date < datetime.date.today()):
                length = int(contractor.lic_expire_date.year -
                             contractor.lic_issue_date.year)
            elif (not contractor.lic_expire_date) and (
                    not contractor.lic_issue_date):
                length = 0
            else:
                length = int(datetime.date.today().year -
                             contractor.lic_issue_date.year)
        except:
            length = "N/A"
        # test issue, won't happen in prod

        try:
            complaint = ComplaintOverall.objects.get(contractor=contractor)
        except:
            complaint = Complaint1
            complaint.case = 0
            complaint.citation = 0
            complaint.arbitration = 0
            complaint.complaint = 0

        if request.user.is_anonymous():
            p_lic_num = None
        else:
            try:
                p_lic_num = str(request.user.professional_profiles.first().
                                professional.lic_num)
            except:
                p_lic_num = None

        # other situation
        user_rating_form = UserRatingForm()
        # review_form = request.session.get('review_form', None)
        # if review_form is None:
        if request.user.is_authenticated:
            review_form = ReviewForm(
                initial={
                    'first_name': request.user.first_name,
                    'last_name': request.user.last_name,
                    'project_date': datetime.datetime.today().strftime(
                        '%Y-%m-%d')
                })
        else:
            review_form = ReviewForm(initial={
                'project_date':
                datetime.datetime.today().strftime('%Y-%m-%d')
            })

        try:
            overview = Overview.objects.get(
                content_type=ContentType.objects.get(model='contractor'),
                object_id=o_id).overview
        except:
            if contractor.license_board:
                data_source = contractor.license_board
            if contractor.csp and contractor.csp != '':
                overview = _(
                    """{lic_name} is a contractor company located in {csp} . The company holds a license number 
                according to {data_source}. According to real-time data analysis, this licensed contractor's hoome score 
                is {score} and is rated as {rank}. The License is verified as active when we checked last time. If you would
                 like to know {lic_name} more, please contact us and we will share more information and data about this
                  contractor to you.""").format(
                        lic_name=contractor.lic_name,
                        csp=contractor.csp,
                        data_source=data_source,
                        score=hscore.score,
                        rank=letter_grade,
                        full_state_name=full_state_name)
            else:
                overview = _(
                    """{lic_name} is a contractor company. The company holds a license number 
                according to {data_source}. According to real-time data analysis, this licensed contractor's hoome score 
                is {score} and is rated as {rank}. The License is verified as active when we checked last time. If you would
                 like to know {lic_name} more, please contact us and we will share more information and data about this
                  contractor to you.""").format(
                        lic_name=contractor.lic_name,
                        data_source=data_source,
                        score=hscore.score,
                        rank=letter_grade,
                        full_state_name=full_state_name)

        overview_form = OverviewForm(initial={'overview': overview})

        info_dict = {
            "contractor": contractor,
            "bg_image": bgimage,
            "overview": overview,
            'review': review,
            "score": hscore.score,
            'bond_history': bh,
            "wc_history": wh,
            "lic_type": lic_type,
            "ratings": ratings,
            'project_photos': project_photos,
            'review_form': review_form,
            "user_rating_form": user_rating_form,
            "complaint": complaint,
            "length": length,
            'p_lic_num': p_lic_num,
            'rank': letter_grade,
            'overview_form': overview_form
        }

        if request.POST.get('review'):
            user_rating_form = UserRatingForm(request.POST)
            review_form = ReviewForm(request.POST)
            # TODO: assign a random password
            # TODO: validator doesn't work
            if review_form.is_valid() and user_rating_form.is_valid():
                # User = #ContentType.objects.get_for_model(settings.AUTH_USER_MODEL)

                # user = User(email=review_form.cleaned_data['email'],
                #             username=review_form.cleaned_data['email'],
                #             last_name=review_form.cleaned_data['last_name'],
                #             first_name=review_form.cleaned_data['first_name'],
                #             password=make_password("aaaaaaa"))
                # user.save()
                model_type = check_professional_type(request)
                review = review_form.save(commit=False)
                if request.user.is_authenticated():
                    review.user = request.user
                review.content_type = ContentType.objects.get(model=model_type)
                review.object_id = contractor.lic_id
                review.save()

                for field in user_rating_form.cleaned_data:
                    user_rating = UserRating(
                        review=review,
                        rating_type=field[0].upper(),
                        rating_score=int(user_rating_form.cleaned_data[field]))
                    user_rating.save()
                # direct to the page to upload photos
                # TODO: ADD PHOTOFORM VALIDATION FOR SECURITY
                content_type = ContentType.objects.get(model='review')
                object_id = int(review.id)
                files = request.FILES.getlist('project photos')
                if len(files) > 0:
                    for f in files:
                        instance = Photo.objects.create(
                            img=f,
                            title=f.name,
                            content_type=content_type,
                            object_id=object_id)
                        instance.save()
                else:
                    pass
                # request.session.pop('review_form', None)
                # TODO: redirect the sucess url and add bootstrap messages: success
                return redirect(request.path)
            else:
                # request.session.update({'review_form': review_form.data})
                info_dict['review_form'] = review_form
                info_dict["user_rating_form"] = user_rating_form
                messages.warning(
                    request,
                    _('Submit Failed. Please verify your content is correct.'))
                return render(request, 'contractor/contractor.html',
                              {"info_dict": info_dict})
        # TODO: need to change here
        elif request.POST.get('overview'):
            edit_overview(request, contractor_id)
            return redirect(request.path)
        else:
            raise Http404(_("Error Pages!"))