Example #1
0
 async def post(self, request):
     body = request.json
     recharge = Recharge()
     recharge.phoneNumber = body.get('phoneNumber')
     if not recharge.phoneNumber.isdigit():
         raise BadRequestException('Invalid phone number')
     if not ObjectId.is_valid(body.get('companyId')):
         raise BadRequestException('Invalid Company Id')
     if not Company.objects.with_id(body.get('companyId')):
         raise BadRequestException('Company not found')
     recharge.companyId = ObjectId(body.get('companyId'))
     company = Company.objects(
         id=ObjectId(recharge.companyId),
         products__match={'id': ObjectId(body.get('productId'))})
     if len(company) == 0:
         raise BadRequestException(
             'This company does not have this product')
     recharge.productId = body.get('productId')
     recharge.value = body.get('value')
     recharge.createdAt = str(datetime.now())
     try:
         recharge.validate()
     except ValidationError as e:
         raise BadRequestException(e.to_dict())
     recharge.save()
     return json(Recharge.buildOne(recharge), status=HTTPStatus.CREATED)
Example #2
0
def student_rankings(student_id):
    applications = Application.objects(student_id=ObjectId(student_id))
    applications = map(lambda a: a.to_dict(), applications)

    for application in applications:
        job = Job.objects(id=ObjectId(application['job_id']))[0]
        application['job'] = job.to_dict()

    print applications

    return render_template('student_rankings.html',
                           student_id=student_id,
                           applications=applications)
Example #3
0
class VoteModel(DynamicDocument):
    author = StringField()
    voter = StringField()
    comment = ObjectId()
    last_update = DateTimeField()
    num_changes = IntField()
    permlink = StringField()
    rshares = IntField()
    vote_percent = IntField()
    weight = FloatField()

    meta = {
        'collection': 'comment_vote_object',
        'indexes': [
            'author',
            'voter',
            'comment',
            'permlink',
            'parent_permlink',
            'last_update'
        ],

        'auto_create_index': True,
        'index_background': True
    }
Example #4
0
class Article(Document):
    meta = {'collection': 'article'}
    id = ObjectId()
    text = StringField(required=True)
    textstate = IntField()
    username=StringField(required=True)
    comments = ListField(StringField())
    state = ListField(IntField())
Example #5
0
def employer_view_student_resume(student_id):
    students = Student.objects(id=ObjectId(student_id))
    student = None
    for student in students:
        student_info = student.to_dict()
    if student is None:
        return "Not found", 404

    return render_template('student_resume.html',
                           student_info=student_info,
                           student_id=student_id,
                           view=True)
Example #6
0
def employer_rankings(employer_id):
    rankings_array = []
    jobs = Job.objects(employer_id=ObjectId(employer_id))
    for job in jobs:
        applications = map(lambda a: a.to_dict(),
                           Application.objects(job_id=job.id))
        job_dict = job.to_dict()
        job_dict['applications'] = applications
        rankings_array.append(job_dict)

    print rankings_array

    return render_template('employer_rankings.html',
                           employer_id=employer_id,
                           rankings_array=rankings_array)
Example #7
0
    def delete(self, user_info: User, recipe_id='', ingredient_id=''):
        recipe = _retrieve_base_recipe(recipe_id, str(user_info.id))

        if recipe.ingredients != None and len(recipe.ingredients) == 1:
            raise BadRequest('no ingredients to delete for this recipe')

        ingredient_id = ObjectId(ingredient_id)

        recipe.ingredients = [
            recipe_ingredient for recipe_ingredient in recipe.ingredients
            if recipe_ingredient.ingredient.id != ingredient_id
        ]

        recipe.save()

        return "", 204
Example #8
0
 def to_internal_value(self, data):
     return ObjectId(data)
Example #9
0
 def clean(self):
     if not self.id:
         self.id = ObjectId()
     self.update_time = datetime.now()
     if not self.create_time:
         self.create_time = datetime.now()
Example #10
0
class CommentModel(DynamicDocument):
    abs_rshares = IntField()
    active = DateTimeField()
    allow_curation_rewards = BooleanField()
    allow_replies = BooleanField()
    allow_votes = BooleanField()
    active_votes = DictField()
    author = StringField()
    author_rewards = IntField()
    beneficiary_payout_symbol = StringField()
    beneficiary_payout_value = FloatField()
    body = StringField()
    cashout_time = DateTimeField()
    category = StringField()
    children = IntField()  # TODO сделать вывод количества всех комментариев
    children_abs_rshares = IntField()
    children_rshares2 = IntField()
    created = DateTimeField()
    curator_payout_symbol = StringField()
    curator_payout_value = FloatField()
    depth = IntField()
    json_metadata = DictField()
    last_payout = DateTimeField()
    last_update = DateTimeField()
    max_accepted_payout_symbol = StringField()
    max_accepted_payout_value = FloatField()
    max_cashout_time = DateTimeField()
    mode = StringField()
    net_rshares = IntField()
    net_votes = IntField()
    parent_author = StringField()
    parent_permlink = StringField()
    percent_steem_dollars = IntField()
    permlink = StringField()
    removed = BooleanField()
    reward_weight = IntField()
    root_comment = ObjectId()
    title = StringField()
    total_payout_symbol = StringField()
    total_payout_value = FloatField()
    total_vote_weight = IntField()
    vote_rshares = IntField()

    meta = {
        'collection':
        'comment_object',
        'ordering': ['-created'],
        'indexes': [
            'author',
            'permlink',
            'created',
            'category',
            'depth',
            'root_comment',
            'parent_permlink',
            'parent_author',
            'mode',
            'json_metadata.app',
            'json_metadata.tags',
        ],
        'auto_create_index':
        True,
        'index_background':
        True
    }
 def to_internal_value(self, data):
     try:
         return ObjectId(smart_str(data))
     except Exception as e:
         raise serializers.ValidationError(e.message)
Example #12
0
class PostModel(DynamicDocument):
    url = StringField()
    abs_rshares = IntField()
    active = DateTimeField()
    allow_curation_rewards = BooleanField()
    allow_replies = BooleanField()
    allow_votes = BooleanField()
    active_votes = DictField()
    author = StringField()
    author_rewards = IntField()
    body = StringField()
    cashout_time = DateTimeField()
    category = StringField()
    children = IntField()  # TODO сделать вывод количества всех комментариев
    children_abs_rshares = IntField()
    children_rshares2 = IntField()
    created = DateTimeField()
    curator_payout_symbol = StringField()
    curator_payout_value = DictField()
    depth = IntField()
    json_metadata = DictField()
    last_payout = DateTimeField()
    last_update = DateTimeField()
    max_accepted_payout_symbol = StringField()
    max_accepted_payout_value = FloatField()
    max_cashout_time = DateTimeField()
    mode = StringField()
    net_rshares = IntField()
    net_votes = IntField()
    parent_author = StringField()
    parent_permlink = StringField()
    percent_steem_dollars = IntField()
    permlink = StringField()
    removed = BooleanField()
    reward_weight = IntField()
    root_comment = ObjectId()
    title = StringField()
    total_payout_symbol = StringField()
    total_payout_value = FloatField()
    total_vote_weight = IntField()
    vote_rshares = IntField()
    author_reputation = IntField()
    beneficiaries = ListField(DictField())
    body_length = IntField()
    community = StringField()
    identifier = StringField()
    max_accepted_payout = DictField()
    patched = BooleanField()
    pending_payout_value = DictField()
    promoted = DictField()
    reblogged_by = ListField(StringField())
    replies = ListField(StringField())  # TODO StringField?
    root_author = StringField()
    root_identifier = StringField()
    root_permlink = StringField()
    root_title = StringField()
    tags = ListField(StringField())
    total_payout_value = DictField()
    total_pending_payout_value = DictField()
    total_vote_weight = IntField()
    vote_rshares = IntField()

    meta = {
        'ordering': ['-created'],

        'indexes': [
            'author',
            'permlink',
            'created',
            'category',
            'json_metadata.location',
            'depth',
            'root_comment',
            'parent_permlink',
            'parent_author',
            'mode',
        ],

        'auto_create_index': True,
        'index_background': True
    }