def article(): article = Article() article.title = 'title1' article.description = 'description1' article.updated_at = 'updated_at1' article.category = category() article.published = 'published1' return article
def post(self, request): article_name = request.POST.get("article_name", "") desc = request.POST.get("desc", "") detail = request.POST.get("detail", "") art_len = request.POST.get("art_len", "dp") read_times = request.POST.get("read_times", "") category = request.POST.get("category", "") tag = request.POST.get("tag", "") author = request.POST.get("author", "") youneed_know = request.POST.get("youneed_know", "") content = request.POST.get("content", "") lesson = request.POST.get("lesson", "") article_org = request.POST.get("article_org", 10) # image_form = ArticleImageForm(request.POST or None, request.FILES or None) image = request.POST.get("image", "/articles/201804/IMG_1084.JPG") if content: post_article = Article() post_article.desc = desc post_article.detail = detail post_article.art_len = art_len post_article.name = article_name post_article.read_times = read_times post_article.category = category post_article.tag = tag author = Author.objects.get(id=int(author)) post_article.author = author post_article.youneed_know = youneed_know article_org = ArticleOrg.objects.get(id=article_org) post_article.article_org = article_org post_article.image = image post_article.save() post_content = Content() post_content.name = article_name post_content.art_content = content lesson = Lesson.objects.get(id=int(lesson)) post_content.lesson = lesson post_content.save() return HttpResponse('{"status":"success","msg":"提交成功"}', content_type='application/json') else: return HttpResponse('{"status":"fail","msg":"提交失败"}', content_type='application/json')
def setUp(self): self.client = Client() Page.objects.create(title='home', slug='home', order=1, visible_in_menu=True) for item in range(12): news_item = NewsItem() news_item.title = f'newsitem_title {item}' news_item.description = f'news description {item}' news_item.author = Author.objects.create( last_name='last_name', first_name='news first_name') news_item.published = True news_item.publication_date = timezone.now() news_item.save() for item in range(6): event = Event() event.title = f'event_title {item}' event.date = timezone.now() + timedelta(days=1) event.short_description = f'desciption {item}' event.save() for item in range(6): gallery = Gallery() gallery.title = f'gallery_title {item}' gallery.author = GalleryAuthor.objects.create( last_name='last_name', first_name='gallery first_name') gallery.date = timezone.now() gallery.save() for item in range(6): article = Article() article.title = f'article_title {item}' article.date = timezone.now() article.category = Category.objects.create(title='category', slug='slug-0') article.author = ArticleAuthor.objects.create( last_name='last_name', first_name='article first_name') article.save()
article.date_published = dateutil.parser.parse(obj['post_modified']) article.text = "%s%s%s" % ('<p>', obj['post_content'].replace(' ','').replace(' \n','').replace('\n\n', '\n').replace('\n', '</p><p>'), '</p>') article.authors.add(usr_dict[obj['post_author']]) for k, v in post_dict.items(): v.save() category_data = open('termzeroo.json') data = json.load(category_data) for obj in data: if (obj['term_taxonomy_id'] == '7') or (obj['term_taxonomy_id'] == '8') or (obj['term_taxonomy_id'] == '9') or (obj['term_taxonomy_id'] == '10'): article = post_dict.get(obj['object_id'], None) if (article != None): article.category = "FT" if (obj['term_taxonomy_id'] == '5') or (obj['term_taxonomy_id'] == '6'): article = post_dict.get(obj['object_id'], None) if (article != None): article.category = "AE" if (obj['term_taxonomy_id'] == '11') or (obj['term_taxonomy_id'] == '12'): article = post_dict.get(obj['object_id'], None) if (article != None): article.category = "LD" if (obj['term_taxonomy_id'] == '13') or (obj['term_taxonomy_id'] == '14'): article = post_dict.get(obj['object_id'], None) if (article != None): article.category = "MD"