本文整理汇总了Python中models.Project.name方法的典型用法代码示例。如果您正苦于以下问题:Python Project.name方法的具体用法?Python Project.name怎么用?Python Project.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Project
的用法示例。
在下文中一共展示了Project.name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addProject
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import name [as 别名]
def addProject(request):
"""
Creates a new project in the database
Returns a JSON thingied thing with the
id on success, or an error message
otherwise
"""
if request.method == "POST":
try:
inputData = json.loads(request.POST['DATA'])
newProject = Project()
newProject.name = inputData['name']
newProject.save()
if len(inputData['components']) > 0:
#We have to ensure we have these components in the linker table
for component_id, quantity in inputData['components']:
component = Component.objects.filter(id=component_id).get()
newBOMQuant = BOMQuant.objects.create(project=newProject, component=component, quantity=quantity)
if len(inputData['notes']) > 0:
#add lots of notes if we have any
for note_id in inputData['notes']:
newNote = Note.objects.filter(id=note_id).get()
newProject.notes.add(newNote)
newProject.save()
json_data = json.dumps({"HTTPRESPONSE": newProject.id})
except Exception, e:
json_data = json.dumps({"ERROR": e.message})
示例2: newProject
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import name [as 别名]
def newProject(request, projectname, monthlygoal):
print projectname
project = Project()
project.user = request.user
project.name = projectname
if monthlygoal != "":
project.monthlygoal = int(monthlygoal)
goal = project.monthlygoal
else:
goal = "-"
print project
project.save()
print "qwe"
dajax = Dajax()
dajax.remove("#newrow")
row = """<tr id="project{0}">
<td>{1}</td>
<td>{2}</td>
<td>0</td>
<td><a href="javascript:void(0)" onClick="Dajaxice.timemanager.removeProject(removeRow, {{'project': '{0}'}});" class="remove"><i class="icon-remove pull-right"></i></a> <a href="javascript:void(0)" onClick="" class="edit"><i class="icon-pencil pull-right"></i></a></td>
</tr>""".format(project.id, projectname, goal)
print row
dajax.append("#projecttable", "innerHTML", row)
dajax.script("$('#newprojectbutton').show();")
return dajax.json()
示例3: import_google_events
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import name [as 别名]
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)
示例4: register
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import name [as 别名]
def register(request):
if request.method == 'POST':
a = request.POST.get('action')
if a == 'register':
register_f = RegisterForm(request.POST)
login_f = LoginForm()
if register_f.is_valid():
try:
User.objects.create_user(
register_f.cleaned_data['username'],
register_f.cleaned_data['email'],
register_f.cleaned_data['password'])
except IntegrityError, e:
if 'username' in str(e):
register_f.add_error('username',
'Username is taken')
elif 'email' in str(e):
register_f.add_error('email',
'Email is already registered')
else:
raise e
else:
user = authenticate(
username=register_f.cleaned_data['username'],
password=register_f.cleaned_data['password'])
login(request, user)
Timezone.objects.create(user=user)
project = Project()
project.user = user
project.name = 'default project'
project.description = 'default project description'
project.color = Project.DEFAULT_COLOR
project.save()
return redirect('dashboard')
elif a == 'login':
register_f = RegisterForm()
login_f = LoginForm(request.POST)
if login_f.is_valid():
user = authenticate(
username=login_f.cleaned_data['username'],
password=login_f.cleaned_data['password'])
if user is None:
login_f.add_error('username',
'Wrong credentials')
else:
login(request, user)
return redirect('dashboard')
else:
register_f = RegisterForm()
login_f = LoginForm()
示例5: create_projects
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import name [as 别名]
def create_projects():
with open('data/projects.json') as projects_file:
projects = json.load(projects_file, strict=False)
for d in projects:
id = d['id']
name = d['name']
author = d['author']
if isinstance(d['description'], str):
description = d['description']
elif isinstance(d['description'], list):
description = '</p><p>'.join(line for line in d['description'])
description = '<p>' + description + '</p>'
project = Project.query.get(id)
if not project:
project = Project(id=id, name=name, author=author,
description=description)
else:
project.name = name
db.session.add(project)
print('Adding', repr(project))
示例6: import_timely_events
# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import name [as 别名]
def import_timely_events(self):
if not self.user.timely_token:
self.response.status = 501
return
header = {
'Authorization': 'Bearer ' + self.user.timely_token,
'Content-Type': 'application/json'
}
if not self.request.get('selected_proj'):
self.response.status = 501
return
# importo l'utente
result = urlfetch.fetch(url='https://api.timelyapp.com/1.0/accounts',
headers=header,
method=urlfetch.GET)
if result.status_code != 200:
self.response.set_status(501)
return
result = json.loads(result.content)
selected_proj = json.loads(self.request.get('selected_proj'))
since = self.request.get('since')
up_to = self.request.get('up_to')
if since != '' and not datetime.strptime(since, '%Y-%m-%d'):
self.response.set_status(201)
self.response.write('Since time is not correct')
return
if up_to != '' and not datetime.strptime(up_to, '%Y-%m-%d'):
self.response.set_status(201)
self.response.write('Up_to time is not correct')
return
num_imported = 0
for proj_id in selected_proj:
if since != '' and up_to != '':
timely_events_url = 'https://api.timelyapp.com/1.0/%s/projects/%s/events?since=%s&upto=%s' % \
(result[0]['id'], proj_id, since, up_to)
else:
timely_events_url = 'https://api.timelyapp.com/1.0/%s/projects/%s/events' % (result[0]['id'], proj_id)
logging.warn(timely_events_url + " " + self.user.timely_token)
events = urlfetch.fetch(
url=timely_events_url,
headers=header,
method=urlfetch.GET)
if events.status_code != 200:
self.response.set_status(501)
return
events = json.loads(events.content)
if len(events) > 0:
num_imported += len(events)
# create project
new_proj = Project(parent=self.user.key)
new_proj.name = events[0]['project']['name'][0:25]
new_proj.hourly_rate = events[0]['project']['hour_rate']
new_proj.put()
self.user.num_projects += 1
self.user.put()
for event in events:
if event['duration']['total_minutes'] > 0:
start_time = datetime.strptime((event['day'] + ' 00:00'), '%Y-%m-%d %H:%M')
end_time = start_time + timedelta(minutes=(event['duration']['total_minutes']))
event_title = event['note'][0:25]
event_description = event['note']
billed = True
self.save_imported_event(new_proj.key, start_time, end_time, event_title, event_description,
billed)
if self.request.get('import_planned') == 'true':
if (event['estimated_duration']['total_minutes'] - event['duration']['total_minutes']) > 0:
start_time = datetime.strptime((event['day'] + ' 00:00'), '%Y-%m-%d %H:%M')
end_time = start_time + timedelta(
minutes=(event['estimated_duration']['total_minutes'] - event['duration']['total_minutes']))
event_title = 'planned-' + event['note'][0:25]
event_description = event['note']
billed = False
self.save_imported_event(new_proj.key, start_time, end_time, event_title,
event_description, billed)
self.response.write(num_imported)