コード例 #1
0
ファイル: views.py プロジェクト: ahmedsalman/userprofile
def professional_experience(request, template_name):
    """
    Add professional experience 
    """
    date_from = False
    date_to = False
    
    if request.is_ajax():
        if request.method == 'POST':
        
            try:
                user = User.objects.get(username = request.user.username)
            except User.DoesNotExist:
                messages.error(request, "You are not a logged in user.")
                return HttpResponseRedirect(reverse('auth_logout'))

            try:
                user_profile = user.get_profile()
            except UserProfile.DoesNotExist:
                messages.error(request, "Profile does not exist.")
                return HttpResponseRedirect(reverse('homepage'))

            post = request.POST.copy()

            start_year = request.POST.get('start_year', '')
            start_month = request.POST.get('start_month', '')
            if start_year and start_month != 'Present':
                start_month = list(calendar.month_name).index(start_month)
                post['date_from'] = datetime.date(int(start_year), start_month, 1)
                date_from = post['date_from']

            end_year = request.POST.get('end_year', '')
            end_month = request.POST.get('end_month', '')
            if end_year and end_month != 'Present':
                end_month = list(calendar.month_name).index(end_month)
                post['date_to'] = datetime.date(int(end_year), end_month, 1)
                date_to = post['date_to']

            form = ProfessionalExperienceForm(post)

            if form.is_valid():
                form.user = request.user
                form.save()
                title = request.POST.get('title', '')
                industries = request.POST.get('industry', '')
                description = request.POST.get('description', '')
                pro_exp = ProfessionalExperience.objects.filter(user__username = request.user.username)
                context = {
                    'experience':pro_exp,
                    'profile':user_profile,
                }
                return render_to_response(template_name, context, context_instance=RequestContext(request))
            else:
                errors = form.errors
                return HttpResponse(simplejson.dumps(errors), mimetype = 'application/json' )

    return HttpResponse(simplejson.dumps('Invalid request type'), mimetype = 'application/json' )
コード例 #2
0
ファイル: views.py プロジェクト: ahmedsalman/userprofile
def update_professional_experience(request, template_name):
#    """
#    get professional experience
#    """

    if request.method == 'POST':
        try:
            user = User.objects.get(username = request.user.username)
        except User.DoesNotExist:
            messages.error(request, "You are not a logged in user.")
            return HttpResponseRedirect( reverse('auth_logout') )

        try:
            user_profile = UserProfile.objects.get(user__username = request.user.username)
        except UserProfile.DoesNotExist:
            messages.error(request, "User Profile is not created yet.")
            return HttpResponseRedirect( reverse('auth_logout') )

        post = request.POST.copy()

        start_year = request.POST.get('start_year', '')
        start_month = request.POST.get('start_month', '')
        if start_year and start_month != 'Present':
            start_month = list(calendar.month_name).index(start_month)
            post['date_from'] = datetime.date(int(start_year), start_month, 1)
            date_from = post['date_from']

        end_year = request.POST.get('end_year', '')
        end_month = request.POST.get('end_month', '')
        if end_year and end_month != 'Present':
            end_month = list(calendar.month_name).index(end_month)
            post['date_to'] = datetime.date(int(end_year), end_month, 1)
            date_to = post['date_to']

        job_id = request.POST.get('job_id', '')
        pe_obj = ProfessionalExperience.objects.get(id=job_id).delete()

        form = ProfessionalExperienceForm(post, instance=pe_obj)

        if form.is_valid():
            form.user = request.user
            form.save()

            pro_exp = ProfessionalExperience.objects.filter(user__username = request.user.username)
            context = {
                'experience':pro_exp,
                'profile':user_profile,
            }
            return render_to_response(template_name, context, context_instance=RequestContext(request))
        else:
            errors = form.errors
            return HttpResponse(simplejson.dumps(errors), mimetype = 'application/json' )