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


Python Site.save方法代码示例

本文整理汇总了Python中models.Site.save方法的典型用法代码示例。如果您正苦于以下问题:Python Site.save方法的具体用法?Python Site.save怎么用?Python Site.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Site的用法示例。


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

示例1: getcurrentsite

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import save [as 别名]
def getcurrentsite(http_post, path_info, query_string):
    """ Returns the site id and the page cache key based on the request.
    """
    url = u'http://%s/%s' % (smart_unicode(http_post.rstrip('/')), \
      smart_unicode(path_info.lstrip('/')))
    pagecachekey = '%s?%s' % (smart_unicode(path_info), \
      smart_unicode(query_string))
    hostdict = hostcache_get()

    if not hostdict:
        hostdict = {}
    if url not in hostdict:
        default, ret = None, None
        for site in Site.objects.all():
            if url.startswith(site.url):
                ret = site
                break
            if not default or site.default_site:
                default = site
        if not ret:
            if default:
                ret = default
            else:
                # Somebody is requesting something, but the user didn't create
                # a site yet. Creating a default one...
                ret = Site(name='Default Feedjack Site/Planet', \
                  url='www.feedjack.org', \
                  title='Feedjack Site Title', \
                  description='Feedjack Site Description. ' \
                    'Please change this in the admin interface.')
                ret.save()
        hostdict[url] = ret.id
        hostcache_set(hostdict)

    return hostdict[url], pagecachekey
开发者ID:weeyoung,项目名称:sentiment-analysis,代码行数:37,代码来源:fjlib.py

示例2: register

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import save [as 别名]
def register(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password1']
        domain = request.POST['domain']
        print "=== User: ", username, " password: ", password, 'domain: ', domain

        new_user = User.objects.create_user(username, '', password)

        # create hash for new user
        hasher = hashlib.md5()
        hasher.update(username + domain)
        h = hasher.hexdigest()
        site = Site(user=new_user, hash=h, domain=domain)
        site.save()
        new_user.save()

        return login_to_page(request, username, password)

    else:
        form = RegistrationForm()
        return render_to_response(
            'registration/registration_form.html',
            {'form' : form},
            context_instance=RC(request, {}),
    )
开发者ID:kailu,项目名称:GrouponX,代码行数:28,代码来源:views.py

示例3: sites

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import save [as 别名]
def sites():
    root_domain = app.config.get("DOMAIN_ROOT")
    port = app.config.get("PORT", None)
    if request.method == "POST":
        domain = request.form["domain"]
        name = request.form["name"]
        if domain and name:
            site = Site()
            site.name = name.strip()
            site.domain = domain.strip()
            conflicting_site = Site.objects.filter(domain=site.domain).first()
            if not conflicting_site:
                site.description = _(
                    "<h1>Introductory text</h1><p>This should "
                    "contain simple help about what is changeable and how."
                    "</p>"
                )
                site.save()
                url = "//%s" % site.domain
                if root_domain:
                    url += ".%s" % root_domain
                if port:
                    url += ":%d" % port
                return redirect(url)
        return redirect(url_for("sites"))
    if root_domain == g.site.domain:
        sites = Site.objects.all()
    else:
        sites = Site.objects.filter(domain__endswith=g.site.domain)
    return render_template("sites.html", sites=sites, root_domain=root_domain, port=port)
开发者ID:sigurdga,项目名称:samklang,代码行数:32,代码来源:app.py

示例4: _tx

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import save [as 别名]
 def _tx():
     site = Site.get_by_key_name(loc["id"])
     if site is None:
         site = Site(key_name=loc["id"])
     site.location = GeoPt(lat = loc["location"][0], lon = loc["location"][1])
     site.name = loc["name"]
     site.region = loc["region"]
     site.save()
开发者ID:tempredirect,项目名称:MetOfficeWatch,代码行数:10,代码来源:views.py

示例5: api

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import save [as 别名]
def api(request):
    user = request.user
    if not user:
        username = request.POST.get("username", "")
        password = request.POST.get("password", "")
        user = authenticate(username= username, password=password)
    if user is not None and user.has_perm("apps.add_task"):
        method = request.POST.get("method")
        if method == "create_task":
            task_data = request.POST.get("task", "")
            sites_data = request.POST.get("sites", "")
            try:
                task = Task(**json.loads(task_data))
                task.user = user
                task.clean_fields()
                sites = []
                sites_data = json.loads(sites_data)
                for site_data in sites_data:
                    site = Site(**site_data)
                    site.clean_fields(exclude=['task'])
                    sites.append(site)
                task.save()
                for site in sites:
                    site.task = task
                    site.save()
                    rule = Rule(**Constants.DEFAULT_RULE)
                    rule.site = site
                    rule.save()
                controller = TaskController(task)
                controller.runTask()
                ret = {"status":"ok", "task":task.id}
            except Exception, e:
                ret = {"status":"InputError", "error_details":str(e)}
        elif method == "run_task":
            try:
                id = request.POST.get("id")
                task = Task.objects.get(id=id)
                controller = TaskController(task)
                controller.runTask()
                ret = {"status":"ok"}
            except Exception, e:
                ret = {"status":"RunError", "error_details":str(e)}
开发者ID:xunyuw,项目名称:iFlyQA,代码行数:44,代码来源:views.py

示例6: import_sites

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import save [as 别名]
 def import_sites(modeladmin, request, queryset):
     with open('D:/Users/mcpherro/PycharmProjects/Sites/sites.csv', 'rb') as f:
         reader = csv.reader(f)
         for row in reader:
             country_name = row[2]
             for c in countries:
                 if row[2]==c[1]:
                     country_name = c[0]
             s = Site(id=row[0], site=row[1], country=country_name, data_source=row[3], site_type=row[7],
                      display=row[8])
             if row[4] != 'NA':
                 s.latitude = row[4]
             if row[5] != 'NA':
                 s.longitude = row[5]
             if row[6] != 'NA':
                 s.altitude = row[6]
             if row[4] != 'NA' and row[5] != 'NA':
                 pnt = django.contrib.gis.geos.GEOSGeometry('POINT(%s %s)' % (row[5], row[4]))
                 s.map_location = pnt
             s.save()
     return None         # Return None to display the change list page again.
开发者ID:cadavis1,项目名称:paleocore,代码行数:23,代码来源:admin.py

示例7: crawl

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import save [as 别名]
def crawl(url):
    '''
    Crawl entire site

    :param url: URL of website
    :type url: str
    '''
    if not url.startswith('http://') and not url.startswith('https://'):
        url = 'http://%s/' % url
    if newurl(url):
        print "New URL"
    else:
        print "URL already in DB"
        return
    print url
    # get correct title, detect language
    p = Site(title=url, url=url, show=0)
    p.published = datetime.datetime.today()
    p.save()

    thr = threading.Thread(target=__crawl_address, args=[url], kwargs={})
    thr.start()
    return
开发者ID:vlasy,项目名称:skool,代码行数:25,代码来源:crawler.py

示例8: populate_blocks

# 需要导入模块: from models import Site [as 别名]
# 或者: from models.Site import save [as 别名]
def populate_blocks():
    existing_site = Site.objects.filter(name=SITE)

    if existing_site.count() > 0:
        print "Site ", SITE, " already exists in database."
        existing_site = existing_site[0]
    else:
        s = Site(name=SITE)
        s.save()
        existing_site = s

    for block_name in BLOCKS:
        existing_block = BedSet.objects.filter(name=block_name, site=existing_site)

        if existing_block.count() > 0:
            print "    Block ", block_name, " already exists in database."
            existing_block = existing_block[0]
        else:
            b = BedSet(name=block_name, site=existing_site)
            b.save()
            existing_block = b
            print "    Saved", block_name, "as Block."

        for bed_name in BLOCKS[block_name]:

            width_UOM = BLOCKS[block_name][bed_name]["width_UOM"]
            existing_width_UOM = LengthUOM.objects.filter(unit=width_UOM)
            if existing_width_UOM.count() > 0:
                print "    WidthUOM ", width_UOM, " already exists in database."
                existing_width_UOM = existing_width_UOM[0]
            else:
                wuom = LengthUOM(unit=width_UOM)
                wuom.save()
                existing_width_UOM = wuom
                print "    Saved", width_UOM, "as WidthUOM."

            length_UOM = BLOCKS[block_name][bed_name]["length_UOM"]
            existing_length_UOM = LengthUOM.objects.filter(unit=length_UOM)
            if existing_length_UOM.count() > 0:
                print "    LengthUOM ", length_UOM, " already exists in database."
                existing_length_UOM = existing_length_UOM[0]
            else:
                luom = LengthUOM(unit=length_UOM)
                luom.save()
                existing_length_UOM = luom
                print "    Saved", length_UOM, "as LengthUOM."

            bed_name = bed_name
            print bed_name
            width = BLOCKS[block_name][bed_name]["width"]
            print width
            length = BLOCKS[block_name][bed_name]["length"]
            width_UOM = existing_width_UOM
            length_UOM = existing_length_UOM

            existing_bed = Bed.objects.filter(name=bed_name, bed_set=existing_block)

            if existing_bed.count() > 0:
                print "    Bed ", bed_name, "in ", existing_block, " already exists in database."
                existing_bed = existing_bed[0]
            else:
                b = Bed(
                    site=existing_site,
                    bed_set=existing_block,
                    name=bed_name,
                    width=width,
                    width_UOM=width_UOM,
                    length=length,
                    length_UOM=length_UOM,
                )
                b.save()
                existing_bed = b
                print "    Saved", bed_name, "in", block_name, "as Bed."
开发者ID:harrywykman,项目名称:data_garden_proudhon,代码行数:75,代码来源:populate.py


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