def add(request, community, widget, render): community_obj = Community.objects.get(key_name=community) widget_config = community_obj.widget_set.get(key_name=widget) class PostForm(forms.Form): title = forms.CharField(max_length=100) tags = forms.CharField(required=False, max_length=100) content = forms.CharField(required=False, widget=forms.Textarea) if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): post = Topic(author=request.user) post.title = form.cleaned_data['title'] post.content = text_markup.render( form.cleaned_data['content'] ) post.raw_content = form.cleaned_data['content'] post.add_tags( form.cleaned_data['tags'] ) post.community = community_obj post.community_widget = widget_config post.save() params = {'id':str(post.id), 'community':community, 'widget':widget} redirect = reverse(display, urlconf=APPS[APP_ID]['urls'], kwargs=params) return HttpResponseRedirect(redirect) else: form = PostForm() # An unbound form context = {'form': form, 'community_obj': community_obj, 'widget_config': widget_config} return render(request, context)
def add(request, user, widget, render): class PostForm(forms.Form): title = forms.CharField(max_length=100) tags = forms.CharField(required=False, max_length=100) content = forms.CharField(required=False, widget=forms.Textarea) if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): post = Topic() post.author = get_current_user() post.title = form.cleaned_data['title'] post.content = text_markup.render( form.cleaned_data['content'] ) post.raw_content = form.cleaned_data['content'] post.add_tags( form.cleaned_data['tags'] ) post.user = get_current_user() post.user_widget = post.author.user_widget_set.get(key_name=widget) post.save() kwargs={ 'user':user, 'widget':widget, 'id':str(post.id)} redirect = reverse('note-user-topic', urlconf=APPS['note']['urls'], kwargs=kwargs) return HttpResponseRedirect(redirect) else: form = PostForm(initial={}) # An unbound form context = {'form': form, 'user':user, 'widget':widget} return render(request, context)
def auth(request): context = {} context['auth'] = Topic.get_auth_class().get_auth() context['auth_comment'] = Comment.get_auth_class().get_auth() return context