本文整理汇总了Python中models.Project.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Project.get_by_id方法的具体用法?Python Project.get_by_id怎么用?Python Project.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Project
的用法示例。
在下文中一共展示了Project.get_by_id方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def get(self):
account = get_account()
placed_bids_ids = account.projects_bidded_on
placed_bids = []
for i in placed_bids_ids:
project_id = int(i)
project = Project.get_by_id(project_id)
project_open = "open"
frmtd_end_date = project.end_date
winner_email = None
if frmtd_end_date is not None:
frmtd_end_date = frmtd_end_date.strftime('%b %d, %Y')
if project.winner is not None:
project_open = "Closed (Winner selected)"
winner_account = Account.get_by_id(int(project.winner))
if winner_account:
winner_email = winner_account.guser.email()
projectJSON = {
'projectid': project_id,
'projectname': project.name,
'bidders': project.bidders,
'winner': project.winner,
'winner_email': winner_email,
'price': project.price,
'bidcount': len(project.bidders),
'enddate': frmtd_end_date,
'additionalstatus': project_open,
'complete': project.complete
}
placed_bids.append(projectJSON)
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps(placed_bids))
示例2: copy_file_to_project
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def copy_file_to_project(filepath, project_id):
"""
Copy file to project dir and return new filepath in project directory.
:param filepath: The file path.
:type filepath: String
:param project_id: Project id from database.
:type project_id: Integer
:returns: The path for this file in project directory or empty string.
:rtype: String
"""
project_path = Project.get_by_id(project_id).dir
file_project_path = search_file(os.path.basename(filepath), project_path)
if file_project_path:
return file_project_path
result = ''
try:
shutil.copy2(filepath, project_path)
result = os.path.join(project_path, os.path.basename(filepath))
except (ValueError, IOError, OSError):
LOGGER.exception('File copy error')
return result
示例3: wrapper
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def wrapper(self, project_id):
project = Project.get_by_id(long(project_id))
if project:
user = users.get_current_user()
if project.owner == user.user_id():
nodes = Node.all()
nodes.ancestor(project)
nodes.order('title')
nodes = tuple(nodes) # prevent re-execution when iterating
request_node, current_node = self.request.get('node'), None
if request_node: # self.request.get always return a string
try:
current_node_id = long(request_node)
except ValueError:
pass
else:
for node in nodes:
if node.key().id() == current_node_id:
current_node = node
break
if current_node is None:
self.redirect(project.permalink)
return
f(self, user, project, nodes, current_node)
else:
self.error(403)
else:
self.redirect('/')
示例4: project
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def project(request, context, id):
project = Project.get_by_id(int(id))
context['project']=project
scraps = Scrap.all().filter("project =", project).order("-created")
context['scraps'] = scraps
return render_to_response( "project.html", context )
示例5: _on_moved_project
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def _on_moved_project(self, event):
"""
On_modified event handler for project files.
This should get called when a project file has been moved.
- If the file exists in database:
- If the target path is inside project directory, change the\
path entry in database.
- If the target path is outside project directory, set the\
file as deleted (project.id = NULL).
- If the file does not exist in database:
- If the target path is inside the project directory, add the\
file into the database.
- If the target path is outside the project directory, do nothing.
:param event: The event.
:type event: :py:class:`watchdog.events.FileSystemEvent`
"""
source = os.path.abspath(event.src_path)
target = os.path.abspath(event.dest_path)
try:
project = Project.get_by_id(self.project_id)
source_file = File.get('one', File.project == project,
File.path == source)
project_path = os.path.abspath(project.dir)
if source_file is not None:
# Case 1
if target.startswith(project_path):
source_file.path = target
act_path = target
action = REVERSE_ACTIONS['Renamed to something']
# Case 2
else:
source_file.project_id = None
act_path = source
action = REVERSE_ACTIONS['Deleted']
source_file.update()
self._project_prototype(act_path, action)
else:
# Case 3
if target.startswith(project_path):
action = REVERSE_ACTIONS['Created']
self._project_prototype(target, action)
# Case 4, should never happen.
else:
pass
except Exception as excp:
log_msg = ('Exception in Project file handler on_moved '
'callback: {exception!s}')
log_msg = log_msg.format(exception=excp)
_logger().exception(log_msg)
示例6: show
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def show(project_id, path):
"""Project page route.
Renders the single page app (SPA) for the project. The SPA will
be the main interface of the user to Sirius.
"""
project = Project.get_by_id(long(project_id))
if (project == None):
return abort(404)
else:
pjson = json.dumps(project.json(), ensure_ascii=False)
return render_template('projects/show.html', project=project, project_json=pjson)
示例7: get
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def get(self, id_or_slug):
from models import Project
completed_projects = Project.get_all_complete()
ongoing_projects = Project.get_all_ongoing()
try:
id = int(id_or_slug, 10)
project = Project.get_by_id(id)
except ValueError:
project = Project.get_by_slug(id_or_slug)
self.render('project_information.html',
project=project,
completed_projects=completed_projects,
ongoing_projects=ongoing_projects)
示例8: delete_project
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def delete_project( request, user, id ):
project = Project.get_by_id(int(id))
if project.user != user:
return HttpResponseForbidden( "<html><body>That doesn't belong to you</body></html>" )
# get nickname of user, to decrement their project_count
nickname = Nickname.all().filter("user =", user).get()
nickname.project_count -= 1
nickname.put()
project.delete()
return HttpResponseRedirect( "/" )
示例9: get
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def get(self, project_id, bidder_id):
project_id = int(project_id)
project = Project.get_by_id(project_id)
if project:
bidder_id = int(bidder_id)
if bidder_id in project.bidders:
project.winner = bidder_id
project.put()
response = {'success': 'Winner chosen.'}
else:
response = {'error': 'Winner not in bidders list.'}
else:
response = {'error': 'No project of given id.'}
self.response.headers['Content-Type'] = 'application/json'
self.response.write(json.dumps(response))
示例10: start_new_session
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def start_new_session(project_id, old_session_id=None):
"""
Creates a session to the database and return a session object.
:param project_id: Project id from database.
:type project_id: Integer
:param old_session_id: A session id of a session which will be continued.
:type old_session_id: Integer
"""
project = Project.get_by_id(project_id)
try:
old_session = Session.get_by_id(old_session_id)
except NoResultFound:
old_session = None
return Session(project, old_session)
示例11: _on_created_scanner
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def _on_created_scanner(self, event):
"""
On_created event handler for project scanned files.
Logs to database.
:param event: The event.
:type event: an instance of :class:`watchdog.events.FileSystemEvent`
"""
try:
project = Project.get_by_id(self.project_id)
if not project.dir:
return
file_path = event.src_path
basename = os.path.basename(file_path)
log_msg = 'On created at: {path} ({name})'
log_msg = log_msg.format(path=project.dir, name=basename)
_logger().debug(log_msg)
new_path = os.path.join(project.dir, basename)
try:
# Let's build the directory path to the file.
path_parts = os.path.dirname(file_path)
path_parts = os.path.splitdrive(path_parts)[1] # (drive, path)
# Now it is for example: [this part]
# C:[\Some\path\To\dir]\myfile.txt
path_parts = path_parts.strip(os.path.sep)
path_parts = path_parts.split(os.path.sep)
# ['Some', 'path', 'To', 'dir']
path_parts = [part.lower() for part in path_parts]
# ['some', 'path', 'to', 'dir']
if 'scan' in path_parts:
# The file is a subdirectory of "scan" folder in
# some sense.
sleep(60)
except (IndexError, ValueError):
pass
shutil.copy2(file_path, new_path)
self._project_prototype(new_path, REVERSE_ACTIONS['Created'])
except Exception as excp:
log_msg = 'Exception in SCAN HANDLER: {exception!s}'
log_msg = log_msg.format(exception=excp)
_logger().exception(log_msg)
示例12: OpenProjectDir
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def OpenProjectDir(self, event):
"""
Opens project directory in windows explorer.
:param event: The GraphicalUserInterface event.
:type event: Event
"""
project_id = self.diwa_state.current_project_id
if project_id < 1:
return
file_path = unicode(Project.get_by_id(project_id).dir)
if file_path:
os.startfile(file_path, u'explore')
else:
log_msg = u'Failed explorer: {0}'
log_msg = log_msg.format(file_path)
LOGGER.exception(log_msg.encode('utf-8')) # FIXME
params = {'message': 'Could not open directory.'}
show_modal_and_destroy(ErrorDialog, self, params)
if event:
event.Skip()
示例13: add_scrap
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_by_id [as 别名]
def add_scrap(request, user):
if not ('content' and 'projectid' in request.POST):
return HttpResponseServerError( "You must include both content and a project id" )
logging.info( str( request.POST ) );
# get project_id
projectid = int(request.POST['projectid'])
# get project
project = Project.get_by_id( projectid )
if project is None:
return HttpResponseNotFound( "Could not find project with id %s"%projectid )
# project needs to be owned by the current user
if project.user != user:
return HttpResponseForbidden( "This project is owned by %s. You are %s. They're not the same."%(project.user, user) )
# scrap content needs to be non-blank
scrap_content = request.POST['content']
if scrap_content.strip()=="":
return HttpResponseServerError( "The scrap content needs to have <i>characters</i>" )
# if it's a URL, file it away as a LinkScrap
parsed_url = urlparse.urlparse( scrap_content )
if parsed_url[0]!="" and parsed_url[1]!="":
# get favicon, if possible
favicon_url = parsed_url[0]+"://"+parsed_url[1]+"/favicon.ico"
try:
favicon_resp = urlfetch.fetch(favicon_url)
if favicon_resp.status_code == 200:
favicon = favicon_resp.content
else:
favicon = None
except DownloadError:
favicon = None
# if it parses as a feed, file it away as a feed scrap
parse_attempt = feedparser.parse(scrap_content)
if parse_attempt.version != "":
# if we're not already subscribed to this feed
if FeedScrap.all().filter("content =", scrap_content).filter("project =", project).count()!=0:
return HttpResponseServerError( "This feed has already been added to this project.Z" )
scrap = FeedScrap( content = scrap_content, project=project, created=datetime.datetime.now(), creator=user, icon=favicon )
scrap.put()
for entry in parse_attempt.entries:
if 'guid' in entry and 'link' in entry and ('updated' in entry or 'published' in entry):
if 'published' in entry:
created = datetime.datetime( *entry.published_parsed[:6] )
elif 'updated' in entry:
created = datetime.datetime( *entry.updated_parsed[:6] )
if FeedItemScrap.all().filter("project=", project).filter("guid =", entry.guid).count()==0:
feed_item_scrap = FeedItemScrap( content=entry.link,
project=project,
created=created,
creator=user,
icon=favicon,
feed=scrap,
guid=entry.guid )
feed_item_scrap.put()
logging.info( feed_item_scrap )
else:
scrap = LinkScrap( content = scrap_content, project=project, created=datetime.datetime.now(), creator=user, icon=favicon )
scrap.put()
else:
scrap = Scrap( content = scrap_content, project=project, creator=user, created=datetime.datetime.now() )
scrap.put()
project.updated = datetime.datetime.now()
project.put()
return render_to_response( "includes/scrap_div.html", {'scrap':scrap} )