Пример #1
0
def profile_basic(request, profile_id=0, template_name='_current.html'):        
    try:
        instance = UserProfile.objects.get(pk=profile_id)
    except UserProfile.DoesNotExist:
        instance = UserProfile()
        
    if request.method == "POST":
        form = UserProfileForm(request.POST, request.FILES)
        if form.is_valid():                            
            opts = {}
            opts['user']=request.user
            opts['instance']=instance
            if(request.user.userprofiles.has_default_profile() == False):
                opts['is_default']=True
            else:
                opts['is_default']=None
            
            form.save(**opts)
            save_file(request.FILES['profile_photo'])
            
            post_action_redirect = reverse('profile_company', kwargs={'profile_id':instance.id})
            
            if instance.current_status == 'S':
                post_action_redirect = reverse('profile_education', kwargs={'profile_id':instance.id})
            return HttpResponseRedirect(post_action_redirect)            
    else:
        form = UserProfileForm(instance=instance)
    return render_to_response(template_name, {'form':form,'user': request.user,'profile_id':profile_id}, 
                              context_instance=RequestContext(request))
Пример #2
0
def current_user_profile_page():
    """
    Route that provides a path to the current users profile page for editting
    """
    form = UserProfileForm(request.form, obj=current_user)
    session.pop('_flashes',None)

    if request.method == 'POST':
        current_user.full_name = request.form.get('full_name')
        current_user.affiliation = request.form.get('affiliation')

        aft_id = request.form.get('affiliation_type')
        aft = AffiliationType.query.filter(
            AffiliationType.id == int(aft_id)).first()
        current_user.affiliation_type = aft

        db.session.commit()
        flash("Profile Information Updated", "message")
        # TODO: Add a redirect

    return render_template('profile/edit_user_profile.html',
                           form=form,
                           form_user=current_user,
                           edit_roles=False,
                           can_associate=True)
Пример #3
0
def profile(request, template_name='profile.html'):
    user = get_object_or_404(SiteUser, id=request.user.id)
    post_signup_redirect = reverse('app.users.settings.views.settings')
            
    try:
        instance = UserSettings.objects.get(pk=user.id)
    except UserSettings.DoesNotExist:
        instance = UserSettings()
        
    if request.method == "POST":
        form = UserProfileForm(request.POST)
        if form.is_valid():                            
            opts = {}
            opts['user']=user                            
            form.save(**opts)
            return HttpResponseRedirect(post_signup_redirect)            
    else:        
        form = UserProfileForm(instance=instance)
    return render_to_response(template_name, {'form':form,'user': user}, 
                              context_instance=RequestContext(request))
Пример #4
0
def admin_user_profile_page():
    """
    Route that provides an path to another users profile page for admin editting
    """
    user_id = request.args.get('user_id')
    user = User.query.filter(User.id == user_id).first()
    if user is None:
        redirect(url_for('main.index'))

    form = UserProfileForm(request.form, obj=user)
    roles = Role.query.all()
    form.roles.choices = [(r.id, r.name) for r in roles]
    current_roles = [r.id for r in user.roles]

    if request.method == "POST":
        user.full_name = request.form.get('full_name')
        user.affiliation = request.form.get('affiliation')

        aft_id = request.form.get('affiliation_type')
        aft = AffiliationType.query.filter(
            AffiliationType.id == int(aft_id)).first()
        user.affiliation_type = aft

        user.roles = []
        for r in form.roles.data:
            rl = Role.query.filter(Role.id == r).first()
            user.roles.append(rl)

        db.session.commit()
        flash("Profile Information Updated", "message")
        # TO DO: Add redirect

    return render_template('profile/edit_user_profile.html',
                           form=form,
                           form_user=user,
                           current_roles=current_roles,
                           edit_roles=True,
                           can_associate=False)