예제 #1
0
def apply(job_id):
    job = Job.query.filter_by(id=job_id).first_or_404()
    delivery = Delivery()
    delivery.delivery_company = job.job_company
    delivery.delivery_job = job.id
    delivery.delivery_user = current_user.id
    db.session.add(delivery)
    db.session.commit()
    return redirect(url_for('.detail', job_id=job_id))
예제 #2
0
파일: views.py 프로젝트: likaiguo/Book-1
def return_book(book_id):
    user_obj = User.objects(id=current_user.id).first()
    book_obj = BookInfo.objects(id=book_id).first()

    if user_obj in book_obj.user_borrowed:
        user_obj.update(pull__borrowed_book=book_obj)
        book_obj.update(inc__num=1, pull__user_borrowed=user_obj)
        flash(u'「{}」, 归还成功'.format(book_obj.title))
        Operation(type='return', user=user_obj, book_info=book_obj).save()
        Delivery.objects(user=user_obj, book=book_obj).update(set__return_time=datetime.now(), set__returned=True)
        return redirect('/')
    else:
        flash(u'非法操作')
        return redirect('/')
예제 #3
0
파일: views.py 프로젝트: likaiguo/Book-1
def profile_info():
    user_obj = User.objects.get(id=current_user.id)
    user_borrowed_books = user_obj.borrowed_book
    deliverys = Delivery.objects(user=user_obj)
    owned_books = BookInfo.objects(owner=user_obj)
    now = datetime.now()
    return render_template('profile.html', books=user_borrowed_books, owned_books=owned_books,
                           user=user_obj, deliverys=deliverys, now=now)
예제 #4
0
    def save_delivery(self, follow_up_object, girl, user):
        """
        The follow up and postnatal form have the same structure.
        Postnatal form will use this function directly while follow up will depend on
        whether the health worker selected 'delivery' as the action taken
        """
        print("action taken delivery")
        baby_birth_date = ""
        baby_death_date = ""
        mother_death_date = ""
        delivery_follow_up_group = follow_up_object["delivery_followup_group"][
            0]
        mother_alive = delivery_follow_up_group["mother_delivery_outcomes"][
            0] == "mother_alive"
        baby_alive = delivery_follow_up_group["baby_delivery_outcomes"][
            0] == "baby_alive"

        if baby_alive:
            baby_birth_date = delivery_follow_up_group["baby_birth_date"][0]
        else:
            baby_death_date = delivery_follow_up_group["baby_death_date"][0]
        if not mother_alive:
            mother_death_date = delivery_follow_up_group["mother_death_date"][
                0]

        birth_place = delivery_follow_up_group["birth_place"][0]
        if birth_place == "HealthFacility":
            birth_place = "Health facility"
        delivery_action_taken = replace_underscore(
            delivery_follow_up_group["action_taken"][0])
        used_contraceptives = "family" in delivery_action_taken
        try:
            contraceptive_group = follow_up_object["family_planning_group"][0]
            postnatal_care = contraceptive_group["postnatal_received"][
                0] == "yes"
        except Exception as e:
            print(e)
            postnatal_care = False
            contraceptive_group = []

        print('save delivery')
        delivery = Delivery(girl=girl,
                            user=user,
                            action_taken=delivery_action_taken,
                            postnatal_care=postnatal_care,
                            mother_alive=mother_alive,
                            baby_alive=baby_alive,
                            delivery_location=birth_place)

        if baby_birth_date:
            delivery.baby_birth_date = baby_birth_date
        else:
            delivery.baby_death_date = baby_death_date
        if mother_death_date:
            delivery.mother_death_date = mother_death_date
        delivery.save()

        if used_contraceptives:
            self.save_family_planning_methods_in_delivery(
                contraceptive_group, delivery)
예제 #5
0
파일: views.py 프로젝트: likaiguo/Book-1
def index():
    book_count = BookInfo.objects.count()
    books = BookInfo.objects.limit(page_limit)
    # user = User.objects.get(id=current_user.id)
    users = User.objects
    book_amount = amount_fake_aggregation.count_all()
    book_out = Delivery.objects(returned__ne=True).count()
    return render_template('index.html', books=books, user=current_user, all_books=books, users=users,
                           page=(book_count/page_limit)+2, current_page=1, book_amount=book_amount, book_out=book_out)
예제 #6
0
파일: views.py 프로젝트: likaiguo/Book-1
def index_page(n):
    # TODO: 分页实现的优化
    skip = (int(n)-1) * page_limit
    book_count = BookInfo.objects.count()
    books = BookInfo.objects.skip(skip).limit(page_limit)
    users = User.objects
    book_amount = amount_fake_aggregation.count_all()
    book_out = Delivery.objects(returned__ne=True).count()
    return render_template('index.html', books=books, user=current_user, all_books=books, users=users,
                           page=(book_count/page_limit)+2, current_page=int(n),
                           book_amount=book_amount, book_out=book_out)
예제 #7
0
def count_pop_book():
    # 统计最受欢迎的图书
    book_name = []
    count = []
    b_id = []
    for book in BookInfo.objects:
        book_name.append(book.title)
        count.append(Delivery.objects(book=book).count())
        b_id.append(book.id)
        result = zip(book_name, count, b_id)
        result_sorted = sorted(result, key=lambda x: x[1], reverse=True)
    return result_sorted
예제 #8
0
def count_borrowed():
    # 统计借过最多书的人
    name = []
    count = []
    u_id = []
    for user in User.objects:
        name.append(user.nickname)
        count.append(Delivery.objects(user=user).count())
        u_id.append(user.id)
    result = zip(name, count, u_id)
    result_sorted = sorted(result, key=lambda x: x[1], reverse=True)
    return result_sorted
예제 #9
0
def delivery():
    form = DeliveryForm()
    delivery = Delivery()
    if form.validate_on_submit():
        delivery.author = current_user
        delivery.courier = Courier.query.filter_by(name=form.courier.data).first()
        delivery.client = Client.query.filter_by(name=form.client.data).first()

        delivery.delivery_num = form.number.data
        delivery.delivery_cost = form.cost.data
        delivery.delivery_time = datetime.utcnow() + timedelta(hours=3)
        db.session.add(delivery)
        db.session.commit()
        return redirect(url_for('path_list'))
    return render_template('delivery.html', form=form, client_data=Client.query.all(), courier_data=Courier.query.all())
예제 #10
0
def index(category=''):
    category_dict = {
        'category': category
    }
    book_count = BookInfo.objects.count()
    if category:
        books = BookInfo.objects.filter(**category_dict)
    else:
        books = BookInfo.objects.limit(PAGE_LIMIT)
    users = User.objects
    book_amount = amount.count_all()
    book_out = Delivery.objects(returned__ne=True).count()
    return render_template('index.html', books=books, user=current_user, all_books=books,
                           users=users, page=(book_count/PAGE_LIMIT)+2, current_page=1,
                           book_amount=book_amount, book_out=book_out)
예제 #11
0
파일: views.py 프로젝트: likaiguo/Book-1
def user_info(id):
    user = User.objects(id=id).first()
    deliverys = Delivery.objects(user=user)
    owned_books = BookInfo.objects(owner=user)
    return render_template('profile_pub.html', user=user, deliverys=deliverys, owned_books=owned_books)
예제 #12
0
import openpyxl
from app.models import Delivery

wb = openpyxl.load_workbook('list.xlsx')

ws = wb.active

for r in ws.rows:
    name = r[0].value
    housetype = r[1].value
    news_type = r[2].value
    image = r[3].value
    etc = r[4].value
    item = Delivery(name=name,
                    housetype=housetype,
                    kind_of_news=news_type,
                    images=image,
                    etc=etc)
    item.save()
    print(item, 'saved')
예제 #13
0
def book_detail(book_id):
    book_obj = BookInfo.objects(id=book_id).first()
    delivers = Delivery.objects(book=book_obj)
    return render_template('detail.html', book=book_obj, delivers=delivers)
예제 #14
0
from app.models import Delivery, Driver

driver1 = Driver("John", "Smith")
driver1.insert()

driver2 = Driver("Karen", "Winters")
driver2.insert()

driver3 = Driver("Inez", "Watson")
driver3.insert()

driver4 = Driver("Mark", "Green")
driver4.insert()

delivery1 = Delivery("Softest White Bread")
delivery1.insert()

delivery2 = Delivery("2% Milk")
delivery2.insert()

delivery3 = Delivery("Eggs")
delivery3.insert()

delivery4 = Delivery("Sugar")
delivery4.insert()

delivery5 = Delivery("Brownies")
delivery5.insert()

예제 #15
0
def post_deliveries(jwt):
    req = request.get_json()
    description = req['description']
    new_delivery = Delivery(description)
    new_delivery.insert()
    return jsonify(new_delivery.format())