Esempio n. 1
0
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')
Esempio n. 2
0
 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)