Skip to content

Commit

Permalink
implemented 'edit' view of 'section' table
Browse files Browse the repository at this point in the history
tiote can now edit rows in a table. It was left unfunctional previously.

Navigation() can now set hash key without firing navigationChangedEvent
  • Loading branch information
Biekei Ojo committed Apr 24, 2012
1 parent 7a6e7ef commit d2a1531
Show file tree
Hide file tree
Showing 12 changed files with 402 additions and 168 deletions.
62 changes: 53 additions & 9 deletions tiote/forms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django import forms
from django.forms.formsets import formset_factory
from django.core import validators
from django.utils.datastructures import SortedDict
from itertools import chain
from django.utils.encoding import StrAndUnicode, force_unicode
from django.utils.html import escape, conditional_escape
from django.utils.safestring import mark_safe
from django.forms import widgets

from tiote import utils

Expand Down Expand Up @@ -72,15 +72,40 @@ def render(self, name, value, attrs=None, choices=()):
output.append(u'</ul>')
return mark_safe(u'\n'.join(output))


class RadioFieldRenderer(StrAndUnicode):
"""
An object used by RadioSelect to enable customization of radio widgets.
"""

def __init__(self, name, value, attrs, choices):
self.name, self.value, self.attrs = name, value, attrs
self.choices = choices

def __iter__(self):
for i, choice in enumerate(self.choices):
yield widgets.RadioInput(self.name, self.value, self.attrs.copy(), choice, i)

def __getitem__(self, idx):
choice = self.choices[idx] # Let the IndexError propogate
return widgets.RadioInput(self.name, self.value, self.attrs.copy(), choice, idx)

def __unicode__(self):
return self.render()

def render(self):
"""Outputs a <ul> for this set of radio fields."""
return mark_safe(u'<ul class="inputs-list">\n%s\n</ul>' % u'\n'.join([u'<li>%s</li>'
% force_unicode(w) for w in self]))


class InsertForm(forms.BaseForm):
def __init__(self, dialect, tbl_struct, tbl_indexes=(), **kwargs):
# keys = ['column','type','null','default','character_maximum_length','numeric_precision', 'extra','column_type']
f = SortedDict()
# dict to increase performance
_l = {}
for i in range(len(tbl_indexes)):
if _l.has_key(tbl_indexes[i][0]): _l[ tbl_indexes[i][0] ].append(i)
else: _l[ tbl_indexes[i][0] ] = [i]
indexed_cols = utils.fns.parse_indexes_query(tbl_indexes)

# determing type of form fields for each column
for row in tbl_struct['rows']:
_c = []
Expand Down Expand Up @@ -145,8 +170,8 @@ def __init__(self, dialect, tbl_struct, tbl_indexes=(), **kwargs):
f[row[0]].help_text = " ".join(_il)
if row[3]: f[row[0]].default = row[3] #default
# work with indexes
if _l.has_key( row[0] ):
for i in _l[row[0]]:
if indexed_cols.has_key( row[0] ):
for i in indexed_cols[row[0]]:
if dialect == 'mysql' and tbl_indexes[i][2] == "PRIMARY KEY":
if row[len(row) - 2].count('auto_increment'): _c.pop(0) # make it not required

Expand All @@ -162,7 +187,25 @@ def __init__(self, dialect, tbl_struct, tbl_indexes=(), **kwargs):

self.base_fields = f
forms.BaseForm.__init__(self, **kwargs)



class EditForm(InsertForm):

def __init__(self, dialect, tbl_struct, tbl_indexes=(), **kwargs):
InsertForm.__init__(self, dialect, tbl_struct, tbl_indexes, **kwargs)

# working with self.fields attribute because this is an instance of InsertForm
# - and not a whole form class definition
self.fields['save_changes_to'] = forms.ChoiceField(
label = 'save changes to',
choices = (('update_row', 'Same row (UPDATE statment)',),
('insert_row', 'Another row (INSERT statement)')
),
initial = 'update_row',
widget = forms.RadioSelect(attrs={'class':'inputs-list'}, renderer = RadioFieldRenderer)
)


# New Database Form
class mysqlDbForm(forms.Form):
def __init__(self, templates=None, users=None, charsets=None, **kwargs):
Expand Down Expand Up @@ -515,7 +558,8 @@ class pgsqlSequenceForm(forms.Form):
class QueryForm(forms.Form):
query = forms.CharField(label = u"Enter your query:",
widget = forms.Textarea(attrs={'class':'required span10','rols':0, 'cols':0, 'style':'height:100px;resize:none;'},) )



def get_dialect_form(form_name, dialect):
'''
structure of dialect_forms:
Expand Down
5 changes: 2 additions & 3 deletions tiote/sql.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from sqlalchemy import create_engine, text
from sqlalchemy.engine.url import URL
from sqlalchemy.exc import OperationalError, ProgrammingError, \
DatabaseError
from sqlalchemy.exc import OperationalError, ProgrammingError, DatabaseError
import datetime
# sqlaclehemy modules

Expand Down Expand Up @@ -64,7 +63,7 @@ def generate_query(query_type, dialect='postgresql', query_data=None):
else: prfx = ""

#queries
if query_type == 'get_row':
if query_type == 'get_single_row':
q0 = "SELECT * FROM {0}{tbl} WHERE {where} LIMIT 1".format(prfx, **query_data)
return (q0,)

Expand Down
13 changes: 12 additions & 1 deletion tiote/static/css/tiote.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ div.table-options a, div.table-options span, div.table-options p {
font-size: 12px;
margin-bottom: 3px;
}

div.table-options p span {
color: #888;
}
div.table-options .paginatn a.last {
padding-right: 6px;
}
Expand Down Expand Up @@ -108,7 +112,7 @@ h5.heading {
}

.subnav .active a {
color: #404040;
color: #888;
}

.undefined {
Expand All @@ -119,6 +123,13 @@ div.white-bg, p.white-bg {
background-color: #fff;
}

.topbar .nav li.active {
color: #fff;
}

.topbar .nav li.active a {
font-weight: bold;
}
/*
SIDEBAR
*/
Expand Down
Loading

0 comments on commit d2a1531

Please sign in to comment.