Skip to content
Snippets Groups Projects
Commit c4c7edc5 authored by Bruno Nocera Zanette's avatar Bruno Nocera Zanette
Browse files

Implement a Better solution to Comma's problem


This commit implemets a more elegant solution to the comma's problem.
On the function call it is given whether the flag is True (to use comma)
or False (to not comma), or an expression.
This expression is based on total rows and the current row.
If row is less then max row it is True, so it will use comma.

Signed-off-by: default avatarBruno Nocera Zanette <brunonzanette@gmail.com>
parent f00bf4b3
Branches
No related tags found
No related merge requests found
......@@ -45,6 +45,8 @@ def write_groupmembers_subsection (db, xml, group_guid):
for (user_id, user_name, user_username)\
in group_members:
row=row+1
wrt.write_open_tag(xml,3,"","{")
prefix='profile/'
......@@ -52,17 +54,9 @@ def write_groupmembers_subsection (db, xml, group_guid):
wrt.write_tag(xml,4,"uid",user_attr,",")
wrt.write_tag(xml,4,"usuario",user_name,"")
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < group_members.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < group_members.rowcount))
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
group_members.close()
#--------------------------------------------------------------------#
......@@ -85,6 +79,8 @@ def write_groupfiles_subsection (db, xml, group_guid):
owner_id, owner_name, owner_username, time)\
in group_files:
row=row+1
wrt.write_open_tag(xml,3,"","{")
prefix='file/download/'
......@@ -106,17 +102,9 @@ def write_groupfiles_subsection (db, xml, group_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < group_files.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < group_files.rowcount))
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
group_files.close()
#--------------------------------------------------------------------#
......@@ -139,6 +127,8 @@ def write_groupforumtopics_subsection (db, xml, group_guid):
owner_id, owner_name, owner_username, time)\
in group_forumtopics:
row=row+1
wrt.write_open_tag(xml,3,"","{")
prefix='discussion/view/'
......@@ -156,17 +146,9 @@ def write_groupforumtopics_subsection (db, xml, group_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < group_forumtopics.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < group_forumtopics.rowcount))
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
group_forumtopics.close()
#--------------------------------------------------------------------#
......@@ -189,6 +171,8 @@ def write_groupbookmarks_subsection (db, xml, group_guid):
owner_id, owner_name, owner_username, time)\
in group_bookmarks:
row=row+1
wrt.write_open_tag(xml,3,"","{")
# 90 = select * from elgg_metastrings where string='address';
......@@ -210,17 +194,9 @@ def write_groupbookmarks_subsection (db, xml, group_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < group_bookmarks.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < group_bookmarks.rowcount))
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
group_bookmarks.close()
#--------------------------------------------------------------------#
......@@ -243,6 +219,8 @@ def write_grouppages_subsection (db, xml, group_guid):
owner_id, owner_name, owner_username, time)\
in group_pages:
row=row+1
wrt.write_open_tag(xml,3,"","{")
prefix='pages/view/'
......@@ -260,17 +238,9 @@ def write_grouppages_subsection (db, xml, group_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < group_pages.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < group_pages.rowcount))
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
group_pages.close()
#--------------------------------------------------------------------#
......@@ -293,6 +263,8 @@ def write_groupvideos_subsection (db, xml, group_guid):
owner_id, owner_name, owner_username, time)\
in group_videos:
row=row+1
# 477 = select * from elgg_metastrings where string='video_url';
video_link=wrt.post_content(db,post_guid, 477)
......@@ -314,17 +286,9 @@ def write_groupvideos_subsection (db, xml, group_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < group_videos.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,"}",(row < group_videos.rowcount))
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
group_videos.close()
#--------------------------------------------------------------------#
......@@ -347,6 +311,8 @@ def write_groupevents_subsection (db, xml, group_guid):
owner_id, owner_name, owner_username, time)\
in group_events:
row=row+1
wrt.write_open_tag(xml,3,"","{")
# 18 = select * from elgg_metastrings where string='venue';
......@@ -388,17 +354,9 @@ def write_groupevents_subsection (db, xml, group_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < group_events.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,"}",(row < group_events.rowcount))
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,2,"]")
wrt.write_close_tag(xml,2,"]",False)
group_events.close()
#--------------------------------------------------------------------#
......@@ -451,18 +409,10 @@ def write_groups_section(db, xml_file):
write_groupvideos_subsection(db, xml, guid)
write_groupevents_subsection(db, xml, guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < groups_info.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,1,sep)
wrt.write_close_tag(xml,1,"}",(row < groups_info.rowcount))
wrt.write_close_tag(xml,0,"]")
wrt.write_close_tag(xml,0,"}")
wrt.write_close_tag(xml,0,"]",False)
wrt.write_close_tag(xml,0,"}",False)
groups_info.close()
......
......@@ -42,6 +42,8 @@ def write_userfriends_subsection (db, xml, user_guid):
for (friend_id, friend_name, friend_username)\
in friends_info:
row=row+1
wrt.write_open_tag(xml,3,"","{")
prefix='profile/'
......@@ -49,18 +51,10 @@ def write_userfriends_subsection (db, xml, user_guid):
wrt.write_tag(xml,4,"uid",friend_attr,",")
wrt.write_tag(xml,4,"usuario",friend_name,"")
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < friends_info.rowcount):
sep="},"
else:
sep="}"
wrt.write_tag(xml,4,str(row),str(friends_info.rowcount),"")
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < friends_info.rowcount))
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
friends_info.close()
#--------------------------------------------------------------------#
......@@ -76,6 +70,8 @@ def write_userowngroup_subsection (db, xml, user_guid):
for (group_id, group_title)\
in user_owngroups:
row=row+1
wrt.write_open_tag(xml,4,"","{")
prefix='groups/profile/'
......@@ -83,17 +79,9 @@ def write_userowngroup_subsection (db, xml, user_guid):
wrt.write_tag(xml,5,"cid",group_attr,",")
wrt.write_tag(xml,5,"titulo",group_title,"")
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < user_owngroups.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,4,sep)
wrt.write_close_tag(xml,4,"}",(row < user_owngroups.rowcount))
wrt.write_close_tag(xml,3,"],")
wrt.write_close_tag(xml,3,"]",True)
user_owngroups.close()
#--------------------------------------------------------------------#
......@@ -109,6 +97,8 @@ def write_usermembergroup_subsection (db, xml, user_guid):
for (group_id, group_title)\
in user_membergroups:
row=row+1
wrt.write_open_tag(xml,4,"","{")
prefix='groups/profile/'
......@@ -116,17 +106,9 @@ def write_usermembergroup_subsection (db, xml, user_guid):
wrt.write_tag(xml,5,"cid",group_attr,",")
wrt.write_tag(xml,5,"titulo",group_title,",")
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < user_membergroups.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,4,sep)
wrt.write_close_tag(xml,4,"}",(row < user_membergroups.rowcount))
wrt.write_close_tag(xml,3,"]")
wrt.write_close_tag(xml,3,"]",False)
user_membergroups.close()
#--------------------------------------------------------------------#
......@@ -136,7 +118,7 @@ def write_usergroups_subsection (db, xml, user_guid):
wrt.write_open_tag(xml,2,"comunidades","{")
write_userowngroup_subsection(db, xml, user_guid)
write_usermembergroup_subsection(db, xml, user_guid)
wrt.write_close_tag(xml,2,"},")
wrt.write_close_tag(xml,2,"}",True)
#--------------------------------------------------------------------#
#--------------------------------------------------------------------#
......@@ -152,6 +134,8 @@ def write_userfiles_subsection (db, xml, user_guid):
for (post_guid, post_title, post_desc, time)\
in user_files:
row=row+1
prefix="file/download/"
file_link=wrt.urlparticipa(prefix,str(post_guid))
......@@ -168,17 +152,9 @@ def write_userfiles_subsection (db, xml, user_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < user_files.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,"}",(row < user_files.rowcount))
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
user_files.close()
#--------------------------------------------------------------------#
......@@ -196,6 +172,8 @@ def write_userblogs_subsection (db, xml, user_guid):
for (post_guid, post_title, post_desc, time)\
in user_blogs:
row=row+1
post_excerpt = db.cursor()
# 64 = select * from elgg_metastrings where string='excerpt';
......@@ -213,17 +191,9 @@ def write_userblogs_subsection (db, xml, user_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < user_blogs.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < user_blogs.rowcount))
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
user_blogs.close()
#--------------------------------------------------------------------#
......@@ -241,6 +211,8 @@ def write_userbookmarks_subsection (db, xml, user_guid):
for (post_guid, post_title, post_desc, time)\
in user_bookmarks:
row=row+1
# 90 = select * from elgg_metastrings where string='address';
bookmark_link=wrt.post_content(db,post_guid,90)
......@@ -256,17 +228,9 @@ def write_userbookmarks_subsection (db, xml, user_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < user_bookmarks.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < user_bookmarks.rowcount))
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
user_bookmarks.close()
#--------------------------------------------------------------------#
......@@ -284,6 +248,8 @@ def write_userpages_subsection (db, xml, user_guid):
for (post_guid, post_title, post_desc, time)\
in user_pages:
row=row+1
prefix='pages/view/'
post_attr=wrt.pidstr(wrt.urlparticipa(prefix,str(post_guid)))
wrt.write_open_tag(xml,3,"","{")
......@@ -295,17 +261,9 @@ def write_userpages_subsection (db, xml, user_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < user_pages.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,"}",(row < user_pages.rowcount))
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
user_pages.close()
#--------------------------------------------------------------------#
......@@ -338,17 +296,9 @@ def write_uservideos_subsection (db, xml, user_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < user_videos.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,"}",(row < user_videos.rowcount))
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,2,"],")
wrt.write_close_tag(xml,2,"]",True)
user_videos.close()
#--------------------------------------------------------------------#
......@@ -367,6 +317,8 @@ def write_userevents_subsection (db, xml, user_guid):
for (post_guid, post_title, post_desc, time)\
in user_events:
row=row+1
# 18 = select * from elgg_metastrings where string='venue';
venue=wrt.post_content(db, post_guid, 18)
......@@ -402,17 +354,9 @@ def write_userevents_subsection (db, xml, user_guid):
wrt.write_comments(db,xml,post_guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < user_events.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,3,sep)
wrt.write_close_tag(xml,3,"}",(row < user_events.rowcount))
wrt.write_close_tag(xml,2,"]")
wrt.write_close_tag(xml,2,"]",False)
user_events.close()
#--------------------------------------------------------------------#
......@@ -432,6 +376,8 @@ def write_users_section (db, xml_file):
for (guid, name, username)\
in users_info:
row=row+1
prefix='profile/'
user_attr=wrt.uidstr(wrt.urlparticipa(prefix,username))
wrt.write_open_tag(xml,1,"","{")
......@@ -454,18 +400,10 @@ def write_users_section (db, xml_file):
write_uservideos_subsection(db, xml, guid)
write_userevents_subsection(db, xml, guid)
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < users_info.rowcount):
sep="},"
else:
sep="}"
wrt.write_close_tag(xml,1,sep)
wrt.write_close_tag(xml,1,"}",(row < users_info.rowcount))
wrt.write_close_tag(xml,0,"]")
wrt.write_close_tag(xml,0,"}")
wrt.write_close_tag(xml,0,"]",False)
wrt.write_close_tag(xml,0,"}",False)
users_info.close()
......
......@@ -168,7 +168,10 @@ def write_open_tag (xml, l, tag_name, sep):
#--------------------------------------------------------------------#
#--------------------------------------------------------------------#
def write_close_tag (xml, l, sep):
def write_close_tag (xml, l, sep, comma_flag):
if comma_flag == True:
xml.write(lvl(l)+sep+","+"\n")
else:
xml.write(lvl(l)+sep+"\n")
#--------------------------------------------------------------------#
......@@ -184,12 +187,14 @@ def write_comments (db, xml, post_guid):
post_comments = db.cursor()
post_comments.execute(qry.qry_post_comments, (post_guid,))
row=0
write_open_tag(xml,4,"comentarios","[")
row=0
for (user_id, user_name, user_username, string, time)\
in post_comments:
row=row+1
write_open_tag(xml,5,"","{")
prefix='profile/'
......@@ -199,17 +204,9 @@ def write_comments (db, xml, post_guid):
write_tag(xml,6,"data",datestr(time),",")
write_tag(xml,6,"mensagem",cdata(string),"")
# Increment the row number to be able to know wheter is the last
# row or not.
row=row+1
if (row < post_comments.rowcount):
sep="},"
else:
sep="}"
write_close_tag(xml,5,sep)
write_close_tag(xml,5,"}",(row < post_comments.rowcount))
write_close_tag(xml,4,"]")
write_close_tag(xml,4,"]",False)
post_comments.close()
#--------------------------------------------------------------------#
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment