def handle_noargs(self, **options): while True: title = raw_input('Title: ') pub_date = raw_input('Published Date: ') if not pub_date: pub_date = datetime.datetime.now() else: pub_date = datetime.datetime.strptime(pub_date, '%m/%d/%Y %H:%M') article = raw_input('Article: ') outside_link = raw_input('Outside link: ') saveit = raw_input('Save it? [y/N]: ') if not saveit.lower() == 'y': self.stdout.write("== Not Saved! ==\n\n") else: n = News(title=title, pub_date=pub_date, article=article, outside_link=outside_link, is_published=True) n.pub_date = pub_date n.save() self.stdout.write("=======News article saved========\n\n") another = raw_input('Create a new one? [y/N]: ') if not another.lower() == 'y': break
def newNews(request): ''' Create news article ''' if request.method == 'POST': # form submitted form = NewsFormAdmin(request.POST, request.FILES) if form.is_valid(): fd = form.cleaned_data news = News(title=fd['title'], article=fd['article'], outside_link=fd['outside_link']) news.save() if request.FILES.get('picture', False): (filename, content) = handle_uploaded_picture(request.FILES['picture'], MAX_IMG_SIZE, THUMB_IMG_SIZE) news.image.save(filename[0], content[0]) news.image_thumb.save(filename[1], content[1]) news.is_published=True news.save() return HttpResponseRedirect('/admin/news/') else: # form not submitted, create populated form for editing form = NewsFormAdmin() return render_to_response('news/customadmin/create.html', {'form': form}, context_instance=RequestContext(request))
def newNews(request): ''' Create news article ''' if request.method == 'POST': # form submitted form = NewsFormAdmin(request.POST, request.FILES) if form.is_valid(): fd = form.cleaned_data news = News(title=fd['title'], article=fd['article'], outside_link=fd['outside_link']) news.save() if request.FILES.get('picture', False): (filename, content) = handle_uploaded_picture(request.FILES['picture'], MAX_IMG_SIZE, THUMB_IMG_SIZE) news.image.save(filename[0], content[0]) news.image_thumb.save(filename[1], content[1]) news.is_published = True news.save() return HttpResponseRedirect('/admin/news/') else: # form not submitted, create populated form for editing form = NewsFormAdmin() return render_to_response('news/customadmin/create.html', {'form': form}, context_instance=RequestContext(request))