Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
ae6d3056
Commit
ae6d3056
authored
Oct 23, 2014
by
Administrator
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEATURE] Ajout rapide de projet
parent
09127513
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
17 deletions
+68
-17
urls.py
gargantext_web/urls.py
+7
-2
views.py
gargantext_web/views.py
+41
-13
admin.py
node/admin.py
+5
-1
projects.html
templates/projects.html
+15
-1
No files found.
gargantext_web/urls.py
View file @
ae6d3056
...
...
@@ -3,7 +3,7 @@ from django.conf.urls import patterns, include, url
from
django.contrib
import
admin
from
gargantext_web.views
import
home
,
projects
,
project
,
corpus
from
gargantext_web.views
import
add_corpus
from
gargantext_web.views
import
add_corpus
,
add_project
admin
.
autodiscover
()
...
...
@@ -16,9 +16,14 @@ urlpatterns = patterns('',
url
(
r'^grappelli/'
,
include
(
'grappelli.urls'
)),
# grappelli URLS
url
(
r'^$'
,
home
),
url
(
r'^add/corpus/$'
,
add_corpus
),
url
(
r'^projects/$'
,
projects
),
url
(
r'^projects/add/$'
,
add_project
),
url
(
r'^project/(\d+)/$'
,
project
),
url
(
r'^project/(\d+)/add/$'
,
add_corpus
),
url
(
r'^add/corpus/$'
,
add_corpus
),
# removed soon
url
(
r'^project/(\d+)/corpus/(\d+)/$'
,
corpus
),
)
...
...
gargantext_web/views.py
View file @
ae6d3056
...
...
@@ -6,7 +6,7 @@ from django.template.loader import get_template
from
django.template
import
Context
#from documents.models import Project, Corpus, Document
from
node.models
import
Node
,
NodeType
from
node.models
import
Node
,
NodeType
,
Project
from
django.contrib.auth.models
import
User
...
...
@@ -84,18 +84,26 @@ def projects(request):
user
=
request
.
user
date
=
datetime
.
datetime
.
now
()
project
=
NodeType
.
objects
.
get
(
name
=
'Project'
)
projects
=
Node
.
objects
.
filter
(
user
=
user
,
type_id
=
project
.
id
)
.
order_by
(
"-date"
)
project
_type
=
NodeType
.
objects
.
get
(
name
=
'Project'
)
projects
=
Node
.
objects
.
filter
(
user
=
user
,
type_id
=
project
_type
.
id
)
.
order_by
(
"-date"
)
number
=
len
(
projects
)
if
request
.
method
==
'POST'
:
# form = ProjectForm(request.POST)
# TODO : protect from sql injection here
name
=
str
(
request
.
POST
[
'name'
])
if
name
!=
""
:
Project
(
name
=
name
,
type
=
project_type
,
user
=
user
)
.
save
()
return
HttpResponseRedirect
(
'/projects/'
)
else
:
form
=
ProjectForm
()
html
=
t
.
render
(
Context
({
\
'user'
:
user
,
\
'date'
:
date
,
\
'projects'
:
projects
,
\
'number'
:
number
,
\
}))
return
HttpResponse
(
html
)
return
render
(
request
,
'projects.html'
,
{
'date'
:
date
,
'form'
:
form
,
'number'
:
number
,
'projects'
:
projects
})
def
project
(
request
,
project_id
):
if
not
request
.
user
.
is_authenticated
():
...
...
@@ -231,7 +239,7 @@ def corpus(request, project_id, corpus_id):
return
HttpResponse
(
html
)
from
node.admin
import
CorpusForm
from
node.admin
import
CorpusForm
,
ProjectForm
class
NameForm
(
forms
.
Form
):
your_name
=
forms
.
CharField
(
label
=
'Your name'
,
max_length
=
100
)
...
...
@@ -242,7 +250,7 @@ class NameForm(forms.Form):
def
add_corpus
(
request
):
# if this is a POST request we need to process the form data
#print(request.method)
#
print(request.method)
if
request
.
method
==
'POST'
:
# create a form instance and populate it with data from the request:
form
=
CorpusForm
(
request
.
POST
,
request
.
FILES
)
...
...
@@ -275,3 +283,23 @@ def add_corpus(request):
return
render
(
request
,
'add_corpus.html'
,
{
'form'
:
form
})
def
add_project
(
request
):
if
request
.
method
==
'POST'
:
print
(
request
.
POST
)
#request.POST['user'] = request.user
form
=
ProjectForm
(
request
.
POST
)
print
(
form
)
if
form
.
is_valid
():
node
=
form
.
save
()
return
HttpResponseRedirect
(
'/projects/'
)
else
:
form
=
ProjectForm
()
return
render
(
request
,
'add_project.html'
,
{
'form'
:
form
})
node/admin.py
View file @
ae6d3056
...
...
@@ -75,9 +75,13 @@ class ProjectAdmin(NodeAdmin):
from
django.db.models.query
import
EmptyQuerySet
class
ProjectForm
(
ModelForm
):
class
Meta
:
model
=
Project
exclude
=
[
'ngrams'
,
'metadata'
,
'resource'
,
'parent'
,
'user'
,
'type'
,
'language'
,
'date'
]
class
CorpusForm
(
ModelForm
):
#parent = ModelChoiceField(EmptyQuerySet)
def
__init__
(
self
,
*
args
,
**
kwargs
):
try
:
self
.
request
=
kwargs
.
pop
(
'request'
,
None
)
...
...
templates/projects.html
View file @
ae6d3056
...
...
@@ -13,9 +13,23 @@
<div
class=
"container theme-showcase"
role=
"main"
>
<div
class=
"jumbotron"
>
<div
class=
"row"
>
<div
class=
"col-md-3"
>
<h1>
My {{number}} projects
</h1>
<p>
Template showing my working space
</p>
<a
class=
"btn btn-primary btn-lg"
role=
"button"
href=
"/admin/node/project/add/"
>
Add a project
</a>
<div
class=
"col-md-4"
></div>
<div
class=
"col-md-4"
></div>
<div
class=
"col-md-4"
>
<form
enctype=
"multipart/form-data"
action=
"/projects/"
method=
"post"
>
{% csrf_token %}
{{ form.non_field_errors }}
{{ form.as_p}}
<input
type=
"submit"
value=
"Add project"
/>
</form>
</div>
</div>
</div>
</div>
</div>
...
...
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