Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
5d5e2334
Commit
5d5e2334
authored
Dec 20, 2013
by
Jean Michel Rouly
Browse files
Parse URL registration form.
parent
9aa64644
Changes
1
Hide whitespace changes
Inline
Side-by-side
go/go/views.py
View file @
5d5e2334
from
go.models
import
URL
from
go.forms
import
URLForm
from
datetime
import
timedelta
from
django.http
import
Http404
from
django.utils
import
timezone
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
django.contrib.auth.decorators
import
login_required
from
django.shortcuts
import
render
,
get_object_or_404
,
redirect
# Homepage view.
@
login_required
def
index
(
request
):
return
render
(
request
,
'index.html'
,
{
url_form
=
URLForm
()
# unbound form
errors
=
[]
if
request
.
method
==
'POST'
:
url_form
=
URLForm
(
request
.
POST
)
# bind dat form
if
url_form
.
is_valid
():
url
=
url_form
.
save
(
commit
=
False
)
url
.
owner
=
request
.
user
expires
=
url_form
.
cleaned_data
[
'expires'
]
if
expires
==
URLForm
.
DAY
:
url
.
expires
=
timezone
.
now
()
+
timedelta
(
days
=
1
)
elif
expires
==
URLForm
.
WEEK
:
url
.
expires
=
timezone
.
now
()
+
timedelta
(
weeks
=
1
)
elif
expires
==
URLForm
.
MONTH
:
url
.
expires
=
timezone
.
now
()
+
timedelta
(
weeks
=
3
)
else
:
pass
# leave the field NULL
url
.
full_clean
()
url
.
save
()
return
redirect
(
'success'
,
url
.
target
,
url
.
short
)
return
render
(
request
,
'index.html'
,
{
'form'
:
url_form
,
},
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment