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 update_from_archive(self, archive, obj): old_pks = list(Page.objects.filter(book=obj).values_list("id", flat=True)) archive = ZipFile(archive) toc = archive.read("toc.py") toc = toc.replace("(", "[").replace(")", "]").replace("'", '"') obj.toc = toc obj.save() pics = [name for name in archive.namelist() if name.startswith("pics/") and not name == "pics/"] archive.extractall(settings.MEDIA_ROOT, pics) appendix_pattern = re.compile(r"^ap(?P<section>[a-z])\.html$") ch_pattern = re.compile(r"^ch(?P<ch>\d+)\.html$") chs_pattern = re.compile(r"^ch(?P<ch>\d+)s(?P<s>\d+)\.html$") for filename in archive.namelist(): if not filename.split(".")[-1] == "html": continue slug = filename[:-5] try: page = Page.objects.get(slug=slug, book=obj) old_pks.remove(page.pk) except Page.DoesNotExist: page = Page(slug=slug, book=obj) # create name if page is new if filename == "index.html": name = u"Первая страница" elif chs_pattern.match(filename): r = chs_pattern.match(filename) name = u"Глава %s, раздел %s" % (int(r.group("ch")), int(r.group("s"))) page.chapter = r.group("ch") page.section = r.group("s") elif ch_pattern.match(filename): r = ch_pattern.match(filename) name = u"Глава %s" % int(r.group("ch")) page.chapter = r.group("ch") elif appendix_pattern.match(filename): r = appendix_pattern.match(filename) name = u"Приложение %s" % r.group("section").upper() page.chapter = u"ap" page.section = r.group("section") else: name = filename page.name = name page.content = archive.read(filename) page.save() Page.objects.filter(pk__in=old_pks).delete() archive.close()
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 save_page(request): title = request.REQUEST["title"] url = request.REQUEST["url"] keywords = request.REQUEST["keywords"] desc = request.REQUEST["desc"] content = request.REQUEST["content"] template = request.REQUEST["template"] id = request.REQUEST["id"] page = Page() if id == "-1" else Page.objects.get(pk=int(id)) logging.info("save") if page: page.title = title page.url = url page.keywords = keywords page.desc = desc page.content = content page.template = template page.save() return HttpResponse("{}")