Exemplo n.º 1
0
    def get_by_answer_user(cls,
                           user, type, search_query=None,
                           page_no=DEFAULT_PAGE_NO,
                           page_size=DEFAULT_PAGE_SIZE,
                           get_total_number=False):

        start = (page_no - 1) * page_size
        end = page_no * page_size

        if search_query:
            objects = cls.repo.search(search_query,
                                      q_dict={
                                          'answer': 'icontains',
                                      })
        else:
            objects = cls.repo.read()  # 分页

        if type != 'all':
            objects = RequestAnswer.objects(
                user_request__in=UserRequest.objects(type=type))
        objects = objects(answer_user=user)
        if get_total_number:
            number_of_objects = objects.count()
            return objects.order_by('-create_time')[start:end], number_of_objects
        else:
            return objects.order_by('-create_time')[start:end]
Exemplo n.º 2
0
 def add_user_request(cls, title, **kwargs):
     now = datetime.utcnow()
     user_request = UserRequest(title=title, create_time=now, **kwargs)
     return user_request.save()
Exemplo n.º 3
0
from server3.entity.project import *
from server3.entity.user import User
from server3.entity.data import Data
from server3.entity.ownership import Ownership
from server3.entity.user_request import UserRequest
from server3.entity.comments import Comments
from server3.entity.request_answer import RequestAnswer
from server3.entity.api import Api
from server3.entity.statistics import Statistics

# ——————————————————————————————————————————————————————— external delete rules
#                                            Defined here to avoid import loops
Project.register_delete_rule(Job, 'project', CASCADE)
DataSet.register_delete_rule(File, 'data_set', CASCADE)
File.register_delete_rule(DataSet, 'file', NULLIFY)
UserRequest.register_delete_rule(User, 'request_star', PULL)

# 删除 user
User.register_delete_rule(App, 'star_users', PULL)
User.register_delete_rule(App, 'favor_users', PULL)
User.register_delete_rule(Module, 'star_users', PULL)
User.register_delete_rule(Module, 'favor_users', PULL)
User.register_delete_rule(Dataset, 'star_users', PULL)
User.register_delete_rule(Dataset, 'favor_users', PULL)
User.register_delete_rule(UserRequest, 'star_user', PULL)
User.register_delete_rule(UserRequest, 'votes_up_user', PULL)

# 删除 job
Job.register_delete_rule(App, 'jobs', PULL)
Job.register_delete_rule(Module, 'jobs', PULL)
Job.register_delete_rule(Dataset, 'jobs', PULL)
Exemplo n.º 4
0
def add_user_request(title, **kwargs):
    now = datetime.utcnow()
    user_request_obj = UserRequest(title=title, create_time=now, **kwargs)
    return user_request_repo.create(user_request_obj)