1 # BC CMS - Content Management System
2 # Copyright (c) 2008, Carlos Daniel Ruvalcaba Valenzuela
5 # Redistribution and use in source and binary forms, with or without modification,
6 # are permitted provided that the following conditions are met:
8 # * Redistributions of source code must retain the above copyright notice, this
9 # list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright notice, this
11 # list of conditions and the following disclaimer in the documentation and/or other
12 # materials provided with the distribution.
13 # * Neither the name of the BlackChair Software nor the names of its contributors may be
14 # used to endorse or promote products derived from this software without specific prior
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 # FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
24 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 from django
.http
import HttpResponse
, HttpResponseRedirect
29 from django
.contrib
.auth
import authenticate
, login
, logout
30 from django
import newforms
as forms
31 from django
.conf
import settings
33 from bcms
.template
import template_django
as template
37 def logmeout(request
):
39 if request
.GET
.has_key('redir'):
40 return HttpResponseRedirect(request
.GET
['redir'])
41 return HttpResponseRedirect("/")
44 if request
.method
== 'POST':
45 username
= request
.POST
['username']
46 passwd
= request
.POST
['passwd']
47 user
= authenticate(username
=username
, password
=passwd
)
50 if request
.GET
.has_key('redir'):
51 return HttpResponseRedirect(request
.GET
['redir'])
52 return HttpResponseRedirect("/")
54 msg
= "Username or password incorrect, please try again."
57 template
= loader
.load('login.html')
59 # Parse and execute the template with given variables
60 stream
= template
.generate(msg
=msg
, user
=request
.user
)
62 # Return rendered template as HTML
63 return HttpResponse(stream
.render('html', doctype
='html'))
65 @template('edit.html')
66 def editPage(request
, lang
, pagename
):
67 if request
.method
== 'POST':
68 title
= request
.POST
['title']
69 contents
= request
.POST
['contents']
70 print (title
, contents
)
72 pg
= Page
.objects
.filter(name__iexact
= pagename
, lang__iexact
= lang
)[0]
74 pg
= Page(name
=pagename
, lang
=lang
, published
=datetime
.datetime
.now())
76 p
= pg
.pagerevision_set
.create(title
=title
, contents
=contents
, author
=0, published
=datetime
.datetime
.now())
78 return HttpResponseRedirect("/%s/%s" % (lang
, pagename
))
81 pg
= Page
.objects
.get(name__iexact
= pagename
, lang__iexact
= lang
)
82 view
= pg
.pagerevision_set
.order_by("-published")[0]
83 contents
= view
.contents
89 ptitle
= 'Editing: ' + pagename
90 args
= dict(contents
=contents
, title
=title
, ptitle
=ptitle
,
91 pagename
=pagename
, user
=request
.user
)
94 @template('view.html')
95 def viewPage(request
, lang
, pagename
):
99 pg
= Page
.objects
.filter(name__iexact
= pagename
, lang__iexact
= lang
)[0]
100 view
= pg
.pagerevision_set
.order_by("-published")[0]
102 return HttpResponse("Requested page (%s) not Found!" % pagename
)
104 args
= dict(title
= view
.title
, contents
= view
.contents
,
105 pagename
= pg
.name
, lang
= lang
)