Beispiel #1
0
    def store_db(self, item):
        engine = db_connect()
        session = sessionmaker(bind=engine)
        session = session()
        news = News()

        imgs = []
        if item['imgs'] is not None:
            for img in item['imgs']:
                i = Imgs()
                i.img = img
                imgs.append(i)

        tags = []
        if item['tags'] is not None:
            for tag in item['tags']:
                t = Tags()
                t.tag = tag.lower()
                news.tags.append(t)

        news.link = item['link']
        news.title = item['title']
        news.subtitle = item['subtitle']
        news.session = item['session']
        news.sub_session = item['sub_session']
        news.author = item['author']
        news.publisher = item['publisher']
        news.text = item['text']
        news.imgs = imgs
        news.datetime = convert_datetime(item['date'], item['hour'])

        session.add(news)
        session.commit()
        session.close()
Beispiel #2
0
def import_news():
    author = UserData.objects.get(id=1)
    print author.username
    for new_old in Stats.objects.all():
        if new_old.catid != 0 and (new_old.catid == 2 or new_old.catid == 3):
            print new_old.id, new_old.name, new_old.catid
            stci = News()

            print author
            # stci.id = new_old.id
            stci.article = new_old.full.replace('http://centrinform.info/', 'http://ci.ua/')
            stci.author = author
            stci.foreword = new_old.min.replace('http://centrinform.info/', 'http://ci.ua/')
            stci.slug = new_old.url
            stci.title = new_old.name
            stci.creation_date = new_old.dat_created
            stci.description = new_old.opisanie
            stci.key_words = new_old.klucheviki
            stci.category = NewsCategory.objects.get(id=new_old.catid)

            stci.save()
            # News.objects.get_or_create(
            #
            #     id=new_old.id,
            #     article=new_old.full.replace('http://centrinform.info/', 'http://ci.ua/'),
            #     author=author,
            #     foreword=new_old.min.replace('http://centrinform.info/', 'http://ci.ua/'),
            #     slug=new_old.url,
            #     title=new_old.name,
            #     creation_date=new_old.dat_created,
            #     description=new_old.opisanie,
            #     key_words=new_old.klucheviki,
            #     category=NewsCategory.objects.get(id=new_old.catid)
            # #   defaults={'category': NewsCategory.objects.get(id=new_old.catid)}  # default применится в случае create
            # )
            # new.article = new_old
            # # new.article = new_old.full.replace('http://centrinform.info/', 'http://ci.ua/')
            # new.author = author
            # new.category = NewsCategory.objects.get(id=new_old.catid)
            # new.foreword = new_old.min.replace('http://centrinform.info/', 'http://ci.ua/')
            # new.part_url = new_old.url
            # new.title = new_old.name
            # new.save()







        # try:
        #
        # except Stats.DoesNotExist:
        #     print u'Нету'
Beispiel #3
0
def new_post(blog_id, username, password, post, publish):
    user = authenticate(username, password)
    item = News()
    item.title = post['title']
    item.description = post['description']
    if post.get('dateCreated'):
        item.dateCreated  = datetime.strptime(str(post['dateCreated']),'%Y%m%dT%H:%M:%S')
    else:
        item.dateCreated = datetime.now().date()
    item.author = user
    item.publish = publish
    item.categories = Categories.objects.get(name=u'Новости сайта')
    item.save()
    return item.pk
Beispiel #4
0
def save(request):
    if isLoggedIn(request):
        req = request.POST
        id = req.get('id')
        title = req.get('title')
        content = req.get('content')
        mag = req.get('mag')
        signature = request.COOKIES.get('signature')
        if not int(id) == 0:
            news = News.objects.filter(id=id).first()
        else:
            news = News()
        if title and content and mag:
            news.title = title
            news.content = content
            news.mag = mag
            news.author = signature
            news.save()
            id = news.id
            news = News.objects.filter(id=id)
            return HttpResponse(serialize('json', news))
    return HttpResponse('0')