当前位置: 首页>>代码示例>>Python>>正文


Python Project.save方法代码示例

本文整理汇总了Python中project.models.Project.save方法的典型用法代码示例。如果您正苦于以下问题:Python Project.save方法的具体用法?Python Project.save怎么用?Python Project.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在project.models.Project的用法示例。


在下文中一共展示了Project.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
    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
开发者ID:njqaaa,项目名称:deploy,代码行数:36,代码来源:services.py

示例2: create_project_form

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
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)
        )
开发者ID:iSscorpio,项目名称:hgfront,代码行数:62,代码来源:views.py

示例3: create

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
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)
开发者ID:rodrigoalveslima,项目名称:runn,代码行数:27,代码来源:views.py

示例4: test_edit_ballot

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
 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)
开发者ID:asrashley,项目名称:ieee-802-11-timeline,代码行数:35,代码来源:tests.py

示例5: test_add_member_to_project

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
 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)
开发者ID:lipengbo,项目名称:portal,代码行数:10,代码来源:tests.py

示例6: projects_new_view

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
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")
开发者ID:keiouu,项目名称:Nirtha,代码行数:13,代码来源:views.py

示例7: get_mock_project

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
def get_mock_project(title):
    """ Generate project.

    :return Project:

    """
    p = Project(
        title=title
    )
    p.save()
    return p
开发者ID:emil2k,项目名称:joltem,代码行数:13,代码来源:models.py

示例8: create_project

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
def create_project(org, name):
    p = Project()
    p.name = name
    p.description = v = paragraphs(random.randint(2, 6))
    p.ong = org
    p.shipping_address = paragraphs(1)
    p.created = timezone.now() + datetime.timedelta(random.randint(-360, 0))
    p.save()

    for i in range(random.randint(1, 10)):
        create_thing(p, "thing%d" % (i+1))
开发者ID:centaurustech,项目名称:socialtocrowd,代码行数:13,代码来源:testdata.py

示例9: create

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
def create(request):
    if Project.objects.filter(author=request.user).filter(draft=True).count() >= 12:#cause it's funny
        project=Project.objects.filter(author=request.user).filter(draft=True)[0]
    else:
        project = Project()
        project.title = None
        project.draft=True
        project.author = request.user
        project.save()

    return(redirect('project.views.edit', project.pk))
开发者ID:Rhombik,项目名称:rhombik-object-repository,代码行数:13,代码来源:views.py

示例10: create

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
    def create(self, validated_data):

        user = self.context['request'].user
        group = [group for group in user.groups.all() if group.name == user.username][0]

        instance = Project()
        instance.name = validated_data['name']
        instance.user = user
        instance.group = group
        instance.save()

        return instance
开发者ID:sdeleeuw,项目名称:dodger,代码行数:14,代码来源:project.py

示例11: test_delete_ballot

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
 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)
开发者ID:asrashley,项目名称:ieee-802-11-timeline,代码行数:55,代码来源:tests.py

示例12: CreateTest

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
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)
开发者ID:rodrigoalveslima,项目名称:runn,代码行数:54,代码来源:tests.py

示例13: create

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
def create(request):

## get the draft or draft a new empty project.
    try:
        project=Project.objects.filter(author=request.user).filter(draft=True)[0]
    except:
        project = Project()
        project.title = None
        project.draft=True
        project.author = request.user
        project.save()

    return editOrCreateStuff(project, request, creating=True)
开发者ID:RTLShadow,项目名称:rhombik-object-repository,代码行数:15,代码来源:views.py

示例14: test_add_remove_project

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
 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)
开发者ID:asrashley,项目名称:ieee-802-11-timeline,代码行数:17,代码来源:tests.py

示例15: ReadTest

# 需要导入模块: from project.models import Project [as 别名]
# 或者: from project.models.Project import save [as 别名]
class ReadTest(TestCase):
    def setUp(self):
        self.client = Client()
        self.username = '[email protected]'
        self.email = '[email protected]'
        self.passwd = 'passwd'
        self.title = 'Test'
        self.area = 'DESIGN'
        self.description = 'Testing...'
        user = User.objects.create_user(self.username, self.email, self.passwd)
        self.project = Project(author=user)
        self.project.save()
        self.job = Job(project=self.project, title=self.title, area=self.area,
                       description=self.description)
        self.job.save()
        self.client.login(username=self.username, password=self.passwd)

    def test_login_required(self):
        self.client.logout()
        response = self.client.get(READ_URL % self.job.id)
        self.assertRedirects(response, LOGIN_URL + '?next=' + READ_URL % self.job.id)

    def test_get(self):
        response = self.client.get(READ_URL % self.job.id)
        self.assertEqual(response.status_code, 200)

    def test_invalid_id(self):
        response = self.client.get(READ_URL % '2')
        self.assertEqual(response.status_code, 404)

    def test_deactivated_project(self):
        self.project.is_active = False
        self.project.save()
        response = self.client.get(READ_URL % self.job.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(READ_URL % self.job.id)
        self.assertEqual(response.status_code, 404)
开发者ID:rodrigoalveslima,项目名称:runn,代码行数:49,代码来源:tests.py


注:本文中的project.models.Project.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。