コード例 #1
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def feed_new_category(request):
    if is_loggedin(request):
        if request.method == 'POST' or request.method == 'FILES':
            cat_form = new_category_form(request.POST, request.FILES)
            if cat_form.is_valid():
                data = {
                    'name': cat_form.cleaned_data['name'],
                    'cover_pic': cat_form.cleaned_data['cover_pic'],
                    'date_created': timezone.now(),
                    'url': slugify(cat_form.cleaned_data['name']),
                    'keywords': cat_form.cleaned_data['keywords'],
                    'description': cat_form.cleaned_data['description'],
                }
                n_c = Category(
                    name=data['name'],
                    cover_pic=data['cover_pic'],
                    date_created=data['date_created'],
                    url=data['url'],
                    keywords=data['keywords'],
                    description=data['description'],
                )
                n_c.save()
                return redirect('../categories/')
            else:
                msg = 'Form not cleaned. Page blog.views.py | Line 230'
                return render(request, 'debug.html', {'message': msg})
        else:
            msg = 'Invalid Access. Page blog.views.py | Line 233'
            return render(request, 'debug.html', {'message': msg})
    else:
        msg = 'Not logged in. Page blog.views.py | Line 236'
        return render(request, 'debug.html', {'message': msg})
コード例 #2
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def pages(request):
    if is_loggedin(request):
        page_list = all_pages()
        return render(request, 'blog/pages.html', {'page_list': page_list})
    else:
        msg = 'You`\re not logged in.'
        return render(request, 'debug.html', {'message': msg})
コード例 #3
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def navs(request):
    if is_loggedin(request):
        nav_links = all_navs()
        return render(request, 'blog/navs.html', {'nav_links': nav_links})
    else:
        msg = 'You`\re not logged in.'
        return render(request, 'debug.html', {'message': msg})
コード例 #4
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def foots(request):
    if is_loggedin(request):
        foot_list = all_foots()
        return render(request, 'blog/foots.html', {'foots': foot_list})
    else:
        msg = 'You`\re not logged in.'
        return render(request, 'debug.html', {'message': msg})
コード例 #5
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def edit_nav(request, nav_id):
    if request.method == 'POST' or request.method == 'FILES':
        # Validating the form
        nav_incoming_form = new_nav_form(request.POST)
        if nav_incoming_form.is_valid():
            # Etracting the data
            author = User.objects.get(login=request.session['username'])
            data = {
                'title': nav_incoming_form.cleaned_data['name'],
                'last_modified': timezone.now(),
                'url': nav_incoming_form.cleaned_data['url'],
            }
            n_n = Post.objects.get(pk=nav_id)
            n_n.title = data['title']
            n_n.last_modified = data['last_modified']
            n_n.url = data['url']
            n_n.save()
            return redirect('../../navs/')
    else:
        if is_loggedin(request):
            active = True
            nav = Post.objects.get(pk=nav_id)
            # Data to be filled into the form
            data_dict = {
                'name': nav.title,
                'url': nav.url,
            }
            # Filling up the data into the edit form
            edit_nav_form = new_nav_form(data_dict)
            return render(request, 'blog/edit_nav.html', {
                'active': active,
                'nav': nav,
                'edit_nav_form': edit_nav_form
            })
コード例 #6
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def posts(request, offset, limit):
    if is_loggedin(request):
        record_list = top_posts(offset, limit)
        return render(request, 'blog/posts.html', {'record_list': record_list})
    else:
        msg = 'You`\re not logged in.'
        return render(request, 'debug.html', {'message': msg})
コード例 #7
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def delete_nav(request, nav_id):
    if is_loggedin(request):
        nav = Post.objects.get(pk=nav_id)
        nav.delete()
        return redirect('../../navs/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 388'
        return render(request, 'debug.html', {'message': msg})
コード例 #8
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def delete_page(request, page_id):
    if is_loggedin(request):
        page = Post.objects.get(pk=page_id)
        page.delete()
        return redirect('../../pages/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 388'
        return render(request, 'debug.html', {'message': msg})
コード例 #9
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def del_category(request, category_id):
    if is_loggedin(request):
        category = Category.objects.get(pk=category_id)
        category.delete()
        return redirect('../../categories/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 388'
        return render(request, 'debug.html', {'message': msg})
コード例 #10
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def del_post(request, post_id):
    if is_loggedin(request):
        post = Post.objects.get(pk=post_id)
        post.delete()
        return redirect('../../posts/1/10/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 379'
        return render(request, 'debug.html', {'message': msg})
コード例 #11
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def delete_foot(request, foot_id):
    if is_loggedin(request):
        foot = Post.objects.get(pk=foot_id)
        foot.delete()
        return redirect('../../foots/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 388'
        return render(request, 'debug.html', {'message': msg})
コード例 #12
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def categories(request):
    if is_loggedin(request):
        category_list = all_categories()
        return render(request, 'blog/categories.html',
                      {'category_list': category_list})
    else:
        msg = 'You`\re not logged in.'
        return render(request, 'debug.html', {'message': msg})
コード例 #13
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def unpublish_nav(request, nav_id):
    if is_loggedin(request):
        nav = Post.objects.get(pk=nav_id)
        nav.unlisted = 1
        nav.save()
        return redirect('../../navs/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 449'
        return render(request, 'debug.html', {'message': msg})
コード例 #14
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def unpublish_foot(request, foot_id):
    if is_loggedin(request):
        foot = Post.objects.get(pk=foot_id)
        foot.unlisted = 1
        foot.save()
        return redirect('../../foots/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 449'
        return render(request, 'debug.html', {'message': msg})
コード例 #15
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def unpublish_category(request, category_id):
    if is_loggedin(request):
        category = Category.objects.get(pk=category_id)
        category.unlisted = 1
        category.save()
        return redirect('../../categories/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 461'
        return render(request, 'debug.html', {'message': msg})
コード例 #16
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def unpublish_page(request, page_id):
    if is_loggedin(request):
        page = Post.objects.get(pk=page_id)
        page.unlisted = 1
        page.save()
        return redirect('../../pages/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 449'
        return render(request, 'debug.html', {'message': msg})
コード例 #17
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def unpublish_post(request, post_id):
    if is_loggedin(request):
        post = Post.objects.get(pk=post_id)
        post.unlisted = 1
        post.save()
        return redirect('../../posts/1/10/')
    else:
        msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 451'
        return render(request, 'debug.html', {'message': msg})
コード例 #18
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def feed_new_page(request):
    if is_loggedin(request):
        if request.method == 'POST' or request.method == 'FILES':
            # Validating the form
            page_form = new_page_form(request.POST, request.FILES)
            if page_form.is_valid():
                # Extracting the data
                author = User.objects.get(login=request.session['username'])
                data = {
                    'title': page_form.cleaned_data['title'],
                    'cover_pic': page_form.cleaned_data['cover_pic'],
                    'content': page_form.cleaned_data['content'],
                    'author': author,
                    'pub_date': timezone.now(),
                    'view_count': 0,
                    'url': slugify(page_form.cleaned_data['title']),
                    'unlisted': 0,
                    'last_modified': timezone.now(),
                    'is_page': 1,
                    'in_nav': 0,
                    'in_footer': 0,
                    'keywords': page_form.cleaned_data['keywords'],
                    'description': page_form.cleaned_data['description'],
                    'social': 0,
                }
                # Instance of page
                n_p = Post(
                    title=data['title'],
                    cover_pic=data['cover_pic'],
                    content=data['content'],
                    author=data['author'],
                    pub_date=data['pub_date'],
                    view_count=data['view_count'],
                    url=data['url'],
                    unlisted=data['unlisted'],
                    last_modified=data['last_modified'],
                    is_page=data['is_page'],
                    in_nav=data['in_nav'],
                    in_footer=data['in_footer'],
                    keywords=data['keywords'],
                    description=data['description'],
                    social=data['social'],
                )
                n_p.save()
                return redirect('../pages/')
            else:
                msg = 'Form not cleaned. Page blog.views.py | Line 230'
                return render(request, 'debug.html', {'message': msg})
        else:
            msg = 'Invalid Access. Page blog.views.py | Line 233'
            return render(request, 'debug.html', {'message': msg})
    else:
        msg = 'Not logged in. Page blog.views.py | Line 236'
        return render(request, 'debug.html', {'message': msg})
コード例 #19
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def edit_post(request, cat, post_id, post_url):
    if request.method == 'POST' or request.method == 'FILES':
        # Validating the form
        post = xedit_post_form(request.POST)
        if post.is_valid():
            #Extracting the data
            author = User.objects.get(login=request.session['username'])
            data = {
                'title': post.cleaned_data['title'],
                'content': post.cleaned_data['content'],
                'url': slugify(post.cleaned_data['title']),
                'last_modified': timezone.now(),
                'keywords': post.cleaned_data['keywords'],
                'description': post.cleaned_data['description'],
                'category':
                Category.objects.get(pk=post.cleaned_data['category']),
            }
            # Instance of the Model Post
            n_p = Post.objects.get(pk=post_id)
            n_p.title = data['title']
            n_p.content = data['content']
            n_p.url = data['url']
            n_p.last_modified = data['last_modified']
            n_p.keywords = data['keywords']
            n_p.description = data['description']
            n_p.category = data['category']
            n_p.save()
            return redirect('../../../../posts/1/10/')
        else:
            msg = 'Form not cleaned. Page blog.views.py | Line 230'
            return render(request, 'debug.html', {'message': msg})
    else:
        if is_loggedin(request):
            active = True
            post = Post.objects.get(pk=post_id)
            # Data to be filled in the editing post form
            data_dict = {
                'title': post.title,
                'content': post.content,
                'keywords': post.keywords,
                'description': post.description,
                'category': post.category
            }
            # Filling up the data into the edit form
            edit_post_form = new_post_form(data_dict)
            return render(request, 'blog/edit_post.html', {
                'active': active,
                'post': post,
                'edit_post_form': edit_post_form
            })
        else:
            msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 379'
            return render(request, 'debug.html', {'message': msg})
コード例 #20
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def feed_new_nav(request):
    if is_loggedin(request):
        if request.method == 'POST':
            nav_form = new_nav_form(request.POST)
            if nav_form.is_valid():
                # Extracting Data
                author = User.objects.get(login=request.session['username'])
                data = {
                    'title': nav_form.cleaned_data['name'],
                    'content': '',
                    'author': author,
                    'pub_date': timezone.now(),
                    'view_count': 0,
                    'url': nav_form.cleaned_data['url'],
                    'unlisted': 0,
                    'last_modified': timezone.now(),
                    'is_page': 0,
                    'in_nav': 1,
                    'in_footer': 0,
                    'keywords': '',
                    'description': '',
                    'social': 0,
                }

                n_n = Post(
                    title=data['title'],
                    content=data['content'],
                    author=data['author'],
                    pub_date=data['pub_date'],
                    view_count=data['view_count'],
                    url=data['url'],
                    unlisted=data['unlisted'],
                    last_modified=data['last_modified'],
                    is_page=data['is_page'],
                    in_nav=data['in_nav'],
                    in_footer=data['in_footer'],
                    keywords=data['keywords'],
                    description=data['description'],
                    social=data['social'],
                )
                n_n.save()
                return redirect('../navs/')
            else:
                msg = 'Form not cleaned. Page blog.views.py | Line 175'
                return render(request, 'debug.html', {'message': msg})
        else:
            msg = 'Invalid Access. Page blog.views.py | Line 178'
            return render(request, 'debug.html', {'message': msg})
    else:
        msg = 'Not logged in. Page blog.views.py | Line 181'
        return render(request, 'debug.html', {'message': msg})
コード例 #21
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def add_foot(request):
    active = True
    if is_loggedin(request):
        return render(request, 'blog/new_foot.html', {
            'active': active,
            'new_foot_form': new_foot_form
        })
    else:
        active = False
        return render(
            request, 'blog/new_foot.html', {
                'message': 'You can\'t add post, you are not logged in',
                'active': active
            })
コード例 #22
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def edit_category(request, category_id, category_url):
    if request.method == 'POST' or request.method == 'FILES':
        # Validating the form
        category = xedit_category_form(request.POST)
        if category.is_valid():
            #Extracting the data
            author = User.objects.get(login=request.session['username'])
            data = {
                'name': category.cleaned_data['name'],
                'last_modified': timezone.now(),
                'url': slugify(category.cleaned_data['name']),
                'keywords': category.cleaned_data['keywords'],
                'description': category.cleaned_data['description'],
            }
            # Instance of the Model Post
            n_c = Category.objects.get(pk=category_id)
            n_c.name = data['name']
            n_c.last_modified = data['last_modified']
            n_c.keywords = data['keywords']
            n_c.url = data['url']
            n_c.description = data['description']
            n_c.save()
            return redirect('../../../categories/')
    else:
        if is_loggedin(request):
            active = True
            category = Category.objects.get(pk=category_id)
            # Data to be filled in the editing post form
            data_dict = {
                'name': category.name,
                'keywords': category.keywords,
                'description': category.description,
            }
            # Filling up the data into the edit form
            edit_category_form = new_category_form(data_dict)
            return render(
                request, 'blog/edit_category.html', {
                    'active': active,
                    'category': category,
                    'edit_category_form': edit_category_form
                })
        else:
            msg = 'Access Denied for non-admin user. Page: Blog.views.py Line: 379'
            return render(request, 'debug.html', {'message': msg})
コード例 #23
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def edit_page(request, page_id):
    if request.method == 'POST' or request.method == 'FILES':
        # Validating the form
        page_incoming_form = xedit_page_form(request.POST)
        if page_incoming_form.is_valid():
            # Etracting the data
            author = User.objects.get(login=request.session['username'])
            data = {
                'title': page_incoming_form.cleaned_data['title'],
                'content': page_incoming_form.cleaned_data['content'],
                'keywords': page_incoming_form.cleaned_data['keywords'],
                'description': page_incoming_form.cleaned_data['description'],
                'last_modified': timezone.now(),
                'url': slugify(page_incoming_form.cleaned_data['title']),
            }
            n_p = Post.objects.get(pk=page_id)
            n_p.title = data['title']
            n_p.content = data['content']
            n_p.keywords = data['keywords']
            n_p.descriptipn = data['description']
            n_p.last_modified = data['last_modified']
            n_p.url = data['url']
            n_p.save()
            return redirect('../../pages/')
    else:
        if is_loggedin(request):
            active = True
            page = Post.objects.get(pk=page_id)
            # Data to be filled into the form
            data_dict = {
                'title': page.title,
                'content': page.content,
                'keywords': page.keywords,
                'description': page.description,
            }
            # Filling up the data into the edit form
            edit_page_form = new_page_form(data_dict)
            return render(request, 'blog/edit_page.html', {
                'active': active,
                'page': page,
                'edit_page_form': edit_page_form
            })
コード例 #24
0
ファイル: views.py プロジェクト: vee-varun/Sulphur
def edit_foot(request, foot_id):
    if request.method == 'POST' or request.method == 'FILES':
        # Validating the form
        foot_incoming_form = new_foot_form(request.POST)
        if foot_incoming_form.is_valid():
            # Etracting the data
            author = User.objects.get(login=request.session['username'])
            data = {
                'title': foot_incoming_form.cleaned_data['title'],
                'last_modified': timezone.now(),
                'content': foot_incoming_form.cleaned_data['content'],
                'url': foot_incoming_form.cleaned_data['url'],
            }
            n_f = Post.objects.get(pk=foot_id)
            n_f.title = data['title']
            n_f.content = data['content']
            n_f.last_modified = data['last_modified']
            n_f.url = data['url']
            n_f.save()
            return redirect('../../foots/')
    else:
        if is_loggedin(request):
            active = True
            foot = Post.objects.get(pk=foot_id)
            # Data to be filled into the form
            data_dict = {
                'title': foot.title,
                'content': foot.content,
                'url': foot.url,
            }
            # Filling up the data into the edit form
            edit_foot_form = new_foot_form(data_dict)
            return render(request, 'blog/edit_foot.html', {
                'active': active,
                'foot': foot,
                'edit_foot_form': edit_foot_form
            })
コード例 #25
0
ファイル: views.py プロジェクト: sirajalam049/sulphur
def dashboard(request):
    if authentication.is_loggedin(request):
        return render(request, 'sadmin/dashboard.html')
    else:
        return redirect('../')
コード例 #26
0
ファイル: views.py プロジェクト: sirajalam049/sulphur
def sadmin(request):
    if authentication.is_loggedin(request):
        return redirect('dashboard/')
    else:
        return render(request, 'sadmin/login.html', {'loginform': loginform})
コード例 #27
0
ファイル: views.py プロジェクト: sirajalam049/sulphur
def login(request):
    # Checking if the user is already loggedin
    if authentication.is_loggedin(request):
        return redirect('../dashboard/')
    else:
        # Validating the login form came from login.html
        logindetails = loginform(request.POST)

        if logindetails.is_valid():
            # Extracting the data from login form
            data = {
                'username': logindetails.cleaned_data['username'],
                'password': logindetails.cleaned_data['password'],
            }
            data['password'] = sha256(
                data['password'].encode('utf-8')).hexdigest()

            # Getting the record by username
            try:
                u = User.objects.get(login=data['username'])
            # sending to login if it is wrong
            except User.DoesNotExist:
                return render(request, 'sadmin/login.html', {
                    'loginform': loginform,
                    'message': 'Username is incorrect',
                })

            if u.password == data['password']:
                # logging in
                request.session['active'] = True

                # Adding the current logged in data into the session
                request.session['id'] = u.id
                request.session['username'] = u.login
                request.session['full_name'] = u.full_name
                request.session['gender'] = u.gender
                request.session['email'] = u.email

                request.session['reg_date_year'] = u.reg_date.year
                request.session['reg_date_month'] = u.reg_date.month
                request.session['reg_date_day'] = u.reg_date.day
                request.session['reg_date_hour'] = u.reg_date.hour
                request.session['reg_date_minute'] = u.reg_date.minute
                request.session['reg_date_second'] = u.reg_date.second

                request.session['display_name'] = u.display_name

                request.session['last_modified_year'] = u.last_modified.year
                request.session['last_modified_month'] = u.last_modified.month
                request.session['last_modified_day'] = u.last_modified.day
                request.session['last_modified_hour'] = u.last_modified.hour
                request.session[
                    'last_modified_minute'] = u.last_modified.minute
                request.session[
                    'last_modified_second'] = u.last_modified.second

                request.session['user_pic'] = u.user_pic

                return redirect('/sadmin/')
            else:
                return render(request, 'sadmin/login.html', {
                    'loginform': loginform,
                    'message': 'Password is incorrect'
                })
        else:
            return render(
                request, 'sadmin/login.html', {
                    'loginform': loginform,
                    'message': 'Form is not valid [sadmin.views.py Line: 57]'
                })