Пример #1
0
def ajax_post_modal(request):
    if request.is_ajax():
        name = request.GET.get('name', None)
        mail = request.GET.get('email', None)
        pk = request.GET.get('pk', None)
        boll = request.GET.get('boll', False)
        old_text = request.GET.get('old_text', "")
        new_text = request.GET.get('new_text', "")
        db = DataBaseController()

        site = Sites.objects.filter(id=pk)[0]
        o = Order(name=name, mail=mail, s_name=site)
        o.save()

        if boll == 'false':
            send_mail_user(name, mail, site.path_tar)
        else:
            rp = Replacer()
            temp_path = rp.replace_text(site.name, old_text, new_text)
            if len(temp_path) > 0:
                send_mail_user(name, mail, temp_path)
                shutil.rmtree(temp_path[:-4])

        return HttpResponse(json.dumps({'error_code': 0}), content_type='application/json')
    else:
        return redirect(reverse_lazy('index'))
Пример #2
0
def ajax_post_form(request):
    if request.is_ajax():
        db = DataBaseController()
        url = url_validate(request.GET.get('url', None))
        name = request.GET.get('name', None)
        mail = request.GET.get('email', None)

        # create or get site
        list_sites = db.get_list_sites(url)
        data = {}

        if len(list_sites) == 0:
            parser = SiteParser()
            data = parser.save_site(url)

            if data == "Site not found":
                return HttpResponse(json.dumps({'error_code': 1}), content_type='application/json')

        site = db.get_site(url, data)

        o = Order(name=name, mail=mail, s_name=site)
        o.save()

        # send_to_mail_user
        boll = request.GET.get('boll', False)
        old_text = request.GET.get('old_text', "")
        new_text = request.GET.get('new_text', "")

        if boll == 'false':
            send_mail_user(name, mail, site.path_tar)
        else:
            rp = Replacer()
            temp_path = rp.replace_text(site.name, old_text, new_text)
            if len(temp_path) > 0:
                send_mail_user(name, mail, temp_path)
                shutil.rmtree(temp_path[:-4])

        return HttpResponse(json.dumps({'error_code': 0}), content_type='application/json')
    else:
        return redirect(reverse_lazy('index'))