def post(self): channel = self.request.get('channel') recipient = self.request.get('recipient') variables = {} if not channel: variables = {'error': 'Channel Name is required'} elif not recipient: variables = {'error': 'Recipient is required'} else: existing_channel = Channel.query(Channel.name == channel).get() if existing_channel: variables = {'error': 'Channel already exists'} else: # Create channel and success message new_channel = Channel(name=channel, recipient=recipient) new_channel.put() variables = {'success': 'Channel added!'} template = JINJA_ENVIRONMENT.get_template('create.html') self.response.write(template.render(variables))
def post(self, request, format='json'): serializer = UserSerializer(data=request.data) if serializer.is_valid(): user = serializer.save() if user: Channel(user=user, slug=get_uname_slug(user.username)).save() json = serializer.data return Response(json, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def create_channel(request): if request.method == 'POST': name = request.POST.get('channel_name', '') user = request.user channel = Channel(name=name, user=user) channel.save() return redirect('home') return render(request, 'forms/create_channel.html')
def post(self, request, *args, **kwargs): if 'excel' in request.FILES: execl_file = request.FILES.get('excel') wb = open_workbook(filename=None, file_contents=request.FILES['excel'].read()) table = wb.sheets()[0] # sheet1 = wb.sheet_by_index(0) rows = table.nrows #获取行数 cols = table.ncols #获取列数 for r in range(1, rows): name = table.cell(r, 0).value bianmaqi = table.cell(r, 1).value jieru = table.cell(r, 2).value type = table.cell(r, 3).value pindao_id = table.cell(r, 4).value beizhu = table.cell(r, 5).value try: a = Channel.objects.filter(name=name) if a: print(name + " 存在") continue elif name == None or name == '': continue else: print(name) channel = Channel() channel.name = name channel.bianmaqi = bianmaqi channel.type = type channel.jieru = jieru channel.save() self.excelmodel(name, bianmaqi, jieru, type, pindao_id, beizhu) except: pass # print(sheet1.rcols) return HttpResponseRedirect( 'http://127.0.0.1:8000/channel/channel/') print(4444444) return super(XadminChannel, self).post(request, args, kwargs)