diff options
author | Shweta Chaughule <shwettach@gmail.com> | 2012-04-16 18:04:12 +0530 |
---|---|---|
committer | Shweta Chaughule <shwettach@gmail.com> | 2012-04-16 18:04:12 +0530 |
commit | 39467038c61056769e91e16c80130214c9811ada (patch) | |
tree | 688cd059c80cbc536a43a06506f95cbcfceb05fd | |
parent | 0aff6c0944e356efd6989093be174180a1a77e93 (diff) | |
download | gnowsys-39467038c61056769e91e16c80130214c9811ada.tar.gz |
Dynamic fomrs created, also files added for them.Property to get type added by Johnson - Shweta and Neeharika ( Citizen Science Group )
-rw-r--r-- | gstudio/templates/gstudio/nodetype_detail.html | 9 | ||||
-rw-r--r-- | objectapp/forms.py | 19 | ||||
-rw-r--r-- | objectapp/static/objectapp/js/noat.js | 51 | ||||
-rw-r--r-- | objectapp/static/objectapp/js/saveat.js | 56 | ||||
-rw-r--r-- | objectapp/static/objectapp/js/savert.js | 59 | ||||
-rw-r--r-- | objectapp/static/objectapp/js/selectRT.js | 60 | ||||
-rw-r--r-- | objectapp/static/objectapp/js/setMember.js | 51 | ||||
-rw-r--r-- | objectapp/static/objectapp/js/setdate.js | 45 | ||||
-rw-r--r-- | objectapp/templates/objectapp/fillAT.html | 28 | ||||
-rw-r--r-- | objectapp/templates/objectapp/fillRT.html | 25 | ||||
-rw-r--r-- | objectapp/templates/objectapp/selectAT.html | 25 | ||||
-rw-r--r-- | objectapp/templates/objectapp/selectRT.html | 39 | ||||
-rw-r--r-- | objectapp/templates/objectapp/skeleton.html | 21 | ||||
-rw-r--r-- | objectapp/urls/ATurl.py | 12 | ||||
-rw-r--r-- | objectapp/urls/RTurl.py | 13 | ||||
-rw-r--r-- | objectapp/urls/__init__.py | 2 | ||||
-rw-r--r-- | objectapp/views/dynamicAT.py | 155 | ||||
-rw-r--r-- | objectapp/views/dynamicRT.py | 256 |
18 files changed, 919 insertions, 7 deletions
diff --git a/gstudio/templates/gstudio/nodetype_detail.html b/gstudio/templates/gstudio/nodetype_detail.html index b69c404..404adb9 100644 --- a/gstudio/templates/gstudio/nodetype_detail.html +++ b/gstudio/templates/gstudio/nodetype_detail.html @@ -250,9 +250,14 @@ {% endwith %} {% endblock %} - <div class="nodetype-content"> +{% if object.reftype == 'Objecttype'%} +<a href="{{ get_absolute_url }}/objects/dynamicAttribute/save/{{ object.title }}">Add Attribute</a> +<br/> +<a href="{{ get_absolute_url }}/objects/dynamicRelation/displayRT/{{ object.title }}">Add Relation</a> +{% endif %} +<div class="nodetype-content"> - </div> +</div> {% block nodetype-widgets %} <div class="nodetype-widgets span-16 last"> {% with object.next_nodetype as next_nodetype %} diff --git a/objectapp/forms.py b/objectapp/forms.py index 6f9df1a..1d12315 100644 --- a/objectapp/forms.py +++ b/objectapp/forms.py @@ -15,8 +15,14 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -from objectapp.models import * +from django import forms from django.forms import ModelForm +from django.forms.fields import DateField +from django.contrib.admin import widgets +from django.contrib.admin.widgets import AdminDateWidget + +from gstudio.models import * +from objectapp.models import * class GbobjectForm(ModelForm): @@ -33,3 +39,14 @@ class SystemForm(ModelForm): class Meta: model = System + +class ContextForm(forms.Form): + + def __init__(self,rdict, *args, **kwargs): + super(ContextForm, self).__init__(*args, **kwargs) + for key, val in rdict.iteritems(): + print key, val + self.fields[str(key)+"_"+str(val)] = getattr(forms,rdict.get(key))(required = False) + + + diff --git a/objectapp/static/objectapp/js/noat.js b/objectapp/static/objectapp/js/noat.js new file mode 100644 index 0000000..ef460ca --- /dev/null +++ b/objectapp/static/objectapp/js/noat.js @@ -0,0 +1,51 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_back").ajaxSend(function(e,xhr,settings){ + + + function getCookie(name) { + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = $.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + function sameOrigin(url) { + // url could be relative or scheme relative or absolute + var host = document.location.host; // host + port + var protocol = document.location.protocol; + var sr_origin = '//' + host; + var origin = protocol + sr_origin; + // Allow absolute or scheme relative URLs to same origin + return (url == origin || url.slice(0, origin.length + 1) == origin + '/') || + (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') || + // or any other URL that isn't scheme relative or absolute i.e relative. + !(/^(\/\/|http:|https:).*/.test(url)); + } + function safeMethod(method) { + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + + if (!safeMethod(settings.type) && sameOrigin(settings.url)) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + }); + $("#id_back").click(function(){ + absolute_url_node = document.getElementById("id_back_url") + window.location.replace(absolute_url_node.value); + }); + + }); + + diff --git a/objectapp/static/objectapp/js/saveat.js b/objectapp/static/objectapp/js/saveat.js new file mode 100644 index 0000000..55e602a --- /dev/null +++ b/objectapp/static/objectapp/js/saveat.js @@ -0,0 +1,56 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_select").ajaxSend(function(e,xhr,settings){ + + + function getCookie(name) { + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = $.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + function sameOrigin(url) { + // url could be relative or scheme relative or absolute + var host = document.location.host; // host + port + var protocol = document.location.protocol; + var sr_origin = '//' + host; + var origin = protocol + sr_origin; + // Allow absolute or scheme relative URLs to same origin + return (url == origin || url.slice(0, origin.length + 1) == origin + '/') || + (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') || + // or any other URL that isn't scheme relative or absolute i.e relative. + !(/^(\/\/|http:|https:).*/.test(url)); + } + function safeMethod(method) { + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + + if (!safeMethod(settings.type) && sameOrigin(settings.url)) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + }); + $("#id_select").change(function(){ + test = $("#id_select").val().toString() + //url = "/objects/context/test2/?id="+test + url = "/objects/dynamic/save/"+test+"/" + $.get(url, function(data){ + window.location.replace(url); + + }); + }); + + }); + + diff --git a/objectapp/static/objectapp/js/savert.js b/objectapp/static/objectapp/js/savert.js new file mode 100644 index 0000000..0e1f8b0 --- /dev/null +++ b/objectapp/static/objectapp/js/savert.js @@ -0,0 +1,59 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_submit_rt").ajaxSend(function(e,xhr,settings){ + + + function getCookie(name) { + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = $.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + function sameOrigin(url) { + // url could be relative or scheme relative or absolute + var host = document.location.host; // host + port + var protocol = document.location.protocol; + var sr_origin = '//' + host; + var origin = protocol + sr_origin; + // Allow absolute or scheme relative URLs to same origin + return (url == origin || url.slice(0, origin.length + 1) == origin + '/') || + (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') || + // or any other URL that isn't scheme relative or absolute i.e relative. + !(/^(\/\/|http:|https:).*/.test(url)); + } + function safeMethod(method) { + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + + if (!safeMethod(settings.type) && sameOrigin(settings.url)) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + }); + $("#id_submit_rt").click(function(){ + left = document.getElementById("id_left") + rt = document.getElementById("id_reltype") + right = document.getElementById("id_right") + absolute_url = document.getElementById("id_back_url") + url = "/objects/dynamicRelation/save/"+ left.value + "/" +rt.value+"/"+right.value+"/" + // alert(url); + $.get(url,function(data){ + window.location.replace(absolute_url.value); + }); + + }); + + }); + + diff --git a/objectapp/static/objectapp/js/selectRT.js b/objectapp/static/objectapp/js/selectRT.js new file mode 100644 index 0000000..7dbbcd8 --- /dev/null +++ b/objectapp/static/objectapp/js/selectRT.js @@ -0,0 +1,60 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_select_rt").ajaxSend(function(e,xhr,settings){ + + + function getCookie(name) { + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = $.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + function sameOrigin(url) { + // url could be relative or scheme relative or absolute + var host = document.location.host; // host + port + var protocol = document.location.protocol; + var sr_origin = '//' + host; + var origin = protocol + sr_origin; + // Allow absolute or scheme relative URLs to same origin + return (url == origin || url.slice(0, origin.length + 1) == origin + '/') || + (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') || + // or any other URL that isn't scheme relative or absolute i.e relative. + !(/^(\/\/|http:|https:).*/.test(url)); + } + function safeMethod(method) { + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + + if (!safeMethod(settings.type) && sameOrigin(settings.url)) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + }); + $("#id_select_rt").change(function(){ + relationtype = $(this).val().toString() + left = document.getElementById("id_left") + document.getElementById("id_reltype").value = relationtype + url = "/objects/dynamicRelation/displaymem/"+ relationtype + "/" +left.value+"/" + // alert(url); + $.get(url,function(data){ + $("#id_div1").empty() + $("#id_div1").html(data) + + }); + + }); + + }); + + diff --git a/objectapp/static/objectapp/js/setMember.js b/objectapp/static/objectapp/js/setMember.js new file mode 100644 index 0000000..a71b675 --- /dev/null +++ b/objectapp/static/objectapp/js/setMember.js @@ -0,0 +1,51 @@ +$ = django.jQuery + + + $(document).ready(function() { + + $("#id_select_mem").ajaxSend(function(e,xhr,settings){ + + + function getCookie(name) { + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = $.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + function sameOrigin(url) { + // url could be relative or scheme relative or absolute + var host = document.location.host; // host + port + var protocol = document.location.protocol; + var sr_origin = '//' + host; + var origin = protocol + sr_origin; + // Allow absolute or scheme relative URLs to same origin + return (url == origin || url.slice(0, origin.length + 1) == origin + '/') || + (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') || + // or any other URL that isn't scheme relative or absolute i.e relative. + !(/^(\/\/|http:|https:).*/.test(url)); + } + function safeMethod(method) { + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + + if (!safeMethod(settings.type) && sameOrigin(settings.url)) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + }); + $("#id_select_mem").change(function(){ + right_member = $(this).val() + document.getElementById("id_right").value = right_member; + // alert("hello "+ right_member); + + }); + + }); diff --git a/objectapp/static/objectapp/js/setdate.js b/objectapp/static/objectapp/js/setdate.js new file mode 100644 index 0000000..42cc4dc --- /dev/null +++ b/objectapp/static/objectapp/js/setdate.js @@ -0,0 +1,45 @@ +$ = django.jQuery + + $(document).ready(function() { + + $('input[name$="DateField"]').ajaxSend(function(e,xhr,settings){ + + + function getCookie(name) { + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = $.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } + function sameOrigin(url) { + // url could be relative or scheme relative or absolute + var host = document.location.host; // host + port + var protocol = document.location.protocol; + var sr_origin = '//' + host; + var origin = protocol + sr_origin; + // Allow absolute or scheme relative URLs to same origin + return (url == origin || url.slice(0, origin.length + 1) == origin + '/') || + (url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') || + // or any other URL that isn't scheme relative or absolute i.e relative. + !(/^(\/\/|http:|https:).*/.test(url)); + } + function safeMethod(method) { + return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method)); + } + + if (!safeMethod(settings.type) && sameOrigin(settings.url)) { + xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken')); + } + }); + + $('input[name$="DateField"]').datepicker({ dateFormat: "yy-mm-dd",minDate: new Date(1800, 1 - 1, 1), changeYear : true, changeMonth: true }); + }); diff --git a/objectapp/templates/objectapp/fillAT.html b/objectapp/templates/objectapp/fillAT.html new file mode 100644 index 0000000..6ddabe4 --- /dev/null +++ b/objectapp/templates/objectapp/fillAT.html @@ -0,0 +1,28 @@ +{% extends "objectapp/base.html" %} +{% load i18n %} +{% block content %} +<form action="." method="POST"> + +{% csrf_token %} + +<b>Details of {{ name }} </b> +<table id= "id_table" class = "class_table"> + <tr> + <th> Attribute Type </th> + <th> Value </th> + </tr> + {% for field in form %} + <tr> + <td>{{ field.label_tag }}</td> + <td>{{ field }} {{ field.errors }}</td> + </tr> + {% endfor %} + <tr> + <td><input type="submit" id="id_submit" value="Go"/></td> + <td><input type="button" id="id_back" value="Back"/></td> + </tr> +</table> +<input type="hidden" id="id_back_url" value="{{ absolute_url_node }}"/> +<input type="hidden" id="id_hidden" value=" "/> +</form> +{% endblock %} diff --git a/objectapp/templates/objectapp/fillRT.html b/objectapp/templates/objectapp/fillRT.html new file mode 100644 index 0000000..875a40f --- /dev/null +++ b/objectapp/templates/objectapp/fillRT.html @@ -0,0 +1,25 @@ + + +{% extends "objectapp/base.html" %} +{% load i18n %} +{% block content %} + +<form method="." action="POST"> +{% csrf_token %} + +<select id = "id_select_mem"> + <option>-select-</option> +{% if memdict %} +{% for key, val in memdict.iteritems %} +<option value="{{ key }}">{{ val }}</option> +{% endfor %} +{% else %} +<option>Nothing</option> +{% endif %} +</select> + +<input type="button" id="id_submit_rt" value="Go"/> + +</form> +{% endblock %} + diff --git a/objectapp/templates/objectapp/selectAT.html b/objectapp/templates/objectapp/selectAT.html new file mode 100644 index 0000000..ce5a95f --- /dev/null +++ b/objectapp/templates/objectapp/selectAT.html @@ -0,0 +1,25 @@ + +{% extends "objectapp/base.html" %} +{% load i18n %} + +{% block content %} + +<form method="POST" action="."> +{% csrf_token %} +Objects : +<select id="id_select"> +<option value="select">-select-</option> +{% if rdict %} +{% for id, val in rdict.items %} + <option value="{{ id }}">{{ val }}</option> +{% endfor %} +{% else %} + <option value="nothing">-Nothing-</option> +{% endif %} +</select> + +<div id = "id_div"> +</div> +</form> + +{% endblock %} diff --git a/objectapp/templates/objectapp/selectRT.html b/objectapp/templates/objectapp/selectRT.html new file mode 100644 index 0000000..cfec3c7 --- /dev/null +++ b/objectapp/templates/objectapp/selectRT.html @@ -0,0 +1,39 @@ + +{% extends "objectapp/base.html" %} +{% load i18n %} + +{% block content %} +<form method="." action="POST"> +{% csrf_token %} +<b>Details of {{ gb }}</b> + +<!-- -------------------------------------------- --> + +<select id ="id_select_rt"> +<option>-select-</option> +{% if final %} +{% for key, val in final.iteritems %} + <option value="{{ key }}">{{ val }}</option> +{% endfor %} +{% else %} + <option> No Relation </option> + <input type="button" id="id_back" value="Back"/> +{% endif %} +</select> + +<!-- -------------------------------------------- --> + +<input id="id_left" type="hidden" value="{{ gbid }}"> +<input id="id_right" type="hidden" value=" "> +<input id="id_reltype" type="hidden" value=" "> +<input id="id_back_url" type="hidden" value="{{ absolute_url_node }}"> + +<!-- -------------------------------------------- --> + +<div id = "id_div1"> +</div> + +<!-- -------------------------------------------- --> + +</form> +{% endblock %} diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html index dff7006..4d4b0a2 100644 --- a/objectapp/templates/objectapp/skeleton.html +++ b/objectapp/templates/objectapp/skeleton.html @@ -46,8 +46,8 @@ display: block; } svg { - margin-left: 10%; - margin-right: 10%; + margin-left: 50%; + margin-right: 50%; display: block; position: absolute; } @@ -63,6 +63,9 @@ {% if LANGUAGE_BIDI %}<link href="{% block stylesheet_rtl %}{% admin_media_prefix %}css/rtl.css{% endblock %}" rel="stylesheet" type="text/css" />{% endif %} <link href="{% admin_media_prefix %}jquery/ui/css/custom-theme/jquery-ui-1.8.custom.css" rel="stylesheet" type="text/css" media="screen" title="no title" charset="utf-8" /> <link href="{% admin_media_prefix %}css/jquery-ui-grappelli-extensions.css" rel="stylesheet" type="text/css" /> + + <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> + {% endblock %} <!-- EXTRASTYLES --> {% block extrastyle %}{% endblock %} @@ -93,6 +96,16 @@ <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_fk.js" type="text/javascript"></script> <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_m2m.js" type="text/javascript"></script> <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_autocomplete_generic.js" type="text/javascript"></script> + <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/saveat.js"></script> + <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/selectRT.js"></script> + <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/setMember.js"></script> + <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/savert.js"></script> + <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/noat.js"></script> + + <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> + <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> + <script type="text/javascript" src="{{ STATIC_URL }}objectapp/js/setdate.js"></script> + <!-- EXTRAHEAD --> {% block extrahead %}{% endblock %} @@ -174,7 +187,7 @@ Javascript for Object type force graph --> <script type="text/javascript" > - var a = 85 * s; + var a = 75 * s; if ( a > 700 ) { @@ -185,7 +198,7 @@ Javascript for Object type force graph var w = a; } - var h = 85 * s, + var h = 75 * s, /* var w = 700, h = 400,*/ diff --git a/objectapp/urls/ATurl.py b/objectapp/urls/ATurl.py new file mode 100644 index 0000000..00122fb --- /dev/null +++ b/objectapp/urls/ATurl.py @@ -0,0 +1,12 @@ +from django.conf.urls.defaults import url
+from django.conf.urls.defaults import patterns
+#from objectapp.views import testview
+
+urlpatterns = patterns('objectapp.views.dynamicAT',
+ url(r'^dynamicattr/$','dynamic_view',
+ name = 'objectapp_dynamic_view'),
+ url(r'^save/(\w.+)/$','dynamic_save',
+ name='objectapp_dynamic_save'),
+ # url(r'^dynamicOT/(\w.+)/$','dynamic_objecttype',
+ # name='objectapp_dynamic_objecttype'),
+ )
diff --git a/objectapp/urls/RTurl.py b/objectapp/urls/RTurl.py new file mode 100644 index 0000000..cea15cd --- /dev/null +++ b/objectapp/urls/RTurl.py @@ -0,0 +1,13 @@ +from django.conf.urls.defaults import url +from django.conf.urls.defaults import patterns +#from objectapp.views import testview + +urlpatterns = patterns('objectapp.views.dynamicRT', + url(r'^displayRT/(\w.+)/$','context_RT', + name='objectapp_context_view'), + url(r'^displaymem/(\w+)/(\w+)/$','context_member', + name='objectapp_context_display'), + url(r'^save/(\w+)/(\w+)/(\w+)/$','context_save', + name='objectapp_context_save'), + ) + diff --git a/objectapp/urls/__init__.py b/objectapp/urls/__init__.py index 2ba09ff..1406f49 100644 --- a/objectapp/urls/__init__.py +++ b/objectapp/urls/__init__.py @@ -81,4 +81,6 @@ urlpatterns = patterns( url(r'^', include('objectapp.urls.quick_gbobject')), url(r'^', include('objectapp.urls.capabilities')), url(r'^', include('objectapp.urls.gbobjects')), + url(r'^dynamicAttribute/', include('objectapp.urls.ATurl')), + url(r'^dynamicRelation/',include('objectapp.urls.RTurl')), ) diff --git a/objectapp/views/dynamicAT.py b/objectapp/views/dynamicAT.py new file mode 100644 index 0000000..52a6256 --- /dev/null +++ b/objectapp/views/dynamicAT.py @@ -0,0 +1,155 @@ + +from django.http import * +from django import forms +from django.shortcuts import render_to_response +from django.template import RequestContext + +from objectapp.models import * +from objectapp.forms import * + +from gstudio.models import * + +def dynamic_view(request): + rdict = {} + for j in Gbobject.objects.all(): + rdict.update({j.id:j.title}) + + template="objectapp/selectAT.html" + context= RequestContext(request,{ 'rdict':rdict }) + return render_to_response(template,context) + +def dynamic_save(request,tit): #view for gb and ot too + testlst = [] + parenttype = [] + attributetype = [] + rdict = {} + nodelist = [] + syst = []#parent for system + try: + offset = str(tit) + except ValueError: + raise Http404() + + #flag = 0 #means its object + + if Objecttype.objects.filter(title = offset): + flag = 1 + elif Gbobject.objects.filter(title = offset): + flag = 0 + elif Systemtype.objects.filter(title = offset): + flag = 2 + + if flag == 1: + parenttype.append(Objecttype.objects.get(title = offset)) + pt_id = NID.objects.get(title = offset) + name = pt_id + + elif flag == 0: + #utit = Gbobject.objects.get(title = offset) + gb=Gbobject.objects.get(title=offset) + name = gb + # checking whether object is gb or system coz created objects are treated as Gbobject n then System objects + if System.objects.filter(title = (gb.ref).title): + gb = System.objects.get(title = offset) + syst = gb.systemtypes.all() + for i in syst: + nodelist = i.nodetype_set.all() + parenttype.append(i) + + for i in nodelist: + parenttype.append(i.ref) + + elif Gbobject.objects.filter(title = (gb.ref).title): + parenttype = gb.objecttypes.all() + + pt_id = NID.objects.get(id = gb.id) + + elif flag == 2: + systype = Systemtype.objects.get(title = offset) + nodelist = systype.nodetype_set.all() + parenttype.append(Systemtype.objects.get(title = offset)) + for i in nodelist: + parenttype.append(i.ref) + pt_id = NID.objects.get(title = offset) + name = pt_id + + + absolute_url_node = name.get_absolute_url() + for each in parenttype: + attributetype.append(each.subjecttype_of.all()) + + attributetype = [num for elem in attributetype for num in elem] + + for each in range(len(attributetype)): + rdict.update({attributetype[each]:str(Attributetype.get_dataType_display(attributetype[each]))}) + + if request.method=='POST': + form = ContextForm(rdict,request.POST) + bound= form.is_bound + + if form.is_valid(): + for key,val in rdict.items(): + testlst.append(str(request.POST[str(key)+"_"+str(val)])) + + for val in range(len(testlst)): + if testlst[val] != '' : + savedict = {'title':testlst[val],'slug':testlst[val], 'svalue':testlst[val], 'subject':pt_id, 'attributetype':rdict.keys()[val]} + att = Attribute.objects.create(**savedict) + att.save() + + return HttpResponseRedirect(absolute_url_node) + else: + form = ContextForm(rdict) + + + template = "objectapp/fillAT.html" + context = RequestContext(request,{'form' : form, 'name':name,'absolute_url_node':absolute_url_node}) + return render_to_response(template,context) + + + +# def dynamic_objecttype(request,iden): #gb view for dynamic at +# testlst = [] +# attributetype = [] +# rdict = {} +# try: +# offset = str(iden) +# except ValueError: +# raise Http404() + +# #uid = Gbobject.objects.get(title = offset) +# gb=Gbobject.objects.get(title=offset) +# parenttype = gb.objecttypes.all() +# pt_id = NID.objects.get(id = gb.id) + + +# for each in parenttype: +# attributetype.append(each.subjecttype_of.all()) + +# attributetype = [num for elem in attributetype for num in elem] + +# for each in range(len(attributetype)): +# rdict.update({attributetype[each]:str(Attributetype.get_dataType_display(attributetype[each]))}) + +# if request.method=='POST': +# form = ContextForm(rdict,request.POST) +# bound= form.is_bound + +# if form.is_valid(): +# for key,val in rdict.items(): +# testlst.append(str(request.POST[str(key)+"_"+str(val)])) + +# for val in range(len(testlst)): +# if testlst[val] != '' : +# savedict = {'title':testlst[val],'slug':testlst[val], 'svalue':testlst[val], 'subject':pt_id, 'attributetype':rdict.keys()[val]} +# att = Attribute.objects.create(**savedict) +# att.save() + +# return HttpResponseRedirect("/objects/") +# else: +# form = ContextForm(rdict) + + +# template = "objectapp/fillAT.html" +# context = RequestContext(request,{'form' : form}) +# return render_to_response(template,context) diff --git a/objectapp/views/dynamicRT.py b/objectapp/views/dynamicRT.py new file mode 100644 index 0000000..f078168 --- /dev/null +++ b/objectapp/views/dynamicRT.py @@ -0,0 +1,256 @@ +from gstudio.models import * +from objectapp.models import * +from django.http import * +from django.shortcuts import render_to_response +from django.template import RequestContext +from django.db import IntegrityError + + +def context_RT(request, gbid): + pt =[] #contains parenttype + reltype =[] #contains relationtype + titledict = {} #contains relationtype's title + inverselist = [] #contains relationtype's inverse + finaldict = {} #contains either title of relationtype or inverse of relationtype + listval=[] #contains keys of titledict to check whether parenttype id is equals to listval's left or right subjecttypeid + + #flag = 0 #check whether OT or OB, flag = 0 means it is OB + + # if its an OT, then parse separately + if Objecttype.objects.filter(title=str(gbid)): + flag = 1 + elif Gbobject.objects.filter(title = str(gbid)): + flag = 0 + elif Systemtype.objects.filter(title = str(gbid)): + flag = 2 + + if flag == 1: + pt.append(Objecttype.objects.get(title = str(gbid))) + name = NID.objects.get(title = str(gbid)) + + for i in range(len(pt)): + if Relationtype.objects.filter(left_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.get(left_subjecttype = pt[i].id)) + if Relationtype.objects.filter(right_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.get(right_subjecttype = pt[i].id)) + + # it converts 2 or more list as one list + #reltype = [num for elem in reltype for num in elem] #this rqud for filtering + + for i in reltype: + titledict.update({i:i.id}) + + + for i in range(len(titledict)): + listval.append(Relationtype.objects.get(title = titledict.keys()[i])) + inverselist.append(titledict.keys()[i].inverse) + + + for j in range(len(pt)): + for i in range(len(listval)): + if pt[j].id == listval[i].left_subjecttype_id : + finaldict.update({titledict.values()[i]:titledict.keys()[i]}) + elif pt[j].id == listval[i].right_subjecttype_id: + finaldict.update({titledict.values()[i]:inverselist[i]}) + + + elif flag == 0: + gb= Gbobject.objects.get(title=str(gbid)) + name = gb + pt = gb.objecttypes.all() + for i in range(len(pt)): + if Relationtype.objects.filter(left_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.get(left_subjecttype = pt[i].id)) + if Relationtype.objects.filter(right_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.get(right_subjecttype = pt[i].id)) + if Relationtype.objects.filter(left_subjecttype = gb): + reltype.append(Relationtype.objects.get(left_subjecttype = gb)) + if Relationtype.objects.filter(right_subjecttype = gb): + reltype.append(Relationtype.objects.get(right_subjecttype = gb)) + + + #reltype = [num for elem in reltype for num in elem] + + for i in reltype: + titledict.update({i:i.id}) + + + for i in range(len(titledict)): + listval.append(Relationtype.objects.get(title = titledict.keys()[i])) + inverselist.append(titledict.keys()[i].inverse) + + for j in range(len(pt)): + for i in range(len(listval)): + if pt[j].id == listval[i].left_subjecttype_id or gb.id == listval[i].left_subjecttype_id : + finaldict.update({titledict.values()[i]: titledict.keys()[i]}) + elif pt[j].id == listval[i].right_subjecttype_id or gb.id == listval[i].right_subjecttype_id: + finaldict.update({titledict.values()[i]:inverselist[i]}) + + elif flag == 2: + systype = Systemtype.objects.get(title = str(gbid)) + nodelist = [] + nodelist = systype.nodetype_set.all() + for i in nodelist: + pt.append(i.ref) + pt.append(systype) + name = NID.objects.get(title = str(gbid)) + + for i in range(len(pt)): + if Relationtype.objects.filter(left_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.get(left_subjecttype = pt[i].id)) + if Relationtype.objects.filter(right_subjecttype = pt[i].id): + reltype.append(Relationtype.objects.get(right_subjecttype = pt[i].id)) + + # it converts 2 or more list as one list + #reltype = [num for elem in reltype for num in elem] #this rqud for filtering + + for i in reltype: + titledict.update({i:i.id}) + + + for i in range(len(titledict)): + listval.append(Relationtype.objects.get(title = titledict.keys()[i])) + inverselist.append(titledict.keys()[i].inverse) + + + for j in range(len(pt)): + for i in range(len(listval)): + if pt[j].id == listval[i].left_subjecttype_id : + finaldict.update({titledict.values()[i]:titledict.keys()[i]}) + elif pt[j].id == listval[i].right_subjecttype_id: + finaldict.update({titledict.values()[i]:inverselist[i]}) + + + absolute_url_node = name.get_absolute_url() + + template="objectapp/selectRT.html" + context = RequestContext(request,{'final':finaldict , 'gb':name ,'gbid':name.id, 'absolute_url_node':absolute_url_node}) + return render_to_response(template,context) + + +def context_member(request,relid, memid):#id of relationtype, id of selected object + try: + relid = int(relid) #relationtype + memid = int(memid) #left member id + except: + raise Http404() + + # checks wheter memid is OT or OB + flag=0 #means OB + + if Objecttype.objects.filter(id = memid): + flag=1 + + nt =[] #contains parent as <Nodetype:parent> + pt= [] #contains parent as <Objecttype:parent> + + if flag == 1: + pt.append(Objecttype.objects.get(id=memid)) + + else: + gb = Gbobject.objects.get(id = memid) + nt = gb.objecttypes.all() + for i in range(len(nt)): #conversion of nodetype in objecttype + pt.append(Objecttype.objects.get(id = nt[i].id)) + + memlist = [] #contains OB and OT for appearing in 1st combo box + + r = Relationtype.objects.get(id = relid) #contains RelationType + + # extracting left and right applicable nodetypes(OB or OT) of RelationType + lefttype = str(r.left_applicable_nodetypes) + righttype = str(r.right_applicable_nodetypes) + + if lefttype == righttype: + if lefttype == "OB" and righttype == "OB": + + if r.left_subjecttype_id == memid: + memlist.append(Gbobject.objects.get(id = r.right_subjecttype_id)) + else : + memlist.append(Gbobject.objects.get(id = r.left_subjecttype_id)) + + elif lefttype == "OT" and righttype == "OT": + for each in range(len(pt)): + if r.left_subjecttype_id == memid or r.left_subjecttype_id == pt[each].id: + o = Objecttype.objects.get(title = NID.objects.get(title=(r.right_subjecttype).title)) + memlist.append(o) + for i in o.get_members: + memlist.append(i) + # elif r.right_subjecttype_id == memid or r.right_subejcttype_id == pt[each].id: + else: + o = Objecttype.objects.get(title = NID.objects.get(title=(r.left_subjecttype).title)) + memlist.append(o) + for i in o.get_members: + memlist.append(i) + else: + if r.left_subjecttype_id == memid: + if righttype == "OB": + memlist.append(Gbobject.objects.get(id = r.right_subjecttype_id)) + + else : + o = Objecttype.objects.get(title = NID.objects.get(title=(r.right_subjecttype).title)) + memlist.append(o) + for i in o.get_members: + memlist.append(i) + + else: + if lefttype == "OB": + memlist.append(Gbobject.objects.get(id = r.left_subjecttype_id)) + + else : + o = Objecttype.objects.get(title = NID.objects.get(title=(r.left_subjecttype).title)) + memlist.append(o) + for i in o.get_members: + memlist.append(i) + + memdict = {} #converting list into dict and to set id of right member as hidden field + for i in memlist: + memdict.update({i.id:i}) + + + template="objectapp/fillRT.html" + context = RequestContext(request,{'memdict':memdict}) + return render_to_response(template,context) + +def context_save(request,leftmem, reltype, rightmem): + try: + leftmem = int(leftmem) + reltype = int(reltype) + rightmem = int(rightmem) + + relation = Relationtype.objects.get(id = reltype) + rightrole = relation.right_subjecttype_id + leftrole = relation.left_subjecttype_id + flag = 1 + if Objecttype.objects.filter(id = leftmem): + if leftmem == leftrole : + flag = 0 + print "Objecttype flag = 0 " + else: + print "Objecttype flag = 1 " + elif Gbobject.objects.filter(id = leftmem): + gb = Gbobject.objects.get(id = leftmem) + pt = gb.objecttypes.all() + for i in range(len(pt)): + if leftmem == leftrole or pt[i].id == leftrole: + flag = 0 + print "Object flag = 0" + else: + print "Object flag = 1" + if flag == 0: + savedict = {'title':relation, 'slug':relation, 'left_subject_id':leftmem, 'right_subject_id':rightmem, 'relationtype_id':reltype, 'left_subject_scope':' ', 'right_subject_scope':' ', 'relationtype_scope':' ' } + else: + savedict = {'title':relation, 'slug':relation, 'left_subject_id':rightmem, 'right_subject_id':leftmem, 'relationtype_id':reltype, 'left_subject_scope':' ', 'right_subject_scope':' ', 'relationtype_scope':' '} + + rtt = Relation.objects.create(**savedict) + rtt.save() + print "leftmem"+ str(leftmem) + " rightmem" + str(rightmem) + " reltype" +str(reltype)+ " leftrole"+ str(leftrole) + " rightrole " + str(rightrole) + print savedict + + return HttpResponseRedirect("/nodetypes/") + #return savedict + + except IntegrityError: #Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails, duplicate key, etc. + raise Http404() + #pass + |