def add_in_widget(request, community, widget, render): community_obj = Community.objects.get(key_name=community) widget_config = community_obj.widget_set.get(key_name=widget) class _TuiForm(forms.Form): title = forms.CharField(required=True, max_length=100) link = forms.URLField(required=True, max_length=250) if request.method == 'POST': form = _TuiForm(request.POST) if form.is_valid(): post = Topic(community=community_obj, community_widget=widget_config, author=request.user) post.title = form.cleaned_data['title'] post.link = form.cleaned_data['link'] post.save() url = reverse(display, kwargs={'id':str(post.id)}) return HttpResponseRedirect(url) else: form = _TuiForm() # An unbound form context = {'form': form, 'community_obj': community_obj, 'widget_config': widget_config, 'user_obj':request.user} return render(request, context)
def add(request, render): if request.method == 'POST': form = TuiForm(request.POST) if form.is_valid(): c = form.cleaned_data['category'] community = Community.objects.get(key_name=c) community_widget = community.widget_set.get(key_name='tui') post = Topic(community=community, community_widget=community_widget, author=request.user) post.title = form.cleaned_data['title'] post.link = form.cleaned_data['link'] post.save() url = reverse(display, kwargs={'id':str(post.id)}) return HttpResponseRedirect(url) else: form = TuiForm(initial={'category': request.GET.get('category', '')}) # An unbound form context = {'form': form, 'user_obj':request.user} return render(request, context)