def get(self, request, *args, **kwargs): context = {} menu = Menu.objects.filter(kind=Menu.Kind.NEWS_LIST).first() page = kwargs['page'] if 'page' in kwargs else 1 on_page = Setting.get('on_page') context['header'] = 'Новости' context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['breadcrumbs'] = menu.get_breadcrumbs_dict() context['menus'] = Menu.get_dict() context['news'] = News.objects.filter().order_by( '-datetime')[(page - 1) * on_page:page * on_page] news_count = News.objects.all().count() pages_count = news_count // on_page + 1 context['pager'] = { 'prev': (page - 1) if page != 1 else None, 'next': (page + 1) if page != pages_count else None, 'page': page, 'pages': list(range(1, pages_count + 1)) } print(context['pager']) return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): page = Page.objects.get(slug=kwargs['slug']) page_images = PageImage.objects.filter(page=page) html = page.html.format( block_directions_p=Blocks.block_directions_p(), block_directions_table=Blocks.block_directions_table(), block_staff_table_deanery=Blocks.block_staff_table( [Staff.Category.DEANERY]), block_staff_table_council=Blocks.block_staff_table( [Staff.Category.COUNCIL]), **{ 'image_url_%s' % (page_image.slug): page_image.image.url for page_image in page_images }) context = {} context['header'] = page.name context['breadcrumbs'] = page.menu.get_breadcrumbs_dict() context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['menus'] = Menu.get_dict() context['page'] = page context['html'] = html if page.is_sidebar: context['sidebar'] = { 'header': page.sidebar_name if page.sidebar_name else None, 'objects': page.menu.childs } return render(request, self.template_name, context)
def resist_post(): pswd = hashlib.sha256(request.form['pswd'].encode("utf-8")).hexdigest() if (pswd == app.config['UPLOAD_PSWD']): enter_name = request.form['name'] enter_caption = request.form['caption'] enter_base = request.form['base'] enter_img = request.files['img'] if enter_img and allowed_file(enter_img.filename): img_path = os.path.join(app.config['UPLOAD_FOLDER'], enter_img.filename) enter_img.save(os.path.join("./main", img_path)) exist = Menu.query.filter_by( name=enter_name).count() #カクテルの名前が登録されているか確認する if exist == 0: #メニューに名前が登録されていなければ登録する print("NewMenu!!Welcome!") #インスタンス作成 new_menu = Menu(name=enter_name, path=img_path, caption=enter_caption, base=enter_base) db.session.add(new_menu) #追加 db.session.commit() #コミット msg = "登録しました。" else: msg = "既に存在するメニューです。" else: msg = "不正なファイルです。" else: msg = 'パスワードが違います。' return render_template('menu_resist.html', title="メニュー登録", message=msg)
def get(self, request, *args, **kwargs): translation.activate('ru') context = {} groups = ScheduleGroup.objects.all() context['groups'] = groups menu = Menu.objects.filter(kind=Menu.Kind.SCHEDULE).first() if 'slug' not in kwargs: context['is_list'] = True context['header'] = 'Расписание' context['breadcrumbs'] = menu.get_breadcrumbs_dict() else: context['is_list'] = False group = ScheduleGroup.objects.get(slug=kwargs['slug']) context['header'] = 'Расписание ' + group.name context['breadcrumbs'] = group.get_breadcrumbs_dict(menu) context['group'] = group context['webpush'] = {'group': 'all'} context['schedule'] = group.get_schedule_dict() menu = Menu.objects.filter(kind=Menu.Kind.CATHEDRA_ITEM).first() context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['menus'] = Menu.get_dict() return render(request, self.template_name, context)
def get(self, request): context = {} menu = Menu.objects.filter(kind=Menu.Kind.CATHEDRA_LIST).first() context['header'] = 'Кафедры' context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['breadcrumbs'] = menu.get_breadcrumbs_dict() context['menus'] = Menu.get_dict() context['cathedras'] = Cathedra.objects.all() return render(request, self.template_name, context)
def _get_context(self, request, *args, **kwargs): context = {} context['header'] = 'Заказ справок' context['breadcrumbs'] = Menu.objects.filter( kind=Menu.Kind.CERTIFICATES).first().get_breadcrumbs_dict() context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['menus'] = Menu.get_dict() return context
def get(self, request, *args, **kwargs): context = {} announcement = Announcement.objects.get(slug=kwargs['slug']) menu = Menu.objects.filter(kind=Menu.Kind.ANNOUNCEMENT_ITEM).first() context['header'] = announcement.name context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['breadcrumbs'] = menu.get_breadcrumbs_dict() context['menus'] = Menu.get_dict() context['announcement'] = announcement return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): context = {} news_item = News.objects.get(slug=kwargs['slug']) menu = Menu.objects.filter(kind=Menu.Kind.NEWS_ITEM).first() context['header'] = news_item.name context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['breadcrumbs'] = menu.get_breadcrumbs_dict() context['menus'] = Menu.get_dict() context['news_item'] = news_item return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): context = {} direction = Direction.objects.get(slug=kwargs['slug']) menu = Menu.objects.filter(kind=Menu.Kind.DIRECTION_ITEM).first() context['header'] = direction.name context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['breadcrumbs'] = direction.get_breadcrumbs_dict(menu) context['menus'] = Menu.get_dict() context['direction'] = direction context['html'] = direction.html return render(request, self.template_name, context)
def get(self, request, *args, **kwargs): context = {} staff = Staff.objects.get(slug=kwargs['slug']) menu = Menu.objects.filter(kind=Menu.Kind.CATHEDRA_ITEM).first() context['header'] = staff.name context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['breadcrumbs'] = staff.get_breadcrumbs_dict(menu) context['menus'] = Menu.get_dict() context['person'] = staff context['html'] = staff.html return render(request, self.template_name, context)
def get(self, request): context = {} # page = Page.objects.get(slug='index') # context['header'] = page.name # context['breadcrumbs'] = page.menu.get_breadcrumbs_dict() # context['page'] = page context['sitename'] = Setting.get('sitename') context['theme'] = css_theme(request) context['menus'] = Menu.get_dict() context['slider'] = News.objects.filter(is_slider=True).order_by('-datetime')[:3] context['news'] = News.objects.filter().order_by('-datetime')[:3] announcements = Announcement.objects.all().order_by('-datetime')[:4] context['announcement'] = announcements[0] context['announcements'] = announcements[1:4] return render(request, self.template_name, context)
def save_nav(request): label = request.REQUEST["label"] url = request.REQUEST["url"] order = request.REQUEST["order"] level = request.REQUEST["level"] pid = request.REQUEST["parent"] id = request.REQUEST["id"] parent = Menu.objects.get(pk=int(pid)) if pid != "-1" else None menu = Menu() if id == "-1" else Menu.objects.get(pk=int(id)) create = True if id == "-1" else False menu.label = label menu.url = url menu.order = order menu.level = 1 if parent is None else parent.level + 1 menu.parent = parent menu.save() obj = {"id": menu.pk, "create": create} return HttpResponse(json.dumps(obj))
def getMenus(rol): '''Retorna los menus asociados a un rol en especifico''' cursor = connection.cursor() cursor.callproc('bsp_get_menus_roles', [True, rol.pk_codigo]) menus = list() for row in cursor.fetchall(): menu = Menu() menu.pk_codigo = row[0] try: menu.fk_menu_codigo = Menu.objects.get(pk_codigo=row[1]) except: menu.fk_menu_codigo = None menu.ct_nombre = row[2] menu.cd_descripcion = row[3] menu.ct_url = row[5] menus.append(menu) return menus
def handle(self, *args, **options): restaurant_count = options["count"] # keep track of used names, streets etc. in the variables below, # so we can prevent duplicates names = [] streets = [] cities = [] # XXX factorize into smaller functions for item in range(restaurant_count): print "generate restaurant %d" % (item + 1) r = Restaurant() r.name = gen_unique_name(names, restaurant_names) r.save() print "generate address" a = Address(country=random.choice(_countries)) a.street = gen_unique_name(streets, street_names) a.street_no = random.randint(1, 100) a.zip = random.randint(1000, 100000) a.city = gen_unique_name(cities, city_names) a.restaurant = r a.save() count = random.randint(5, 25) print "generate %d tables" % count for i in range(1, 1 + count): t = Table() t.restaurant = r t.no = i t.save() print "add supported payment methods" for _ in range(2, len(_payment_methods)): method = random.choice(_payment_methods) if method not in r.payment_method.all(): r.payment_method.add(method) r.save() print "generate menu" m = Menu() m.currency = random.choice(_currencies) m.language = _languages[2] m.restaurant = r m.save() m.translations.add(_languages[0]) m.translations.add(_languages[1]) m.save() items = [] _cat_names = [] count = random.randint(3, 12) itemid = 1 print "generate %d categories" % count for j in range(1, 1 + count): c = Category() c.menu = m c.ordering = j c.view = random.choice(_views) c.save() count = random.randint(4, 20) # i18n stuff name = gen_unique_name(_cat_names, category_names) for lang in _languages: c18n = CategoryI18n() c18n.category = c c18n.language = lang c18n.name = name if lang.abbr != "en": c18n.name += "(%s)" % lang.abbr c18n.save() print "generate %d items" % count for _ in range(1, count): item = Item() item.no = itemid itemid += 1 item.category = c item.price = "%.2f" % random.uniform( 1, 110) # 2 decimal points item.save() item.image.save("item%d.jpg" % item.id, random.choice(_pictures), save=True) count = random.randint(0, 8) # "assign %d allergens" % count for k in range(count): a = random.choice(_allergens).allergen if a in ItemAllergen.objects.filter(item=item, allergen=a): continue traces = bool(random.randint(0, 1)) ItemAllergen.objects.get_or_create( item=item, allergen=a, traces=traces)[0].save() item.save() # i18n stuff name = gen_unique_name(items, food_names) for lang in _languages: i18n = ItemI18n() i18n.item = item i18n.language = lang i18n.name = name if lang.abbr != "en": i18n.name += "(%s)" % lang.abbr i18n.description = "Very delicious %s. It is made with love and all the care it is needed to make a great %s." % ( name, name) i18n.save() print self.stdout.write('Successfully added %d restaurants' % restaurant_count)