django-views

from django.views.decorators.csrf import csrf_exempt
from django.conf import settings
from django.views.generic  import ListView,DetailView,CreateView,UpdateView
from django.http import HttpResponseRedirect,JsonResponse
from django.db.models import  Q
def DeployListView(ListView):
    template_name=
    paginate_by=

    def get_queryset(self):
        return object_list
    
    def get_context_data(self,**kwargs):
        context=super().get_context_data(**kwargs)
                query_string = self.request.META.get(‘QUERY_STRING‘)

        if ‘page‘ in query_string:
            query_list = query_string.split(‘&‘)
            query_list = [elem for elem in query_list if not elem.startswith(‘page‘)]
            query_string = ‘?‘ + "&".join(query_list) + ‘&‘
        elif query_string is not None:
            query_string = ‘?‘ + query_string + ‘&‘
        context[‘current_url‘] = query_string
        return context
    
    def get_success_url(self):
        return reverse_lazy("deploy:list")
        


def DeployCreateView(CreateView):
    template_name=‘deploy/create_deploy.html‘
    form_class=DeployForm
    model=DeployPool
    
    def form_invalid(self,form):
        return self.render_to_response({‘form‘:form})
        
    def form_valid(self,form):
        user=self.request.user
        if not is_right(app.id, action.id, 0, user):
            messages.error(self.request, ‘没有权限,请联系此应用管理员:‘ + str(app.manage_user), extra_tags=‘c-error‘)
            return self.render_to_response({‘form‘: form})
        
        DeployPool.objects.create()
        return HttpResponseRedirect(reverse("deploy:list"))


class DeployUpdateView(UpdateView):
    template_name = ‘deploy/edit_deploy.html‘
    model = DeployPool
    form_class = DeployForm

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context[‘current_page‘] = "deploy-edit"
        context[‘current_page_name‘] = "编辑发布单"
        context[‘app_id‘] = self.kwargs.get(self.pk_url_kwarg, None)
        return context

    def get_success_url(self):
        return reverse_lazy("deploy:list")


class DeployDetailView(DetailView):
    template_name = ‘deploy/detail_deploy.html‘
    model = DeployPool

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context[‘current_page_name‘] = "发布单详情"
        context[‘now‘] = timezone.now()
        return context

django-views

上一篇:idea激活码最新版_2021.06.23


下一篇:k8s-nginx二进制报Illegal instruction (core dumped)