[web2py] Re: How to get the last few records except the last record

2017-10-26 Thread sesenmaister
records  = db(db.post.author == auth.user_id).select(orderby=(db.post.ALL, 
limitby=(0,10))*[:-1]*

On Thursday, October 26, 2017 at 7:03:00 AM UTC+2, Maurice Waka wrote:
>
> If using the code: limitby=(0,10) am able to get the last 10 records,  Is 
> there a way to get the same(last few records) except the very last 
> record(last record posted to the db) from the db.
>  I have tried:
> records  = db(db.post.author == auth.user_id).select(orderby=(db.post.ALL, 
> limitby=(0,-9))...getting a blank screen instead
> regards
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: IntegrityError('FOREIGN KEY constraint failed',)

2017-10-25 Thread sesenmaister
Hi, your shown code is incomplete. It seems you are doing an insert or 
update to the db.

This "FOREIGN KEY constriaint failed" is meaning that in one of your 
referenced fields [db.student.guardian, db.student.class_name] you tried to 
reference a registry that doesn't exist on the parent tables [db.guardian, 
db.class_name]

As an example, *db.student.insert(db.guardian=2)* will raise this error if 
*db.guardian(2)==None*  (doesn't exist).




On Wednesday, October 25, 2017 at 9:55:28 AM UTC+2, mostwanted wrote:
>
>
>
> *WHEN I TRY ENTERING A STUDENT'S DETAILS AND SELECTING THEIR GUARDIAN AS 
> FROM THE DROP DOWN MENU AS REFERNCED I GET A FOREIGN CONSTRAINT FAILED 
> ERROR MESSAGEMY TABLES*
>
> db.define_table('guardian',
> Field('surname', requires=IS_NOT_EMPTY()),
> Field('name', requires=IS_NOT_EMPTY()),
> Field('contact_number'),
> format='%(surname)s')
> 
> db.define_table('student',
> Field('surname', requires=IS_NOT_EMPTY()),
> Field('name', requires=IS_NOT_EMPTY()),
> Field('photo', 'upload', requires=IS_NOT_EMPTY()),
> Field('guardian', 'reference guardian'),
> Field('class_name', 'reference student_class'),
> Field('dob', 'date', requires=IS_NOT_EMPTY()),
> format='%(surname)s')
>
> *MY CONTROLLER*
>
> def show_students():
> show_students=db(db.student).select(db.student.ALL)
> return locals()
>
>
>
> *MY VIEW*
> SELECT A STUDENT TO VIEW THEIR PROFILE
> 
> 
> SURNAME
> NAME
> CLASS
> GUARDIAN
> 
> {{for students in show_students:}}
> 
> {{=A('VIEW', _class="glyphicon glyphicon-user", 
> _href=URL('student_profile', args=students.id))}} | 
>  {{=students.surname}}
> {{=students.name}}
> {{=students.class_name.class_name}}
> {{=students.guardian.guardian}}
> 
> {{pass}}
> 
> 
>
>
> *MY TRACEBACK ERROR*
>  FOREIGN KEY constraint failed 
>
>
>
> Traceback (most recent call last):
>   File "/home/mostwanted/web2py/gluon/restricted.py", line 219, in restricted
> exec(ccode, environment)
>   File "/home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py" 
> , line 
> 696, in 
>   File "/home/mostwanted/web2py/gluon/globals.py", line 409, in 
> self._caller = lambda f: f()
>   File "/home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py" 
> , line 
> 147, in insert
> if form.accepts(request.vars, session):
>   File "/home/mostwanted/web2py/gluon/sqlhtml.py", line 1862, in accepts
> self.vars.id = self.table.insert(**fields)
>   File "/home/mostwanted/web2py/gluon/packages/dal/pydal/objects.py", line 
> 734, in insert
> ret = self._db._adapter.insert(self, row.op_values())
>   File "/home/mostwanted/web2py/gluon/packages/dal/pydal/adapters/base.py", 
> line 486, in insert
> raise e
> IntegrityError: FOREIGN KEY constraint failed
>
> Error snapshot [image: help] 
> 
>  
>
> (FOREIGN KEY constraint failed) 
>
> inspect attributes 
> Frames 
>
>- 
>
>*File /home/mostwanted/web2py/gluon/restricted.py in restricted at 
>line 219* code arguments variables 
>- 
>
>*File 
>/home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py in 
> at line 696* code arguments variables 
>- 
>
>*File /home/mostwanted/web2py/gluon/globals.py in  at line 409* 
>code arguments variables 
>- 
>
>*File 
>/home/mostwanted/web2py/applications/SRMS/controllers/appadmin.py in 
> insert 
>at line 147* code arguments variables 
>- 
>
>*File /home/mostwanted/web2py/gluon/sqlhtml.py in accepts at line 1862* 
>code arguments variables 
>- 
>
>*File /home/mostwanted/web2py/gluon/packages/dal/pydal/objects.py in 
>insert at line 734* code arguments variables 
>- 
>
>*File 
>/home/mostwanted/web2py/gluon/packages/dal/pydal/adapters/base.py in 
> insert 
>at line 486* code arguments variables 
>Function argument list 
>
>(self=, table=surname, name, photo, guardian, class_name, dob)>, 
>fields=[(, 'Leburu'), (object>, 'Percy'), (, '2010-10-05'), 
>(, 5), (, 21), 
>(, 
>'student.photo.a21f46af61cba907.706963322e6a7067.jpg')])
>Code listing 
>
>481.
>482.
>483.
>484.
>485.
>486.
>
>487.
>488.
>489.
>490.
>
>self.execute(query)
>except:
>e = sys.exc_info()[1]
>if hasattr(table, '_on_insert_error'):
>return table._on_insert_error(table, fields, e)
>raise e
>

[web2py] Re: IS_NOT_EMPTY_OR(IS_IN_SET((),multiple=True))

2016-05-09 Thread sesenmaister


When using the validator IS_IN_SET(..)  , it will require the values are in the 
set. So it will require not to be empty.







On Sunday, May 8, 2016 at 6:51:23 PM UTC+2, billmac...@gmail.com wrote:
>
> I would like to have a set that requires to be not empty. But looking at 
> the documentation there are no such thing as IS_NOT_EMPTY_OR like we have 
> for  IS_EMPTY_OR. Any thoughts?
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: How To Select Only The Latest Rows from a Table

2016-05-09 Thread sesenmaister
What does mean "DOES NOT WORK? Are you getting an OperationalError?

Use the argument *groupby *instead of *distinct*, and you'll get the 
desired results. 


On Sunday, May 8, 2016 at 9:33:44 AM UTC+2, PRACHI VAKHARIA wrote:
>
>
>
> *How To Select Only The Latest Rows from a Table*
>
> For a Table structure as below:
> *Table(*
> *PrimaryKey,*
> *FieldName1,*
> *FieldName2,*
> *Time)*
>
> FieldName1 and FieldName2 are not unique.
>
> *Goal: To select only the latest row for each FieldName2*
>
> *Items = db(db.Table.FieldName1 != Value1).select(orderby=~db.Table.Time, 
> limitby=limitby, distinct=db.Table.FieldName2)*
>
> How to write the above statement so that it selects All the rows from the 
> Table such that:
> – For any given condition which here is: *db.Table.FieldName1 != Value1** 
> (works)*
> – Select All Rows from Table* (works)*
> – Order those rows by Time field* (works)*
> – limit selection by limitby number* (works)*
> *– And Selects only the Latest row for FieldName2 : Latest measured by 
> Time** ( **distinct=db.Table.FieldName2  DOES NOT WORK)*
>
>
> Thank you, very much for reading. Only the part of selecting the distinct 
> last element for FieldName2 does not work and I cannot figure it out. I 
> hope someone can help.
>
>
>
> —
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [web2py] Re: Table.import_from_csv_file preserving ids

2016-03-04 Thread sesenmaister
For the record,

To import preserving ids,  import_from_csv_file() needs as parameters:
(given a csv with `id` column and not using another unique column (ex. 
`uuid`))

*id_offset = {} id_map = None*

If the table is not empty, it's needed to tuncate() before importing, or 
use parameter restore=True for the function to do the truncate()
db.table.import_from_csv_file(ofile, id_offset={}, id_map=None)

The bits inside the function import_from_csv_file in dal.py are:

if not (id_map or cid is None or id_offset is None or unique_idx):
csv_id = long(line[cid])
curr_id = self.insert(**dict(items))
if first:
first = False
# First curr_id is bigger than csv_id,
# then we are not restoring but
# extending db table with csv db table
id_offset[self._tablename] = (curr_id-csv_id) \
if curr_id > csv_id else 0
# create new id until we get the same as old_id+offset
while curr_id < csv_id+id_offset[self._tablename]:
self._db(self._db[self][colnames[cid]] == curr_id).delete()
curr_id = self.insert(**dict(items))


On Tuesday, August 21, 2012 at 3:35:56 AM UTC+2, Alan Etkin wrote:
>
> > Here's a part of the function import_from_csv_file in trunk dal.py. 
> Judging 
> > by its description it appears to provide the ability to preserve the 
> ids. 
>
> Yes I saw it too, but I cannot find within the code where the original 
> ids are used. I added an extra id_preserve argument and modified the 
> method to do insert or update without id mapping, but I could not test 
> it so far. Besides, as you already mentioned, the non-trunk version 
> does not support preserving ids and setting id_map parameter doesn't 
> either. 
>
> Regards 
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] truncate() not resetting the counter id in one table

2012-06-13 Thread sesenmaister
Some evil happended, and truncate() has stopped working properly in editor: 
doesn't reset the counter id, as did before, but only for one of my tables.

def cleaning_db():
 db.table1.truncate()
 db.table2.truncate()

 def myAction(): 
  cleaning_db()
  db.table1.insert(car='chev')
  db.table2.insert(car='chev')
  return len(db().select(db.table1.ALL)==len(db().select(db.table2.ALL)



myAction returns False

Counter id is at position 1 for table2. For table1 is at position 3892 (and 
counting...)

I was programming from editor in localhost, filling tables using the insert 
and update methods, nothing complex. So I'm very surprised. How could it 
be? How can I prevent this to happen?


[web2py] Re: truncate() not resetting the counter id in one table

2012-06-13 Thread sesenmaister
I'm using SQLDB('sqlite://mydb.db').

I was extracting info from a table using regular expressions, and inserting 
and updating the info in a new table. I had truncate()d a lot of times the 
table which later had the problem. 


On Thursday, June 14, 2012 5:53:34 AM UTC+2, Massimo Di Pierro wrote:


 db.table.truncate just runs the sql TRUNCATE TABLE table. There is 
 basically no web2py logic outside the SQL. Which database are you using? Is 
 there an event that triggered the change in behavior?


 On Wednesday, 13 June 2012 21:16:12 UTC-5, sesenmaister wrote:

 Some evil happended, and truncate() has stopped working properly in 
 editor: doesn't reset the counter id, as did before, but only for one of my 
 tables.

 def cleaning_db():
 db.table1.truncate()
 db.table2.truncate()

 def myAction(): 
  cleaning_db()
  db.table1.insert(car='chev')
  db.table2.insert(car='chev')
  return 
 len(db().select(db.table1.ALL)==len(db().select(db.table2.ALL)



 myAction returns False

 Counter id is at position 1 for table2. For table1 is at position 3892 
 (and counting...)

 Using db.table1.drop() for once, database works fine again.

 But I was programming from editor in localhost, filling tables using the 
 insert and update methods, nothing complex. So I'm very surprised. How can 
 I prevent this to happen again?



[web2py] Re: For all users using web2py editor on Firefox: solution to the blurry or ghosty text

2012-06-07 Thread sesenmaister
Sorry, the good value for *document.getElementById('**
textarea').style.opacity* is *0.1*

Value 0, is thiner than in chrome and the cursor disappear.


Re: [web2py] Fluxflex will be shut down and no longer available on June 30, 2012

2012-06-06 Thread sesenmaister
Andrew, I have the same question. Today I wanted to get payed hosting on 
FluxFlex. And now I have no idea where to go. I'm not pro, stdudying python 
and web2py for pleasure, I've got no idea how to install web2py in a 
normal server and have no idea if all hostings permit that. So FluxFlex 
was my salvation. Now I'm gonna loose so many days for the simple thing of 
deploying. If any advice in getting a way, please I'd be very very glad.

jsesen

El miércoles, 6 de junio de 2012 19:35:44 UTC+2, Andrew escribió:

 So where do we go now?



Re: [web2py] Hosting services recommendation

2012-06-06 Thread sesenmaister
lot of thanks Anthony, now that fluxflex is going down this link pointed me 
to new valid options

jsesen

El viernes, 6 de enero de 2012 15:54:41 UTC+1, Anthony escribió:

 See https://groups.google.com/d/topic/web2py/e2SL5ViOhL4/discussion



[web2py] For all users using web2py editor on Firefox: solution to the blurry or ghosty text

2012-06-04 Thread sesenmaister
 When using the web2py editor on firefox, text gets 1 pixel fatter, and 
makes the sensation of being blurry. I've got friends that seem comfortable 
with this little effect. But it disturbed me a lot, and therefore I went to 
Chrome, where the text appears just how it must. And I was some upset, 
because of that. 

Taking a look to the css in Firebug, appears a class .hidden, with opacity 
set to 0.2.

For the sake of hell thanks to the *Greasemonkey plugin for firefox*, that 
permits using scripts things as the CSS for modifying web surfing.

Install plugin, and create a new user script:

*Name*: whatever_name
*Namespace*:  whatever_unique_name
*Description*: blablabla

here goes in wich webs we want the script to be running, so: 
*Includes*:  http*/admin/default/edit/*

And then, add the magic words to the generated new script:
document.getElementById('textarea').style.opacity = 0;


I was very upset. I like firefox, and I hate been forced to change to 
another browser. I seeked a lot and anything I found helped me. So I hope 
this to be so helpful for others as it has been to me.

jsesen






[web2py] For all users using web2py editor on Firefox: solution to the blurry or ghosty text

2012-06-04 Thread sesenmaister
 

 When using the web2py editor on firefox, text gets 1 pixel fatter, and 
makes the sensation of being blurry. I've got friends that seem comfortable 
with this little effect. But it disturbed me a lot, and therefore I went to 
Chrome, where the text appears just how it must. And I was some upset, 
because of that. 

 

Taking a look to the css in Firebug, appears a class .hidden, with opacity 
set to 0.2.

 

For the sake of hell thanks to the Greasemonkey plugin for firefox, that 
permits using scripts things as the CSS for modifying web surfing.

 

Install plugin, and create a new user script:

 

Name: whatever_name

Namespace:  whatever_unique_name

Description: blablabla

 

here goes in wich webs we want the script to be running, so: 

Includes:  http*/admin/default/edit/*

 

And then, add the magic words to the generated new script:

document.getElementById('textarea').style.opacity = 0;

 

 

I was very upset. I like firefox, and I hate been forced to change to 
another browser. I seeked a lot and anything I found helped me. So I hope 
this to be so helpful for others as it has been to me.

 

jsesen


[web2py] Re: Why the web2py shell returns different results?

2012-05-16 Thread sesenmaister
1.-both editor and shell use different type of encofing: sure

2.-both editor and shell throw the same answer: yes
 import sys
 sys.stdin.encoding
‘cp850'

3.-both editor and shell throw the same answer: yes
import sys
sys.getdefaultencoding()
'ascii'

4.-due to my lack of knowledge, I must be practical, and forget the 
environent encoding and go to the point directly

html_txt=urllib2.urlopen(url).read()
print html_txt.headers.getheader('Content-Type')
text/html; charset=iso-latin-1

ok, its encoding is iso-latin-1 (same as iso-8859-1) so, If I want my 
documents in UTF-8:
html_inPreferredEncoding=unicode(html_txt,'iso-8859-1').encode('utf-8')

the same as:
html_inPreferredEncoding=html_txt.unicode('iso-8859-1').encode('utf-8')




[web2py] Why the web2py shell returns different results?

2012-05-09 Thread sesenmaister
When I use web2py 1.99.7 shell  (web2py.exe -S welcome) :

 unicode('Äpple','utf-8')
Traceback (most recent call last):
  File console, line 1, in module
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8e in position 0: 
unexpected code byte

 unicode('Äpple','iso-8859-1')
u'\x8epple'

When running normally web2py (as localhost 127.0.0.1):

def codificacion1():
response.write(unicode('Äpple','utf-8'))
response.write('br,escape=False')
response.write(unicode('Äpple','iso-8859-1'))
return ()

it returns:

Äpple Äpple

How can I do for having same results in the shell?



Re: [web2py] Why the web2py shell returns different results?

2012-05-09 Thread sesenmaister


El miércoles, 9 de mayo de 2012 22:48:29 UTC+2, Ricardo Pedroso escribió:

 On Wed, May 9, 2012 at 7:56 PM, sesenmaister sesenmais...@gmail.com 
 wrote: 
  When I use web2py 1.99.7 shell  (web2py.exe -S welcome) : 
  
  unicode('Äpple','utf-8') 
  Traceback (most recent call last): 
File console, line 1, in module 
  UnicodeDecodeError: 'utf8' codec can't decode byte 0x8e in position 0: 
  unexpected code byte 

 Here you are saying to unicode function that the string is encoded in 
 utf-8 so it will try to 
 decode using utf-8 codec but your terminal emulator is configured to 
 iso-8859-1 
 so when you enter 'Äpple' you put it encoded in iso-8859-1 


  unicode('Äpple','iso-8859-1') 
  u'\x8epple' 


  When running normally web2py (as localhost 127.0.0.1): 
  
  def codificacion1(): 
  response.write(unicode('Äpple','utf-8')) 
  response.write('br,escape=False') 
  response.write(unicode('Äpple','iso-8859-1')) 
  return () 
  
  it returns: 
  
  Äpple Äpple 

 Here you are using some editor configured to use utf-8. So when you write 
 'Äpple' is in utf-8. 


 To see the differences from both worlds you can do in shell: 

 print repr('Äpple') 

 In web2py: 

 def codificacion1(): 
 response.write(repr('Äpple')) 

 And I am almost 100% sure that you will get a different sequence of 
 bytes. 
  

Que grande, you bet you're true.  It's what you said. 



  How can I do for having same results in the shell? 

 Your terminal emulator and your editor both need to have the same 
 capabilities and configured identically. 


In both emulator and editor I had got:
 
import sys
sys.stdin.encoding
'cp850'
 
So I thouught they were in the same way.

Is there a non very comlex way to set the emulator to be same as the editor?
  
 


 Ricardo