示例#1
0
文件: views.py 项目: apalade/fingo
def _add(request, form):
  # Check if the user is active or not
  if not request.user.is_active:
    return

  # Save news
  prof.start('news-add')
  news = form.save(commit=False)
  news.user = request.user
  news.save()
  prof.stop('news-add')

  # Publish on wall?
  if not('anonymous' in form.cleaned_data and form.cleaned_data['anonymous']):
    if 'fb_wall' in form.cleaned_data and form.cleaned_data['fb_wall']:
        try:
          FacebookSystem.post_gossip_to_wall(request.COOKIES,
                                             news,
                                             'me')
        except facebook.GraphAPIError:
          # TODO: Error when the user logs out from facebook between
          # loading /news/add and submiting it
          pass

  # Save images if any
  prof.start('news-add-save-images')
  for image in request.FILES.getlist('images'):
    img = Image(news=news, image=image)
    img.save()
  prof.stop('news-add-save-images')


  # Send e-mail
  if news.about_id:
    NotificationSystem.create(news.about_id, 
                              const.NotifConst.NEW_GOSSIP_ME,
                              {'username': request.user.username,
                              'anonymous': news.anonymous,
                              'name': prettyuser.user_or_first_name(request.user),
                              })