本文整理汇总了Python中project.models.Project.author_id方法的典型用法代码示例。如果您正苦于以下问题:Python Project.author_id方法的具体用法?Python Project.author_id怎么用?Python Project.author_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类project.models.Project
的用法示例。
在下文中一共展示了Project.author_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_result
# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import author_id [as 别名]
def calculate_result(self, url, userPK, **kwargs):
print("importing project : {}".format(url))
response=get_response(url)
goo=response.read()
dom=html.fromstring(goo)
#print(dom.xpath('//*[contains(@class,\'thing-header-data\')]/h1/text()'))
# Getting some metadatas for the project.
#this is probably fine. If you're confused, feel free to make it more verbose.
project=Project()
project.author_id = userPK# User.objects.get(pk=userPK)
project.title = dom.xpath('//*[contains(@class,\'thing-header-data\')]/h1/text()')[0].strip()
tags = dom.xpath("//*[contains(@class,\'thing-info-content thing-detail-tags-container\')]/div/a/text()")
project.draft=True
if Project.objects.filter(title=project.title):
import datetime
project.title+= " -- "+str(datetime.datetime.today())
project.save()
for tag in tags:
project.tags.add(tag)
## get special text files. (readme, instructions, license)
import html2text
h2t = html2text.HTML2Text()
#Get the reame file, do stuff to it.
readme = etree.tostring(dom.xpath("//*[@id = 'description']")[0])
readme = readme.encode("utf-8")
readme = h2t.handle(readme)
import unicodedata
readmeItem=fileobject()
readmeItem.parent=project#projectObject['SID']
readmeItem.isReadme = True
readmename="README.md"
readmefile=u""+unicodedata.normalize('NFKD',readme).encode('ascii','ignore')
print(readmename)
print(readmefile)
readmeItem.fromText(readmefile,readmename)
readmeItem.save()
project.bodyFile=readmeItem
project.save()
print("bodyFile:")
print(project.bodyFile)
#projectObject['readme'] = u""+unicodedata.normalize('NFKD',readme).encode('ascii','ignore')
#also a markdown file I guess we'd want.
try:
instructions = etree.tostring(dom.xpath("//*[@id = 'instructions']")[0])
instructions = u""+h2t.handle(instructions).encode('ascii','ignore')
instructionItem=fileobject()
instructionItem.parent=project#Object['SID']
name="Instructions.md"
filename=instructions
instructionItem.fromText(filename,name)
instructionItem.save()
except IndexError:
pass
#print("xpath to get the instructions IndexError'd")
## now, because the format of the license on thingi is always the same, we can pull this off.
## but I expect it is rather fragile.
licenseurl =dom.xpath("//*[contains(@class,\'license-text\')]/a/@href")[2].strip()
licensetext = dom.xpath("//*[contains(@class,\'license-text\')]/a/text()")[1].strip()
licenceItem=fileobject()
licenceItem.parent=project#Object['SID']
lname="License.md"
lfile="["+licensetext+"]("+licenseurl+")"
licenceItem.fromText(lfile,lname)
licenceItem.save()
## get all the projects image and file objects
#grab files
filelist = dom.xpath('//*[contains(@class,\'thing-file\')]/a/@href')
#Grab only raw images.
imagelist = dom.xpath('//*[contains(@class,\'thing-gallery-thumbs\')]/div[@data-track-action="viewThumb"][@data-thingiview-url=""]/@data-large-url')
fileurls=[urlparse.urljoin('http://www.thingiverse.com/', fl) for fl in imagelist+filelist]
print("fileurls:")
print(fileurls)
bundle_o_tasks=[]
for fileurl in fileurls:
bundle_o_tasks+=[ThingiFileTask().si(url=fileurl,projectPK=project.pk)]
filetask = chord(bundle_o_tasks)
filetask(ResaveProjectTask().si(projectPK=project.pk))
return(project.title)