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


Python Project.get_absolute_url方法代码示例

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


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

示例1: edit_project

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

示例2: ProjectsModelsTest

# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_absolute_url [as 别名]
class ProjectsModelsTest(TestCase):
    """ Documents models tests"""
    def setUp(self):
        self.project = Project(name='test')
        self.project.save()

        self.taskstatus = TaskStatus(name='test')
        self.taskstatus.save()

        self.task = Task(name='test', project=self.project, status=self.taskstatus)
        self.task.save()

    def test_task_priority_human(self):
        """Default priority should be 3, text representation should be 'Normal'
        """
        self.assertEqual(self.task.priority, 3)
        self.assertEqual(self.task.priority_human(), 'Normal')

    def test_get_estimated_time_default(self):
        """Default estimated time is None, string representation is empty string """
        self.assertIsNone(self.task.estimated_time)
        self.assertEqual(self.task.get_estimated_time(), '')

    def test_get_estimated_time_one_min(self):
        self.task.estimated_time = 1
        self.assertEqual(self.task.get_estimated_time(), ' 1 minutes')

    def test_get_estimated_time_zero_min(self):
        self.task.estimated_time = 0
        self.assertEqual(self.task.get_estimated_time(), 'Less than 1 minute')

    def test_get_estimated_time_60_min(self):
        self.task.estimated_time = 60
        self.assertEqual(self.task.get_estimated_time(), ' 1 hours ')

    def test_get_estimated_time_61_min(self):
        self.task.estimated_time = 61
        self.assertEqual(self.task.get_estimated_time(), ' 1 hours  1 minutes')

    def test_model_task_get_absolute_url(self):
        self.task.get_absolute_url()

    # def test_save TODO: save is overridden and has some extra logic

    def test_get_absolute_url(self):
        """Test if get_absolute_url works without raising any exception"""
        self.project.get_absolute_url()

    def add_time_slot(self, total_time):
        duser, created = DjangoUser.objects.get_or_create(username='testuser')
        time_from = datetime(year=2015, month=8, day=3)
        time_to = time_from + total_time
        timeslot = TaskTimeSlot(task=self.task, user=duser.profile, time_from=time_from, time_to=time_to)
        timeslot.save()

    def test_get_total_time_default(self):
        self.assertEqual(self.task.get_total_time(), timedelta())

    def test_get_total_time_with_timeslots1(self):
        total_time = timedelta(hours=3)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time(), total_time)

    def test_get_total_time_tuple_default(self):
        self.assertIsNone(self.task.get_total_time_tuple())

    def test_get_total_time_tuple(self):
        total_time = timedelta(hours=3)
        self.add_time_slot(total_time)
        h, m, s = self.task.get_total_time_tuple()
        self.assertEqual((h, m, s), (3, 0, 0))

    def test_get_total_time_string_default(self):
        self.assertEqual(self.task.get_total_time_string(), '0 minutes')

    def test_get_total_time_string_one_min(self):
        total_time = timedelta(minutes=1)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), ' 1 minutes')

    def test_get_total_time_string_zero_min(self):
        total_time = timedelta(minutes=0)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), '0 minutes')

    def test_get_total_time_string_30_secs(self):
        total_time = timedelta(seconds=30)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), 'Less than 1 minute')

    def test_get_total_time_string_60_min(self):
        total_time = timedelta(minutes=60)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), ' 1 hours ')

    def test_get_total_time_string_61_min(self):
        total_time = timedelta(minutes=61)
        self.add_time_slot(total_time)
        self.assertEqual(self.task.get_total_time_string(), ' 1 hours  1 minutes')

#.........这里部分代码省略.........
开发者ID:tovmeod,项目名称:anaf,代码行数:103,代码来源:tests.py

示例3: add_or_edit_project

# 需要导入模块: from models import Project [as 别名]
# 或者: from models.Project import get_absolute_url [as 别名]
def add_or_edit_project(request, project_author=None, project_pk=None, is_add=False):
    user = request.user

    project = None
    if not is_add:
        project = get_object_or_404(Project, pk=project_pk)

        if project.wont_be_completed:
            return oops("This project is set as 'won't be completed': you can't edit it")

            # only a project's author can edit it
        if not user == project.author:
            return oops("Only a project's author can edit it.")

    if request.method == "POST":
        if is_add:
            project = Project(proposed_by=user, author=user)
        elif project.author != user:
            return oops("Only a project's author can edit it.")

        form = ProjectForm(request.POST)
        if form.is_valid():
            project.title = form.cleaned_data["title"]
            # if form.cleaned_data['event']:
            # 	project.event = get_object_or_404(Event, pk=form.cleaned_data['event'])
            project.description_markdown = form.cleaned_data["description"]
            if form.cleaned_data["time_estimate"]:
                project.hour_estimate = form.cleaned_data["time_estimate"]
            if project.p_completed:
                project.showcase_markdown = form.cleaned_data["showcase"]

            if not project.p_completed:
                not_involved = form.cleaned_data["not_involved"]
                if not_involved:
                    project.looking_for_admin = True
                    if not is_add:
                        user.message_set.create(
                            message="The project is now set as 'looking for admin'. You have admin rights until someone else clicks 'Become admin for this project'."
                        )
                        project.remove_member(user)
                else:
                    project.looking_for_admin = False

            tags = form.cleaned_data["tags"]

            project.save()

            # Need to save() before calling this, so we couldn't do it up there
            if is_add and not not_involved:
                project.join_user(user)

            project.set_tags(tags)

            return HttpResponseRedirect(project.get_absolute_url())
    elif not is_add:
        # initialize the form with existing project info
        form = ProjectForm(
            initial={
                "title": project.title,
                "description": project.description_markdown,
                "showcase": project.showcase_markdown,
                "tags": project.get_editable_tags,
                "time_estimate": project.hour_estimate,
            }
        )
    else:
        form = ProjectForm()

    return render_to_response(
        "projects/add_or_edit_project.html",
        {"form": form, "is_editing": not is_add, "project": project},
        context_instance=RequestContext(request),
    )
开发者ID:clusterify,项目名称:clusterify,代码行数:75,代码来源:views.py


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