本文整理汇总了Python中models.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_projects
def import_projects(projects=projects):
from models import Project, ProjectPhoto, ProjectFloorPlan
for p in projects:
project = Project(title=p['title'],
subtitle=p['subtitle'],
slogan=p['slogan'],
location=p['location'],
cover_picture_url=p['cover_picture_url'],
cover_thumb_url=p['cover_thumb_url'],
development_status=p['development_status'],
description=p['description'])
project.put()
fps = []
for fp in p['floor_plans']:
floor_plan = ProjectFloorPlan(caption=fp['caption'],
thumb_url=fp['thumb_url'],
picture_url=fp['picture_url'],
project=project)
fps.append(floor_plan)
db.put(fps)
photos = []
for fp in p['photos']:
photo = ProjectPhoto(caption=fp['caption'],
thumb_url=fp['thumb_url'],
picture_url=fp['picture_url'],
project=project)
photos.append(photo)
db.put(photos)
示例2: project_new
def project_new( self, name, settings ):
owner = current_handler.auth.user.auth_id
project = Project( name=name, owner=owner, settings=settings )
project.put()
return {
'key': str( project.key() )
}
示例3: post
def post(self):
title = self.request.POST.get('title')
code = self.request.POST.get('code')
admins = [Util.getUsernameFromEmail(users.get_current_user().email())]
project = Project(title=title, code=code, admins=admins)
project.put()
self.redirect('/' + project.code + '/organize')
示例4: project_add_typed
def project_add_typed(request, project_id, response_format='html'):
"""Project add to preselected parent project"""
parent_project = None
if project_id:
parent_project = get_object_or_404(Project, pk=project_id)
if not request.user.profile.has_permission(parent_project, mode='x'):
parent_project = None
if request.POST:
if 'cancel' not in request.POST:
project = Project()
form = ProjectForm(
request.user.profile, project_id, request.POST, instance=project)
if form.is_valid():
project = form.save()
project.set_user_from_request(request)
return HttpResponseRedirect(reverse('projects_project_view', args=[project.id]))
else:
return HttpResponseRedirect(reverse('projects'))
else:
form = ProjectForm(request.user.profile, project_id)
context = _get_default_context(request)
context.update({'form': form, 'project': parent_project})
return render_to_response('projects/project_add_typed', context,
context_instance=RequestContext(request), response_format=response_format)
示例5: create_project
def create_project():
# with lock:
# form = CreateProjectForm(request.form)
# if request.method == 'POST' and form.validate_on_submit():
debug_set = current_app.config["DEBUG"]
if debug_set == True:
print "\n\n\n==========> account->views.py -> create_project() "
# print "=====> is_private() :", form.is_private.data
form = CreateProjectForm()
if form.validate_on_submit():
new_proj = Project(
prj_name=form.name.data,
prj_desc=form.desc.data,
is_private=form.is_private.data,
owner=current_user.get_id(),
)
prj_id = new_proj.save()
# Add a user as an owner of a project
proj = Project.get_project_for_projectid(prj_id)
print "project.is_private 2:", proj.is_private
owner_name = current_user.firstname + " " + current_user.lastname
proj.add_member(name=owner_name, email=current_user.get_id(), role=Project.ROLE_OWNER)
flash("New project has been created.", category="index_page")
# Generate a project owner's appkey & save it to ProjectMemberKey coll.
# keygen = KeyGenerator()
# key = keygen.getkey(settings.APPKEY_LENGTH)
key = utils.generate_key()
prjmemkey = ProjectMemberKey(prj_id=proj.prj_id, appkey=key, member_email=proj.owner)
prjmemkey.save()
return redirect(url_for(".list_projects"))
return render_template("create_project.html", form=form)
示例6: edit_project
def edit_project(request, project_id=None):
# http://wiki.ddenis.com/index.php?title=Django,_add_and_edit_object_together_in_the_same_form
if project_id:
print "exists"
project = get_object_or_404(Project, pk=project_id)
if request.user not in project.users.all():
return HttpResponseForbidden()
else:
print "doesn't exist"
project = Project()
if request.method == "POST":
form = ProjectForm(request.POST, instance=project)
if form.is_valid():
form.save()
return HttpResponseRedirect(project.get_absolute_url())
else:
form = ProjectForm(instance=project)
if project_id:
template_name = "edit_project.html"
else:
template_name = "new_project.html"
return render(request, template_name, {"form": form, "project": project})
示例7: register
def register():
if request.method=='POST' and request.form['company']:
#deal with uploaded files
full_path = ''
if request.files['file_path']:
file_obj = request.files['file_path']
file_name = file_obj.filename
full_path = os.path.join(app.config['PROJECT_FOLDER'], file_name)
file_obj.save(full_path)
#insert a new project
project = Project(company = request.form['company'],
address = request.form['address'],
invest = request.form['invest'],
time = request.form['time'],
name = request.form['name'],
major = request.form['major'],
phone = request.form['phone'],
email = request.form['email'],
position = request.form['position'],
holds = request.form['holds'],
introduction = request.form['introduction'],
team = request.form['team'],
business = request.form['business'],
file_path = full_path
)
project.save()
msg = 'success'
return render_template('register.html', msg = msg)
print 'not'
return render_template('register.html')
示例8: create_project
def create_project():
#with lock:
form = CreateProjectForm(request.form)
if request.method == 'POST' and form.validate():
new_proj = Project(prj_name=form.name.data, prj_desc=form.desc.data,
is_private=form.is_private.data, owner=current_user.get_id())
print 'project.is_private:', new_proj.is_private
prj_id = new_proj.save()
# Add a user as an owner of a project
proj = Project.get_project_for_projectid(prj_id)
print 'project.is_private 2:', proj.is_private
owner_name = current_user.firstname + ' ' + current_user.lastname
proj.add_member(name=owner_name, email=current_user.get_id(),
role=Project.ROLE_OWNER)
flash("New project has been created.", category='index_page')
# Generate a project owner's appkey & save it to ProjectMemberKey coll.
#keygen = KeyGenerator()
#key = keygen.getkey(APPKEY_LENGTH)
key = utils.generate_key()
prjmemkey = ProjectMemberKey(prj_id=proj.prj_id, appkey=key,
member_email=proj.owner)
prjmemkey.save()
return redirect(url_for('.list_projects'))
return render_template('create_project.html', form=form)
示例9: addproject
def addproject(request):
# If a user is authenticated and this is a post request, then
# we proceed. Otherwise return an invalid page
U = request.user
if request.user.is_authenticated() and request.POST:
deadline = request.POST.get('deadline')
pid = int(request.POST.get('parentid'))
projectname = request.POST.get('projectname')
projectColor = taskViews.genRandomColor();
P = Project(user=U,name=projectname,date_started=timezone.now(),deadline=deadline,date_finished=timezone.now(),parentid=pid,color=projectColor)
P.save()
# Loop through all the tasks posted with this project and create them as
# unassigned tasks if they don't have deadlines
index = 1;
while not (request.POST.get(str(index)) is None):
newTaskName = request.POST.get(str(index))
taskDeadline = request.POST.get("time"+str(index))
timeRequired = request.POST.get("timeReq"+str(index))
index = index + 1
if newTaskName == "":
continue
else:
taskViews.createTaskForUserFromList(newTaskName,U,P,taskDeadline,timeRequired)
return HttpResponseRedirect('/todolist/projects'+str(U.id))
else :
return HttpResponseRedirect('/todolist/invalid_project_add')
示例10: import_google_events
def import_google_events(self):
if not self.request.get('selected_calendars'):
self.response.status = 501
return
selected_calendars = json.loads(self.request.get('selected_calendars'))
credentials = self.user.google_credentials
if not credentials:
self.response.status = 501
return
http = httplib2.Http()
http = credentials.authorize(http)
service = build('calendar', 'v3', http=http)
page_token = None
num_imported = 0
for calendarId in selected_calendars:
events = service.events().list(calendarId=calendarId, pageToken=page_token).execute()
if len(events) > 0:
# creating project
new_proj = Project(parent=self.user.key)
new_proj.name = events['summary'][0:25]
new_proj.put()
self.user.num_projects += 1
self.user.put()
while True:
for event in events['items']:
if 'dateTime' in event['start']:
start_time = datetime.strptime((event['start']['dateTime'])[0:16], '%Y-%m-%dT%H:%M')
else:
start_time = datetime.strptime((event['start']['date'] + 'T00:00'), '%Y-%m-%dT%H:%M')
if 'dateTime' in event['end']:
end_time = datetime.strptime((event['end']['dateTime'])[0:16], '%Y-%m-%dT%H:%M')
else:
end_time = datetime.strptime((event['end']['date'] + 'T00:00'), '%Y-%m-%dT%H:%M')
event_title = event['summary'][0:25]
event_description = (event['summary'])[0:200]
event_url = event['htmlLink']
if self.request.get('import_as_billed') == 'true':
billed = True
else:
billed = False
self.save_imported_event(new_proj.key, start_time, end_time, event_title, event_description,
billed, event_url)
num_imported += 1
page_token = events.get('nextPageToken')
if not page_token:
break
events = service.events().list(calendarId=calendarId, pageToken=page_token).execute()
if len(events) == 0:
break
self.response.write(num_imported)
示例11: add_project
def add_project(request, user):
if request.method=="POST":
# process form
# fail if the name is blank
name = request.POST['name'].strip()
if name == "":
return HttpResponseRedirect( "?error=the+name+needs+to+contain+letters" )
# make and put project
project = Project(user=user,name=name,updated=datetime.datetime.now())
project.put()
# increment project_count
nickname = Nickname.all().filter("user =", user).get()
nickname.project_count += 1
nickname.put()
logging.info( project.key().id() )
# return rendered project div
return render_to_response( "includes/project_div.html", {'project':{'name':project.name,'id':project.key().id()}} )
return render_to_response( "add_project.html", {'error':request.GET.get('error',None)} )
示例12: delete
def delete(self, key):
if auth.user_is_admin():
Project.get(key).delete()
else:
Messages.add('Only and administrator may delete projects. This ' +
'incident has been logged.')
return self.redirect('/projects')
示例13: post
def post(self):
action = self.request.get('action', 'add')
if action == 'add':
if len(self.request.get('name'))<2:
raise Exception("project name must be at least 2 characters long")
if len(self.request.get('currency'))<1:
raise Exception("project currency must be at least one character long")
# create the project and return the new location to go to
project = Project(name=self.request.get('name'), currency=self.request.get('currency'))
project.put()
# add access rights for this user to the new project
rights = ProjectRights(project=project, user=users.GetCurrentUser(), right=Security.Right_Owner)
rights.put()
# redirect to summary
self.response.out.write("/summary?project=%(key)s" % {'key':project.key()})
elif action == 'delete':
# remove me from the projects right list
project = Project.get(self.request.get('project', ''))
if (not project):
raise Exception("Unknown project!")
# check rights of current user for this project, and deny access if not permitable
rights = ProjectRights.gql("WHERE user=:user and project=:project", user=users.get_current_user(), project=project).get()
if rights:
rights.delete()
# redirect to my page
self.response.out.write("/")
else:
raise Exception("Unknown action '%(action)s'!" % {'action':action})
示例14: post
def post(self):
# if we don't have a user then throw
# an unauthorised error
user = users.get_current_user()
if not user:
self.render_403()
return
name = self.request.get("name")
# check we have a value
if name:
# then check we have a value which isn't just spaces
if name.strip():
if Project.all().filter('name =', name).count() == 0:
# we also need to check if we have something with the same slug
if Project.all().filter('slug =', slugify(unicode(name))).count() == 0:
try:
project = Project(
name=name,
user=users.get_current_user(),
)
project.put()
logging.info("project added: %s" % project.name)
except db.BadValueError, e:
logging.error("error adding project: %s" % e)
示例15: create_project
def create_project():
config.reload()
form = ProjectForm()
ds_forms = dict([
(cls.populates, cls()) for cls in DataSourceForm.__subclasses__()])
form.datasource_type.choices = [
(cls.populates, cls.name) for cls in DataSourceForm.__subclasses__()]
form.datasource_type.choices.insert(0, (None, "-- Select Data Source --"))
new_project = Project()
if form.validate_on_submit():
form.populate_obj(new_project)
ds_form = ds_forms[form.datasource_type.data]
if ds_form.validate():
new_project.datasource = \
getattr(models, form.datasource_type.data)()
ds_form.populate_obj(new_project.datasource)
db.session.add(new_project)
db.session.commit()
flash("New project successfully created.")
return redirect(url_for('view_project', id=new_project.id))
return render_template("project/create.html",
form=form, ds_forms=ds_forms, project=new_project)