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
6239e326
Commit
6239e326
authored
Jan 20, 2015
by
Administrator
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'samuel' into unstable
parents
87ff5323
6d6ccfa1
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
222 additions
and
101 deletions
+222
-101
urls.py
gargantext_web/urls.py
+1
-1
views.py
gargantext_web/views.py
+163
-69
admin.py
node/admin.py
+43
-6
models.py
node/models.py
+0
-25
formexample.html
templates/tests/formexample.html
+15
-0
No files found.
gargantext_web/urls.py
View file @
6239e326
...
...
@@ -63,7 +63,7 @@ urlpatterns = patterns('',
url
(
r'^ngrams$'
,
views
.
ngrams
),
url
(
r'^nodeinfo/(\d+)$'
,
views
.
nodeinfo
),
url
(
r'^tests/mvc$'
,
views
.
tests_mvc
),
url
(
r'^tests/mvc-listdocuments$'
,
views
.
tests_mvc_listdocuments
)
,
url
(
r'^tests/mvc-listdocuments$'
,
views
.
tests_mvc_listdocuments
)
)
...
...
gargantext_web/views.py
View file @
6239e326
This diff is collapsed.
Click to expand it.
node/admin.py
View file @
6239e326
...
...
@@ -92,6 +92,49 @@ class ResourceForm(ModelForm):
model
=
Resource
exclude
=
[
'user'
,
'guid'
,
'digest'
]
# for formexample.html
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
class
CustomForm
(
forms
.
Form
):
name
=
forms
.
CharField
(
label
=
'Name'
,
max_length
=
199
,
required
=
True
)
parsing_options
=
ResourceType
.
objects
.
all
()
.
values_list
(
'id'
,
'name'
)
type
=
forms
.
IntegerField
(
widget
=
forms
.
Select
(
choices
=
parsing_options
)
,
required
=
True
)
file
=
forms
.
FileField
()
# Description: clean_file()
"""
* file_.content_type - Example: ['application/pdf', 'image/jpeg']
* len(file_) - file size.
2.5MB - 2621440
5MB - 5242880
10MB - 10485760
20MB - 20971520
50MB - 5242880
100MB 104857600
250MB - 214958080
500MB - 429916160
"""
def
clean_file
(
self
):
file_
=
self
.
cleaned_data
.
get
(
'file'
)
#Filename length
if
len
(
file_
.
name
)
>
30
:
from
datetime
import
datetime
file_
.
name
=
str
(
datetime
.
now
()
.
microsecond
)
raise
forms
.
ValidationError
(
_
(
'Come on dude, name too long. Now is:'
+
file_
.
name
))
#File size
if
len
(
file_
)
>
104857600
:
raise
forms
.
ValidationError
(
_
(
'File to heavy! (<100MB svp mec).'
))
## File type:
# if file_.content_type == "application/zip":
# raise forms.ValidationError(_('We need a zip pls.'))
return
file_
class
CorpusForm
(
ModelForm
):
#parent = ModelChoiceField(EmptyQuerySet)
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -99,12 +142,6 @@ class CorpusForm(ModelForm):
self
.
request
=
kwargs
.
pop
(
'request'
,
None
)
super
(
CorpusForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
parent_type
=
NodeType
.
objects
.
get
(
name
=
"Project"
)
#parent_type = NodeType.objects.get(name=self._parent_nodetype_name)
# self.fields['parent'].queryset = Node.objects.filter(
# user_id=self.request.user.id,
# type_id=parent_type.id
# )
#self.fields['language'].queryset = Language.objects.filter(implemented=1)
except
Exception
as
error
:
print
(
"Error with"
,
error
)
...
...
node/models.py
View file @
6239e326
...
...
@@ -129,33 +129,10 @@ class Node(CTENode):
return
Resource
.
objects
.
select_related
(
'node_resource'
)
.
filter
(
node_resource__node
=
self
)
def
add_resource
(
self
,
**
kwargs
):
# print("printing arguments for add_resource():")
# print(kwargs)
# from django.core.files.storage import default_storage
# from django.core.files.base import ContentFile
# import os
# thefile = kwargs["file"]
# path = default_storage.save('tmp/somename.zip', ContentFile(thefile.read()))
# tmp_file = os.path.join(MEDIA_ROOT, path)
# print(tmp_file)
# kwargs["file"] = tmp_file
# print("final kwargs:")
# print(kwargs)
# only for tests
resource
=
Resource
(
guid
=
str
(
time
()),
digest
=
str
(
time
()),
**
kwargs
)
#resource = Resource(**kwargs)
resource
.
save
()
print
(
"printing rresource.file:"
)
print
(
resource
.
file
)
# print("printing the resource 01____:")
# print(resource.file)
# print("printing the resource 02____: asdasdasd")
# User
if
'user'
not
in
kwargs
and
'user_id'
not
in
kwargs
:
...
...
@@ -193,8 +170,6 @@ class Node(CTENode):
'europress_french'
:
EuropressFileParser
,
'europress_english'
:
EuropressFileParser
,
})[
resource
.
type
.
name
]()
print
(
"parse_resources:"
)
print
(
resource
.
file
)
metadata_list
+=
parser
.
parse
(
str
(
resource
.
file
))
# retrieve info from the database
type_id
=
NodeType
.
objects
.
get
(
name
=
'Document'
)
.
id
...
...
templates/tests/formexample.html
0 → 100644
View file @
6239e326
<html>
<body>
<form
action=
"/formexample/"
enctype=
"multipart/form-data"
method=
"post"
>
{% csrf_token %}
{{ form.as_p }}
<input
type=
"submit"
value=
"OK"
>
</form>
{% if msg %}
<p>
Response: {{msg}}
</p>
{% endif %}
</body>
</html>
\ No newline at end of file
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