当前位置: 首页>>代码示例>>Python>>正文


Python shortcuts.render_to_string函数代码示例

本文整理汇总了Python中mitxmako.shortcuts.render_to_string函数的典型用法代码示例。如果您正苦于以下问题:Python render_to_string函数的具体用法?Python render_to_string怎么用?Python render_to_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了render_to_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_invite_email

def send_invite_email(request):
    try:
        data,filtered=filter_user(request)
        data=data.filter(subscription_status='Imported')
        remain=request.GET.get('remain')
        count=request.GET.get('count')
        wait=data[:int(count)]
        for item in wait:
            reg = Registration.objects.get(user_id=item.user_id)
            d = {'name': "%s %s" % (item.user.first_name,item.user.last_name), 'key': reg.activation_key,'district': item.district.name}
            subject = render_to_string('emails/activation_email_subject.txt', d)
            subject = ''.join(subject.splitlines())
            message = render_to_string('emails/activation_email.txt', d)
            try:
                send_html_mail(subject, message, settings.SUPPORT_EMAIL, [item.user.email])
            except Exception as e:
                # log.warning('unable to send reactivation email', exc_info=true)
                raise Exception('unable to send reactivation email: %s' % e)
            item.subscription_status='Unregistered'
            item.invite_date=datetime.datetime.now(UTC)
            item.save()
            db.transaction.commit()
        ret={"success":True,"sent":len(wait),"remain":data.count()}
    except Exception as e:
       ret={"success":False,"error":"%s" % e}
    return HttpResponse(json.dumps(ret))
开发者ID:EduPepperPDTesting,项目名称:pepper2013-testing,代码行数:26,代码来源:views.py

示例2: update_creator_group_callback

def update_creator_group_callback(sender, **kwargs):
    """
    Callback for when the model's creator status has changed.
    """
    user = kwargs['user']
    updated_state = kwargs['state']
    update_course_creator_group(kwargs['caller'], user, updated_state == CourseCreator.GRANTED)

    studio_request_email = settings.MITX_FEATURES.get('STUDIO_REQUEST_EMAIL','')
    context = {'studio_request_email': studio_request_email}

    subject = render_to_string('emails/course_creator_subject.txt', context)
    subject = ''.join(subject.splitlines())
    if updated_state == CourseCreator.GRANTED:
        message_template = 'emails/course_creator_granted.txt'
    elif updated_state == CourseCreator.DENIED:
        message_template = 'emails/course_creator_denied.txt'
    else:
        # changed to unrequested or pending
        message_template = 'emails/course_creator_revoked.txt'
    message = render_to_string(message_template, context)

    try:
        user.email_user(subject, message, studio_request_email)
    except:
        log.warning("Unable to send course creator status e-mail to %s", user.email)
开发者ID:nageshgoyal,项目名称:edx-platform,代码行数:26,代码来源:admin.py

示例3: send_invite_email

def send_invite_email(request):
    try:
        data = filter_user(request)
        data = data.filter(subscription_status="Imported")
        remain = request.GET.get("remain")
        count = request.GET.get("count")
        wait = data[: int(count)]
        for item in wait:
            reg = Registration.objects.get(user_id=item.user_id)
            d = {
                "name": "%s %s" % (item.first_name, item.last_name),
                "key": reg.activation_key,
                "district": item.cohort.district.name,
            }
            subject = render_to_string("emails/activation_email_subject.txt", d)
            subject = "".join(subject.splitlines())
            message = render_to_string("emails/activation_email.txt", d)
            try:
                item.user.email_user(subject, message, "[email protected]")  # settings.default_from_email
            except Exception as e:
                # log.warning('unable to send reactivation email', exc_info=true)
                raise Exception("unable to send reactivation email: %s" % e)
            item.subscription_status = "Unregistered"
            item.invite_date = datetime.datetime.now(UTC)
            item.save()
            db.transaction.commit()
        ret = {"success": True, "sent": len(wait), "remain": data.count()}
    except Exception as e:
        ret = {"success": False, "error": "%s" % e}
    return HttpResponse(json.dumps(ret))
开发者ID:EduPepperPD,项目名称:pepper2013,代码行数:30,代码来源:views.py

示例4: confirm_email_change

def confirm_email_change(request, key):
    ''' User requested a new e-mail. This is called when the activation
    link is clicked. We confirm with the old e-mail, and update
    '''
    try:
        try:
            pec = PendingEmailChange.objects.get(activation_key=key)
        except PendingEmailChange.DoesNotExist:
            transaction.rollback()
            return render_to_response("invalid_email_key.html", {})

        user = pec.user
        address_context = {
            'old_email': user.email,
            'new_email': pec.new_email
        }

        if len(User.objects.filter(email=pec.new_email)) != 0:
            transaction.rollback()
            return render_to_response("email_exists.html", {})

        subject = render_to_string('emails/email_change_subject.txt', address_context)
        subject = ''.join(subject.splitlines())
        message = render_to_string('emails/confirm_email_change.txt', address_context)
        up = UserProfile.objects.get(user=user)
        meta = up.get_meta()
        if 'old_emails' not in meta:
            meta['old_emails'] = []
        meta['old_emails'].append([user.email, datetime.datetime.now().isoformat()])
        up.set_meta(meta)
        up.save()
        # Send it to the old email...
        try:
            user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
        except Exception:
            transaction.rollback()
            log.warning('Unable to send confirmation email to old address', exc_info=True)
            return render_to_response("email_change_failed.html", {'email': user.email})

        user.email = pec.new_email
        user.save()
        pec.delete()
        # And send it to the new email...
        try:
            user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
        except Exception:
            transaction.rollback()
            log.warning('Unable to send confirmation email to new address', exc_info=True)
            return render_to_response("email_change_failed.html", {'email': pec.new_email})

        transaction.commit()
        return render_to_response("email_change_successful.html", address_context)
    except Exception:
        # If we get an unexpected exception, be sure to rollback the transaction
        transaction.rollback()
        raise
开发者ID:IITBinterns13,项目名称:edx-platform-dev,代码行数:56,代码来源:views.py

示例5: change_email_request

def change_email_request(request):
    ''' AJAX call from the profile page. User wants a new e-mail.
    '''
    ## Make sure it checks for existing e-mail conflicts
    if not request.user.is_authenticated:
        raise Http404

    user = request.user

    if not user.check_password(request.POST['password']):
        return HttpResponse(json.dumps({'success': False,
                                        'error': 'Invalid password'}))

    new_email = request.POST['new_email']
    try:
        validate_email(new_email)
    except ValidationError:
        return HttpResponse(json.dumps({'success': False,
                                        'error': 'Valid e-mail address required.'}))

    if User.objects.filter(email=new_email).count() != 0:
        ## CRITICAL TODO: Handle case sensitivity for e-mails
        return HttpResponse(json.dumps({'success': False,
                                        'error': 'An account with this e-mail already exists.'}))

    pec_list = PendingEmailChange.objects.filter(user=request.user)
    if len(pec_list) == 0:
        pec = PendingEmailChange()
        pec.user = user
    else:
        pec = pec_list[0]

    pec.new_email = request.POST['new_email']
    pec.activation_key = uuid.uuid4().hex
    pec.save()

    if pec.new_email == user.email:
        pec.delete()
        return HttpResponse(json.dumps({'success': False,
                                        'error': 'Old email is the same as the new email.'}))

    d = {'key': pec.activation_key,
         'old_email': user.email,
         'new_email': pec.new_email}

    subject = render_to_string('emails/email_change_subject.txt', d)
    subject = ''.join(subject.splitlines())
    message = render_to_string('emails/email_change.txt', d)

    res = send_mail(
        subject, message, settings.DEFAULT_FROM_EMAIL, [pec.new_email])

    return HttpResponse(json.dumps({'success': True}))
开发者ID:hughdbrown,项目名称:edx-platform,代码行数:53,代码来源:views.py

示例6: render_notifications

def render_notifications(request, course, notifications):
    context = {
        "notifications": notifications,
        "get_discussion_title": partial(get_discussion_title, request=request, course=course),
        "course": course,
    }
    return render_to_string("courseware/notifications.html", context)
开发者ID:NikolayStrekalov,项目名称:edx-platform,代码行数:7,代码来源:views.py

示例7: purchase

    def purchase(
        self,
        first="",
        last="",
        street1="",
        street2="",
        city="",
        state="",
        postalcode="",
        country="",
        ccnum="",
        cardtype="",
        processor_reply_dump="",
    ):
        """
        Call to mark this order as purchased.  Iterates through its OrderItems and calls
        their purchased_callback

        `first` - first name of person billed (e.g. John)
        `last` - last name of person billed (e.g. Smith)
        `street1` - first line of a street address of the billing address (e.g. 11 Cambridge Center)
        `street2` - second line of a street address of the billing address (e.g. Suite 101)
        `city` - city of the billing address (e.g. Cambridge)
        `state` - code of the state, province, or territory of the billing address (e.g. MA)
        `postalcode` - postal code of the billing address (e.g. 02142)
        `country` - country code of the billing address (e.g. US)
        `ccnum` - last 4 digits of the credit card number of the credit card billed (e.g. 1111)
        `cardtype` - 3-digit code representing the card type used (e.g. 001)
        `processor_reply_dump` - all the parameters returned by the processor

        """
        self.status = "purchased"
        self.purchase_time = datetime.now(pytz.utc)
        self.bill_to_first = first
        self.bill_to_last = last
        self.bill_to_city = city
        self.bill_to_state = state
        self.bill_to_country = country
        self.bill_to_postalcode = postalcode
        if settings.MITX_FEATURES["STORE_BILLING_INFO"]:
            self.bill_to_street1 = street1
            self.bill_to_street2 = street2
            self.bill_to_ccnum = ccnum
            self.bill_to_cardtype = cardtype
            self.processor_reply_dump = processor_reply_dump
        # save these changes on the order, then we can tell when we are in an
        # inconsistent state
        self.save()
        # this should return all of the objects with the correct types of the
        # subclasses
        orderitems = OrderItem.objects.filter(order=self).select_subclasses()
        for item in orderitems:
            item.purchase_item()
        # send confirmation e-mail
        subject = _("Order Payment Confirmation")
        message = render_to_string("emails/order_confirmation_email.txt", {"order": self, "order_items": orderitems})
        try:
            send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])
        except smtplib.SMTPException:
            log.error("Failed sending confirmation e-mail for order %d", self.id)
开发者ID:NikolayStrekalov,项目名称:edx-platform,代码行数:60,代码来源:models.py

示例8: wrap_xmodule

def wrap_xmodule(template, block, view, frag, context):  # pylint: disable=unused-argument
    """
    Wraps the results of get_html in a standard <section> with identifying
    data so that the appropriate javascript module can be loaded onto it.

    get_html: An XModule.get_html method or an XModuleDescriptor.get_html method
    module: An XModule
    template: A template that takes the variables:
        content: the results of get_html,
        display_name: the display name of the xmodule, if available (None otherwise)
        class_: the module class name
        module_name: the js_module_name of the module
    """

    # If XBlock generated this class, then use the first baseclass
    # as the name (since that's the original, unmixed class)
    class_name = getattr(block, 'unmixed_class', block.__class__).__name__

    template_context = {
        'content': frag.content,
        'display_name': block.display_name,
        'class_': class_name,
        'module_name': block.js_module_name,
    }

    return wrap_fragment(frag, render_to_string(template, template_context))
开发者ID:chenkaigithub,项目名称:edx-platform,代码行数:26,代码来源:xmodule_modifiers.py

示例9: contact_us_modal_submit

def contact_us_modal_submit(request):
    ret = {"success":True}
    
    if request.POST.get("send_by_js") != 'true':
        ret['success'] = False
        return HttpResponse(json.dumps(ret))

    fullname = request.POST.get("fullname_modal")
    email = request.POST.get("email_modal")
    state = request.POST.get("state_modal")
    district = request.POST.get("district_modal")
    
    from django.core.mail import send_mail
    from mitxmako.shortcuts import render_to_response, render_to_string
    from smtplib import SMTPException
    from mail import send_html_mail

    d = {"email":email, "fullname":fullname, "state":state, "district":district}
    subject = "PepperPd Contact Us From " + request.META['HTTP_HOST']
    body = render_to_string('emails/contact_us_modal_body.txt', d)

    # todo: catch SMTPAuthenticationError and SMTPException

    send_html_mail(subject, body, settings.SUPPORT_EMAIL, [
        settings.SUPPORT_EMAIL,
        "[email protected]",  
        "[email protected]",
        "[email protected]", 
        "[email protected]",
        "[email protected]"
        ])

    return HttpResponse(json.dumps(ret))
开发者ID:EduPepperPDTesting,项目名称:pepper2013-testing,代码行数:33,代码来源:views.py

示例10: password_reset

def password_reset(request):
    ''' Attempts to send a password reset e-mail. '''
    if request.method != "POST":
        raise Http404

    # By default, Django doesn't allow Users with is_active = False to reset their passwords,
    # but this bites people who signed up a long time ago, never activated, and forgot their
    # password. So for their sake, we'll auto-activate a user for whom password_reset is called.
    try:
        user = User.objects.get(email=request.POST['email'])
        user.is_active = True
        user.save()
    except:
        log.exception("Tried to auto-activate user to enable password reset, but failed.")

    form = PasswordResetForm(request.POST)
    if form.is_valid():
        form.save(use_https=request.is_secure(),
                  from_email=settings.DEFAULT_FROM_EMAIL,
                  request=request,
                  domain_override=request.get_host())
        return HttpResponse(json.dumps({'success': True,
                                        'value': render_to_string('registration/password_reset_done.html', {})}))
    else:
        return HttpResponse(json.dumps({'success': False,
                                        'error': 'Invalid e-mail'}))
开发者ID:dfoulser,项目名称:edx-platform,代码行数:26,代码来源:views.py

示例11: hint_manager

def hint_manager(request, course_id):
    try:
        get_course_with_access(request.user, course_id, 'staff', depth=None)
    except Http404:
        out = 'Sorry, but students are not allowed to access the hint manager!'
        return HttpResponse(out)
    if request.method == 'GET':
        out = get_hints(request, course_id, 'mod_queue')
        return render_to_response('courseware/hint_manager.html', out)
    field = request.POST['field']
    if not (field == 'mod_queue' or field == 'hints'):
        # Invalid field.  (Don't let users continue - they may overwrite other db's)
        out = 'Error in hint manager - an invalid field was accessed.'
        return HttpResponse(out)

    if request.POST['op'] == 'delete hints':
        delete_hints(request, course_id, field)
    if request.POST['op'] == 'switch fields':
        pass
    if request.POST['op'] == 'change votes':
        change_votes(request, course_id, field)
    if request.POST['op'] == 'add hint':
        add_hint(request, course_id, field)
    if request.POST['op'] == 'approve':
        approve(request, course_id, field)
    rendered_html = render_to_string('courseware/hint_manager_inner.html', get_hints(request, course_id, field))
    return HttpResponse(json.dumps({'success': True, 'contents': rendered_html}))
开发者ID:LukeLu1263,项目名称:edx-platform,代码行数:27,代码来源:hint_manager.py

示例12: _get_html

    def _get_html():

        if type(module) in [SequenceModule, VerticalModule]:  # TODO: make this more general, eg use an XModule attribute instead
            return get_html()

        module_id = module.id
        if module.descriptor.has_score:
            histogram = grade_histogram(module_id)
            render_histogram = len(histogram) > 0
        else:
            histogram = None
            render_histogram = False

        if settings.MITX_FEATURES.get('ENABLE_LMS_MIGRATION'):
            [filepath, filename] = getattr(module.descriptor, 'xml_attributes', {}).get('filename', ['', None])
            osfs = module.system.filestore
            if filename is not None and osfs.exists(filename):
                # if original, unmangled filename exists then use it (github
                # doesn't like symlinks)
                filepath = filename
            data_dir = osfs.root_path.rsplit('/')[-1]
            giturl = getattr(module.lms, 'giturl', '') or 'https://github.com/MITx'
            edit_link = "%s/%s/tree/master/%s" % (giturl, data_dir, filepath)
        else:
            edit_link = False
            # Need to define all the variables that are about to be used
            giturl = ""
            data_dir = ""

        source_file = module.lms.source_file  # source used to generate the problem XML, eg latex or word

        # useful to indicate to staff if problem has been released or not
        # TODO (ichuang): use _has_access_descriptor.can_load in lms.courseware.access, instead of now>mstart comparison here
        now = datetime.datetime.now(UTC())
        is_released = "unknown"
        mstart = module.descriptor.lms.start

        if mstart is not None:
            is_released = "<font color='red'>Yes!</font>" if (now > mstart) else "<font color='green'>Not yet</font>"

        staff_context = {'fields': [(field.name, getattr(module, field.name)) for field in module.fields],
                         'lms_fields': [(field.name, getattr(module.lms, field.name)) for field in module.lms.fields],
                         'xml_attributes' : getattr(module.descriptor, 'xml_attributes', {}),
                         'location': module.location,
                         'xqa_key': module.lms.xqa_key,
                         'source_file': source_file,
                         'source_url': '%s/%s/tree/master/%s' % (giturl, data_dir, source_file),
                         'category': str(module.__class__.__name__),
                         # Template uses element_id in js function names, so can't allow dashes
                         'element_id': module.location.html_id().replace('-', '_'),
                         'edit_link': edit_link,
                         'user': user,
                         'xqa_server': settings.MITX_FEATURES.get('USE_XQA_SERVER', 'http://xqa:[email protected]/xqa'),
                         'histogram': json.dumps(histogram),
                         'render_histogram': render_histogram,
                         'module_content': get_html(),
                         'is_released': is_released,
                         }
        return render_to_string("staff_problem_info.html", staff_context)
开发者ID:Fyre91,项目名称:edx-platform,代码行数:59,代码来源:xmodule_modifiers.py

示例13: reactivation_email_for_user

def reactivation_email_for_user(user):
    reg = Registration.objects.get(user=user)

    d = {'name': user.profile.name,
         'key': reg.activation_key}

    subject = render_to_string('emails/activation_email_subject.txt', d)
    subject = ''.join(subject.splitlines())
    message = render_to_string('emails/activation_email.txt', d)

    try:
        res = user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
    except:
        log.warning('Unable to send reactivation email', exc_info=True)
        return HttpResponse(json.dumps({'success': False, 'error': 'Unable to send reactivation email'}))

    return HttpResponse(json.dumps({'success': True}))
开发者ID:Fyre91,项目名称:edx-platform,代码行数:17,代码来源:views.py

示例14: render_js

def render_js(package, path):
    template_name = package.template_name or "mako/js.html"
    context = package.extra_context
    context.update({
        'type': guess_type(path, 'text/javascript'),
        'url': try_staticfiles_lookup(path)
    })
    return render_to_string(template_name, context)
开发者ID:2bj,项目名称:edx-platform,代码行数:8,代码来源:__init__.py

示例15: render_purchase_form_html

def render_purchase_form_html(cart):
    """
    Renders the HTML of the hidden POST form that must be used to initiate a purchase with CyberSource
    """
    return render_to_string('shoppingcart/cybersource_form.html', {
        'action': get_purchase_endpoint(),
        'params': get_signed_purchase_params(cart),
    })
开发者ID:AzizYosofi,项目名称:edx-platform,代码行数:8,代码来源:CyberSource.py


注:本文中的mitxmako.shortcuts.render_to_string函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。