Пример #1
0
def deletetheme():
    try:
        Themes.objects(id=request.forms.get('id')).delete()
        save_path = os.path.join(os.getcwd(),'static','css', request.forms.get('name') + '.css')
        save_path = os.path.abspath(save_path)
        if os.path.exists(save_path):
            os.remove(save_path)
        return 'ok'
    except:
        return 'failed'
Пример #2
0
def deletetheme():
    try:
        Themes.objects(id=request.forms.get('id')).delete()
        save_path = os.path.join(os.getcwd(), 'static', 'css',
                                 request.forms.get('name') + '.css')
        save_path = os.path.abspath(save_path)
        if os.path.exists(save_path):
            os.remove(save_path)
        return 'ok'
    except:
        return 'failed'
Пример #3
0
def uploadtheme():
    file = request.files.get('newtheme')
    if file:
        name, ext = os.path.splitext(file.filename)
        if ext == '.css':
            try:
                save_path = os.path.join(os.getcwd(), 'static', 'css',
                                         file.filename)
                print(save_path)
                save_path = os.path.abspath(save_path)
                if os.path.exists(save_path):
                    os.remove(save_path)
                file.save(save_path)
                theme = None
                try:
                    theme = Themes.objects.get(title=name)
                except:
                    pass

                if not theme:
                    for t in Themes.objects():
                        t.isactive = False
                        t.save()
                    theme = Themes()
                    theme.title = name
                    theme.date = datetime.now()
                    theme.isactive = True
                    theme.save()

                themecount = Themes.objects().count()
                returned_themes = Themes.objects.order_by('-date').skip(
                    (int(1) - 1) * 10).limit(10)
                data = {
                    "themes": returned_themes,
                    "count": themecount,
                    "ceil": math.ceil(themecount / 10),
                    "currentPage": 1
                }
                return template('admin/views/themes.jinja2', data)
            except Exception as e:
                return template('admin/views/themes.jinja2',
                                {'errorMessage': str(e)})
        else:
            return template('admin/views/themes.jinja2',
                            {'errorMessage': 'file extension not allowed!'})
    else:
        return template('admin/views/themes.jinja2',
                        {'errorMessage': "couldn't save file"})
    return template('admin/views/themes.jinja2')
Пример #4
0
def uploadtheme():
    file = request.files.get('newtheme')
    if file:
        name, ext = os.path.splitext(file.filename)
        if ext == '.css':
            try:
                save_path = os.path.join(os.getcwd(),'static','css', file.filename)
                print(save_path)
                save_path = os.path.abspath(save_path)
                if os.path.exists(save_path):
                    os.remove(save_path)
                file.save(save_path)
                theme = None
                try:
                    theme = Themes.objects.get(title=name)
                except:
                    pass

                if not theme:
                    for t in Themes.objects():
                        t.isactive = False
                        t.save()
                    theme = Themes()
                    theme.title = name
                    theme.date = datetime.now()
                    theme.isactive = True
                    theme.save()

                themecount = Themes.objects().count()
                returned_themes = Themes.objects.order_by('-date').skip((int(1) - 1) * 10).limit(10)
                data = {
                    "themes": returned_themes,
                    "count": themecount,
                    "ceil": math.ceil(themecount / 10),
                    "currentPage": 1
                }
                return template('admin/views/themes.jinja2', data)
            except Exception as e:
                return template('admin/views/themes.jinja2', {'errorMessage': str(e)})
        else:
            return template('admin/views/themes.jinja2', {'errorMessage': 'file extension not allowed!'})
    else:
        return template('admin/views/themes.jinja2', {'errorMessage': "couldn't save file"})
    return template('admin/views/themes.jinja2')
Пример #5
0
def activatetheme():
    try:
        theme = Themes.objects.get(id=request.forms.get('id'))
        if theme and not theme.isactive:
            for t in Themes.objects():
                t.isactive = False
                t.save()
            theme.isactive = True
            theme.save()
        return 'ok'
    except Exception as e:
        print(str(e))
        return 'failed'
Пример #6
0
def activatetheme():
    try:
        theme = Themes.objects.get(id=request.forms.get('id'))
        if theme and not theme.isactive:
            for t in Themes.objects():
                t.isactive = False
                t.save()
            theme.isactive = True
            theme.save()
        return 'ok'
    except Exception as e:
        print(str(e))
        return 'failed'
Пример #7
0
def themes(page=1):
    try:
        returned_themes = Themes.objects.order_by('-date').skip((int(page) - 1) * 10).limit(10)
        themecount = Themes.objects().count()
        data = {
            "themes": returned_themes,
            "count": themecount,
            "ceil": math.ceil(themecount / 10),
            "currentPage": page
        }
    except:
        return template('admin/views/login.jinja2', {'errorMessage': 'DB error'})
    return template('admin/views/themes.jinja2', data)
Пример #8
0
def themes(page=1):
    try:
        returned_themes = Themes.objects.order_by('-date').skip(
            (int(page) - 1) * 10).limit(10)
        themecount = Themes.objects().count()
        data = {
            "themes": returned_themes,
            "count": themecount,
            "ceil": math.ceil(themecount / 10),
            "currentPage": page
        }
    except:
        return template('admin/views/login.jinja2',
                        {'errorMessage': 'DB error'})
    return template('admin/views/themes.jinja2', data)