Пример #1
0
def move_all_scrolls_to_basic(user, from_inventory):
    basic_inventory = Inventory.objects(owner=user.id,
                                        is_basic=True).first()
    sii_ls = ScrollInInventory.objects(inventory=from_inventory.id)
    for sii in sii_ls:
        sii.inventory = basic_inventory.to_dbref()
        sii.save()
Пример #2
0
def put_scroll_to_another_inventory(user,from_inv_id,
                                    scroll_id,to_inv_id):
    from_inv = Inventory.objects(owner=user.id,
                                 id=from_inv_id).first()
    to_inv = Inventory.objects(owner=user.id,
                               id=to_inv_id).first()
    scroll = Scroll.objects(owner=user.id,
                            id=scroll_id).first()
    if from_inv and to_inv and scroll:
           sii= for_inventory.move_scroll_between_inventories(scroll,
                                                              from_inv,to_inv)
           if sii:
               return "", 202
           else:
               return "", 404
    else:
        return "", 404
Пример #3
0
def get_post_inventory(user):
    if request.method == 'GET':
        return Inventory.objects(owner=user.id).to_json()

    if request.method == 'POST':
        name = request.json.get('name')
        res = for_inventory.create_inventory(user,name)
        return json.dumps(res)
Пример #4
0
def delete_inventory(user, inv):
    errors = []
    success = False
    inv = Inventory.objects(owner=user.id, id=id).first()
    if inv:
        if inv.is_basic:
            errors.append('You can not delete this inventory')
        else:
            move_all_scrolls_to_basic(user, inv)
            inv.delete()
            success = True
    else:
        errors.append("This inventory is not yours")

    return {'success': success, 'errors': errors}
Пример #5
0
def delete_inventory(user, inv):
    errors = []
    success = False
    inv = Inventory.objects(owner=user.id,
                            id = id).first()
    if inv:
        if inv.is_basic:
            errors.append('You can not delete this inventory')
        else:
            move_all_scrolls_to_basic(user,inv)
            inv.delete()
            success = True
    else:
        errors.append("This inventory is not yours")

    return {'success':success, 'errors':errors}
Пример #6
0
def get_scrolls_from_inventory(user,inventory_id):
    inv = Inventory.objects(id=inventory_id,
                            owner=user).first()
    if inv:
        sii_ls = ScrollInInventory.objects(inventory=inv.id)
        scrolls = []
        for sii in sii_ls:
           scroll_obj = Scroll.objects(id=sii.scroll.id).first()
           scroll = {'id': str(scroll_obj.id),
                     'is_finished': scroll_obj.is_finished,
                     'description': scroll_obj.description,
                     'name': scroll_obj.name}
           scrolls.append(scroll)

        return json.dumps(scrolls)
    else:
        return "", 404
Пример #7
0
def check_for_finished_scrolls():
    for scroll in Scroll.objects(is_finished=False):
        current_time = datetime.now()
        if scroll.end <= current_time:
            print('Scroll name ' + scroll.name)
            scroll.is_finished = True
            scroll.save()
            inv = Inventory.objects(owner=scroll.owner.id,
                                    is_basic=True).first()
            sii = ScrollInInventory()
            sii.scroll = scroll.to_dbref()
            sii.inventory = inv.to_dbref()
            sii.save()
            #inform user with node.js
            payload = {
                'user_id': str(scroll.owner.id),
                'scroll_name': scroll.name
            }
            requests.post(settings.WEBSOCKET_IP + '/scrolls/ready',
                          data=payload)
Пример #8
0
def move_all_scrolls_to_basic(user, from_inventory):
    basic_inventory = Inventory.objects(owner=user.id, is_basic=True).first()
    sii_ls = ScrollInInventory.objects(inventory=from_inventory.id)
    for sii in sii_ls:
        sii.inventory = basic_inventory.to_dbref()
        sii.save()