Exemple #1
0
def update_view(request, Version):
    mess = ''
    Upda = False
    boo, update_, yum = init(Version)
    latest_version = update_['latest_version']
    releases = update_['releases']
    VersionDict = releases[latest_version]
    url = VersionDict['release_url']

    if request.user.is_authenticated():
        username = request.user.username
        pers = user_admin(str(username))

    if boo:
        mess = '发现可用新版本。'
        Upda = True
    else:
        mess = '已更新至最新版本。'
        Upda = False

    dic = {
        "username": str(username),  # 用户名称
        "admin": pers,  # 超级管理员
        "boo": boo,
        "mess": mess,
        "yum": yum,
        "update": update_,
        "Version": Version,
        "latest_version": VersionDict
    }

    return render(request, 'home/update.html', dic), latest_version, url, Upda
Exemple #2
0
def create(request):
    if request.method == 'GET':
        auth_logins = False
        username = None
        pers = None

        if request.user.is_authenticated():
            username = request.user.username
            pers = user_admin(str(username))
            auth_logins = True

        from app.utli.datetimenow import datetime_unix
        a_tid_unix = "%s" % str(datetime_unix())

        content = {
            'auth_login': auth_logins,
            'username': str(username),  # 用户名称
            'admin': pers,  # 超级管理员
            'unix': a_tid_unix,
        }

        return render(request, 'home/editors.html', content)

    if request.method == 'POST':
        comment_title = request.POST.get('title', '')
        comment_content = request.POST.get('content', '')
        comment_unix = request.GET.get('unix')
        username = request.user.username
        comment_title = xss(comment_title)

        if comment_title and comment_content:

            from app.models import App_Blog
            from django.contrib.auth.models import User
            from app.utli.datetimenow import datetime_ymd
            a_time = datetime_ymd()
            user = User.objects.get(username=username)

            App_Blog(
                title=comment_title,
                content=comment_content,
                time_add=a_time,
                time_now=a_time,
                username=user,
                tid_unix=comment_unix
            ).save()

            return HttpResponseRedirect('/')

        dic = {
            'title': comment_title,
            'content': comment_content,
            'err': u'不能为空'
        }

        return render(request, 'home/editors.html', dic)
Exemple #3
0
def app_edit_get(request, tid, unix):
    tid_con = models.App_Blog.objects.get(id=tid)
    tid_user = tid_con.username
    username = request.user.username

    if str(tid_user) == str(username) or user_admin(str(username)):
        title = tid_con.title
        content = tid_con.content
        print('content', unix)

        dic = {'tid': tid, 'title': title, 'content': content, 'unix': unix}
        return dic
Exemple #4
0
def delete(request, tid):
    if request.method == 'GET':
        unix = request.GET.get('unix')

        path = ROOT + '/static/upload'
        tid_con = models.App_Blog.objects.get(id=tid)
        tid_user = tid_con.username
        username = request.user.username

        if str(tid_user) == str(username) or user_admin(str(username)):
            from app.utli.rm import rm
            rm(path, unix)
            tid_con.delete()

        return HttpResponseRedirect('/')
Exemple #5
0
def info(request):
    from account.permiss import auth_permissions
    pers = None
    username = None
    auth_logins = False

    if request.user.is_authenticated():
        username = request.user.username
        pers = auth_permissions.user_admin(str(username))
        auth_logins = True

    content = {
        'auth_login': auth_logins,
        'username': str(username),  # 用户名称
        'admin': pers,  # 超级管理员
    }

    return render(request, 'error/403.html', content)
Exemple #6
0
def updates(request):
    if request.method == 'GET':
        global number
        global auth_install
        number = 0
        auth_install = False

        from account.permiss.auth_permissions import user_admin
        from update.utli.wget import set_update
        set_update()

        per = user_admin(request.user.username)

        global latest_version
        global release_url
        global version

        data = UTCS()
        time = "%s-%s-%s %s:%s:%s" % (
            data.year, data.month, data.day,
            data.hour, data.minute, data.second)

        ver = update.objects.all().values('version')

        if not ver:
            update(version=version, time=time).save()
            ver = update.objects.all().values('version')
            pass

        version = ver[0]['version']

        rend, latest_version, release_url, upda = update_view(request, version)
        if upda:
            auth_update = True
        else:
            auth_update = False
            pass

        latest_version = latest_version
        release_url = release_url
        print('latest_version', latest_version, 'release_url', release_url)
        return rend
Exemple #7
0
def user_home(request):
    cont = models.App_GET_Text_all()
    len_blog = 0
    # content_dict = {}
    value_dict = {}
    # conlist_dict = {}
    value = []
    # contents_dicts = {}

    time_date = '2018-01-01 00:00:00'

    if request.method == 'GET':
        if request.user.is_authenticated():
            username = request.user.username
            pers = user_admin(str(username))
            auth_logins = True

        else:
            username = '******'
            pers = None
            auth_logins = False

    Inits = 0

    for i in cont:
        ids = i.id
        data = datetimenow.datetimenow(i.time_now)
        mark = markdown.markdown(i.content)
        __, number = datetimenow.DateTimes(str(data).split('.')[0])

        if int(Inits) == int(number):
            value.append({
                "title": i.title,
                "content": mark,
                "username": str(i.username),
                "time_now": str(data).split('.')[0],
                "id": ids
            })

            time_date = str(data).split('.')[0]
            # log.d('value.append', 'Add')

        else:
            if time_date != '2018-01-01 00:00:00' and value:
                # log.d('value_dict', 'Add')
                value_dict[str(Inits)] = {
                    'time': time_date,
                    'contents_dicts': value
                }

            if int(Inits) == 0:
                len_blog = len(value)

            value = []
            Inits = int(number)

    if len(value) > 1:
        if time_date != '2018-01-01 00:00:00' and value:
            # log.d('len(value)', len(value))
            value_dict[str(Inits)] = {
                'time': time_date,
                'contents_dicts': value
            }

        value = []
        Inits = int(number)

    content = {
        'auth_login': auth_logins,
        'username': str(username),  # 用户名称
        'admin': pers,  # 超级管理员
        'len_blog': len_blog,
        'value_dict': value_dict  # 文章等等
    }

    return render(request, 'home/home.html', content)
Exemple #8
0
def index(request):
    pers = None
    username = None
    auth_logins = False
    cont = models.App_GET_Text_all()

    Inits = 0
    value = []
    len_blog = 0
    time_date = '2018-01-01 00:00:00'
    value_dict = {}

    if request.user.is_authenticated():
        username = request.user.username
        pers = user_admin(str(username))
        auth_logins = True

    for i in cont:
        ids = i.id
        data = datetimenow.datetimenow(i.time_now)
        mark = markdown.markdown(i.content)
        __, number = datetimenow.DateTimes(str(data).split('.')[0])

        if int(Inits) == int(number):
            tid_user = False

            tid_con = models.App_Blog.objects.get(id=ids)
            usern = tid_con.username

            if str(usern) == str(username) or pers:
                tid_user = True

            from app.utli.xss import xss
            comment_title = xss(i.title)
            # comment_content = xss(comment_content=mark)

            comment_content = mark

            value.append({
                "title": comment_title,
                "content": comment_content,
                "username": str(i.username),
                "time_now": str(data).split('.')[0],
                "id": ids,
                "tid_user": tid_user,
                "unix": i.tid_unix,
            })

            time_date = str(data).split('.')[0]
            # log.d('value.append', 'Add')

        else:

            if int(Inits) == 0:
                len_blog = len(value)

            if time_date != '2018-01-01 00:00:00' and value:
                # log.d('value_dict', 'Add')
                value_dict[str(Inits)] = {
                    'time': time_date,
                    'contents_dicts': value
                }

            value = []
            Inits = int(number)

    if len(value) > 0:
        if time_date != '2018-01-01 00:00:00' and value:
            value_dict[str(Inits)] = {
                'time': time_date,
                'contents_dicts': value
            }

        # print('len_blog', len_blog)
        if int(Inits) == 0:
            len_blog = len(value)

        value = []
        Inits = int(number)

    content = {
        'auth_login': auth_logins,
        'username': str(username),  # 用户名称
        'admin': pers,  # 超级管理员
        'len_blog': len_blog,
        'value_dict': value_dict  # 文章等等
    }

    return content