示例#1
0
def public_user_profile(request, profile_user):
    state = State()
    user_summary = get_public_user_class()(profile_user)
    state.add(user_summary)
    return state.to_response({
        "userId": profile_user.id,
    })
示例#2
0
文件: views.py 项目: dbribe/DemoANPR
def documentation(request):
    state = State()

    documentation_entries = DocumentationEntry.objects.all().prefetch_related("article")
    for entry in documentation_entries:
        state.add(entry)
        state.add(entry.article)

    return state.to_response({"documentationEntryId": 1})
示例#3
0
文件: stream.py 项目: dbribe/DemoANPR
 def view_func(request):
     ids = int_list(request.GET.getlist("ids[]"))
     if len(ids) > max_ids:
         # TODO: log this, may need to ban some asshole
         from establishment.errors.errors import BaseError
         return BaseError.TOO_MANY_OBJECTS
     state = State(request)
     for obj in cls.objects.get(id__in=ids):
         if not permission_filter or permission_filter(obj):
             state.add(obj)
     return state
示例#4
0
文件: views.py 项目: dbribe/DemoANPR
def get_blogpost(request):
    try:
        blog_post = BlogEntry.objects.get(url_name=str(request.GET["entryUrlName"]))
        if not blog_post.visible and not request.user.is_superuser:
            return BaseError.NOT_ALLOWED
    except ObjectDoesNotExist:
        return BaseError.OBJECT_NOT_FOUND
    state = State()
    state.add(blog_post)
    state.add(blog_post.article)
    return state
示例#5
0
文件: views.py 项目: dbribe/DemoANPR
def get_article_state(article):
    article_edits = ArticleEdit.objects.filter(article=article)

    state = State()
    state.add(article)
    state.add_all(article_edits)

    # TODO: Language should be loaded in PublicState
    from establishment.content.models import Language
    state.add_all(Language.objects.all())
    return state
示例#6
0
文件: views.py 项目: dbribe/DemoANPR
def latest_forum_state():
    state = State()

    forum_threads = ForumThread.objects.filter(hidden=False)\
                                       .order_by("-message_thread__last_activity")\
                                       .prefetch_related("message_thread", "parent", "content", "content__reaction_collection")[:5]

    for forum_thread in forum_threads:
        state.add(forum_thread)
        state.add(forum_thread.parent)

    return state
示例#7
0
文件: views.py 项目: dbribe/DemoANPR
def fetch_article(request):
    article_ids = request.GET.getlist("ids[]")
    article_ids = [int(x) for x in article_ids]
    if len(article_ids) > 128:
        return ContentError.REQUESTED_TOO_MANY_ARTICLES
    articles = Article.objects.filter(id__in=article_ids)

    state = State()

    for article in articles:
        if article.is_available_to(request.user):
            state.add(article)

    return state.to_response()
示例#8
0
def change_user_group(request):
    group_id = int(request.POST["groupId"])
    group = UserGroup.get_group_by_id(group_id)
    if not request.user.is_superuser and group.owner_id != request.user.id:
        return BaseError.NOT_ALLOWED

    state = State()
    user_id = int(request.POST["userId"])
    action = request.POST["action"]
    if action == "remove":
        UserGroupMember.objects.filter(user_id=user_id,
                                       group_id=group_id).delete()
    elif action == "add":
        group_member, created = UserGroupMember.objects.get_or_create(
            user_id=user_id, group_id=group_id)
        state.add(group_member)
    return state
示例#9
0
def private_chat_post(request):
    if not request.user.is_superuser:
        # TODO: this needs multiple throttlers
        user_run_throttler = UserActionThrottler(request.user, "post-message",
                                                 60, 60)
        if not user_run_throttler.increm():
            return ChatError.MESSAGE_LIMIT_EXCEEDED

    private_chat_id = int(request.POST["privateChatId"])
    content = request.POST["message"]

    try:
        private_chat = PrivateChat.objects.get(id=private_chat_id)
    except Exception as e:
        # TODO: log this
        return BaseError.OBJECT_NOT_FOUND

    can_post, error = private_chat.can_post(request.user, content)
    if not can_post:
        # TODO: log this
        return error

    message_instance, json_response = private_chat.create_message_from_request(
        request)

    state = State()
    state.add(private_chat)
    state.add(private_chat.message_thread)
    state.add(message_instance)

    private_chat.user_posted(request.user, message_instance)

    private_chat.publish_event("privateMessage", {},
                               extra={
                                   "messageId": message_instance.id,
                                   "privateChatId": private_chat.id,
                                   "state": state
                               },
                               stream_names=private_chat.get_user_streams())

    return json_response