本文整理汇总了Python中project.models.Project类的典型用法代码示例。如果您正苦于以下问题:Python Project类的具体用法?Python Project怎么用?Python Project使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Project类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
def create(request):
if request.method == 'POST':
form = CreateForm(request.POST, request.FILES)
if form.is_valid():
project = Project(
author=request.user,
name=form.cleaned_data['name'],
description=form.cleaned_data['description'],
status=form.cleaned_data['status'],
area=form.cleaned_data['area'],
website=form.cleaned_data['website'],
image=form.cleaned_data['image']
)
project.save()
return redirect(
request,
'project-read',
[project.id],
{request.url_name: 'True'}
)
else:
form = CreateForm()
params = {'form': form}
params.update(csrf(request))
return response(request, params)
示例2: create
def create(data, user):
createDate = datetime.now().strftime('%Y%m%d')
projectsToday = Project.objects.filter(createDate=createDate).order_by('-id')
nextIndex = "%02d" % (1 + int(projectsToday[0].dateIndex) if projectsToday.count() else 1)
parent = Project.objects.get(id=data['parent']) if data['parent'] != '0' else None
project = Project(status=1, name=data['name'], type=data['type'], department=data['department'],suffix=data['suffix'],remote=data['allRemote'],
relatedId=data['relatedId'], onlineDate=data['onlineDate'],
testType=1, createDate=createDate, dateIndex=nextIndex,
createPerson=user.pk, parent=parent, pmtType=data['pmtType'],delay=0)
# 新建项目
project.save()
projectExtend = ProjectExtend(project=project, description=data['description'])
projectExtend.save()
try:
staffs = Pmt().getRelativeStaffsByProjectId(project.relatedId)['task'] or []
print ("---------------")
print (staffs)
# if len(staffs) > 0:
for staff in staffs:
position=staff['position']
if '质量' in position:
position='QA'
staffModel = RelatedPerson(project=project, relatedId=1, \
name=staff['english_name'], chineseName=staff['chinese_name'], \
email=staff['email'], position=position, type=0)
staffModel.save()
except:
print("==========")
return project.id
示例3: test_edit_ballot
def test_edit_ballot(self):
proj = Project(name='test',order=0, doc_type='STD', description='test edit ballot', task_group='TGx', par_date=datetime.datetime.now())
proj.save()
bal = Ballot(number=123,project=proj, ballot_type=Ballot.WGInitial.code, draft='1.0', opened=datetime.datetime.now(), pool=100)
bal.closed = bal.opened + datetime.timedelta(days=15)
bal.save()
url = reverse('ballot.views.edit_ballot',args=[bal.number])
response = self._check_page(url)
data = response.context['form'].initial
for key in data.keys():
if data[key] is None:
data[key] = ''
data['curpk'] = bal.pk
data['draft'] = '2.0'
data['submit']='Save'
form = BallotForm(data, instance=bal)
valid = form.is_valid()
self.failUnless(valid)
response = self.client.post(url,data)
self.failIf(response.status_code!=302 and response.status_code!=303)
self.failUnlessEqual(Ballot.objects.count(),1)
bal = Ballot.objects.get(pk=123)
self.failUnlessEqual(float(bal.draft),2.0)
# test renumbering the ballot, which should cause the old ballot object to be deleted
data['number'] = 125
form = BallotForm(data, instance=bal)
valid = form.is_valid()
self.failUnless(valid)
response = self.client.post(url,data)
self.failIf(response.status_code!=302 and response.status_code!=303)
self.failUnlessEqual(Ballot.objects.count(),1)
bal = Ballot.objects.get(pk=125)
self.failUnlessRaises(Ballot.DoesNotExist,Ballot.objects.get,pk=123)
示例4: create_project_form
def create_project_form(request):
"""
Form to create a new project
"""
# First we check to see the site has been set up, otherwise we throw the user to the config screen
if not bool(os.path.isdir(Project.project_options.repository_directory)):
request.user.message_set.create(message="The site has not been set up yet. Log in as your admin user and create your settings!")
return HttpResponseRedirect(reverse('site-config'))
if request.is_ajax():
template ='project/project_create_ajax.html'
else:
template = 'project/project_create.html'
# Lets check if this form is being shown or processed
if request.method == "POST":
# We're processing the form, so lets create the instance
form = NewProjectForm(request.POST, auto_id=False)
# The form is correct, lets proceeed.
if form.is_valid():
# Lets check the user has conformed to a sites T&C's
if form.cleaned_data['t_and_c'] == True:
# Create the project instance
project = Project(
project_id = string.lower(form.cleaned_data['project_id']),
project_name = form.cleaned_data['project_name'],
short_description = form.cleaned_data['short_description'],
full_description = form.cleaned_data['full_description'],
project_manager = request.user,
hgweb_style = form.cleaned_data.get('hgweb_style', ''),
project_icon = form.cleaned_data['project_icon'],
)
# Ok, we're all good, so lets save.
project.save()
# We'll tell the user that there site has been saved
request.user.message_set.create(message=_("The project " + form.cleaned_data['project_name'] + " has been created"))
if request.is_ajax():
return HttpResponse(
"{'success': 'true', 'url': '" + reverse('project-detail', kwargs={'slug':form.cleaned_data['project_id']}) + "', 'project': " + json_encode(project) + "}"
, mimetype="application/json")
else:
return HttpResponseRedirect(reverse('project-detail', kwargs={'slug': form.cleaned_data['project_id']}))
else:
return render_to_response(template,
{
'form':form.as_table(),
}, context_instance=RequestContext(request)
)
#return HttpResponseRedirect(reverse('project-detail', kwargs={'slug':form.cleaned_data['name_short']}))
else:
form = NewProjectForm()
is_auth = request.user.is_authenticated()
return render_to_response(template,
{
'form':form.as_table(),
'is_auth': is_auth
}, context_instance=RequestContext(request)
)
示例5: test_add_member_to_project
def test_add_member_to_project(self):
owner = User.objects.all()[0]
category = Category.objects.all()[0]
project = Project(name="sdn project", owner=owner, category=category)
project.save()
self.assertTrue(project.memberships.count() == 1) #: there is a default member which is the owner
project.add_member(User.objects.all()[1])
self.assertTrue(project.memberships.count() == 2)
示例6: projects_new_view
def projects_new_view(request):
#TODO - check permissions
try:
o = Project(title=request.GET['title'], description=request.GET['description'], created_by=request.user)
o.save()
auth, created = ProjectAuthLevel.objects.get_or_create(task_add=True, task_edit=True, subproject_add=True, subproject_edit=True)
no = ProjectMembership(project=o, user=request.user, level=auth)
no.save()
except:
return HttpResponse("Something went wrong!")
return HttpResponse("1")
示例7: get_mock_project
def get_mock_project(title):
""" Generate project.
:return Project:
"""
p = Project(
title=title
)
p.save()
return p
示例8: test_delete_ballot
def test_delete_ballot(self):
proj = Project(name='test',order=0, doc_type='STD', \
description='test_delete_ballot', task_group='TGx', \
par_date=datetime.datetime.now())
proj.save()
bal = Ballot(number=123,project=proj, draft='1.0', \
opened=datetime.datetime.now(), pool=100, \
ballot_type=Ballot.WGInitial.code)
bal.closed = bal.opened + datetime.timedelta(days=15)
bal.save()
self.failUnlessEqual(bal.pk,123)
self.failUnlessEqual(Ballot.objects.count(),1)
url = reverse('ballot.views.main_page',args=[])
response = self._check_page(url)
self.failUnlessEqual(Ballot.objects.count(),1)
self.wait_for_backlog_completion(DenormalizedBallot, 10)
run_test_task_queue(self.client)
self.failUnlessEqual(Ballot.objects.count(),1)
dn = DenormalizedBallot.objects.get(pk=bal.pk)
self.failIfEqual(dn,None)
self.failUnlessEqual(Ballot.objects.count(),1)
Ballot.objects.filter(pk=bal.number).delete()
run_test_task_queue(self.client)
self.failUnlessRaises(DenormalizedBallot.DoesNotExist, DenormalizedBallot.objects.get, pk=123)
bal = Ballot(number=124,project=proj, draft='2.0', opened=datetime.datetime.now(), \
pool=100, ballot_type=Ballot.WGInitial.code)
bal.closed = bal.opened + datetime.timedelta(days=15)
bal.save()
run_test_task_queue(self.client)
url = reverse('ballot.views.edit_ballot',args=[bal.number])
response = self._check_page(url)
data = response.context['form'].initial
for key in data.keys():
if data[key] is None:
data[key] = ''
data['curpk'] = bal.pk
data['delete']='Delete'
form = BallotForm(data, instance=bal)
valid = form.is_valid()
self.failUnless(valid)
response = self.client.post(url,data)
self.failIf(response.status_code!=302 and response.status_code!=303)
url = reverse('del_ballot',args=[bal.number])
response.get('Location').index(url)
response = self._check_page(url)
match = re.search(r'input\s+type="submit"\s+name="confirm"', str(response), re.IGNORECASE)
self.assertTrue(match)
data = {"confirm":"Yes, I'm sure"}
response = self.client.post(url,data)
self.failIf(response.status_code!=302 and response.status_code!=303)
self.failUnlessRaises(Ballot.DoesNotExist, Ballot.objects.get, pk=124)
run_test_task_queue(self.client)
self.failUnlessRaises(DenormalizedBallot.DoesNotExist, DenormalizedBallot.objects.get, pk=124)
示例9: CreateTest
class CreateTest(TestCase):
def setUp(self):
self.client = Client()
self.username = '[email protected]'
self.email = '[email protected]'
self.passwd = 'passwd'
self.text = 'Message text...'
user = User.objects.create_user(self.username, self.email, self.passwd)
self.project = Project(author=user)
self.project.save()
self.client.login(username=self.username, password=self.passwd)
def test_login_required(self):
self.client.logout()
response = self.client.get(CREATE_URL % self.project.id)
self.assertRedirects(response, LOGIN_URL + '?next=' + \
CREATE_URL % self.project.id)
def test_get(self):
response = self.client.get(CREATE_URL % self.project.id)
self.assertEqual(response.status_code, 200)
def test_post(self):
self.client.post(CREATE_URL % self.project.id, {'text': self.text})
message = Message.objects.get(author__username=self.username)
self.assertEqual(message.is_active, True)
self.assertEqual(message.created, date.today())
self.assertEqual(message.project, self.project)
self.assertEqual(message.text, self.text)
def test_next(self):
response = self.client.post(CREATE_URL % self.project.id + '?next=' + LOGIN_URL,
{'text': self.text})
self.assertRedirects(response, LOGIN_URL + '?message-create=True')
def test_deactivated_project(self):
self.project.is_active = False
self.project.save()
response = self.client.get(CREATE_URL % self.project.id)
self.assertEqual(response.status_code, 404)
def test_deactivated_project_author(self):
username = '[email protected]'
email = '[email protected]'
passwd = 'abc'
user = User.objects.create_user(username, email, passwd)
self.client.logout()
self.client.login(username=username, password=passwd)
self.project.author.is_active = False
self.project.author.save()
response = self.client.get(CREATE_URL % self.project.id)
self.assertEqual(response.status_code, 404)
示例10: test_add_remove_project
def test_add_remove_project(self):
self.failUnlessEqual(Project.objects.count(),0)
proj = Project(name='test',order=0, doc_type='STD', description='test_add_remove_project', task_group='TGx', par_date=datetime.datetime.now())
proj.save()
self.failUnlessEqual(Project.objects.count(),1)
run_test_task_queue(self.client)
self.failUnlessEqual(Project.objects.count(),1)
self.failUnlessEqual(DenormalizedProject.objects.count(),1)
dn = DenormalizedProject.objects.get(pk=proj.pk)
self.failIfEqual(dn,None)
self.failUnlessEqual(Project.objects.count(),1)
proj.delete()
self.failUnlessEqual(Project.objects.count(),0)
run_test_task_queue(self.client)
self.failUnlessEqual(DenormalizedProject.objects.count(),0)
示例11: delete_like
def delete_like(cls, project_id, scientist_id):
project = yield Project.get_by_id(project_id)
project.likes -= 1
scientist = yield Scientist.get_by_id(scientist_id)
scientist.liked_projects.remove(project_id)
yield project.save(fields=['likes'])
yield scientist.save(fields=['liked_projects'])
示例12: add_like
def add_like(cls, project_id, scientist_id):
project = yield Project.get_by_id(project_id)
project.likes += 1
scientist = yield Scientist.get_by_id(scientist_id)
scientist.liked_projects = list(set(scientist.liked_projects.append(project_id)))
yield project.save(fields=['likes'])
yield scientist.save(fields=['liked_projects'])
示例13: delete
def delete(cls, project_id):
"""
Удалить участников, удалить вакансии, поставить статус откликам - удаленные.
У ученого убрать из managing_project_ids.
"""
project = yield Project.get_by_id(project_id)
for participant_id in project.participants:
yield cls.delete_participant(participant_id)
for vacancy_id in project.vacancies:
yield cls.delete_vacancy(vacancy_id)
for response_id in project.responses:
yield cls.set_del_status_response(response_id)
scientist = yield Scientist.get_by_id(project.manager_id)
scientist.managing_project_ids.remove(project_id)
yield scientist.save(fields=[u'managing_project_ids'], columns=[u'managing_project_ids'])
yield Project.delete(project_id, tbl=Project.TABLE)
示例14: get_my_projects
def get_my_projects(cls, manager_id):
scientist_columns = [u'managing_project_ids']
scientist_json = yield Scientist.get_json_by_id(manager_id, columns=scientist_columns)
# [{scientist_id, vacancy_id, message}]
project_ids = scientist_json.get(u'managing_project_ids', [])
if not project_ids:
raise gen.Return([])
projects = []
for project_id in project_ids:
project_columns = [u'title', u'responses']
project_json = yield Project.get_json_by_id(project_id, columns=project_columns)
project_json.update(project_id=project_id)
raw_responses = project_json.pop(u'responses', [])
if not raw_responses:
project_json.update(responses=[])
projects.append(project_json)
continue
responses = []
for response in raw_responses:
response_data = yield cls.get_response_data(response)
responses.append(response_data)
project_json.update(responses=responses)
projects.append(project_json)
raise gen.Return(projects)
示例15: get_context_data
def get_context_data(self, *args, **kwargs):
ctx = super(Index, self).get_context_data(*args, **kwargs)
ctx['top_projects'] = Project.top(3)
ctx["all_projects"] = Project.latests(7)
# Latests project bigger need
needs = []
for p in Project.latests(4):
need = p.things.all().order_by("quantity")
if not need:
continue
needs.append(need[0])
ctx["needs"] = needs
ctx["donnors"] = Donation.objects.all().order_by('-shipping__created')
return ctx