コード例 #1
0
ファイル: db.py プロジェクト: albertmatyi/motelferdinand
def populate():

    for cat in CategoryModel.all():
        # this will cascade on all contents / bookables and their translations
        cat.delete()
        pass
    titles = ['About', 'Location',
              'Rooms', 'Guestbook']
              #, 'Restaurants', 'Sightseeing',
    #'Partners', 'Documents', 'About']

    catidx = 0
    gallAdded = False
    for title in titles:
        cm = CategoryModel(order=catidx, visible=True, parent_category=None)
        desc = lambda: get_random_text(Random().randint(100, 300)).replace('\n', '<br/>')
        cm.i18n = {'en': {'title': title, 'description': desc()},
                   'ro': {'title': title + 'ro', 'description': desc()},
                   'hu': {'title': title + 'hu', 'description': desc()}}
        key = cm.put()

        # add bookables
        if title is 'Rooms':
            init_bookables(key)

        # add random number of contents
        for i in range(0, Random().randint(2, 5)):
            init_contents(key, i, not gallAdded)
            gallAdded = True
        catidx += 1
        pass
    pass
コード例 #2
0
def home():
    lang_id = si18n.get_lang_id()
    is_admin = users.is_current_user_admin()

    qry = CategoryModel.all().filter("parent_category", None)
    if not is_admin:
        qry = qry.filter("visible", True)

    categories = [e.to_dict() for e in qry]
    prod = "Development" not in os.environ["SERVER_SOFTWARE"]
    return render_template(
        "/main.html",
        js_data={
            "categories": categories,
            "languages": prop.get_languages(),
            "currency": currency.get_data(),
            "language": lang_id,
            "bookings": [],
            "si18n": si18n.translations_js,
            "is_admin": is_admin,
            "new_bookings_nr": BookingModel.get_number_of_new() if is_admin else 0,
        },
        is_admin=is_admin,
        is_production=prod,
        logout_url=users.create_logout_url("/"),
    )
    pass
コード例 #3
0
 def populate_field(self, dictionary, key):
     if key is 'category':
         self.category = CategoryModel.get_by_id(long(dictionary[key]))
     elif key is 'prices':
         self.validate_prices_for(
             int(dictionary['places']),
             dictionary['prices'])
         self.prices = json.dumps(dictionary[key])
     else:
         super(BookableModel, self).populate_field(dictionary, key)
     pass
コード例 #4
0
def admin_move_bookable(entityId):
    bookable = BookableModel.get_by_id(entityId)
    jsd = request_helper.get_json_data()
    bookable.category = CategoryModel.get_by_id(long(jsd['category_id']))
    bookable.put()
    return json.dumps(bookable.to_dict())
コード例 #5
0
ファイル: content.py プロジェクト: albertmatyi/motelferdinand
def admin_move_content(entityId):
    content = ContentModel.get_by_id(entityId)
    jsd = request_helper.get_json_data()
    content.category = CategoryModel.get_by_id(long(jsd['category_id']))
    content.put()
    return json.dumps(content.to_dict())
コード例 #6
0
ファイル: content.py プロジェクト: albertmatyi/motelferdinand
 def populate_field(self, dictionary, key):
     if key is 'category':
         self.category = CategoryModel.get_by_id(long(dictionary[key]))
     else:
         super(ContentModel, self).populate_field(dictionary, key)
コード例 #7
0
def admin_delete_category(entityId):
    if request.method == "DELETE" or request.values["_method"] == "DELETE":
        CategoryModel.get_by_id(entityId).delete()
        return '{ "value" : "OK" }'