Beispiel #1
0
 def mutate(self, info, title, body, username):
     user = User.query.filter_by(username=username).first()
     post = Post(title=title, body=body)
     if user is not None:
         post.author = user
     db.session.add(post)
     db.session.commit()
     return CreatePost(post=post)
Beispiel #2
0
def index(request):
    if request.method == "POST":
        userid = get_object_or_404(User, username=request.user)
        body = request.POST.get('body')
        p = Post()
        p.author = userid
        p.body = body
        p.save()
        return HttpResponseRedirect('/')
    show_followed = False
    if str(request.user) != 'AnonymousUser':
        u = UserProfile.objects.get(user__username=request.user)
        show_cookie = bool(request.COOKIES.get('show_followed', ''))
        if show_cookie:
            posts = u.followed_posts()
        else:
            posts = Post.objects.order_by('-timestamp')
    return render_to_response('index.html',
                              locals(),
                              context_instance=RequestContext(request))
Beispiel #3
0
def index(request):
	if request.method == "POST":
		userid = get_object_or_404(User, username=request.user)
		body = request.POST.get('body')
		p = Post()
		p.author = userid
		p.body = body
		p.save()
		return HttpResponseRedirect('/')
	show_followed = False
	if str(request.user) != 'AnonymousUser':
		u = UserProfile.objects.get(user__username=request.user)
		show_cookie = bool(request.COOKIES.get('show_followed', ''))
		if show_cookie:
			posts = u.followed_posts()
		else:
			posts = Post.objects.order_by('-timestamp')
	return render_to_response(
		'index.html',
		locals(),
		context_instance=RequestContext(request))
Beispiel #4
0
 def create(self, validated_data):
     post = Post(**validated_data)
     post.author = User.objects.first()
     post.created = datetime.datetime.now()
     post.save()
     return post
 def handle(self, **options):
     Menu.objects.get_or_create(
         name='menu'
     )
     Menu.objects.get_or_create(
         name='bottom_menu'
     )
     post_count = int(options.get('post-count', 100))
     comment_limit = int(options.get('comment-limit', 100))
     random_rate = lambda: int(random() * 1000)
     get_rand = lambda _list: _list[int(random()*len(_list))]
     blog_types = map(
         lambda type: BlogType.objects.get_or_create(name=type)[0],
         (getattr(settings, 'DEFAULT_BLOG_TYPE', 'main'), 'talks', 'personal',)
     )
     random_type = partial(get_rand, blog_types)
     users = map(
         lambda username: User.objects.get_or_create(username=username)[0],
         ('bob', 'paul', 'mike', 'anna', 'sasha', 'katya', 'masha',)
     )
     map(
         lambda user: Profile.objects.get_or_create(
             user=user,
             rate=random_rate(),
             posts_rate=random_rate(),
             comments_rate=random_rate(),
             blogs_rate=random_rate(),
         )[0], users
     )
     random_user = partial(get_rand, users)
     blogs = map(
         lambda (blog_name, url): Blog.objects.get_or_create(
             name=blog_name,
             owner=random_user(),
             type=random_type(),
             description=url,
             rate=random_rate(),
             rate_count=random_rate(),
         )[0], (
             (u'астрономии', 'astronomy.xml'),
             (u'геологии', 'geology.xml'),
             (u'гироскопии', 'gyroscope.xml'),
             (u'литературоведению', 'literature.xml'),
             (u'маркетингу', 'marketing.xml'),
             (u'математике', 'mathematics.xml'),
             (u'музыковедению', 'music.xml'),
             (u'политологии', 'polit.xml'),
             (u'почвоведению', 'agrobiologia.xml'),
             (u'правоведению', 'law.xml'),
             (u'психологии', 'psychology.xml'),
             (u'страноведению', 'geography.xml'),
             (u'физике', 'physics.xml'),
             (u'философии', 'philosophy.xml'),
             (u'химии', 'chemistry.xml'),
             (u'эстетике', 'estetica.xml'),
         )
     )
     random_blog = partial(get_rand, blogs)
     random_comment = lambda limit: Post.objects.all()[int(random() * limit)].title
     for counter in range(post_count):
         post = Post()
         post.author = random_user()
         post.blog = random_blog()
         post.title, post.text = obtain_spring(post.blog.description)
         post.rate = random_rate()
         post.rate_count = random_rate()
         post.save(edit=False, retry=True)
         post.set_tags(','.join(post.title.split()))
         last = root = post.create_comment_root()
         limit = int(random() * comment_limit)
         while limit:
             if not int(random()*3):
                 last = root
             last = last.add_child(
                 post=post,
                 author=random_user(),
                 text=random_comment(counter),
                 created=datetime.now(),
                 rate=random_rate(),
                 rate_count=random_rate()
             )
             limit -= 1
Beispiel #6
0
 def handle(self, **options):
     Menu.objects.get_or_create(name='menu')
     Menu.objects.get_or_create(name='bottom_menu')
     post_count = int(options.get('post-count', 100))
     comment_limit = int(options.get('comment-limit', 100))
     random_rate = lambda: int(random() * 1000)
     get_rand = lambda _list: _list[int(random() * len(_list))]
     blog_types = map(
         lambda type: BlogType.objects.get_or_create(name=type)[0], (
             getattr(settings, 'DEFAULT_BLOG_TYPE', 'main'),
             'talks',
             'personal',
         ))
     random_type = partial(get_rand, blog_types)
     users = map(
         lambda username: User.objects.get_or_create(username=username)[0],
         (
             'bob',
             'paul',
             'mike',
             'anna',
             'sasha',
             'katya',
             'masha',
         ))
     map(
         lambda user: Profile.objects.get_or_create(
             user=user,
             rate=random_rate(),
             posts_rate=random_rate(),
             comments_rate=random_rate(),
             blogs_rate=random_rate(),
         )[0], users)
     random_user = partial(get_rand, users)
     blogs = map(
         lambda (blog_name, url): Blog.objects.get_or_create(
             name=blog_name,
             owner=random_user(),
             type=random_type(),
             description=url,
             rate=random_rate(),
             rate_count=random_rate(),
         )[0], (
             (u'астрономии', 'astronomy.xml'),
             (u'геологии', 'geology.xml'),
             (u'гироскопии', 'gyroscope.xml'),
             (u'литературоведению', 'literature.xml'),
             (u'маркетингу', 'marketing.xml'),
             (u'математике', 'mathematics.xml'),
             (u'музыковедению', 'music.xml'),
             (u'политологии', 'polit.xml'),
             (u'почвоведению', 'agrobiologia.xml'),
             (u'правоведению', 'law.xml'),
             (u'психологии', 'psychology.xml'),
             (u'страноведению', 'geography.xml'),
             (u'физике', 'physics.xml'),
             (u'философии', 'philosophy.xml'),
             (u'химии', 'chemistry.xml'),
             (u'эстетике', 'estetica.xml'),
         ))
     random_blog = partial(get_rand, blogs)
     random_comment = lambda limit: Post.objects.all()[int(random() * limit)
                                                       ].title
     for counter in range(post_count):
         post = Post()
         post.author = random_user()
         post.blog = random_blog()
         post.title, post.text = obtain_spring(post.blog.description)
         post.rate = random_rate()
         post.rate_count = random_rate()
         post.save(edit=False, retry=True)
         post.set_tags(','.join(post.title.split()))
         last = root = post.create_comment_root()
         limit = int(random() * comment_limit)
         while limit:
             if not int(random() * 3):
                 last = root
             last = last.add_child(post=post,
                                   author=random_user(),
                                   text=random_comment(counter),
                                   created=datetime.now(),
                                   rate=random_rate(),
                                   rate_count=random_rate())
             limit -= 1