def _index(root, root_len):
     for mfile in root.iterdir():
         if mfile.is_dir():
             yield loader.render_to_string(
                 'static_analysis/treeview_folder.html',
                 {'file': mfile.name,
                  'subfiles': _index(mfile, root_len)},
             )
             continue
         yield loader.render_to_string(
             'static_analysis/treeview_file.html',
             {'file': mfile.name,
              'path': mfile.as_posix()[root_len + 1: -len(mfile.name)]},
         )
Esempio n. 2
0
def start(request, object_id=None):
    """ Start a Vulture listener on a (possibly) remote host
    :param object_id: MongoDB object_id of listener to start
    :param request: Django request object
    """
    l = ListenAddress.objects.with_id(ObjectId(object_id))

    # Populate a dict with passphrases, if any
    passphrases = None
    if request.POST:
        passphrases = dict()
        for data in request.POST:
            # Listener management
            m = re.match('keypass_([A-Fa-f0-9]{24})', data)
            if m != None:
                id_ssl_profile = m.group(1)
                passphrases["ssl_{}".format(
                    id_ssl_profile)] = request.POST.get(
                        "keypass_{}".format(id_ssl_profile))
    else:
        # Check if there is the need to provide a pass phrase to start a listener
        need_passphrase = False
        for app in l.get_apps():
            if app.need_passphrase():
                need_passphrase = True
        if need_passphrase:
            var = loader.render_to_string('application_askpass.html',
                                          {'listener': l})
            ret = {'status': False, 'need_pass': True, 'html': var}
            return JsonResponse(ret)
    return start_api(request, object_id, passphrases)
Esempio n. 3
0
def send_email(email, send_type='register'):
    # 发送之前保存到数据库,到时候查询链接是否存在
    # 实例化一个EmailVerifyRecord对象
    email_record = EmailVerifyRecord()
    # 生成随机code放入链接
    code = random_str(16)
    email_record.code = code
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()

    # 定义邮件内容
    if send_type == 'register':
        email_title = 'hotpig慕课小站 注册激活链接'
        email_body = '请点击下面的链接激活你的账号: http://127.0.0.1:8000/active/{0}'.format(
            code)
        # 使用Django内置函数完成邮件发送,四个参数:主题、邮件内容、从哪里发、接收者list
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        # 如果发送成功
        # if send_status:
        #     pass
        return send_status
    elif send_type == 'forget':
        email_title = 'hotpig慕课小站 找回密码链接'
        email_body = loader.render_to_string('email_forget.html',
                                             {'active_code': code})
        msg = EmailMessage(email_title, email_body, EMAIL_FROM, [email])
        msg.content_subtype = 'html'
        send_status = msg.send()
        return send_status
Esempio n. 4
0
def send_notification(request):
    instance_user = User.objects.get(username=auth.get_user(request).username)
    email_template_name = 'password_reset/recovery_email.txt'
    email_subject_template_name = 'password_reset/recovery_email_subject.txt'
    context = {
        'site': get_site(request),
        'user': instance_user,
        'username': instance_user.username,
        'token': signing.dumps(instance_user.pk, salt="password_recovery"),
        'secure': request.is_secure(),
    }
    body = loader.render_to_string(email_template_name, context).strip()
    subject = loader.render_to_string(email_subject_template_name,
                                      context).strip()
    send_mail(subject, body, settings.DEFAULT_FROM_EMAIL,
              [instance_user.email])
    return HttpResponseRedirect("/profile/")
Esempio n. 5
0
def send_notification(request):
    instance_user = User.objects.get(username=auth.get_user(request).username)
    email_template_name = 'password_reset/recovery_email.txt'
    email_subject_template_name = 'password_reset/recovery_email_subject.txt'
    context = {
        'site': get_site(request),
        'user': instance_user,
        'username': instance_user.username,
        'token': signing.dumps(instance_user.pk, salt="password_recovery"),
        'secure': request.is_secure(),
    }
    body = loader.render_to_string(email_template_name,
                                   context).strip()
    subject = loader.render_to_string(email_subject_template_name,
                                      context).strip()
    send_mail(subject, body, settings.DEFAULT_FROM_EMAIL,
              [instance_user.email])
    return HttpResponseRedirect("/profile/")
Esempio n. 6
0
def get_works(request):
    if request.is_ajax():
        slice = request.POST['slice']
        print(slice)
        work_place = Work.objects.all()
        if slice:
            work_place = work_place[:int(slice)]
        html = loader.render_to_string('my_work.html',
                                       {'work_place': work_place})
        data = {'html': html}
        return JsonResponse(data)
    raise Http404
Esempio n. 7
0
 def letter_password_change(self, url):
     new_key = self.make_new_key()
     html_content = loader.render_to_string(
         'account/letter_change_password.html', {
             'person': self,
             'url': url + new_key + '/'
         })
     text_content = 'This is an important message.'
     msg = EmailMultiAlternatives("Information for change your password!",
                                  text_content, settings.DEFAULT_FROM_EMAIL,
                                  [self.user.email])
     msg.attach_alternative(html_content, "text/html")
     try:
         msg.send()
     except Exception:
         if settings.CELERY_NO_SEND_EMAIL:
             return
         raise self.LetterPasswordChangeError
Esempio n. 8
0
def generar_oficio (request, formato) :

    post = request.POST

    datos = {'prelacion' : datos_prelacion,
             'exceso' : datos_exceso,
             'colision' : datos_colision,
             'prorroga' : datos_prorroga,
             'regimen' : datos_regimen,
             'ingresocpu' : datos_ingresocpu,
             }

    nombre_estudiante = post['nombre']
    cid_estudiante = post['nac'] + '-' + post['cedula']

    e = guardar_estudiante(nombre_estudiante, cid_estudiante)

    s = Solicitud(estudiante = e, tipo = formato)
    s.save()

    #Nombre de plantilla en latex para formato
    tex_tpl_filename = 'solicitudes/formatos/' + formato + '.tex'

    #Nombre de archivos a generar
    filename = "EISULA_%s_%d" % (s.tipo, s.id);
    
    tex_filename = join (tex_pdf_dir, filename + '.tex')
    pdf_filename = join (tex_pdf_dir, filename + '.pdf')
    
    variables = datos[formato](post)
    variables['regimen'] = formato == 'regimen'
    variables['id'] = s.id

    #t tiene el contenido del oficio de solicitud como cadena
    t = loader.render_to_string(tex_tpl_filename, variables)

    open (tex_filename, 'w').write(t)

    system ('pdflatex -output-directory ' + tex_pdf_dir + ' '
            + tex_filename)
    
    return HttpResponseRedirect ('/solicitudes/generada/' + filename + '/')
def login_handler(request):
    username = request.POST.get('username')
    password = request.POST.get('password')
    isChecked = request.POST.get('is_checked', '')

    if password == '':
        context = {'error' : '密码不能为空'}
        return render(request, 'login/login.html', context)

    u = User()
    if u.findName(username, password):
        request.session['user'] = username
        if isChecked == '' or 1==1:
        #if isChecked == 'on':
            context = {'s' : 1}
            content = loader.render_to_string('pub/1.html',context,request)
            hp = HttpResponse(content)
            hp.set_cookie('user', username)
            return hp

        return redirect('/login/')
    context = {'error' : '用户名或密码错误'}
    return render(request, 'login/login.html', context)
Esempio n. 10
0
def render_widget(post_count):
    return loader.render_to_string('blog/partial/blog_widget.html', {'posts': Post.objects.order_by('-created')[:post_count]})
Esempio n. 11
0
def best_gamers():
    gamers = PythonGameResult.objects.order_by('score').reverse().all()[:3]
    return loader.render_to_string("python_game/best_gamers.html", {'gamers': gamers})