Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
djnro
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
djnro
Commits
b9e65644
Commit
b9e65644
authored
Oct 17, 2012
by
Leonidas Poulopoulos
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added urls in institution form
parent
54a9c979
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
40 deletions
+73
-40
.gitignore
.gitignore
+1
-0
edumanage/forms.py
edumanage/forms.py
+15
-20
edumanage/views.py
edumanage/views.py
+14
-6
templates/edumanage/institution_edit.html
templates/edumanage/institution_edit.html
+38
-8
templates/edumanage/services_edit.html
templates/edumanage/services_edit.html
+5
-6
No files found.
.gitignore
View file @
b9e65644
settings.py
settings.py
urls.py
urls.py
*.pyc
*.pyc
local.db
edumanage/forms.py
View file @
b9e65644
...
@@ -47,7 +47,6 @@ class NameFormSetFact(BaseGenericInlineFormSet):
...
@@ -47,7 +47,6 @@ class NameFormSetFact(BaseGenericInlineFormSet):
emptyForms
=
True
emptyForms
=
True
for
i
in
range
(
0
,
self
.
total_form_count
()):
for
i
in
range
(
0
,
self
.
total_form_count
()):
form
=
self
.
forms
[
i
]
form
=
self
.
forms
[
i
]
pprint
.
pprint
(
form
.
__dict__
)
if
len
(
form
.
cleaned_data
)
!=
0
:
if
len
(
form
.
cleaned_data
)
!=
0
:
emptyForms
=
False
emptyForms
=
False
langs
.
append
(
form
.
cleaned_data
.
get
(
'lang'
,
None
))
langs
.
append
(
form
.
cleaned_data
.
get
(
'lang'
,
None
))
...
@@ -59,30 +58,26 @@ class NameFormSetFact(BaseGenericInlineFormSet):
...
@@ -59,30 +58,26 @@ class NameFormSetFact(BaseGenericInlineFormSet):
class
UrlFormSetFact
(
BaseGenericInlineFormSet
):
class
UrlFormSetFact
(
BaseGenericInlineFormSet
):
def
clean
(
self
):
def
clean
(
self
):
#raise forms.ValidationError, "Clean method called"
if
any
(
self
.
errors
):
if
any
(
self
.
errors
):
return
return
pprint
.
pprint
(
self
.
forms
)
for
i
in
range
(
0
,
self
.
total_form_count
()):
for
i
in
range
(
0
,
self
.
total_form_count
()):
form
=
self
.
forms
[
i
]
form
=
self
.
forms
[
i
]
pprint
.
pprint
(
len
(
form
.
cleaned_data
))
if
len
(
form
.
cleaned_data
)
==
0
:
if
len
(
form
.
cleaned_data
)
==
0
:
#raise forms.ValidationError, "Fill in at least one url "
pass
pass
#print "ERROROROROR"
#self.append_non_form_error("not enough subs")
# pass
return
return
# raise forms.ValidationError('Invalid date range')
class
UrlFormSetFactInst
(
BaseGenericInlineFormSet
):
def
clean
(
self
):
if
any
(
self
.
errors
):
# def save(self, commit=True, request=None):
return
# for uform in self.forms:
url_types
=
[]
# urls = uform.save(commit=False)
emptyForms
=
True
# urls.content_object = self.instance
for
i
in
range
(
0
,
self
.
total_form_count
()):
# urls.save()
form
=
self
.
forms
[
i
]
# return self.save_existing_objects(commit) + self.save_new_objects(commit)
if
len
(
form
.
cleaned_data
)
!=
0
:
emptyForms
=
False
url_types
.
append
(
form
.
cleaned_data
.
get
(
'urltype'
,
None
))
if
emptyForms
:
raise
forms
.
ValidationError
,
"Fill in at least the info url"
if
"info"
not
in
url_types
:
raise
forms
.
ValidationError
,
"Fill in at least the info url"
edumanage/views.py
View file @
b9e65644
...
@@ -86,22 +86,30 @@ def add_institution_details(request, institution_pk):
...
@@ -86,22 +86,30 @@ def add_institution_details(request, institution_pk):
try
:
try
:
inst_details
=
InstitutionDetails
.
objects
.
get
(
institution
=
inst
)
inst_details
=
InstitutionDetails
.
objects
.
get
(
institution
=
inst
)
form
=
InstDetailsForm
(
instance
=
inst_details
)
form
=
InstDetailsForm
(
instance
=
inst_details
)
UrlFormSet
=
generic_inlineformset_factory
(
URL_i18n
,
extra
=
2
,
formset
=
UrlFormSetFactInst
,
can_delete
=
True
)
except
InstitutionDetails
.
DoesNotExist
:
except
InstitutionDetails
.
DoesNotExist
:
form
=
InstDetailsForm
()
form
=
InstDetailsForm
()
form
.
fields
[
'institution'
]
=
forms
.
ModelChoiceField
(
queryset
=
Institution
.
objects
.
filter
(
pk
=
institution_pk
),
empty_label
=
None
)
form
.
fields
[
'institution'
]
=
forms
.
ModelChoiceField
(
queryset
=
Institution
.
objects
.
filter
(
pk
=
institution_pk
),
empty_label
=
None
)
UrlFormSet
=
generic_inlineformset_factory
(
URL_i18n
,
extra
=
2
,
can_delete
=
True
)
urls_form
=
UrlFormSet
(
prefix
=
'urlsform'
)
form
.
fields
[
'contact'
]
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Contact
.
objects
.
filter
(
pk__in
=
getInstContacts
(
inst
)))
form
.
fields
[
'contact'
]
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Contact
.
objects
.
filter
(
pk__in
=
getInstContacts
(
inst
)))
return
render_to_response
(
'edumanage/institution_edit.html'
,
{
'institution'
:
inst
,
'form'
:
form
},
return
render_to_response
(
'edumanage/institution_edit.html'
,
{
'institution'
:
inst
,
'form'
:
form
,
'urls_form'
:
urls_form
},
context_instance
=
RequestContext
(
request
,
base_response
(
request
)))
context_instance
=
RequestContext
(
request
,
base_response
(
request
)))
elif
request
.
method
==
'POST'
:
elif
request
.
method
==
'POST'
:
request_data
=
request
.
POST
.
copy
()
request_data
=
request
.
POST
.
copy
()
UrlFormSet
=
generic_inlineformset_factory
(
URL_i18n
,
extra
=
2
,
formset
=
UrlFormSetFactInst
,
can_delete
=
True
)
try
:
try
:
inst_details
=
InstitutionDetails
.
objects
.
get
(
institution
=
inst
)
inst_details
=
InstitutionDetails
.
objects
.
get
(
institution
=
inst
)
form
=
InstDetailsForm
(
request_data
,
instance
=
inst_details
)
form
=
InstDetailsForm
(
request_data
,
instance
=
inst_details
)
urls_form
=
UrlFormSet
(
request_data
,
instance
=
inst_details
,
prefix
=
'urlsform'
)
except
InstitutionDetails
.
DoesNotExist
:
except
InstitutionDetails
.
DoesNotExist
:
form
=
InstDetailsForm
(
request_data
)
form
=
InstDetailsForm
(
request_data
)
if
form
.
is_valid
():
urls_form
=
UrlFormSet
(
request_data
,
prefix
=
'urlsform'
)
UrlFormSet
=
generic_inlineformset_factory
(
URL_i18n
,
extra
=
2
,
formset
=
UrlFormSetFactInst
,
can_delete
=
True
)
if
form
.
is_valid
()
and
urls_form
.
is_valid
():
instdets
=
form
.
save
()
instdets
=
form
.
save
()
urls_form
.
instance
=
instdets
urls_inst
=
urls_form
.
save
()
return
HttpResponseRedirect
(
reverse
(
"institutions"
))
return
HttpResponseRedirect
(
reverse
(
"institutions"
))
else
:
else
:
try
:
try
:
...
@@ -111,7 +119,7 @@ def add_institution_details(request, institution_pk):
...
@@ -111,7 +119,7 @@ def add_institution_details(request, institution_pk):
inst
=
False
inst
=
False
form
.
fields
[
'institution'
]
=
forms
.
ModelChoiceField
(
queryset
=
Institution
.
objects
.
filter
(
pk
=
institution_pk
),
empty_label
=
None
)
form
.
fields
[
'institution'
]
=
forms
.
ModelChoiceField
(
queryset
=
Institution
.
objects
.
filter
(
pk
=
institution_pk
),
empty_label
=
None
)
form
.
fields
[
'contact'
]
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Contact
.
objects
.
filter
(
pk__in
=
getInstContacts
(
inst
)))
form
.
fields
[
'contact'
]
=
forms
.
ModelMultipleChoiceField
(
queryset
=
Contact
.
objects
.
filter
(
pk__in
=
getInstContacts
(
inst
)))
return
render_to_response
(
'edumanage/institution_edit.html'
,
{
'institution'
:
inst
,
'form'
:
form
},
return
render_to_response
(
'edumanage/institution_edit.html'
,
{
'institution'
:
inst
,
'form'
:
form
,
'urls_form'
:
urls_form
},
context_instance
=
RequestContext
(
request
,
base_response
(
request
)))
context_instance
=
RequestContext
(
request
,
base_response
(
request
)))
...
...
templates/edumanage/institution_edit.html
View file @
b9e65644
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
<li
class=
"active"
>
Add-Edit
</li>
<li
class=
"active"
>
Add-Edit
</li>
{% endblock %}
{% endblock %}
{% block extrahead %}
{% block extrahead %}
<script
type=
"text/javascript"
src=
"/static/js/jquery.formset.js"
></script>
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$
(
"
#adduserSubmit
"
).
click
(
function
(){
$
(
"
#adduserSubmit
"
).
click
(
function
(){
...
@@ -45,7 +46,23 @@ $(document).ready(function() {
...
@@ -45,7 +46,23 @@ $(document).ready(function() {
return
false
;
return
false
;
});
});
$
(
'
#urlsform tbody tr
'
).
formset
({
prefix
:
'
{{urls_form.prefix}}
'
,
formCssClass
:
"
dynamic-formset1
"
,
added
:
addButton
,
});
$
(
"
.delete-row
"
).
prepend
(
'
<i class="icon-remove-sign icon-white"></i>
'
).
addClass
(
'
btn btn-small btn-warning
'
);
$
(
"
.add-row
"
).
prepend
(
'
<i class="icon-plus-sign icon-white"></i>
'
).
addClass
(
'
btn btn-small btn-info
'
);
});
});
function
addButton
(
row
){
$
(
row
).
find
(
"
.delete-row
"
).
prepend
(
'
<i class="icon-remove-sign icon-white"></i>
'
).
addClass
(
'
btn btn-small btn-warning
'
);
}
</script>
</script>
{% endblock %}
{% endblock %}
...
@@ -103,12 +120,25 @@ $(document).ready(function() {
...
@@ -103,12 +120,25 @@ $(document).ready(function() {
{% endif %}
<span
class=
"help-block"
>
{{ form.contact.help_text }}
</span>
{% endif %}
<span
class=
"help-block"
>
{{ form.contact.help_text }}
</span>
</div>
</div>
</div>
</div>
<div
class=
"control-group {% if form.url.errors %} error {% endif %}"
>
<div
class=
"control-group {% for err in urls_form.errors %}{% if err|length > 0 %}error{% endif %}{% endfor %}{% if urls_form.non_form_errors %}error{% endif %}"
>
<label
class=
"control-label"
for=
"id_url"
>
URL(s)
</label>
<label
class=
"control-label"
for=
"id_urls"
>
Urls
</label>
{{urls_form.management_form}}
<div
class=
"controls"
>
<div
class=
"controls"
>
{{ form.url }}
{% for err in urls_form.errors %}{% if err|length > 0 %}
<span
class=
"help-inline"
>
{{err}}
</span>
{% endif %}{% endfor %}
{% if form.url.errors %}
<span
class=
"help-inline"
>
{{ form.url.errors|join:", " }}
</span>
{% if urls_form.non_form_errors %}
<span
class=
"help-inline"
>
{{ urls_form.non_form_errors|join:", "}}
</span>
{% endif %}
{% endif %}
<span
class=
"help-block"
>
{{ form.url.help_text }}
</span>
<table
id=
"urlsform"
><thead><tr><td>
url
</td><td>
type
</td><td>
language
</td></tr></thead><tbody>
{% for formset in urls_form.forms %}
{{ formset.id }}
<tr
id=
"{{ formset.prefix }}-row"
>
<td>
{% if formset.instance.pk %}{{ formset.DELETE }}{% endif %}{{ formset.url }}{% if formset.url.errors %}
<br><div
class=
"help-inline"
>
{{ formset.url.errors|join:", " }}
</div>
{% endif %}
</td>
<td>
{{formset.urltype}}{% if formset.urltype.errors %}
<br><p
class=
"help-inline"
>
{{ formset.urltype.errors|join:", " }}
</p>
{% endif %}
</td>
<td>
{{formset.lang}}{% if formset.lang.errors %}
<br><p
class=
"help-inline"
>
{{ formset.lang.errors|join:", " }}
</p>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody></table>
</div>
</div>
</div>
</div>
<div
class=
"control-group {% if form.oper_name.errors %} error {% endif %}"
>
<div
class=
"control-group {% if form.oper_name.errors %} error {% endif %}"
>
...
...
templates/edumanage/services_edit.html
View file @
b9e65644
...
@@ -7,8 +7,7 @@
...
@@ -7,8 +7,7 @@
{% endblock %}
{% endblock %}
{% block extrahead %}
{% block extrahead %}
<script
type=
"text/javascript"
src=
"/static/js/jquery.formset.js"
></script>
<script
type=
"text/javascript"
src=
"/static/js/jquery.formset.js"
></script>
<script
type=
"text/javascript"
<script
type=
"text/javascript"
src=
"http://maps.googleapis.com/maps/api/js?sensor=false"
></script>
src=
"http://maps.googleapis.com/maps/api/js?sensor=false"
></script>
<script
src=
"/static/js/jquery_csrf_protect.js"
type=
"text/javascript"
></script>
<script
src=
"/static/js/jquery_csrf_protect.js"
type=
"text/javascript"
></script>
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
...
...
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