本文整理汇总了Python中microsite_configuration.microsite.get_value函数的典型用法代码示例。如果您正苦于以下问题:Python get_value函数的具体用法?Python get_value怎么用?Python get_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_logo_url
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 = microsite.get_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 = microsite.get_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: send_mail_to_student
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_key`: id of course (a CourseKey)
`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'] = microsite.get_value(
'SITE_NAME',
param_dict.get('site_name', '')
)
subject = None
message = None
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 = microsite.get_value(
'email_from_address',
settings.DEFAULT_FROM_EMAIL
)
send_mail(subject, message, from_address, [student], fail_silently=False)
return True
else:
return False
示例3: __getattr__
def __getattr__(self, name):
try:
if isinstance(microsite.get_value(name), dict):
return microsite.get_dict(name, getattr(base_settings, name))
return microsite.get_value(name, getattr(base_settings, name))
except KeyError:
return getattr(base_settings, name)
示例4: get_logo_url
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 = microsite.get_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 = microsite.get_value('university')
if university is None and settings.FEATURES.get('IS_EDX_DOMAIN', False):
return '{static_url}images/edx-theme/edx-logo-77x36.png'.format(
static_url=settings.STATIC_URL
)
elif university:
return '{static_url}images/{uni}-on-edx-logo.png'.format(
static_url=settings.STATIC_URL, uni=university
)
else:
return '{static_url}images/default-theme/logo.png'.format(
static_url=settings.STATIC_URL
)
示例5: get_setting
def get_setting(self, name):
""" Get the value of a setting, or raise KeyError """
microsite_oauth = microsite.get_value("SOCIAL_AUTH_OAUTH_SECRETS", False)
if microsite_oauth:
current = microsite_oauth.get(self.backend_name, {})
if name is "KEY":
return current.get("KEY")
if name is "SECRET":
site_key = microsite.get_value("microsite_name")
secrets = settings.MICROSITE_SECRETS.get(site_key, {}).get("SOCIAL_AUTH_OAUTH_SECRETS", {})
return current.get("SECRET", secrets.get(self.backend_name))
if name == "KEY":
return self.key
if name == "SECRET":
if self.secret:
return self.secret
# To allow instances to avoid storing secrets in the DB, the secret can also be set via Django:
return getattr(settings, "SOCIAL_AUTH_OAUTH_SECRETS", {}).get(self.backend_name, "")
if self.other_settings:
other_settings = json.loads(self.other_settings)
assert isinstance(other_settings, dict), "other_settings should be a JSON object (dictionary)"
return other_settings[name]
raise KeyError
示例6: view_student_survey
def view_student_survey(user, survey_name, course=None, redirect_url=None, is_required=False, skip_redirect_url=None):
"""
Shared utility method to render a survey form
NOTE: This method is shared between the Survey and Courseware Djangoapps
"""
redirect_url = redirect_url if redirect_url else reverse('dashboard')
dashboard_redirect_url = reverse('dashboard')
skip_redirect_url = skip_redirect_url if skip_redirect_url else dashboard_redirect_url
survey = SurveyForm.get(survey_name, throw_if_not_found=False)
if not survey:
return HttpResponseRedirect(redirect_url)
# the result set from get_answers, has an outer key with the user_id
# just remove that outer key to make the JSON payload simplier
existing_answers = survey.get_answers(user=user).get(user.id, {})
platform_name = microsite.get_value('platform_name', settings.PLATFORM_NAME)
context = {
'existing_data_json': json.dumps(existing_answers),
'postback_url': reverse('submit_answers', args=[survey_name]),
'redirect_url': redirect_url,
'skip_redirect_url': skip_redirect_url,
'dashboard_redirect_url': dashboard_redirect_url,
'survey_form': survey.form,
'is_required': is_required,
'mail_to_link': microsite.get_value('email_from_address', settings.CONTACT_EMAIL),
'platform_name': platform_name,
'course': course,
}
return render_to_response("survey/survey.html", context)
示例7: handle_va_enrollment_event
def handle_va_enrollment_event(sender, student, **kwargs):
"""
set Marketo VA Learning Path Enrolled for Lead corresponding to user
"""
if not (get_value("course_enable_marketo_integration", None) and not \
getattr(settings.FEATURES, "COURSE_ENABLE_MARKETO_INTEGRATION", None)
):
return
logger.info(('Setting VA Learning Path Enrolled and edX registered for Lead with email {0}.').format(student.email))
mkto_field_id_va = get_value("marketo_va_enrollment_field_id", None)
mkto_field_id_edx = get_value("marketo_edx_enrollment_field_id", None)
if not mkto_field_id_va:
logger.warn(('Can\'t set VA Learning Path Enrolled for Lead with email {0}.').format(student.email))
if not mkto_field_id_edx:
logger.warn(('Can\'t set edX Registered for Lead with email {0}.').format(student.email))
try:
mc = get_marketo_client()
status = mc.execute(method='update_lead', lookupField='email',
lookupValue=student.email,
values={mkto_field_id_va: True,
mkto_field_id_edx: True})
if status != 'updated':
raise MarketoException({'message': "Update failed with status {0}".format(status), 'code': None})
except MarketoException as e:
logger.warn(('Can\'t set VA Learning Path Enrolled or edX Registered for Lead with email {0}.').format(student.email))
示例8: get_visible_courses
def get_visible_courses():
"""
Return the set of CourseDescriptors that should be visible in this branded instance
"""
filtered_by_org = microsite.get_value('course_org_filter')
_courses = modulestore().get_courses(org=filtered_by_org)
courses = [c for c in _courses
if isinstance(c, CourseDescriptor)]
courses = sorted(courses, key=lambda course: course.number)
subdomain = microsite.get_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([SlashSeparatedCourseKey.from_deprecated_string(c) for c in settings.COURSE_LISTINGS[subdomain]])
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 = microsite.get_all_orgs()
return [course for course in courses if course.location.org not in org_filter_out_set]
示例9: current
def current(cls, *args):
"""
Get the current config model for the provider according to the enabled slugs for this site.
The site configuration expects the value of THIRD_PARTY_AUTH_ENABLED_PROVIDERS to be a dict
of backend_name and the slug being used for the configuration object.
E.g.
"THIRD_PARTY_AUTH_ENABLED_PROVIDERS":{
"google-oauth2":"my-slug-for-this-provider"
}
"""
enabled_providers = microsite.get_value('THIRD_PARTY_AUTH_ENABLED_PROVIDERS', {})
# In a very specific case, azuread-oauth2 does not have a microsite context.
if not microsite.is_request_in_microsite():
try:
microsite.set_by_domain(get_current_request().site.domain)
enabled_providers = microsite.get_value('THIRD_PARTY_AUTH_ENABLED_PROVIDERS', {})
microsite.clear()
except Exception: # pylint: disable=broad-except
pass
if not enabled_providers:
return super(OAuth2ProviderConfig, cls).current(*args)
provider_slug = enabled_providers.get(args[0])
if provider_slug:
return super(OAuth2ProviderConfig, cls).current(provider_slug)
return super(OAuth2ProviderConfig, cls).current(None)
示例10: send_mail_to_student
def send_mail_to_student(student, param_dict):
"""
Check parameters, set text template and send email to student
"""
if "course" in param_dict:
param_dict["course_name"] = param_dict["course"].display_name
param_dict["site_name"] = microsite.get_value("SITE_NAME", param_dict["site_name"])
subject = None
message = None
message_type = param_dict["message"]
email_template_dict = {
"allowed_enroll": ("ccx/enroll_email_allowedsubject.txt", "ccx/enroll_email_allowedmessage.txt"),
"enrolled_enroll": ("ccx/enroll_email_enrolledsubject.txt", "ccx/enroll_email_enrolledmessage.txt"),
"allowed_unenroll": ("ccx/unenroll_email_subject.txt", "ccx/unenroll_email_allowedmessage.txt"),
"enrolled_unenroll": ("ccx/unenroll_email_subject.txt", "ccx/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:
message = message.strip()
subject = "".join(subject.splitlines())
from_address = microsite.get_value("email_from_address", settings.DEFAULT_FROM_EMAIL)
send_mail(subject, message, from_address, [student], fail_silently=False)
示例11: show_cart
def show_cart(request):
"""
This view shows cart items.
"""
cart = Order.get_cart_for_user(request.user)
is_any_course_expired, expired_cart_items, expired_cart_item_names, valid_cart_item_tuples = \
verify_for_closed_enrollment(request.user, cart)
site_name = microsite.get_value('SITE_NAME', settings.SITE_NAME)
if is_any_course_expired:
for expired_item in expired_cart_items:
Order.remove_cart_item_from_order(expired_item, request.user)
cart.update_order_type()
callback_url = request.build_absolute_uri(
reverse("shoppingcart.views.postpay_callback")
)
form_html = render_purchase_form_html(cart, callback_url=callback_url)
context = {
'order': cart,
'shoppingcart_items': valid_cart_item_tuples,
'amount': cart.total_cost,
'is_course_enrollment_closed': is_any_course_expired,
'expired_course_names': expired_cart_item_names,
'site_name': site_name,
'form_html': form_html,
'currency_symbol': settings.PAID_COURSE_REGISTRATION_CURRENCY[1],
'currency': settings.PAID_COURSE_REGISTRATION_CURRENCY[0],
'enable_bulk_purchase': microsite.get_value('ENABLE_SHOPPING_CART_BULK_PURCHASE', True)
}
return render_to_response("shoppingcart/shopping_cart.html", context)
示例12: send_mail_to_student
def send_mail_to_student(student, param_dict):
"""
Check parameters, set text template and send email to student
"""
if 'course' in param_dict:
param_dict['course_name'] = param_dict['course'].display_name
param_dict['site_name'] = microsite.get_value(
'SITE_NAME',
param_dict['site_name']
)
subject = None
message = None
message_type = param_dict['message']
email_template_dict = {
'allowed_enroll': (
'ccx/enroll_email_allowedsubject.txt',
'ccx/enroll_email_allowedmessage.txt'
),
'enrolled_enroll': (
'ccx/enroll_email_enrolledsubject.txt',
'ccx/enroll_email_enrolledmessage.txt'
),
'allowed_unenroll': (
'ccx/unenroll_email_subject.txt',
'ccx/unenroll_email_allowedmessage.txt'
),
'enrolled_unenroll': (
'ccx/unenroll_email_subject.txt',
'ccx/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:
message = message.strip()
subject = ''.join(subject.splitlines())
from_address = microsite.get_value(
'email_from_address',
settings.DEFAULT_FROM_EMAIL
)
send_mail(
subject,
message,
from_address,
[student],
fail_silently=False
)
示例13: __init__
def __init__(self, items_data, item_id, date, is_invoice, total_cost, payment_received, balance):
"""
Accepts the following positional arguments
items_data - A list having the following items for each row.
item_description - String
quantity - Integer
list_price - float
discount - float
item_total - float
id - String
date - datetime
is_invoice - boolean - True (for invoice) or False (for Receipt)
total_cost - float
payment_received - float
balance - float
"""
# From settings
self.currency = settings.PAID_COURSE_REGISTRATION_CURRENCY[1]
self.logo_path = microsite.get_value("PDF_RECEIPT_LOGO_PATH", settings.PDF_RECEIPT_LOGO_PATH)
self.cobrand_logo_path = microsite.get_value(
"PDF_RECEIPT_COBRAND_LOGO_PATH", settings.PDF_RECEIPT_COBRAND_LOGO_PATH
)
self.tax_label = microsite.get_value("PDF_RECEIPT_TAX_ID_LABEL", settings.PDF_RECEIPT_TAX_ID_LABEL)
self.tax_id = microsite.get_value("PDF_RECEIPT_TAX_ID", settings.PDF_RECEIPT_TAX_ID)
self.footer_text = microsite.get_value("PDF_RECEIPT_FOOTER_TEXT", settings.PDF_RECEIPT_FOOTER_TEXT)
self.disclaimer_text = microsite.get_value("PDF_RECEIPT_DISCLAIMER_TEXT", settings.PDF_RECEIPT_DISCLAIMER_TEXT)
self.billing_address_text = microsite.get_value(
"PDF_RECEIPT_BILLING_ADDRESS", settings.PDF_RECEIPT_BILLING_ADDRESS
)
self.terms_conditions_text = microsite.get_value(
"PDF_RECEIPT_TERMS_AND_CONDITIONS", settings.PDF_RECEIPT_TERMS_AND_CONDITIONS
)
self.brand_logo_height = microsite.get_value(
"PDF_RECEIPT_LOGO_HEIGHT_MM", settings.PDF_RECEIPT_LOGO_HEIGHT_MM
) * mm
self.cobrand_logo_height = microsite.get_value(
"PDF_RECEIPT_COBRAND_LOGO_HEIGHT_MM", settings.PDF_RECEIPT_COBRAND_LOGO_HEIGHT_MM
) * mm
# From Context
self.items_data = items_data
self.item_id = item_id
self.date = ModuleI18nService().strftime(date, 'SHORT_DATE')
self.is_invoice = is_invoice
self.total_cost = '{currency}{amount:.2f}'.format(currency=self.currency, amount=total_cost)
self.payment_received = '{currency}{amount:.2f}'.format(currency=self.currency, amount=payment_received)
self.balance = '{currency}{amount:.2f}'.format(currency=self.currency, amount=balance)
# initialize the pdf variables
self.margin = 15 * mm
self.page_width = letter[0]
self.page_height = letter[1]
self.min_clearance = 3 * mm
self.second_page_available_height = ''
self.second_page_start_y_pos = ''
self.first_page_available_height = ''
self.pdf = None
示例14: checkout_receipt
def checkout_receipt(request):
""" Receipt view. """
page_title = _('Receipt')
is_payment_complete = True
payment_support_email = microsite.get_value('payment_support_email', settings.PAYMENT_SUPPORT_EMAIL)
payment_support_link = '<a href=\"mailto:{email}\">{email}</a>'.format(email=payment_support_email)
is_cybersource = all(k in request.POST for k in ('signed_field_names', 'decision', 'reason_code'))
if is_cybersource and request.POST['decision'] != 'ACCEPT':
# Cybersource may redirect users to this view if it couldn't recover
# from an error while capturing payment info.
is_payment_complete = False
page_title = _('Payment Failed')
reason_code = request.POST['reason_code']
# if the problem was with the info submitted by the user, we present more detailed messages.
if is_user_payment_error(reason_code):
error_summary = _("There was a problem with this transaction. You have not been charged.")
error_text = _(
"Make sure your information is correct, or try again with a different card or another form of payment."
)
else:
error_summary = _("A system error occurred while processing your payment. You have not been charged.")
error_text = _("Please wait a few minutes and then try again.")
for_help_text = _("For help, contact {payment_support_link}.").format(payment_support_link=payment_support_link)
else:
# if anything goes wrong rendering the receipt, it indicates a problem fetching order data.
error_summary = _("An error occurred while creating your receipt.")
error_text = None # nothing particularly helpful to say if this happens.
for_help_text = _(
"If your course does not appear on your dashboard, contact {payment_support_link}."
).format(payment_support_link=payment_support_link)
commerce_configuration = CommerceConfiguration.current()
# user order cache should be cleared when a new order is placed
# so user can see new order in their order history.
if is_payment_complete and commerce_configuration.enabled and commerce_configuration.is_cache_enabled:
cache_key = commerce_configuration.CACHE_KEY + '.' + str(request.user.id)
cache.delete(cache_key)
context = {
'page_title': page_title,
'is_payment_complete': is_payment_complete,
'platform_name': microsite.get_value('platform_name', settings.PLATFORM_NAME),
'verified': SoftwareSecurePhotoVerification.verification_valid_or_pending(request.user).exists(),
'error_summary': error_summary,
'error_text': error_text,
'for_help_text': for_help_text,
'payment_support_email': payment_support_email,
'username': request.user.username,
'nav_hidden': True,
'is_request_in_themed_site': is_request_in_themed_site()
}
return render_to_response('commerce/checkout_receipt.html', context)
示例15: test_clear
def test_clear(self):
"""
Tests microsite.clear works as expected.
"""
microsite.set_by_domain(self.microsite_subdomain)
self.assertEqual(
microsite.get_value('platform_name'),
'Test Microsite'
)
microsite.clear()
self.assertIsNone(microsite.get_value('platform_name'))