Example #1
0
File: views.py Project: yatna/macc
def change_pass_page(request):
    retval = check(request)
    if retval <> None:
        return retval
    return HttpResponse(
        jinja_environ.get_template('change_password.html').render(
            {"pcuser": request.user.pcuser}))
Example #2
0
File: views.py Project: yatna/macc
def post_new(request):
    #check for user login
    retval = check(request)
    if retval <> None:
        return retval
    owner = request.user.pcuser
    title_post = request.REQUEST['title']
    description_post = request.REQUEST['description']

    entry = Post(
        owner=owner,
        title_post=title_post,
        description_post=description_post,
    )
    entry.save()
    return HttpResponse(
        jinja_environ.get_template('notice.html').render({
            "pcuser":
            request.user.pcuser,
            "text":
            'Post created successfully.',
            "text1":
            'Click here to view post.',
            "link":
            '/view_post/?key=' + str(entry.id)
        }))
Example #3
0
def edit_post(request):
    retval = check(request)
    if retval <> None:
        return retval
    
    owner = request.user.pcuser
    postid = request.REQUEST['postid']
    postobj = None
    try:
        postobj = Post.objects.get(pk=postid)
    except Exception as e:
        return HttpResponse(e)
    
    title_post = request.REQUEST['title']
    description_post = request.REQUEST['description']
    
    
    postobj.title_post = title_post
    postobj.description_post = description_post
    
    postobj.save()
    
    postobj.owner.save()
    return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":request.user.pcuser,
                                                                          "text":'Post edited successfully.',"text1":'Click here to view post.', "link": '/view_post/?key=' + str(postobj.id)}))
Example #4
0
def change_pass(request):
    if "reset_pass" in request.REQUEST.keys():
        reset_pass = request.REQUEST['reset_pass']
        if reset_pass == "":
            return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":None,
                                                                                  "text":'<p>Invalid Request</p>', "text1":'<p>click here to go to the homepage</p>',"link":'/'}))
        user = Pcuser.objects.filter(reset_pass=reset_pass)
        if len(user)==0 or 'pass' not in request.REQUEST.keys():
            return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":None,
                                                                                  "text":'Invalid Request.',"text1":'Please go back or click here to go to the homepage',"link":'/'}))
        user = user[0].user
        user.set_password(request.REQUEST['pass'])
        user.save()
        user.pcuser.reset_pass = ""
        user.pcuser.save()
        logout(request)
        return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":None,
                                                                              "text":'Password Changed.',"text1":'Please click here to go to the homepage and log in again.',"link":'/logout_do/'}))
    else:
        retval = check(request)
        if retval <> None:
            return retval
        if "pass" not in request.REQUEST.keys() or "oldpass" not in request.REQUEST.keys():
            return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":request.user.pcuser,
                                                                                  "text":'Invalid Request.', "text1":'Please go back or click here to go to the homepage',"link":'/'}))
        if not request.user.check_password(request.REQUEST['oldpass']):
            return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":request.user.pcuser,
                                                                                  "text":'Invalid Old Password.',"text1":'Click here to go to the homepage',"link":'/'}))
        request.user.set_password(request.REQUEST['pass'])
        request.user.save()
        logout(request)
        return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":None,
                                                                              "text":'Password Changed.',"text1":'Please click here to go to the homepage and log in again.',"link":'/logout_do/'}))
Example #5
0
File: views.py Project: yatna/macc
def delete_post(request):
    retval = check(request)
    if retval <> None:
        return retval
    user = request.user

    postid = request.REQUEST['postid']

    postobj = None
    try:
        postobj = Post.objects.get(pk=postid)
    except Exception as e:
        return HttpResponse(e)

    postobj.delete()

    return HttpResponse(
        jinja_environ.get_template('notice.html').render({
            "pcuser":
            request.user.pcuser,
            "text":
            'Post Deleted successfully.',
            "text1":
            'Click here to go to home page.',
            "link":
            '/'
        }))
Example #6
0
def dashboard(request):
    
    retval = check(request)
    if retval <> None:
        return retval
    
    template_values = {'pcuser' : request.user.pcuser,
                    }
    return HttpResponse(jinja_environ.get_template('dashboard.html').render(template_values)) 
Example #7
0
File: views.py Project: yatna/macc
def post_form(request):
    retval = check(request)
    if retval <> None:
        return retval
    return HttpResponse(
        jinja_environ.get_template('newpost.html').render({
            "pcuser":
            request.user.pcuser,
            'owner':
            request.user.pcuser
        }))
Example #8
0
File: views.py Project: yatna/macc
def dashboard(request):

    retval = check(request)
    if retval <> None:
        return retval

    template_values = {
        'pcuser': request.user.pcuser,
    }
    return HttpResponse(
        jinja_environ.get_template('dashboard.html').render(template_values))
Example #9
0
def view_post(request):
    retval = check(request)
    if retval <> None:
        return retval

    try:
        pcuser=request.user.pcuser
        key=request.REQUEST['key']
        postobj=Post.objects.get(id=key)
        return HttpResponse(jinja_environ.get_template('viewpost.html').render({"pcuser":request.user.pcuser, 'post':postobj}))
    except Exception as e:
        return HttpResponse(e)
Example #10
0
def delete_post(request, post_id):

    retval = check(request)
    if retval is not None:
        return retval

    if request.method == 'POST':
        if delete_post_by_id(post_id):
            return HttpResponseRedirect(reverse('malaria:list_posts'))
        else:
            raise Http404
    else:
        return render(request,
                      'malaria/delete_post.html',
                      {'post_id': post_id})
Example #11
0
def view_post(request, post_id):

    retval = check(request)
    if retval is not None:
        return retval

    post = get_post_by_id(post_id)
    revpost = get_revpost_of_owner(post_id)
    # revpost may not exist yet so do not check it
    if post:
        return render(request,
                      'malaria/view_post.html',
                      {'post': post,
                       'revpost': revpost})
    else:
        raise Http404
Example #12
0
def post_new(request):
    #check for user login
    retval = check(request)
    if retval <> None:
        return retval
    owner = request.user.pcuser
    title_post = request.REQUEST['title']
    description_post = request.REQUEST['description']
    
    entry = Post(owner=owner, 
                 title_post=title_post,
                 description_post=description_post,
                 )
    entry.save()
    return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":request.user.pcuser,
                                                                          "text":'Post successful.',"text1":'Click here to go to home.',
                                                                          "link": '/'}))
Example #13
0
def delete_post(request):
    retval = check(request)
    if retval <> None:
        return retval
    user = request.user

    postid = request.REQUEST['postid']
        
    postobj = None
    try:
        postobj = Post.objects.get(pk=postid)
    except Exception as e:
        return HttpResponse(e)
    
    postobj.delete()

    return HttpResponse(jinja_environ.get_template('notice.html').render({"pcuser":request.user.pcuser,
                                                                          "text":'Post Deleted successfully.', "text1":'Click here to go to home page.',"link":'/'}))
Example #14
0
File: views.py Project: yatna/macc
def edit_post_page(request):
    retval = check(request)
    if retval <> None:
        return retval

    try:
        pcuser = request.user.pcuser
        key = request.REQUEST['key']
        postobj = Post.objects.get(id=key)
        return HttpResponse(
            jinja_environ.get_template('editpost.html').render({
                "pcuser":
                request.user.pcuser,
                'post':
                postobj
            }))
    except Exception as e:
        return HttpResponse(e)
Example #15
0
def create_post(request):

    # check if the user is logged in
    retval = check(request)
    if retval is not None:
        return retval

    form = PostForm()
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.owner = request.user.pcuser
            post.save()
            return render(request,
                          'malaria/notice.html',
                          {'text': 'Post created successfully.',
                           'text1': 'Click here to view post.',
                           'post': post})
    return render(request,
                  'malaria/create_post.html',
                  {'form': form})
Example #16
0
File: views.py Project: yatna/macc
def view_post(request):
    retval = check(request)
    if retval <> None:
        return retval

    try:
        pcuser = request.user.pcuser
        key = request.REQUEST['key']
        postobj = Post.objects.get(id=key)

        revpostobj = RevPost.objects.filter(owner_rev_post_id=key)

        return HttpResponse(
            jinja_environ.get_template('viewpost.html').render({
                "pcuser":
                request.user.pcuser,
                'post':
                postobj,
                'revpostobj':
                revpostobj
            }))
    except Exception as e:
        return HttpResponse(e)
Example #17
0
File: views.py Project: yatna/macc
def edit_post(request):
    retval = check(request)
    if retval <> None:
        return retval

    owner = request.user.pcuser
    postid = request.REQUEST['postid']
    postobj = None
    revpostobj = None
    try:
        postobj = Post.objects.get(pk=postid)
    except Exception as e:
        return HttpResponse(e)

    title_post = request.REQUEST['title']
    description_post = request.REQUEST['description']

    if postobj.title_post <> title_post:
        if postobj.description_post <> description_post:

            entry = RevPost(
                owner_rev=owner,
                owner_rev_post=postobj,
                title_post_rev=postobj.title_post,
                description_post_rev=postobj.description_post,
                title_change=True,
                description_change=True,
            )
            entry.save()

        else:

            entry = RevPost(
                owner_rev=owner,
                owner_rev_post=postobj,
                title_post_rev=postobj.title_post,
                description_post_rev=postobj.description_post,
                title_change=True,
                description_change=False,
            )
            entry.save()

    else:
        if postobj.description_post <> description_post:

            entry = RevPost(
                owner_rev=owner,
                owner_rev_post=postobj,
                title_post_rev=postobj.title_post,
                description_post_rev=postobj.description_post,
                title_change=False,
                description_change=True,
            )
            entry.save()

        else:

            entry = RevPost(
                owner_rev=owner,
                owner_rev_post=postobj,
                title_post_rev=postobj.title_post,
                description_post_rev=postobj.description_post,
                title_change=False,
                description_change=False,
            )
            entry.save()

    postobj.title_post = title_post
    postobj.description_post = description_post

    postobj.save()

    postobj.owner.save()
    return HttpResponse(
        jinja_environ.get_template('notice.html').render({
            "pcuser":
            request.user.pcuser,
            "text":
            'Post edited successfully.',
            "text1":
            'Click here to view post.',
            "link":
            '/view_post/?key=' + str(postobj.id)
        }))
Example #18
0
def change_pass_page(request):
    retval = check(request)
    if retval <> None:
        return retval
    return HttpResponse(jinja_environ.get_template('change_password.html').render({"pcuser":request.user.pcuser}))
Example #19
0
def post_form(request):
    retval = check(request)
    if retval <> None:
        return retval
    return HttpResponse(jinja_environ.get_template('newpost.html').render({"pcuser":request.user.pcuser, 'owner':request.user.pcuser}))
Example #20
0
def edit_post(request, post_id):

    retval = check(request)
    if retval is not None:
        return retval

    post = get_post_by_id(post_id)
    if post:
        if request.method == 'POST':

            # need to get the original title_post and description_post
            # before it is changed when calling instance on PostForm
            orig_title = post.title_post
            orig_desc = post.description_post
            form = PostForm(request.POST, instance=post)

            if form.is_valid():

                owner = request.user.pcuser
                edited_title = form.cleaned_data['title_post']
                edited_desc = form.cleaned_data['description_post']

                if (orig_title != edited_title) or \
                   (orig_desc != edited_desc):

                    post = form.save(commit=False)
                    post.owner = owner
                    post.save()

                    revpost_title_change = False
                    revpost_desc_change = False

                    if(orig_title != edited_title):
                        revpost_title_change = True
                    if(orig_desc != edited_desc):
                        revpost_desc_change = True

                    revpost = RevPost(owner_rev=owner,
                                      owner_rev_post=post,
                                      title_post_rev=orig_title,
                                      description_post_rev=orig_desc,
                                      title_change=revpost_title_change,
                                      description_change=revpost_desc_change)
                    revpost.save()

                    return render(request,
                                  'malaria/notice.html',
                                  {'text': 'Post edited successfully.',
                                   'text1': 'Click here to view post.',
                                   'post': post})
                else:
                    return render(request,
                                  'malaria/notice.html',
                                  {'text': 'No changes to Post made.',
                                   'text1': 'Click here to view post.',
                                   'post': post})
            else:
                return render(request,
                              'malaria/edit_post.html',
                              {'form': form, 'post': post})
        else:
            form = PostForm(instance=post)
            return render(request,
                          'malaria/edit_post.html',
                          {'form': form, 'post': post})
    else:
        raise Http404
Example #21
0
File: views.py Project: yatna/macc
def change_pass(request):
    if "reset_pass" in request.REQUEST.keys():
        reset_pass = request.REQUEST['reset_pass']
        if reset_pass == "":
            return HttpResponse(
                jinja_environ.get_template('notice.html').render({
                    "pcuser": None,
                    "text": '<p>Invalid Request</p>',
                    "text1": '<p>click here to go to the homepage</p>',
                    "link": '/'
                }))
        user = Pcuser.objects.filter(reset_pass=reset_pass)
        if len(user) == 0 or 'pass' not in request.REQUEST.keys():
            return HttpResponse(
                jinja_environ.get_template('notice.html').render({
                    "pcuser": None,
                    "text": 'Invalid Request.',
                    "text1":
                    'Please go back or click here to go to the homepage',
                    "link": '/'
                }))
        user = user[0].user
        user.set_password(request.REQUEST['pass'])
        user.save()
        user.pcuser.reset_pass = ""
        user.pcuser.save()
        logout(request)
        return HttpResponse(
            jinja_environ.get_template('notice.html').render({
                "pcuser":
                None,
                "text":
                'Password Changed.',
                "text1":
                'Please click here to go to the homepage and log in again.',
                "link":
                '/logout_do/'
            }))
    else:
        retval = check(request)
        if retval <> None:
            return retval
        if "pass" not in request.REQUEST.keys(
        ) or "oldpass" not in request.REQUEST.keys():
            return HttpResponse(
                jinja_environ.get_template('notice.html').render({
                    "pcuser":
                    request.user.pcuser,
                    "text":
                    'Invalid Request.',
                    "text1":
                    'Please go back or click here to go to the homepage',
                    "link":
                    '/'
                }))
        if not request.user.check_password(request.REQUEST['oldpass']):
            return HttpResponse(
                jinja_environ.get_template('notice.html').render({
                    "pcuser":
                    request.user.pcuser,
                    "text":
                    'Invalid Old Password.',
                    "text1":
                    'Click here to go to the homepage',
                    "link":
                    '/'
                }))
        request.user.set_password(request.REQUEST['pass'])
        request.user.save()
        logout(request)
        return HttpResponse(
            jinja_environ.get_template('notice.html').render({
                "pcuser":
                None,
                "text":
                'Password Changed.',
                "text1":
                'Please click here to go to the homepage and log in again.',
                "link":
                '/logout_do/'
            }))