def create_channel(request): """ Creates a group. """ if request.method == 'POST': form = ChannelForm(request.POST) if form.is_valid(): channel = form.save(commit=False) channel.owner = request.user channel.channel_slug = generate_channel_slug(settings.CHANNEL_SLUG_LENGTH) channel.api_link = generate_api_key(API_KEY_LEN) channel.save() channel.owner.userprofile.channels.add(channel.id) return redirect(reverse('update_channel', args=[channel.id,])) else: context = {'form': form} else: form = ChannelForm() context = {'form': form} return render(request, 'create_channel.html', context)
def create_channel(request): """ Creates a group. """ if request.method == 'POST': form = ChannelForm(request.POST) if form.is_valid(): channel = form.save(commit=False) channel.owner = request.user channel.channel_slug = generate_channel_slug( settings.CHANNEL_SLUG_LENGTH) channel.api_link = generate_api_key(API_KEY_LEN) channel.save() channel.owner.userprofile.channels.add(channel.id) return redirect(reverse('update_channel', args=[ channel.id, ])) else: context = {'form': form} else: form = ChannelForm() context = {'form': form} return render(request, 'create_channel.html', context)
def reset_slug(self, request, queryset): for q in queryset: channel_slug = generate_channel_slug(settings.CHANNEL_SLUG_LENGTH) q.channel_slug = channel_slug q.save()