コード例 #1
0
    def form_valid(self, form):
        owner = self.request.user

        source = form.instance.source
        destination = form.instance.destination

        self.pr = PullRequest(owner=owner,
                              source=source,
                              destination=destination,
                              comment=form.instance.comment)
        try:
            self.pr.full_clean()
        except ValidationError:
            return redirect('editoritem_compare',
                            args=(source.pk, destination.pk))

        self.pr.save()

        if self.pr.destination.can_be_edited_by(owner):
            self.pr.accept(owner)
            messages.add_message(
                self.request, messages.SUCCESS,
                render_to_string('pullrequest/accepted_message.html',
                                 {'pr': self.pr}))
            return redirect(self.pr.destination.get_absolute_url())
        else:
            messages.add_message(
                self.request, messages.INFO,
                render_to_string('pullrequest/created_message.html',
                                 {'pr': self.pr}))
            return redirect(self.pr.source.get_absolute_url())
コード例 #2
0
class CreatePullRequestView(generic.CreateView):
    model = PullRequest
    form_class = editor.forms.CreatePullRequestForm

    template_name = "pullrequest/new.html"

    def form_valid(self, form):
        owner = self.request.user

        source = form.instance.source
        destination = form.instance.destination

        self.pr = PullRequest(owner=owner, source=source, destination=destination, comment=form.instance.comment)
        try:
            self.pr.full_clean()
        except ValidationError:
            return redirect('editoritem_compare', args=(source.pk, destination.pk))

        self.pr.save()

        if self.pr.destination.can_be_edited_by(owner):
            self.pr.accept(owner)
            messages.add_message(self.request, messages.SUCCESS, render_to_string('pullrequest/accepted_message.html', {'pr':self.pr}))
            return redirect(self.pr.destination.get_absolute_url())
        else:
            messages.add_message(self.request, messages.INFO, render_to_string('pullrequest/created_message.html', {'pr':self.pr}))
            return redirect(self.pr.source.get_absolute_url())

    def get_context_data(self, *args, **kwargs):
        context = super(CreatePullRequestView, self).get_context_data(**kwargs)

        context['source'] = EditorItem.objects.get(pk=int(self.request.GET.get('source')))
        context['destination'] = EditorItem.objects.get(pk=int(self.request.GET.get('destination')))

        return context
コード例 #3
0
class CreatePullRequestView(generic.CreateView):
    model = PullRequest
    form_class = editor.forms.CreatePullRequestForm

    template_name = "pullrequest/new.html"

    def form_valid(self, form):
        owner = self.request.user

        source = form.instance.source
        destination = form.instance.destination

        self.pr = PullRequest(owner=owner,source=source,destination=destination,comment=form.instance.comment)
        try:
            self.pr.full_clean()
        except ValidationError as e:
            return redirect('editoritem_compare',args=(source.pk,destination.pk))

        self.pr.save()

        if self.pr.destination.can_be_edited_by(owner):
            self.pr.accept(owner)
            messages.add_message(self.request, messages.SUCCESS, render_to_string('pullrequest/accepted_message.html',{'pr':self.pr}))
            return redirect(self.pr.destination.get_absolute_url())
        else:
            messages.add_message(self.request, messages.INFO, render_to_string('pullrequest/created_message.html',{'pr':self.pr}))
            return redirect(self.pr.source.get_absolute_url())

    def get_context_data(self,*args,**kwargs):
        context = super(CreatePullRequestView, self).get_context_data(**kwargs)

        context['source'] = EditorItem.objects.get(pk=int(self.request.GET.get('source')))
        context['destination'] = EditorItem.objects.get(pk=int(self.request.GET.get('destination')))

        return context
コード例 #4
0
    def form_valid(self, form):
        owner = self.request.user

        source = form.instance.source
        destination = form.instance.destination

        self.pr = PullRequest(owner=owner,source=source,destination=destination,comment=form.instance.comment)
        try:
            self.pr.full_clean()
        except ValidationError as e:
            return redirect('editoritem_compare',args=(source.pk,destination.pk))

        self.pr.save()

        if self.pr.destination.can_be_edited_by(owner):
            self.pr.accept(owner)
            messages.add_message(self.request, messages.SUCCESS, render_to_string('pullrequest/accepted_message.html',{'pr':self.pr}))
            return redirect(self.pr.destination.get_absolute_url())
        else:
            messages.add_message(self.request, messages.INFO, render_to_string('pullrequest/created_message.html',{'pr':self.pr}))
            return redirect(self.pr.source.get_absolute_url())