Beispiel #1
0
 def post(self):
     news = News()
     news.title = self.request.get("title")
     news.slug_title = self.request.get("slug_title")
     news.content = self.request.get("content")
     news.when_published = datetime.utcnow()
     news.put()
     self.response.out.write(news.to_json("title", "is_deleted", "is_active", "is_starred"))
    def post(self):
        def error(description):
            self.render('/notifications/news_add.html', error=description)

        title = self.request.get('title')

        if not title:
            return error(u'Введите заголовок')

        text = self.request.get('text')
        if not text:
            return error(u'Введите текст')
        image_url = self.request.get('image_url')

        send_now = bool(self.request.get('send_now'))
        if send_now:
            start = datetime.utcnow()
        else:
            start = self.request.get('start')
            if start:
                try:
                    start = datetime.strptime(start, HTML_STR_TIME_FORMAT)
                except ValueError:
                    return error(u'Неверное время начала')
            else:
                return error(u'Введите время начала')
            if start < datetime.utcnow():
                return error(u'Введите время больше текущего в utc')

        notification = None
        if self.request.get('send_push'):
            channels = []
            company_namespace = namespace_manager.get_namespace()

            company_channel = get_channels(company_namespace)[COMPANY_CHANNEL]
            channels.append(Channel(name=u'Всем', channel=company_channel))
            for venue in Venue.query(Venue.active == True).fetch():
                if self.request.get(str(venue.key.id())):
                    venue_channel = get_channels(company_namespace)[VENUE_CHANNEL]
                    channels.append(Channel(name=venue.title, channel=venue_channel))
            notification = Notification(start=start, text=text, header=title, channels=channels,
                                    should_popup=False)

        news = News(text=text, title=title, image_url=image_url, start=start, notification=notification)

        news.put()
        new_url = get_new_image_url('News', news.key.id(), url=image_url)
        if new_url:
            news.image_url = new_url
            news.put()
        taskqueue.add(url='/task/news/start', method='POST', eta=start, params={
            'news_id': news.key.id()
        })
        self.redirect('/company/notifications/news/list')
Beispiel #3
0
def news_post():
    form = NewsForm()
    if form.validate_on_submit():
        news = News(view = 0, title = form.title.data,url = form.url.data,hot = False)
        try:
            news.put()
            flash(u'저장 성공', 'success')
            return redirect(url_for('new_list'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'failure')
            return redirect(url_for('new_list'))
    return render_template('news_post.html', form=form,title= request.args.get('title'), url= request.args.get('url'))
Beispiel #4
0
def news_post():
    form = NewsForm()
    if form.validate_on_submit():
        news = News(view = 0, title = form.title.data,url = form.url.data,hot = False)
        try:
            news.put()
            search.Index(name=_INDEX_NAME).add(create_doc(news.key.id(),news.title,news.url,news.post_time))
            flash(u'저장 성공', 'success')
            return redirect(url_for('new_list'))
        except CapabilityDisabledError:
            flash(u'App Engine Datastore is currently in read-only mode.', 'failure')
            return redirect(url_for('new_list'))
    return render_template('news_post.html', form=form,title= request.args.get('title'), url= request.args.get('url'),counter=counter.load_and_get_count("view"),acc=ACC)
Beispiel #5
0
    #logging.debug('URL %s saved (status code %s).' % (url,str(result.status_code)))
  except (urlfetch.DownloadError, urlfetch.DeadlineExceededError, urlfetch.InternalTransientError):
    # Request timed out or failed.
    # ...
    urlinstance.valid=urlinstance.valid-1
    urlinstance.put()
    logging.warning('Urlfetch \'%s\' failed.' % (url))
        

  # Update News
  if channelinstance.private==False and date.date()>=today:
    try:
      news=News(content='Link')
      news.link=url
      news.link_text=url_title or url
      news.put()
      #logging.debug('News updated')
    except:
      logging.warning('News update failed')
  else:
    logging.info('News not updated, private channel/old url')
  
  if not url_title:
    url_title=''.join(url.split('/')[-1:])
  #logging.debug('Title: %s' % (url_title))

  # Create Document (FullTextSearch)
  doc_id=str(urlinstance.key.id())
  try:
    doc = search.Document(doc_id=doc_id,fields=[
      search.TextField(name='channel', value=channel),