Example #1
0
 def handle(self, *args, **options):
     for i in range(1, 100):
         p = Post()
         p.title = 'Post number %s' % i
         p.content = 'Post content number %s' % i
         p.save()
         print('Saving %s' % i)
Example #2
0
def pub(request):
    try:
        payload = simplejson.loads(request.body)

        post = Post()
        content = Content()
        content.content = payload['content']
        post.title = payload['title']
        post.author = request.user
        post.content = content

        try:
            content.save()
            post.save()


        except Exception as e:
            print(e)
            return HttpResponse("pub content save error")

        try:
            post.save()
            return JsonResponse({
                'post_id': post.id,
                'title': post.title,
                'author': post.author.name,
                'content': post.content.content
            })
        except Exception as e:
            print(e)
            return HttpResponse("pub content save error")
    except Exception as e:
        print(e)
        return HttpResponse("pub content save error")
Example #3
0
 def create(
     title,
     content,
     author,
 ):
     post = Post()
     post.title = title
     post.content = content
     post.author = author
     post.save()
     return post
Example #4
0
def make_post(request, id_):
    if request.method == 'POST':
        title = str(request.POST.get('title', False))
        image = request.FILES.get('image', False)
        video = str(request.POST.get('video', False))
        audio = str(request.POST.get('audio', False))
        description = str(request.POST.get('content', False))
        for_coop = int(request.POST.get('for_cooperative', False))
        count = 0
        attachments = []
        while request.FILES.get('attachment' + str(count), False) is not False:
            attachments.append(
                request.FILES.get('attachment' + str(count), False))
            count = count + 1
        if title and description:
            if id_ != 'new':
                new_post = Post.objects.get(id=id_)
            else:
                new_post = Post()
            new_post.author_id = request.user.id
            new_post.title = title
            new_post.author_status = author_status(request.user.id)
            new_post.date_posted = timezone.datetime.now()
            new_post.content = description
            if image:
                new_post.image = image
            if video:
                new_post.video = video
            if audio:
                new_post.audio = audio
            if for_coop == 1:
                new_post.for_cooperative = True
                member = Member.objects.get(user_id=request.user.id)
                new_post.cooperative_name = member.coop_detail().name
            new_post.save()
            for val in attachments:
                new_attachment = Attachment()
                new_attachment.post = new_post
                new_attachment.file = val
                new_attachment.save()

            return render(request, 'post/make_post.html', {
                'message': 'Your post has been uploaded',
                'status': 'success'
            })
        else:
            return render(request, 'post/make_post.html', {
                'message': 'All fields must be filled',
                'status': 'danger'
            })

    return render(request, 'post/make_post.html')
Example #5
0
def add_post(request):
    if request.method == "POST":
        form = PostAddForm(request.POST)
        if form.is_valid():
            post_name = form.cleaned_data["name"]
            post_content = form.cleaned_data["content"]
            post = Post()
            post.name = post_name
            post.content = post_content
            post.user = request.user
            post.is_visible = True
            post.save()
            return HttpResponseRedirect(reverse('detail', args=[post.pk]))
        else:
            messages.error(request, _("form is not valid"))

        ctx = {"form": form }
    else:
        form = PostAddForm()
        ctx = {"form": form} 
    return render(request, "add_post.html", ctx)
Example #6
0
 def post(self, request):
     if request.user.is_authenticated:
         content = request.POST.get('content')
         hashtag = request.POST.get('hashtag').upper().replace(" ", "")
         feeling = request.POST.get('feeling')
         tag_friends = request.POST.get('tag_friends')
         public = request.POST.get('public')
         photo = ''
         try:
             photo = request.FILES['photo']
         except:
             pass
         new_post = Post()
         new_post.content = content
         new_post.photo = photo
         new_post.hashtag = hashtag
         new_post.feeling = feeling
         new_post.tag_friends = tag_friends
         new_post.public = public
         new_post.user = request.user
         new_post.save()
         return redirect('post:ShowPost', new_post.post)
Example #7
0
def store(request):
    post = Post()
    post.title = request.POST['title']
    post.content = request.POST['content']
    post.save()
    return redirect('/posts')
Example #8
0
 def POST(self, post_id=None):
     """保存日志信息"""
     import pytz
     
     if post_id:
         post = Post.get_by_id(int(post_id))
     else:
         post = Post()
     
     inp = web.input()
     
     post.title = inp.title
     post.alias = inp.alias
     post.content = inp.content
     post.excerpt = inp.excerpt
     if inp.get('date'):
         tz = pytz.timezone(blog.timezone)
         date = inp.get('date')
         date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
         date_tz = date.replace(tzinfo=tz)
         # datetime = time.mktime(date)
         post.date = date_tz
     post.allow_comment = bool(inp.get('allow_comment'))
     post.allow_ping = bool(inp.get('allow_ping'))
     post.hidden = bool(inp.get('hidden'))
     
     # 以下分类代码写的比较乱
     # 文章添加分类最简单,直接分类统计加1
     # 分类修改则取得原分类减1,新分类加1
     # 删除分类则将旧分类减1
     category_key = inp.get('category')
     if category_key:
         category = Category.get(category_key)
     if post.category:
         if unicode(post.category.key()) != unicode(category_key):
             post.category.count = post.category.count - 1
             post.category.save()
             if category_key:
                 post.category = category
                 category.count = category.count + 1
                 category.save()
             else:
                 post.category = None
     elif category_key:
         post.category = category
         category.count = category.count + 1
         category.save()
     
     tags = inp.tags
     if tags:
         tags = tags.split(',')
         post.tags = tags
         for tag in tags:
             Tag.add(tag)
     post.save()
     
     clear_cache()
     
     from google.appengine.api import taskqueue
     queue = taskqueue.Queue()
     url = '/task/ping_sites'
     ping_task = taskqueue.Task(countdown=5, url=url)
     queue.add(ping_task)
     
     raise web.seeother('/admin/posts')