예제 #1
0
파일: views.py 프로젝트: SlavaAf/lpcopy24
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'))
예제 #2
0
파일: admin.py 프로젝트: SlavaAf/lpcopy24
    def save_model(self, request, obj, form, change):
        db = DataBaseController()
        url = url_validate(obj.url)

        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')

        obj.url = data['url']
        obj.slug = data['slug']
        obj.name = data['name']
        obj.path_dir = data['path_dir']
        obj.path_index = data['path_index']
        obj.path_img = data['path_img']
        obj.path_tar = data['path_tar']

        super(SitesAdmin, self).save_model(request, obj, form, change)