Commit 6239e326 authored by Administrator's avatar Administrator

Merge branch 'samuel' into unstable

parents 87ff5323 6d6ccfa1
......@@ -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)
)
......
This diff is collapsed.
......@@ -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)
......
......@@ -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
......
<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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment