def handle(self, *args, **options): print('Start loading...') Page.objects.all().delete() Slider.objects.all().delete() Gallery.objects.all().delete() # главная path = os.path.join(BASE_DIR, '..', 'data', 'index.txt') with open(path, 'r') as f: txt = f.read() print(txt) p = Page() p.title = 'О нас' p.content = txt p.alias = 'home' p.save() # расписание path = os.path.join(BASE_DIR, '..', 'data', 'schedule.txt') with open(path, 'r') as f: txt = f.read() print(txt) p = Page() p.title = 'Расписание' p.content = txt p.alias = 'schedule' p.save() # импорт картинок слайдера for i in range(1, 5): img = '%s.jpg' % i img_abspath = os.path.join(BASE_DIR, '..', 'data', img) print('Importing... %s' % img_abspath) s = Slider() s.title = img s.desc = 'Description of %s' % img s.save() with open(img_abspath, 'rb') as doc_file: s.image.save(img, File(doc_file), save=True) # импорт галереи for i in range(1, 22): img = '%s.jpg' % i img_abspath = os.path.join(BASE_DIR, '..', 'data', 'gallery', img) g = Gallery() g.title = img g.save() with open(img_abspath, 'rb') as doc_file: g.image.save(img, File(doc_file), save=True)
def handle(self, *args, **kwargs): print('Loading data into database....') try: p = Page.objects.get(name_slug='index') except: p = Page() p.name_slug = 'index' p.title = 'Welcome to the WEZOM support desktop!' p.content = 'You can send your message here.' p.save() print('Creating main page!') try: u = User.objects.get(username='******') except: u = User() u.username = '******' u.is_active = True u.is_superuser = True u.is_staff = True u.save() u.set_password('admin') u.save() print('Creating superuser login admin password admin.') load_cat()
def handle(self, *args, **options): print('loading pages....') Page.objects.all().delete() p = Page() p.title = "Main page" p.alias = "main" p.content = "Content" p.save() p = Page() p.title = "Contact page" p.content = "Content" p.alias = "contact" p.save() p = Page() p.title = "Shop page" p.alias = "shop" p.content = "Content" p.save()
def handle(self, *args, **options): print 'Start' Page.objects.all().delete() p = Page() p.title = 'логин admin пароль 123' p.content = 'Conteentttt ttttt t tt ' p.alias = 'main' p.meta_keywords = 'main' p.meta_description = 'main' p.meta_title = 'main' p.save() print 'Page main was created'
def add_page(request): """Page with a form for creating an article.""" if no_access(request, 'pages'): return HttpResponseRedirect(reverse('no_access')) grp = get_info(request) error = '' p = { 'url': '', 'title': '', 'text': '', 'pic': '', 'date': '', 'paragraphs': [], 'access': '', 'status': '', 'order': '', 'tags': '' } if request.method == 'POST': try: url = request.POST['url'] title = request.POST['title'] pic = request.POST['pic'] order = int(request.POST['order']) access = request.POST['access'] status = request.POST['status'] text = request.POST['text'] tags = request.POST['tags'] p['url'] = url p['title'] = title p['text'] = text p['pic'] = pic p['access'] = access p['status'] = status p['order'] = order p['tags'] = tags parags = [] taglist = [x.strip() for x in tags.split(',')] i = 1 while 'section_title_' + str(i) in request.POST: parags.append({ 'title': request.POST['section_title_' + str(i)], 'text': request.POST['section_text_' + str(i)], 'order': i }) i += 1 p['paragraphs'] = parags if title == '': raise Exception('Enter page title.') if url == '': raise Exception('Enter page URL') if order < 0: raise Exception('Order must be a positive number.') if len(Page.objects.filter(order=order)) > 0: raise Exception('Order number must be unique') for par in parags: if par['title'] == '': raise Exception('Sections must have titles') except Exception as ex: error = ex else: pag = Page(title=title, url=url, pic=pic, order=order, access=access, status=status, text=text, add_date=datetime.now().date(), added_by=request.user.username) pag.save() for tag in taglist: if len(Tag.objects.filter(name=tag)) == 1: pag.tags.add(Tag.objects.get(name=tag)) else: tg = Tag(name=tag) tg.save() pag.tags.add(tg) pag.save() for parag in parags: paragraph = Paragraph(title=parag['title'], text=parag['text'], order=parag['order'], page=pag) paragraph.save() return HttpResponseRedirect(reverse('admin_pages')) template = loader.get_template('main/admin_edit_page.html') context = RequestContext(request, { 'page': p, 'error_message': error, 'edit': 'no', 'group': grp }) return HttpResponse(template.render(context))