本文整理汇总了Python中microsite_configuration.middleware.MicrositeConfiguration.get_microsite_configuration_value方法的典型用法代码示例。如果您正苦于以下问题:Python MicrositeConfiguration.get_microsite_configuration_value方法的具体用法?Python MicrositeConfiguration.get_microsite_configuration_value怎么用?Python MicrositeConfiguration.get_microsite_configuration_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类microsite_configuration.middleware.MicrositeConfiguration
的用法示例。
在下文中一共展示了MicrositeConfiguration.get_microsite_configuration_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_logo_url
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def get_logo_url():
"""
Return the url for the branded logo image to be used
"""
# if the MicrositeConfiguration has a value for the logo_image_url
# let's use that
image_url = MicrositeConfiguration.get_microsite_configuration_value('logo_image_url')
if image_url:
return '{static_url}{image_url}'.format(
static_url=settings.STATIC_URL,
image_url=image_url
)
# otherwise, use the legacy means to configure this
university = MicrositeConfiguration.get_microsite_configuration_value('university')
if university is None:
return '{static_url}images/header-logo.png'.format(
static_url=settings.STATIC_URL
)
return '{static_url}images/{uni}-on-edx-logo.png'.format(
static_url=settings.STATIC_URL, uni=university
)
示例2: get_visible_courses
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def get_visible_courses():
"""
Return the set of CourseDescriptors that should be visible in this branded instance
"""
_courses = modulestore().get_courses()
courses = [c for c in _courses
if isinstance(c, CourseDescriptor)]
courses = sorted(courses, key=lambda course: course.number)
subdomain = MicrositeConfiguration.get_microsite_configuration_value('subdomain', 'default')
# See if we have filtered course listings in this domain
filtered_visible_ids = None
# this is legacy format which is outside of the microsite feature -- also handle dev case, which should not filter
if hasattr(settings, 'COURSE_LISTINGS') and subdomain in settings.COURSE_LISTINGS and not settings.DEBUG:
filtered_visible_ids = frozenset(settings.COURSE_LISTINGS[subdomain])
filtered_by_org = MicrositeConfiguration.get_microsite_configuration_value('course_org_filter')
if filtered_by_org:
return [course for course in courses if course.location.org == filtered_by_org]
if filtered_visible_ids:
return [course for course in courses if course.id in filtered_visible_ids]
else:
# Let's filter out any courses in an "org" that has been declared to be
# in a Microsite
org_filter_out_set = MicrositeConfiguration.get_all_microsite_orgs()
return [course for course in courses if course.location.org not in org_filter_out_set]
示例3: marketing_link
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def marketing_link(name):
"""Returns the correct URL for a link to the marketing site
depending on if the marketing site is enabled
Since the marketing site is enabled by a setting, we have two
possible URLs for certain links. This function is to decides
which URL should be provided.
"""
# link_map maps URLs from the marketing site to the old equivalent on
# the Django site
link_map = settings.MKTG_URL_LINK_MAP
enable_mktg_site = MicrositeConfiguration.get_microsite_configuration_value(
'ENABLE_MKTG_SITE',
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
)
if enable_mktg_site and name in settings.MKTG_URLS:
# special case for when we only want the root marketing URL
if name == 'ROOT':
return settings.MKTG_URLS.get('ROOT')
return settings.MKTG_URLS.get('ROOT') + settings.MKTG_URLS.get(name)
# only link to the old pages when the marketing site isn't on
elif not enable_mktg_site and name in link_map:
# don't try to reverse disabled marketing links
if link_map[name] is not None:
return reverse(link_map[name])
else:
log.warning("Cannot find corresponding link for name: {name}".format(name=name))
return '#'
示例4: nav_institute_register
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def nav_institute_register(request, extra_context=None):
"""
This view will display the institute registration form
"""
#if request.user.is_authenticated():
# return redirect(reverse('dashboard'))
#if settings.FEATURES.get('AUTH_USE_MIT_CERTIFICATES_IMMEDIATE_SIGNUP'):
# Redirect to branding to process their certificate if SSL is enabled
# and registration is disabled.
# return redirect(reverse('root'))
context = {
'course_id': request.GET.get('course_id'),
'enrollment_action': request.GET.get('enrollment_action'),
'platform_name': MicrositeConfiguration.get_microsite_configuration_value(
'platform_name',
settings.PLATFORM_NAME
),
}
if extra_context is not None:
context.update(extra_context)
#if context.get("extauth_domain", '').startswith(external_auth.views.SHIBBOLETH_DOMAIN_PREFIX):
# return render_to_response('register-shib.html', context)
return render_to_response('institute_register.html', context)
示例5: index
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def index(request):
"""
Redirects to main page -- info page if user authenticated, or marketing if not
"""
if settings.COURSEWARE_ENABLED and request.user.is_authenticated():
return redirect(reverse("dashboard"))
if settings.FEATURES.get("AUTH_USE_MIT_CERTIFICATES"):
from external_auth.views import ssl_login
return ssl_login(request)
enable_mktg_site = MicrositeConfiguration.get_microsite_configuration_value(
"ENABLE_MKTG_SITE", settings.FEATURES.get("ENABLE_MKTG_SITE", False)
)
if enable_mktg_site:
return redirect(settings.MKTG_URLS.get("ROOT"))
university = MicrositeConfiguration.match_university(request.META.get("HTTP_HOST"))
# keep specialized logic for Edge until we can migrate over Edge to fully use
# microsite definitions
if university == "edge":
context = {"suppress_toplevel_navigation": True}
return render_to_response("university_profile/edge.html", context)
# we do not expect this case to be reached in cases where
# marketing and edge are enabled
return student.views.index(request, user=request.user)
示例6: student_approve
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def student_approve(request,post_override=None):
"""
This view will allow the Institute coordinater to approve registered students
"""
if not request.user.is_authenticated:
raise Http404
post_vars = post_override if post_override else request.POST
student_id = post_vars['student_id']
status = post_vars['student_status']
try:
Student_object = Student_Institute.objects.filter(id=student_id)[0]
status_id = int ( Institute_Status.objects.filter(name=status)[0].id )
Student_object.status_id = status_id
Student_object.save()
except:
raise
context= { }
if status=="Approved" :
# composes Approve Student email
subject = render_to_string('emails/approve_student_email_subject.txt',context)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message = render_to_string('emails/approve_student_email_body.txt',context)
else :
#composes Reject Student email
subject = render_to_string('emails/reject_student_email_subject.txt',context)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message = render_to_string('emails/reject_student_email_body.txt',context)
# don't send email if we are doing load testing or random user generation for some reason
if not (settings.FEATURES.get('AUTOMATIC_AUTH_FOR_TESTING')):
from_address = MicrositeConfiguration.get_microsite_configuration_value(
'email_from_address',
settings.DEFAULT_FROM_EMAIL
)
try:
_res = Student_object.user.email_user(subject, message, from_address)
except:
log.warning('Unable to send Approve/Reject email to user', exc_info=True)
js['value'] = _('Could not send Approve/Reject e-mail.')
# What is the correct status code to use here? I think it's 500, because
# the problem is on the server's end -- but also, the account was created.
# Seems like the core part of the request was successful.
return JsonResponse(js, status=500)
return HttpResponse(json.dumps({'success': True}))
示例7: safe_get_host
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def safe_get_host(request):
"""
Get the host name for this request, as safely as possible.
If ALLOWED_HOSTS is properly set, this calls request.get_host;
otherwise, this returns whatever settings.SITE_NAME is set to.
This ensures we will never accept an untrusted value of get_host()
"""
if isinstance(settings.ALLOWED_HOSTS, (list, tuple)) and "*" not in settings.ALLOWED_HOSTS:
return request.get_host()
else:
return MicrositeConfiguration.get_microsite_configuration_value("site_domain", settings.SITE_NAME)
示例8: login_page
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def login_page(request):
"""
Display the login form.
"""
csrf_token = csrf(request)["csrf_token"]
return render_to_response(
"login.html",
{
"csrf": csrf_token,
"forgot_password_link": "//{base}/login#forgot-password-modal".format(base=settings.LMS_BASE),
"platform_name": MicrositeConfiguration.get_microsite_configuration_value(
"platform_name", settings.PLATFORM_NAME
),
},
)
示例9: refund_cert_callback
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def refund_cert_callback(sender, course_enrollment=None, **kwargs):
"""
When a CourseEnrollment object calls its unenroll method, this function checks to see if that unenrollment
occurred in a verified certificate that was within the refund deadline. If so, it actually performs the
refund.
Returns the refunded certificate on a successful refund; else, it returns nothing.
"""
# Only refund verified cert unenrollments that are within bounds of the expiration date
if not course_enrollment.refundable():
return
target_certs = CertificateItem.objects.filter(course_id=course_enrollment.course_id, user_id=course_enrollment.user, status='purchased', mode='verified')
try:
target_cert = target_certs[0]
except IndexError:
log.error("Matching CertificateItem not found while trying to refund. User %s, Course %s", course_enrollment.user, course_enrollment.course_id)
return
target_cert.status = 'refunded'
target_cert.refund_requested_time = datetime.now(pytz.utc)
target_cert.save()
target_cert.order.status = 'refunded'
target_cert.order.save()
order_number = target_cert.order_id
# send billing an email so they can handle refunding
subject = _("[Refund] User-Requested Refund")
message = "User {user} ({user_email}) has requested a refund on Order #{order_number}.".format(user=course_enrollment.user,
user_email=course_enrollment.user.email,
order_number=order_number)
to_email = [settings.PAYMENT_SUPPORT_EMAIL]
from_email = [MicrositeConfiguration.get_microsite_configuration_value(
'payment_support_email',
settings.PAYMENT_SUPPORT_EMAIL
)]
try:
send_mail(subject, message, from_email, to_email, fail_silently=False)
except (smtplib.SMTPException, BotoServerError):
err_str = 'Failed sending email to billing request a refund for verified certiciate (User {user}, Course {course}, CourseEnrollmentID {ce_id}, Order #{order})'
log.error(err_str.format(
user=course_enrollment.user,
course=course_enrollment.course_id,
ce_id=course_enrollment.id,
order=order_number))
return target_cert
示例10: course_about
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def course_about(request, course_id):
if MicrositeConfiguration.get_microsite_configuration_value(
'ENABLE_MKTG_SITE',
settings.FEATURES.get('ENABLE_MKTG_SITE', False)
):
raise Http404
course = get_course_with_access(request.user, course_id, 'see_exists')
registered = registered_for_course(course, request.user)
if has_access(request.user, course, 'load'):
course_target = reverse('info', args=[course.id])
else:
course_target = reverse('about_course', args=[course.id])
show_courseware_link = (has_access(request.user, course, 'load') or
settings.FEATURES.get('ENABLE_LMS_MIGRATION'))
# Note: this is a flow for payment for course registration, not the Verified Certificate flow.
registration_price = 0
in_cart = False
reg_then_add_to_cart_link = ""
if (settings.FEATURES.get('ENABLE_SHOPPING_CART') and
settings.FEATURES.get('ENABLE_PAID_COURSE_REGISTRATION')):
registration_price = CourseMode.min_course_price_for_currency(course_id,
settings.PAID_COURSE_REGISTRATION_CURRENCY[0])
if request.user.is_authenticated():
cart = shoppingcart.models.Order.get_cart_for_user(request.user)
in_cart = shoppingcart.models.PaidCourseRegistration.contained_in_order(cart, course_id)
reg_then_add_to_cart_link = "{reg_url}?course_id={course_id}&enrollment_action=add_to_cart".format(
reg_url=reverse('register_user'), course_id=course.id)
# see if we have already filled up all allowed enrollments
is_course_full = CourseEnrollment.is_course_full(course)
return render_to_response('courseware/course_about.html',
{'course': course,
'registered': registered,
'course_target': course_target,
'registration_price': registration_price,
'in_cart': in_cart,
'reg_then_add_to_cart_link': reg_then_add_to_cart_link,
'show_courseware_link': show_courseware_link,
'is_course_full': is_course_full})
示例11: course_about
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def course_about(request, course_id):
if MicrositeConfiguration.get_microsite_configuration_value(
"ENABLE_MKTG_SITE", settings.FEATURES.get("ENABLE_MKTG_SITE", False)
):
raise Http404
course = get_course_with_access(request.user, course_id, "see_exists")
registered = registered_for_course(course, request.user)
if has_access(request.user, course, "load"):
course_target = reverse("info", args=[course.id])
else:
course_target = reverse("about_course", args=[course.id])
show_courseware_link = has_access(request.user, course, "load") or settings.FEATURES.get("ENABLE_LMS_MIGRATION")
# Note: this is a flow for payment for course registration, not the Verified Certificate flow.
registration_price = 0
in_cart = False
reg_then_add_to_cart_link = ""
if settings.FEATURES.get("ENABLE_SHOPPING_CART") and settings.FEATURES.get("ENABLE_PAID_COURSE_REGISTRATION"):
registration_price = CourseMode.min_course_price_for_currency(
course_id, settings.PAID_COURSE_REGISTRATION_CURRENCY[0]
)
if request.user.is_authenticated():
cart = shoppingcart.models.Order.get_cart_for_user(request.user)
in_cart = shoppingcart.models.PaidCourseRegistration.contained_in_order(cart, course_id)
reg_then_add_to_cart_link = "{reg_url}?course_id={course_id}&enrollment_action=add_to_cart".format(
reg_url=reverse("register_user"), course_id=course.id
)
return render_to_response(
"courseware/course_about.html",
{
"course": course,
"registered": registered,
"course_target": course_target,
"registration_price": registration_price,
"in_cart": in_cart,
"reg_then_add_to_cart_link": reg_then_add_to_cart_link,
"show_courseware_link": show_courseware_link,
},
)
示例12: ins_selection
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def ins_selection(request, post_override=None):
"""
This view allows Student to select Institute in Student Dashboard
"""
if not request.user.is_authenticated:
raise Http404
user = request.user
post_vars = post_override if post_override else request.POST
institute_id = post_vars['ins_id']
status=Institute_Status.objects.filter(name="Pending")[0].id
try:
Student_Institute(user=user, institute_id=institute_id,status_id=status).save()
except:
raise
# composes Institute Selection Information Mail
subject = render_to_string('emails/select_institute_subject.txt',{})
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message = render_to_string('emails/select_institute_body.txt',{})
# don't send email if we are doing load testing or random user generation for some reason
if not (settings.FEATURES.get('AUTOMATIC_AUTH_FOR_TESTING')):
from_address = MicrositeConfiguration.get_microsite_configuration_value(
'email_from_address',
settings.DEFAULT_FROM_EMAIL
)
try:
ic_role_id = Role.objects.filter(name="Institute Coordinator")[0].id
Institute_Designation_object = Institute_Designation.objects.filter(institute_id=institute_id, role_id=ic_role_id)[0]
_res = Institute_Designation_object.user.email_user(subject, message, from_address)
except:
log.warning('Unable to send email to institute coordinator', exc_info=True)
js['value'] = _('Could not send e-mail.')
# What is the correct status code to use here? I think it's 500, because
# the problem is on the server's end -- but also, the account was created.
# Seems like the core part of the request was successful.
return JsonResponse(js, status=500)
return HttpResponse(json.dumps({'success': True}))
示例13: courses
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def courses(request):
"""
Render the "find courses" page. If the marketing site is enabled, redirect
to that. Otherwise, if subdomain branding is on, this is the university
profile page. Otherwise, it's the edX courseware.views.courses page
"""
enable_mktg_site = settings.FEATURES.get(
"ENABLE_MKTG_SITE"
) or MicrositeConfiguration.get_microsite_configuration_value("ENABLE_MKTG_SITE", False)
if enable_mktg_site:
return redirect(marketing_link("COURSES"), permanent=True)
if not settings.FEATURES.get("COURSES_ARE_BROWSABLE"):
raise Http404
# we do not expect this case to be reached in cases where
# marketing is enabled or the courses are not browsable
return courseware.views.courses(request)
示例14: login_page
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def login_page(request):
"""
Display the login form.
"""
csrf_token = csrf(request)['csrf_token']
if (settings.FEATURES['AUTH_USE_CERTIFICATES'] and
ssl_get_cert_from_request(request)):
# SSL login doesn't require a login view, so redirect
# to course now that the user is authenticated via
# the decorator.
return redirect('/course')
return render_to_response(
'login.html',
{
'csrf': csrf_token,
'forgot_password_link': "//{base}/login#forgot-password-modal".format(base=settings.LMS_BASE),
'platform_name': MicrositeConfiguration.get_microsite_configuration_value('platform_name', settings.PLATFORM_NAME),
}
)
示例15: send_mail_to_student
# 需要导入模块: from microsite_configuration.middleware import MicrositeConfiguration [as 别名]
# 或者: from microsite_configuration.middleware.MicrositeConfiguration import get_microsite_configuration_value [as 别名]
def send_mail_to_student(student, param_dict):
"""
Construct the email using templates and then send it.
`student` is the student's email address (a `str`),
`param_dict` is a `dict` with keys
[
`site_name`: name given to edX instance (a `str`)
`registration_url`: url for registration (a `str`)
`course_id`: id of course (a `str`)
`auto_enroll`: user input option (a `str`)
`course_url`: url of course (a `str`)
`email_address`: email of student (a `str`)
`full_name`: student full name (a `str`)
`message`: type of email to send and template to use (a `str`)
`is_shib_course`: (a `boolean`)
]
Returns a boolean indicating whether the email was sent successfully.
"""
# add some helpers and microconfig subsitutions
if 'course' in param_dict:
param_dict['course_name'] = param_dict['course'].display_name_with_default
param_dict['site_name'] = MicrositeConfiguration.get_microsite_configuration_value(
'SITE_NAME',
param_dict['site_name']
)
subject = None
message = None
# see if we are running in a microsite and that there is an
# activation email template definition available as configuration, if so, then render that
message_type = param_dict['message']
email_template_dict = {
'allowed_enroll': (
'emails/enroll_email_allowedsubject.txt',
'emails/enroll_email_allowedmessage.txt'
),
'enrolled_enroll': (
'emails/enroll_email_enrolledsubject.txt',
'emails/enroll_email_enrolledmessage.txt'
),
'allowed_unenroll': (
'emails/unenroll_email_subject.txt',
'emails/unenroll_email_allowedmessage.txt'
),
'enrolled_unenroll': (
'emails/unenroll_email_subject.txt',
'emails/unenroll_email_enrolledmessage.txt'
)
}
subject_template, message_template = email_template_dict.get(message_type, (None, None))
if subject_template is not None and message_template is not None:
subject = render_to_string(subject_template, param_dict)
message = render_to_string(message_template, param_dict)
if subject and message:
# Remove leading and trailing whitespace from body
message = message.strip()
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
from_address = MicrositeConfiguration.get_microsite_configuration_value(
'email_from_address',
settings.DEFAULT_FROM_EMAIL
)
send_mail(subject, message, from_address, [student], fail_silently=False)