Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#127152289] Add a company field for user profiles #54

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions common/djangoapps/student/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from util.milestones_helpers import is_entrance_exams_enabled



UNENROLL_DONE = Signal(providing_args=["course_enrollment", "skip_refund"])
log = logging.getLogger(__name__)
AUDIT_LOG = logging.getLogger("audit")
Expand Down Expand Up @@ -454,6 +455,15 @@ def user_post_save_callback(sender, **kwargs):
)


class UserCompany(models.Model):
'''Holds the company field for each student user profile'''
userprofile = models.OneToOneField(UserProfile, on_delete=models.CASCADE, primary_key=True, related_name='company', default='')
company = models.CharField(blank=True, null=True, max_length=50, db_index=True)

class Meta(object):
db_table = "auth_usercompany"


class UserSignupSource(models.Model):
"""
This table contains information about users registering
Expand Down
28 changes: 28 additions & 0 deletions common/djangoapps/student/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
# Note that this lives in openedx, so this dependency should be refactored.
from openedx.core.djangoapps.user_api.preferences import api as preferences_api
from openedx.core.djangoapps.programs.utils import get_programs_for_dashboard
from django.shortcuts import get_object_or_404


log = logging.getLogger("edx.student")
Expand Down Expand Up @@ -513,6 +514,29 @@ def is_course_blocked(request, redeemed_registration_codes, course_key):
return blocked


def profile_progress(user):
profile = get_object_or_404(UserProfile, user=user)

profile_fields = [profile.name,
profile.language,
profile.year_of_birth,
profile.gender,
profile.level_of_education,
profile.country,
profile.bio,
profile.profile_image_uploaded_at]

completed_fields = len(filter(lambda x: x is not None, profile_fields))

# check for company name
if hasattr(profile, 'company'):
completed_fields += 1

percentage_completed = int((float(completed_fields) / float(len(profile_fields)+1) * 100))

return percentage_completed


@login_required
@ensure_csrf_cookie
def dashboard(request):
Expand Down Expand Up @@ -676,6 +700,9 @@ def dashboard(request):
else:
redirect_message = ''

# get progress for profile
profile_completed = profile_progress(user)

context = {
'enrollment_message': enrollment_message,
'redirect_message': redirect_message,
Expand Down Expand Up @@ -706,6 +733,7 @@ def dashboard(request):
'courses_requirements_not_met': courses_requirements_not_met,
'nav_hidden': True,
'course_programs': course_programs,
'profile_completed': profile_completed,
}

return render_to_response('dashboard.html', context)
Expand Down
Binary file modified conf/locale/zh_CN/LC_MESSAGES/django.mo
Binary file not shown.
Loading