Пример #1
0
def _post_winning_submission(poll, submission_id):
    user = UserProfile.objects.get(username=poll.bot_name)
    submission = Submission.objects.get(id=submission_id)
    post = Post(user=user,
                category=poll.category,
                title="{}: {}".format(poll.stub, submission.title),
                url=submission.url,
                type='image',
                nsfw=True,
                crowd=submission.crowd)
    post.save()
    text = poll.winning_text.format(title=poll.title,
                                    stub=poll.stub,
                                    username=submission.user.username)

    comment = Comment(user=user, post=post, text=text, crowd=submission.crowd)
    comment.save()
    winning_user = UserProfile.objects.get(id=submission.user.id)
    winning_user.poll_votes += 1
    winning_user.save()
    submission.delete()
    # Notify the winner they won
    notify_users(user_ids=[winning_user.id],
                 from_user=UserProfile.objects.get(username=poll.bot_name),
                 text="Your {} submission won!".format(poll.title),
                 identifier=post.id,
                 type='comment',
                 level='info')
Пример #2
0
def _post_winning_submission(poll, submission_id):
    user = UserProfile.objects.get(username=poll.bot_name)
    submission = Submission.objects.get(id=submission_id)
    post = Post(user=user,
                category=poll.category,
                title="{}: {}".format(poll.stub, submission.title),
                url=submission.url,
                type='image',
                nsfw=True,
                crowd=submission.crowd)
    post.save()
    text = poll.winning_text.format(
        title=poll.title,
        stub=poll.stub,
        username=submission.user.username)

    comment = Comment(user=user,
                      post=post,
                      text=text,
                      crowd=submission.crowd)
    comment.save()
    winning_user = UserProfile.objects.get(id=submission.user.id)
    winning_user.poll_votes += 1
    winning_user.save()
    submission.delete()
    # Notify the winner they won
    notify_users(
        user_ids=[winning_user.id],
        from_user=UserProfile.objects.get(username=poll.bot_name),
        text="Your {} submission won!".format(poll.title),
        identifier=post.id,
        type='comment',
        level='info')
Пример #3
0
def new_post():
	form = PostForm()
	if form.validate_on_submit():
		if form.picture.data:
			post = Post(title=form.title.data, content=form.content.data, image_file=save_picture(form.picture.data), author=current_user)
		else:
			post = Post(title=form.title.data, content=form.content.data, author=current_user)
		db.session.add(post)
		db.session.commit()
		flash('Your post has been created', 'success')
		return redirect(url_for('main.events'))
	return render_template('create_post.html', title='New Post', form=form, legend="New Post")
Пример #4
0
def cron(request):
    # Get all the votes (may need to improve filtering on poll here).
    # TODO(pcsforeducation) support multiple polls
    user = UserProfile.objects.get(username='******')
    week = datetime.datetime.now().isocalendar()[1] - WEEK_1
    category = Category.objects.get(name='Fantasy')
    post = Post(user=user,
                category=category,
                title="Official Week {} Shit Talk Thread".format(week),
                type='text')
    post.save()
    return HttpResponse('OK')
Пример #5
0
def reply_post(request, post_id):
    main_post = get_object_or_404(Post, pk=post_id)
    isReply = reply_Post.objects.all().filter(replied_post=main_post)
    user_profile = UserProfile.objects.get(user=request.user)
    if isReply.count() > 0:
        for reply in isReply:
            main_post = reply.main_post

    reply_list = reply_Post.objects.all().filter(main_post=main_post)
    form = ReplyPostForm(request.POST or None)
    context = {
        'main_post': main_post,
        'reply_list': reply_list,
        'form': form,
        'user_profile': user_profile
    }
    if request.method == "POST":
        post_content = request.POST.get('post-content', 'hey')
        if (len(post_content) > 255):
            messages.error(request, 'Post 255 karekteri geçemez.')
            return render(request, 'reply_post.html', context)
        post_type = 'Yorum'
        category = 'Diğer'
        publish_date = datetime.datetime.now()
        publish_by = UserProfile.objects.get(user=request.user)
        likecount = 0
        replycount = 0
        post = Post(post_type=post_type,
                    category=category,
                    publish_date=publish_date,
                    publish_by=publish_by,
                    content=post_content,
                    replycount=replycount)
        main_post.replycount += 1
        main_post.save()
        post.save()
        new_reply = reply_Post()
        new_reply.main_post = main_post
        new_reply.replied_post = post
        if main_post.post_type == 'Soru':
            new_reply.reply_post_type = 'Soru'
        else:
            new_reply.reply_post_type = 'Yorum'
        new_reply.save()
        target_url = main_post.get_reply_url()
        notify.send(request.user,
                    recipient=main_post.publish_by.user,
                    verb='postuna yorum yaptı.',
                    description=target_url)
        return redirect('home')
    else:
        return render(request, 'reply_post.html', context)
Пример #6
0
def contact():
    if request.method == 'POST':

        auth = User.query.filter_by(
            user_name=current_user.user_id).first_or_404()
        #  print(post)

        cats = Category.query.filter_by(
            cat_name=request.form['cat']).first_or_404()
        print(cats.cat_id)

        p = Post(post_title=request.form['name'],
                 post_content=request.form['comment'],
                 post_date="2017",
                 author=auth,
                 cat=cats)
        if Tags.query.filter_by(tagname=request.form['tag']).first():
            t = Tags.query.filter_by(tagname=request.form['tag']).first()
        else:
            t = Tags(tagname=request.form['tag'])

        db.session.add(t)
        db.session.add(p)
        t.tags.append(p)

        db.session.commit()

    for a in request.form.keys():
        print(a, request.form[a])
        return render_template("contact.html",
                               title='form sent!',
                               usercomment=p)
    else:
        title = 'contact form'
        return render_template("contact.html", title=title)
Пример #7
0
def buildPosts():
    posts = []
    con = """
    The new ComposerLinter subclass has been created, if you maintain or use a linter that uses Composer to install the dependency. Consider having that linter use ComposerLinter to get added
  benifits!

  JRuby <http://jruby.org/> support has been added! Any linter that uses the RubyLinter subclass will have search for jruby if no other ruby executable is found.

  You may have also noted SublimeLinter run a little faster lately. That's because in the last update we switched to the new usage of the async eventlisteners. You shouldn't see any negative effects but if you do please reach out to use in our Issue Tracker <https://github.com/SublimeLinter/SublimeLinter3/issues>

  Thank you for the continued support of SublimeLinter! We are extremely appreciative of your usage, support, and contributions.


    """
    for i in range(1, 6):
        u = User(user_name="ahmad " + str(i), password="******")

        db.session.add(u)

        p = Post(post_title="title" + str(i),
                 post_content=con + "",
                 post_date="2017",
                 author_id=i,
                 category_id=i)

        db.session.add(p)
        c = Category(cat_name="catgo " + str(i))
        db.session.add(c)
        admin = User('admin', '*****@*****.**')
        # posts.append(p)

    db.session.commit()
    return posts
Пример #8
0
def buildnewpost():
    u = User(user_name="اضعر فرهادی")
    db.session.add(u)
    c1 = Category(cat_name="فرم ها")
    db.session.add(c1)
    c2 = Category(cat_name="وضعیت کلاس ها")
    db.session.add(c2)
    c3 = Category(cat_name="سرفصل دروس")
    db.session.add(c3)
    c4 = Category(cat_name="رشته های موجود")
    db.session.add(c4)
    c5 = Category(cat_name="آرشیو اخبار")
    db.session.add(c5)

    p = Post(
        post_title="همایش",
        post_content="همایش بزرگ مهندسین کامپیوتر در سرزمین دنیای کامپیوتر",
        post_date="2017/6/12",
        author=u,
        cat=c2)
    db.session.add(p)

    t = Tags(tagname="کامپیوتر")
    db.session.add(t)
    t.tags.append(p)
    db.session.commit()
Пример #9
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data, content=form.content.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your Post has been created!',"success")
        return redirect(url_for('new_post'))
    return render_template('create_post.html', title="Create Post", form=form, legend="Update Post")
Пример #10
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data, content=form.content.data, author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('main.index'))
    return render_template('Post/create_post.html', header='Create Your Post',
                           form=form, legend='New Post')
Пример #11
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    CId=form.CId.data,
                    image_file=form.image_file.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')

        return redirect(url_for('home'))
    return render_template("home2.html", title='Posts', form=form)
Пример #12
0
def new():
    form = NewPostForm()
    if form.validate_on_submit():
        lang_id = Language.query.filter_by(name=form.language.data).first().id
        post = Post(title=form.title.data,
                    code=form.code.data,
                    user_id=current_user.id,
                    language_id=lang_id,
                    description=form.description.data)
        db.session.add(post)
        db.session.commit()
        flash('You post has been created successfully!', 'success')
        return redirect(url_for('main.home'))
    return render_template('create_post.html', title='New', form=form)
Пример #13
0
def send_question(request):
    user_profile = UserProfile.objects.get(user=request.user)
    if request.method == "POST":
        post_content = request.POST.get('post-content', 'hey')
        if (len(post_content) > 255):
            messages.error(request, 'Post 255 karekteri geçemez.')
            return render(request, 'post.html', {'user_profile': user_profile})
        post_type = 'Soru'
        category = request.POST.get('category')
        publish_date = datetime.datetime.now()
        publish_by = UserProfile.objects.get(user=request.user)
        likecount = 0
        replycount = 0
        post = Post(post_type=post_type,
                    category=category,
                    publish_date=publish_date,
                    publish_by=publish_by,
                    content=post_content,
                    replycount=replycount)
        post.save()
        return redirect('home')
    else:
        return render(request, 'post.html', {'user_profile': user_profile})
Пример #14
0
def new_post():
    form = CreatePost()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user)
        db.session.add(post)
        db.session.commit()
        flash('Post has been created', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='Create_Post')
Пример #15
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        post = Post(title=form.title.data,
                    content=form.content.data,
                    author=current_user,
                    date_posted=datetime.now(timezone('Asia/Kolkata')))
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='Add Post')
Пример #16
0
def index(request):
    template = loader.get_template('website/index.html')
    officers = UserProfile.objects.filter(user_type=3, approved=True)
    # context = RequestContext(request, { 'officers': officers })
    # return HttpResponse(template.render(context))
    posts = [Post() for i in range(5)]
    post_data = open("website/posts.out", "r")
    post_data = json.loads(post_data.read())
    img_path = 'static/website/images/icons/post'
    for i in range(len(posts)):
        posts[i].text = post_data[i][0]
        posts[i].url = post_data[i][1]
        posts[i].date = post_data[i][2]
        posts[i].img_video = img_path + str(i) + ".jpg"
        posts[i].likes = post_data[i][5]
    context = {'posts': posts, 'officers': officers}
    template.render(Context(context))

    return render(request, 'website/index.html', context)
Пример #17
0
def add_news():
    category_list = db.session.query(Category.name).all()

    if request.method == "POST":
        if request.form['submit'] == '' or request.form['submit'] == None:
            print('Not exists')
        else:
            input_request = request.form
            last_post = db.session.query(Post).filter()
            category = db.session.query(Category.id).filter(Category.name == input_request['post_categories']).one()
            input_category_id = category.id
            print(input_category_id)
            if input_category_id == None:
                print('Category Not exists')
            else:
                post = Post(
                    user_id=1,
                    title=input_request['post_title'],
                    content=request.form['post_content'],
                    image_url= 'blog-9.jpg',
                )
                db.session.add(post)
                db.session.commit()

                print('add new post')
                all_post = db.session.query(Post).all()
                last_id = all_post[-1].id
                print('last id success')
                post_category = PostCategory(
                    post_id = last_id,
                    category_id = input_category_id
                )
                db.session.add(post_category)
                db.session.commit()

                print(" دسنه بندی هم ست شد:)")

    return render_template('add-news.html', page_title="افزودن خبر", categories = category_list)
Пример #18
0
	def test(self):
		time = timezone.now() + datetime.timedelta(days=30)
		future = Post(Created=time)
		self.assertEqual(future.recent_Created(), False)
Пример #19
0
def get_absolute_uri(post: Post) -> str:
    """Return the full URL to a given post."""
    return post.get_absolute_url()
Пример #20
0
 def post(self, args):
     post = Post()
     post.parse(args)
     db.session.add(post)
     db.session.commit()
     return PostJson(post).to_json(), status.HTTP_201_CREATED
Пример #21
0
 def test(self):
     time = timezone.now() + datetime.timedelta(days=30)
     future = Post(Created=time)
     self.assertEqual(future.recent_Created(), False)
Пример #22
0
def build_url(request: HttpRequest, post_obj: Post) -> str:
    """Create a full URL for a Post object for Stripe."""
    http_type = "http://" if settings.DEBUG else "https://"
    return http_type + request.get_host() + post_obj.get_absolute_url()