def approve_quote(modeladmin, request, queryset): for submitted_quote in queryset: new_quote = Quote() new_quote.quote = submitted_quote.quote new_quote.attribution = submitted_quote.attribution new_quote.save() #send a notification email if submitted_quote.submitter_email != '': send_approve_email(submitted_quote.submitter_email, new_quote.pk) submitted_quote.delete()
def clean(self): id = self.cleaned_data.get('id') name = self.cleaned_data.get('name') email = self.cleaned_data.get('email') if not name: raise forms.ValidationError('name is required') if not email: raise forms.ValidationError('email is required') if id: quote = Quote.objects.get(id=id) quote.name = name quote.email = email else: quote = Quote(name=name, email=email) quote.save()
def add_quote(request): if request.method == 'POST': print request.POST post_quote = '' post_comment = '' post_author = '' quote_form = QuoteForm(request.POST.copy(), prefix='quote') if quote_form.is_valid(): cd = quote_form.cleaned_data post_quote = cd['quote'] post_comment = cd['comment'] post_author = cd['author'] quote = Quote() if post_comment: print 'post_comment',post_comment comment = Comment() comment.text = post_comment comment.save() quote.comment = comment author, created = Author.objects.get_or_create(name__iexact=post_author) if post_author: author.name = post_author else: author.name = 'Anonymous' author.save() quote.author = author quote.quote = post_quote quote.save() else: print "Quote_form is not valid!" data = { 'quote_text': post_quote, 'quote_comment': post_comment, 'quote_author': post_author, } return HttpResponse(simplejson.dumps(data)) raise Http404
def submit(request): if request.method == 'POST': quote = Quote( text=request.POST['text'], submitter=request.user, ) quote.save() tag_string = request.POST['tags'] if len(tag_string) > 0: tag_texts = [Tag.make_valid_tag(text.strip()) for text in tag_string.split(',')] for text in tag_texts: if len(text) > 0: tag = Tag.objects.filter(text=text).first() if tag is None: tag = Tag(text=text) tag.save() quote.tags.add(tag) return redirect(reverse('app:detail', args=(quote.id,))) form = QuoteForm() context = {'form': form} return render(request, 'app/submit.html', context)
def _create_quote_and_save(quote, quoter, added_by): new_quote = Quote(text=quote, quoted_by=quoter, added_by=added_by) new_quote.save() return new_quote