コード例 #1
0
    def change_view(self, request, pk, *args, **kwargs):
        """
		编辑页面
		:param request:
		:return:
		"""
        # 当前编辑对象
        current_change_object = self.model_class.objects.filter(pk=pk).first()
        if not current_change_object:
            return HttpResponse("需要修改的对象不存在,请重新选择")

        model_form_class = self.get_model_form_class(is_add=False)
        if request.method == "GET":
            form = model_form_class(instance=current_change_object)
            return render(request, 'stark/change.html', {"form": form})

        form = model_form_class(data=request.POST,
                                instance=current_change_object)
        if form.is_valid():
            self.form_database_save(request, form, True, *args, **kwargs)
            # 在数据库中保存成功后,跳转回列表页面(携带原来的参数)
            parse_url = ParseUrl(request=self.request,
                                 namespace=self.site.namespace,
                                 name=self.get_list_url_name)
            url = parse_url.memory_url()
            return redirect(url)
        return render(request, 'stark/change.html', {"form": form})
コード例 #2
0
	def display_reset_pwd(self, obj=None, is_header=None):
		if is_header:
			return "重置密码"
		parse_url = ParseUrl(request=self.request, namespace=self.site.namespace, name=self.get_url_name('reset_pwd'),
		                     pk=obj.pk)
		url = parse_url.memory_url()
		return mark_safe('<a href="%s">重置密码</a>' % url)
コード例 #3
0
	def display_record(self,obj=None,is_header=None):
		if is_header:
			return '跟进记录'

		record_url = ParseUrl(request=self.request, namespace=self.site.namespace, name=self.get_url_name('record_view'),
		                     pk=obj.pk)
		url = record_url.memory_url()
		return mark_safe('<a href="%s">查看跟进</a>'%url)
コード例 #4
0
	def delete_view(self, request, pk):
		"""
		删除页面
		:param request:
		:param pk:
		:return:
		"""
		parse_url = ParseUrl(request=self.request, namespace=self.site.namespace, name=self.get_list_url_name)
		cancel = parse_url.memory_url()
		if request.method == "GET":
			return render(request,'stark/delete.html',{'cancel':cancel})
		current_delete_object = self.model_class.objects.filter(pk=pk).delete()
		return redirect(cancel)
コード例 #5
0
	def add_view(self, request):
		"""
		添加页面
		:param request:
		:return:
		"""
		model_form_class = self.get_model_form_class()
		if request.method == "GET":
			form = model_form_class()
			return render(request,'stark/change.html',{"form":form})

		form = model_form_class(data=request.POST)
		if form.is_valid():
			self.form_database_save(form,is_update=False)
			# 在数据库中保存成功后,跳转回列表页面(携带原来的参数)
			parse_url = ParseUrl(request=self.request,namespace=self.site.namespace,name=self.get_list_url_name)
			url = parse_url.memory_url()
			return redirect(url)
		return render(request, 'stark/change.html', {"form": form})
コード例 #6
0
	def reset_password(self, request, pk):
		"""
		重置密码的视图函数
		:param request:
		:param pk:
		:return:
		"""
		userinfo_object = models.UserInfo.objects.filter(id=pk).first()
		if not userinfo_object:
			return HttpResponse("用户不存在,无法进行重置!")
		if request.method == "GET":
			form = ResetPasswordForm()
			return render(request, 'stark/change.html', {'form': form})
		form = ResetPasswordForm(data=request.POST)
		if form.is_valid():
			userinfo_object.password = form.cleaned_data['password']
			userinfo_object.save()
			parse_url = ParseUrl(request=self.request, namespace=self.site.namespace, name=self.get_list_url_name)
			url = parse_url.memory_url()
			return redirect(url)
		return render(request, 'stark/change.html', {'form': form})