Changeset 080097 in indico
- Timestamp:
- 07/15/11 11:53:05 (23 months ago)
- Branches:
- master, burotel, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b1, v0.98b2, v0.99, 051b2622c51afb171a1dedb46a0df4fbb0cbd02e, 0da0c1403bae8e51d8229f460181c71b9e6dda72
- Children:
- bedc940
- Parents:
- 3fb24b
- git-author:
- Pedro Ferreira <jose.pedro.ferreira@…> (07/13/11 14:22:15)
- git-committer:
- Pedro Ferreira <jose.pedro.ferreira@…> (07/15/11 11:53:05)
- Location:
- indico
- Files:
-
- 2 added
- 10 edited
-
MaKaC/common/indexes.py (modified) (4 diffs)
-
MaKaC/conference.py (modified) (13 diffs)
-
MaKaC/services/implementation/category.py (modified) (3 diffs)
-
MaKaC/statistics.py (modified) (1 diff)
-
MaKaC/webinterface/pages/category.py (modified) (6 diffs)
-
MaKaC/webinterface/tpls/CategoryDisplay.tpl (modified) (1 diff)
-
MaKaC/webinterface/tpls/EventHeader.tpl (modified) (1 diff)
-
MaKaC/webinterface/wcomponents.py (modified) (4 diffs)
-
core/index/__init__.py (modified) (1 diff)
-
core/index/base.py (modified) (6 diffs)
-
core/index/catalog.py (added)
-
core/index/event.py (added)
Legend:
- Unmodified
- Added
- Removed
-
indico/MaKaC/common/indexes.py
r8b23c0 r080097 980 980 pass 981 981 982 class DoubleIndex(Index):983 984 def __init__( self, name='' ):985 if name != '':986 self._name = name987 self._words = OOBTree()988 self._ids = OOBTree()989 990 def _addItem( self, value, item ):991 if value != "":992 words = self._words993 if words.has_key(value):994 if item not in words[value]:995 l = words[value]996 l.append(item)997 words[value] = l998 else:999 words[value] = [ item ]1000 self.setIndex(words)1001 id = self._itemToId(item)1002 if self._ids.has_key(value):1003 if id not in self._ids[value]:1004 l = self._ids[value]1005 l.append(id)1006 self._ids[value] = l1007 else:1008 self._ids[value] = [id]1009 self._p_changed = 11010 1011 def _withdrawItem( self, value, item ):1012 if self._words.has_key(value):1013 if item in self._words[value]:1014 words = self._words1015 l = words[value]1016 l.remove(item)1017 words[value] = l1018 self.setIndex(words)1019 id = self._itemToId(item)1020 if self._ids.has_key(value):1021 if id in self._ids[value]:1022 l = self._ids[value]1023 l.remove(id)1024 self._ids[value] = l1025 self._p_changed = 11026 1027 def _itemToId(self, item):1028 #to be overloaded1029 return ""1030 1031 def initIndex(self):1032 self._words = OOBTree()1033 self._ids = OOBTree()1034 self._p_changed = 11035 1036 def getLowerIndex(self):1037 if self._words.keys():1038 return min(self._words.keys())1039 return None1040 1041 class OAIDoubleIndex(DoubleIndex):1042 1043 def __init__(self, name='' ):1044 DoubleIndex.__init__(self, name)1045 self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 )1046 1047 def initIndex( self ):1048 DoubleIndex.initIndex(self)1049 self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 )1050 1051 def getElements(self, from_date, until_date):1052 if not (from_date or until_date):1053 return self.getAllElements()1054 1055 if from_date:1056 fd = datetime(int(from_date[0:4]), int(from_date[5:7]), int(from_date[8:10]), tzinfo=timezone('UTC'))1057 else:1058 fd = self.firstDate1059 1060 if until_date:1061 ud = datetime(int(until_date[0:4]), int(until_date[5:7]), int(until_date[8:10]), tzinfo=timezone('UTC'))1062 else:1063 ud = nowutc().replace( hour=23, minute=59, second=59, microsecond=0 )1064 1065 res = []1066 if fd > ud:1067 return res1068 delta = timedelta(1)1069 while fd <= ud:1070 d = fd.strftime("%Y-%m-%d")1071 if d in self._words:1072 res.extend(self._words[d])1073 fd += delta1074 return res1075 1076 1077 def getElementIds(self, from_date, until_date):1078 if not (from_date or until_date):1079 return self.getAllElementIds()1080 1081 if from_date:1082 fd = datetime(int(from_date[0:4]), int(from_date[5:7]), int(from_date[8:10]), tzinfo=timezone('UTC'))1083 else:1084 fd = self.firstDate1085 1086 if until_date:1087 ud = datetime(int(until_date[0:4]), int(until_date[5:7]), int(until_date[8:10]), tzinfo=timezone('UTC'))1088 else:1089 ud = nowutc().replace( hour=23, minute=59, second=59, microsecond=0 )1090 1091 res = []1092 if fd > ud:1093 return res1094 1095 delta = timedelta(1)1096 while fd <= ud:1097 d = fd.strftime("%Y-%m-%d")1098 if d in self._ids:1099 res.extend(self._ids[d])1100 fd += delta1101 return res1102 1103 def getAllElements(self):1104 res = []1105 for date in self._words.keys():1106 res.extend(self._words[date])1107 return res1108 1109 def getAllElementIds(self):1110 res = []1111 for date in self._ids.keys():1112 res.extend(self._ids[date])1113 return res1114 1115 def unindexElement( self, cont ):1116 date = cont.getOAIModificationDate().strftime("%Y-%m-%d")1117 self._withdrawItem( date, cont )1118 1119 1120 class OAIContributionIndex( OAIDoubleIndex ):1121 def __init__(self, name='' ):1122 OAIDoubleIndex.__init__(self, name)1123 self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 )1124 1125 def initIndex( self ):1126 OAIDoubleIndex.initIndex(self)1127 self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 )1128 1129 def _itemToId(self, item):1130 from MaKaC.conference import Contribution, SubContribution1131 if isinstance(item, Contribution):1132 return "%s:%s"%(item.getConference().getId(), item.getId())1133 elif isinstance(item, SubContribution):1134 return "%s:%s:%s"%(item.getConference().getId(), item.getContribution().getId(), item.getId())1135 return ""1136 1137 def getContributions(self, from_date, until_date):1138 return OAIDoubleIndex.getElements(self, from_date, until_date)1139 1140 def getContributionsIds(self, from_date, until_date):1141 return OAIDoubleIndex.getElementIds(self, from_date, until_date)1142 1143 def getAllContributions(self):1144 return OAIDoubleIndex.getAllElements(self)1145 1146 def getAllContributionsIds(self):1147 return OAIDoubleIndex.getAllElementIds(self)1148 1149 def unindexContribution( self, cont ):1150 return OAIDoubleIndex.unindexElement(self, cont)1151 1152 def indexContribution( self, cont ):1153 # Logger.get('oai/indexes').debug("\tINDEXING %s from conf %s" % (cont.getId(), cont.getConference().getId()))1154 if not self.isIndexable(cont):1155 # Logger.get('oai/indexes').debug("\t\tUNINDEXED - contribution is not indexable")1156 self.unindexContribution(cont)1157 return1158 from MaKaC.conference import ContribStatusWithdrawn1159 if not isinstance(cont.getContribution().getCurrentStatus(), ContribStatusWithdrawn):1160 date = cont.getOAIModificationDate()1161 strDate = date.strftime("%Y-%m-%d")1162 if date < self.firstDate:1163 self.firstDate = date1164 self._addItem( strDate, cont )1165 1166 class OAIContributionModificationDateIndex( OAIContributionIndex ):1167 _name = "OAIContributionModificationDate"1168 1169 def isIndexable(self, conf):1170 # only public conferences shoud be indexed1171 return not conf.hasAnyProtection()1172 1173 1174 class OAIPrivateContributionModificationDateIndex( OAIContributionIndex ):1175 _name = "OAIPrivateContributionModificationDate"1176 1177 def __init__( self, name='' ):1178 OAIContributionIndex.__init__(self, name)1179 1180 def indexContribution( self, cont ):1181 if not cont.hasAnyProtection():1182 self.unindexContribution(cont)1183 return1184 from MaKaC.conference import ContribStatusWithdrawn1185 if not isinstance(cont.getContribution().getCurrentStatus(), ContribStatusWithdrawn):1186 date = cont.getOAIModificationDate()1187 strDate = date.strftime("%Y-%m-%d")1188 if date < self.firstDate:1189 self.firstDate = date1190 self._addItem( strDate, cont )1191 1192 class OAIDeletedContributionModificationDateIndex( OAIContributionModificationDateIndex ):1193 _name = "OAIDeletedContributionModificationDate"1194 1195 def indexContribution( self, cont ):1196 date = cont.getOAIModificationDate()1197 strDate = date.strftime("%Y-%m-%d")1198 if date < self.firstDate:1199 self.firstDate = date1200 self._addItem( strDate, cont )1201 1202 class OAIDeletedPrivateContributionModificationDateIndex(OAIDeletedContributionModificationDateIndex):1203 _name = "OAIDeletedPrivateContributionModificationDate"1204 1205 1206 class OAIDeletedContributionCategoryIndex( OAIContributionIndex ):1207 _name = "OAIDeletedContributionCategory"1208 1209 def __init__( self, name='' ):1210 OAIContributionIndex.__init__(self, name)1211 1212 def _itemToId(self, item):1213 return item.getId()1214 1215 def indexContribution( self, cont ):1216 for catId in cont.getCategoryPath():1217 self._addItem( catId, cont )1218 1219 def unindexContribution( self, cont ):1220 for catId in cont.getCategoryPath():1221 self._withdrawItem( catId, cont )1222 1223 def getContributions(self, catId):1224 if not catId in self._ids:1225 return []1226 return self._words[catId]1227 1228 def getContributionsIds(self, catId):1229 if not catId in self._ids:1230 return []1231 return self._ids[catId]1232 1233 def getAllConferences(self):1234 return self.getAllElements()1235 1236 def getAllConferencesIds(self):1237 return self.getAllElementIds()1238 1239 class OAIDeletedPrivateContributionCategoryIndex( OAIDeletedContributionCategoryIndex ):1240 _name = "OAIDeletedPrivateContributionCategory"1241 1242 1243 class OAIConferenceIndex( OAIDoubleIndex ):1244 1245 def __init__( self, name='' ):1246 OAIDoubleIndex.__init__(self, name)1247 self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 )1248 1249 def initIndex( self ):1250 OAIDoubleIndex.initIndex(self)1251 self.firstDate = nowutc().replace( hour=0, minute=0, second=0, microsecond=0 )1252 1253 def _itemToId(self, item):1254 return item.getId()1255 1256 def unindexElement( self, conf ):1257 date = conf.getOAIModificationDate().strftime("%Y-%m-%d")1258 self._withdrawItem( date, conf )1259 1260 def unindexConference( self, conf ):1261 self.unindexElement(conf)1262 1263 def getConferences(self, from_date, until_date):1264 return OAIDoubleIndex.getElements(self, from_date, until_date)1265 1266 def getConferencesIds(self, from_date, until_date):1267 if not (from_date or until_date):1268 return self.getAllConferencesIds()1269 1270 if from_date:1271 fd = datetime(int(from_date[0:4]), int(from_date[5:7]), int(from_date[8:10]), tzinfo=timezone('UTC'))1272 else:1273 fd = self.firstDate1274 1275 if until_date:1276 ud = datetime(int(until_date[0:4]), int(until_date[5:7]), int(until_date[8:10]), tzinfo=timezone('UTC'))1277 else:1278 ud = nowutc().replace( hour=23, minute=59, second=29, microsecond=0 )1279 1280 res = []1281 if fd > ud:1282 return res1283 1284 delta = timedelta(1)1285 while fd <= ud:1286 d = fd.strftime("%Y-%m-%d")1287 if d in self._ids:1288 res.extend(self._ids[d])1289 fd += delta1290 1291 return res1292 1293 def getAllConferences(self):1294 return OAIDoubleIndex.getAllElements(self)1295 1296 def getAllConferencesIds(self):1297 return OAIDoubleIndex.getAllElementIds(self)1298 1299 1300 class OAIConferenceModificationDateIndex( OAIConferenceIndex ):1301 _name = "OAIConferenceModificationDate"1302 1303 def __init__( self, name='' ):1304 OAIConferenceIndex.__init__(self, name)1305 1306 def indexConference( self, conf ):1307 1308 if conf.hasAnyProtection():1309 self.unindexConference(conf)1310 return1311 date = conf.getOAIModificationDate()1312 strDate = date.strftime("%Y-%m-%d")1313 if date < self.firstDate:1314 self.firstDate = date1315 self._addItem( strDate, conf )1316 1317 def isIndexable(self, conf):1318 # only public conferences shoud be indexed1319 return not conf.hasAnyProtection()1320 1321 1322 class OAIPrivateConferenceModificationDateIndex( OAIConferenceModificationDateIndex ):1323 _name = "OAIPrivateConferenceModificationDate"1324 1325 def __init__( self, name='' ):1326 OAIConferenceIndex.__init__(self, name)1327 1328 def indexConference( self, conf ):1329 if not conf.hasAnyProtection():1330 self.unindexConference(conf)1331 return1332 date = conf.getOAIModificationDate()1333 strDate = date.strftime("%Y-%m-%d")1334 if date < self.firstDate:1335 self.firstDate = date1336 self._addItem( strDate, conf )1337 1338 class OAIDeletedConferenceModificationDateIndex( OAIConferenceModificationDateIndex ):1339 _name = "OAIDeletedConferenceModificationDate"1340 1341 def isIndexable(self, conf):1342 # only public conferences shoud be indexed1343 return not conf.hasAnyProtection()1344 1345 class OAIDeletedPrivateConferenceModificationDateIndex( OAIPrivateConferenceModificationDateIndex ):1346 _name = "OAIDeletedPrivateConferenceModificationDate"1347 1348 1349 class OAIDeletedConferenceCategoryIndex( OAIConferenceIndex ):1350 _name = "OAIDeletedConferenceCategory"1351 1352 def __init__( self, name='' ):1353 OAIConferenceIndex.__init__(self, name)1354 1355 def indexConference( self, conf ):1356 for catId in conf.getCategoryPath():1357 self._addItem( catId, conf )1358 1359 def unindexConference( self, conf ):1360 for catId in conf.getCategoryPath():1361 self._withdrawItem( catId, conf )1362 1363 def getConferences(self, catId):1364 if not catId in self._ids:1365 return []1366 return self._words[catId]1367 1368 def getConferencesIds(self, catId):1369 if not catId in self._ids:1370 return []1371 return self._ids[catId]1372 1373 1374 class OAIDeletedPrivateConferenceCategoryIndex( OAIDeletedConferenceCategoryIndex ):1375 _name = "OAIDeletedPrivateConferenceCategory"1376 1377 982 1378 983 class IndexException(Exception): 1379 984 pass 985 1380 986 1381 987 class IntStringMappedIndex(Persistent): … … 1468 1074 records = self._textIdx.apply(text.decode('utf8')).items() 1469 1075 return [(self.getString(record[0]), record[1]) for record in records] 1076 1470 1077 1471 1078 class IndexesHolder( ObjectHolder ): … … 1479 1086 "pendingSubmittersTasks", "pendingManagers", 1480 1087 "pendingManagersTasks", "pendingCoordinators", 1481 "pendingCoordinatorsTasks", "webcasts", "collaboration", 1482 "OAIConferenceModificationDate", 1483 "OAIContributionModificationDate", 1484 "OAIPrivateConferenceModificationDate", 1485 "OAIPrivateContributionModificationDate", 1486 "OAIDeletedConferenceModificationDate", 1487 "OAIDeletedContributionModificationDate", 1488 "OAIDeletedConferenceCategory", 1489 "OAIDeletedContributionCategory", 1490 "OAIDeletedPrivateConferenceModificationDate", 1491 "OAIDeletedPrivateContributionModificationDate", 1492 "OAIDeletedPrivateConferenceCategory", 1493 "OAIDeletedPrivateContributionCategory"] 1088 "pendingCoordinatorsTasks", "webcasts", "collaboration"] 1494 1089 1495 1090 def getIndex( self, name ): … … 1546 1141 raise MaKaCError(_("Tried to retrieve collaboration index, but Collaboration plugins are not present")) 1547 1142 1548 # OAI date indices1549 elif id=="OAIConferenceModificationDate":1550 Idx[str(id)] = OAIConferenceModificationDateIndex()1551 elif id=="OAIContributionModificationDate":1552 Idx[str(id)] = OAIContributionModificationDateIndex()1553 elif id=="OAIPrivateConferenceModificationDate":1554 Idx[str(id)] = OAIPrivateConferenceModificationDateIndex()1555 elif id=="OAIPrivateContributionModificationDate":1556 Idx[str(id)] = OAIPrivateContributionModificationDateIndex()1557 elif id=="OAIDeletedConferenceModificationDate":1558 Idx[str(id)] = OAIDeletedConferenceModificationDateIndex()1559 elif id=="OAIDeletedContributionModificationDate":1560 Idx[str(id)] = OAIDeletedContributionModificationDateIndex()1561 elif id=="OAIDeletedPrivateConferenceModificationDate":1562 Idx[str(id)] = OAIDeletedPrivateConferenceModificationDateIndex()1563 elif id=="OAIDeletedPrivateContributionModificationDate":1564 Idx[str(id)] = OAIDeletedPrivateContributionModificationDateIndex()1565 1566 1567 # category indices1568 elif id=="OAIDeletedConferenceCategory":1569 Idx[str(id)] = OAIDeletedConferenceCategoryIndex()1570 elif id=="OAIDeletedContributionCategory":1571 Idx[str(id)] = OAIDeletedContributionCategoryIndex()1572 elif id=="OAIDeletedPrivateConferenceCategory":1573 Idx[str(id)] = OAIDeletedPrivateConferenceCategoryIndex()1574 elif id=="OAIDeletedPrivateContributionCategory":1575 Idx[str(id)] = OAIDeletedPrivateContributionCategoryIndex()1576 else:1577 Idx[str(id)] = Index()1578 1579 1143 return Idx[str(id)] 1580 1144 -
indico/MaKaC/conference.py
ra7cc00 r080097 56 56 57 57 from persistent import Persistent 58 from BTrees.OOBTree import OOBTree, OOTreeSet 58 from BTrees.OOBTree import OOBTree, OOTreeSet, OOSet 59 59 from BTrees.OIBTree import OIBTree,OISet,union 60 60 import MaKaC … … 97 97 from MaKaC.common.contextManager import ContextManager 98 98 from sets import Set 99 import zope.interface 99 100 100 101 from indico.modules.scheduler import Client, tasks 102 from indico.util.date_time import utc_timestamp 103 from indico.core.index import IIndexableByStartDateTime, IUniqueIdProvider, Catalog 101 104 102 105 … … 106 109 """ 107 110 111 zope.interface.implements(IUniqueIdProvider, 112 IIndexableByStartDateTime) 113 108 114 def setModificationDate(self, date = None): 109 115 """ … … 113 119 date = nowutc() 114 120 self._modificationDS = date 121 122 def __conform__(self, proto): 123 124 if proto == IIndexableByStartDateTime: 125 return utc_timestamp(self.getStartDate()) 126 else: 127 return None 115 128 116 129 … … 1102 1115 1103 1116 def removeConference( self, conf, notify=True, delete = False ): 1104 if not (conf in self. getConferenceList()):1117 if not (conf in self.conferences): 1105 1118 return 1106 1119 … … 1126 1139 return res 1127 1140 1141 def iteritems(self, *args): 1142 return self.conferences.iteritems(*args) 1143 1144 def itervalues(self, *args): 1145 return self.conferences.itervalues(*args) 1146 1128 1147 def getConferenceList( self, sortType=1 ): 1129 1148 """returns the list of conferences included in the current category. … … 1135 1154 sortType=3--> Alphabetically - Reversed 1136 1155 """ 1156 1137 1157 res = sorted(self.conferences, cmp=Conference._cmpByDate) 1158 1138 1159 if sortType==2: 1139 1160 res.sort(Conference._cmpTitle) … … 1158 1179 return res 1159 1180 1160 def getPreviousEvent(self, conf): 1161 cl=self.getConferenceList() 1162 v=None 1163 try: 1164 i=cl.index(conf) 1165 if i>0: 1166 v=cl[i-1] 1167 except ValueError, e: 1168 pass 1169 return v 1170 1171 def getNextEvent(self, conf): 1172 cl=self.getConferenceList() 1173 v=None 1174 try: 1175 i=cl.index(conf) 1176 if i<(len(cl)-1): 1177 v=cl[i+1] 1178 except ValueError, e: 1179 pass 1180 return v 1181 1182 def getFirstEvent(self, conf=None): 1183 cl=self.getConferenceList() 1184 if len(cl)>0 and cl[0]!=conf: 1185 return cl[0] 1186 return None 1187 1188 def getLastEvent(self, conf=None): 1189 cl=self.getConferenceList() 1190 if len(cl)>0 and cl[-1]!=conf: 1191 return cl[-1] 1192 return None 1181 def getNeighborEvents(self, conf): 1182 1183 index = Catalog.getIdx('categ_conf_sd').getCategory(conf.getOwner().getId()) 1184 first, last = list(index[index.minKey()])[0], list(index[index.maxKey()])[-1] 1185 1186 categIter = index.itervalues() 1187 1188 prev = None 1189 for c in categIter: 1190 if c == conf: 1191 break 1192 prev = c 1193 1194 nextEvt = next(categIter, None) 1195 1196 return prev, nextEvt, first, last 1193 1197 1194 1198 def _setNumConferences(self): … … 1198 1202 self._incNumConfs(sc.getNumConferences()) 1199 1203 else: 1200 self._incNumConfs(len(self. getConferenceList()))1204 self._incNumConfs(len(self.conferences)) 1201 1205 1202 1206 def getNumConferences( self ): … … 2075 2079 @staticmethod 2076 2080 def _cmpByDate(self, toCmp): 2077 if not isinstance(toCmp, Conference):2078 return cmp(hash(self), hash(toCmp))2079 2081 res = cmp(self.getStartDate(), toCmp.getStartDate()) 2080 2082 if res != 0: … … 2084 2086 2085 2087 def __cmp__(self, toCmp): 2086 if not isinstance(toCmp, Conference): 2088 if isinstance(toCmp, Conference): 2089 return cmp(self.getId(), toCmp.getId()) 2090 else: 2087 2091 return cmp(hash(self), hash(toCmp)) 2088 return cmp(self.getId(), toCmp.getId())2089 2092 2090 2093 def __eq__(self, toCmp): … … 2432 2435 catDateIdx.indexConf(self) 2433 2436 2437 Catalog.getIdx('categ_conf_sd').index_obj(self) 2438 2434 2439 def unindexConf( self ): 2435 2440 calIdx = indexes.IndexesHolder().getIndex('calendar') … … 2437 2442 catDateIdx = indexes.IndexesHolder().getIndex('categoryDate') 2438 2443 catDateIdx.unindexConf(self) 2444 2445 Catalog.getIdx('categ_conf_sd').unindex_obj(self) 2439 2446 2440 2447 def __generateNewContribTypeId( self ): -
indico/MaKaC/services/implementation/category.py
r4e5048 r080097 24 24 25 25 import datetime 26 from itertools import islice 26 27 from MaKaC.services.implementation.base import ProtectedModificationService, ParameterManager 27 28 from MaKaC.services.implementation.base import ProtectedDisplayService, ServiceBase … … 33 34 from MaKaC.common.fossilize import fossilize 34 35 from MaKaC.user import PrincipalHolder, Avatar, Group 36 37 from indico.core.index import Catalog 35 38 36 39 class CategoryBase(object): … … 147 150 148 151 def _getAnswer( self ): 149 pastEvents = list(self._target.getConferenceList())[0:self._lastIdx] 152 index = Catalog.getIdx('categ_conf_sd').getCategory(self._categ.getId()) 153 pastEvents = list(islice(index.itervalues(), self._lastIdx)) 150 154 return WConferenceListEvents(pastEvents, self._aw).getHTML() 151 155 -
indico/MaKaC/statistics.py
r07abe7 r080097 121 121 stats["resources"] += scat._statistics["resources"] 122 122 123 elif len(cat.getConferenceList()) > 0:124 for event in cat. getConferenceList():123 elif cat.conferences: 124 for event in cat.conferences: 125 125 cls._processEvent(dbi, event, stats) 126 126 -
indico/MaKaC/webinterface/pages/category.py
r08a2885 r080097 38 38 from MaKaC.common.cache import CategoryCache 39 39 from MaKaC.i18n import _ 40 40 41 from MaKaC.webinterface.common.timezones import TimezoneRegistry 41 42 from MaKaC.webinterface.common.tools import escape_html … … 43 44 from pytz import timezone 44 45 from MaKaC.common.TemplateExec import truncateTitle 46 47 from indico.util.i18n import i18nformat 48 from indico.core.index import Catalog 45 49 46 50 … … 135 139 vars["img"] = self._target.getIconURL() 136 140 vars["categ"] = self._target; 137 subcats = self._target.getSubCategoryList() 138 confs = self._target.getConferenceList() 139 if len(subcats) > 0: 141 subcats = self._target.subcategories 142 143 confs = self._target.conferences 144 if subcats: 140 145 cl=wcomponents.WCategoryList( self._target ) 141 146 params = {"categoryDisplayURLGen": vars["categDisplayURLGen"], "material": self._getMaterialHTML()} 142 147 vars["contents"] = cl.getHTML( self._aw, params ) 143 elif len(confs) > 0:148 elif confs: 144 149 pastEvents = self._aw.getSession().getVar("fetchPastEventsFrom") 145 150 showPastEvents = pastEvents and self._target.getId() in pastEvents or self._aw.getUser() and self._aw.getUser().getPersonalInfo().getShowPastEvents() … … 1489 1494 def getVars( self ): 1490 1495 1496 index = Catalog.getIdx('categ_conf_sd').getCategory(self._categ.getId()) 1491 1497 vars = wcomponents.WTemplated.getVars( self ) 1492 1498 vars["locator"] = self._categ.getLocator().getWebForm() … … 1506 1512 vars['containsEvents'] = True 1507 1513 vars["removeItemsURL"] = vars["actionConferencesURL"] 1508 vars["items"] = self.__getConferenceItems( reversed(self._categ.getConferenceList()), vars["confModifyURLGen"], vars["confModifyURLOpen"])1514 vars["items"] = self.__getConferenceItems(index.itervalues(), vars["confModifyURLGen"], vars["confModifyURLOpen"]) 1509 1515 else: 1510 1516 vars['containsEvents'] = False … … 2023 2029 if info.HelperMaKaCInfo.getMaKaCInfoInstance().isCacheActive(): 2024 2030 vars["clearCache"] = _("""<form action="%s" method="POST"><input type="submit" class="btn" value="_("clear category cache")"></form>""") % urlHandlers.UHCategoryClearCache.getURL(self._categ) 2025 if len(self._categ.getConferenceList()):2031 if self._categ.conferences: 2026 2032 vars["clearCache"] += _("""<form action="%s" method="POST"><input type="submit" class="btn" value="_("clear conference caches")"></form>""") % urlHandlers.UHCategoryClearConferenceCaches.getURL(self._categ) 2027 2033 return vars -
indico/MaKaC/webinterface/tpls/CategoryDisplay.tpl
r9ac2af7 r080097 11 11 <li><a href="<%= urlHandlers.UHCategoryDisplay.getURL(categ.owner) %>"><%= _("Go to parent category") %></a>|</li> 12 12 <% end %> 13 <% if categ. getConferenceList() != []: %>13 <% if categ.conferences: %> 14 14 <li><a href="<%= urlHandlers.UHCategoryToiCal.getURL(categ) %>"><%= _("iCal export")%></a>|</li> 15 15 <% end %> -
indico/MaKaC/webinterface/tpls/EventHeader.tpl
r9ac2af7 r080097 2 2 owner = conf.getOwnerList()[0] 3 3 4 prev = owner.getPreviousEvent(conf) 5 next = owner.getNextEvent(conf) 6 first = owner.getFirstEvent(conf) 7 last = owner.getLastEvent(conf) 4 prev, next, first, last = owner.getNeighborEvents(conf) 8 5 9 6 # If printURL is set then show the print button -
indico/MaKaC/webinterface/wcomponents.py
rc922b1 r080097 22 22 23 23 import os,types,string 24 import itertools 24 25 from xml.sax.saxutils import escape, quoteattr 25 26 from copy import copy … … 65 66 from MaKaC.common.contextManager import ContextManager 66 67 68 from indico.util.date_time import utc_timestamp 69 from indico.core.index import Catalog 70 67 71 import re 72 73 MIN_PRESENT_EVENTS = 6 74 OPTIMAL_PRESENT_EVENTS = 10 75 68 76 69 77 class WTemplated(OldObservable): … … 3280 3288 def __init__( self, category, wfRegm, showPastEvents ): 3281 3289 self._categ = category 3282 self._list = category.getConferenceList()3283 3290 self._showPastEvents = showPastEvents 3284 3291 … … 3287 3294 return WTemplated.getHTML( self, params ) 3288 3295 3289 def _findFirstEventFromCurrentMonth(self): 3290 currentDate = nowutc() 3291 return self._findEventIdx(datetime(currentDate.year, currentDate.month, 1, tzinfo=timezone('utc'))) 3292 3293 def _findPresentEvent(self): 3294 currentDate = nowutc() 3295 return self._findEventIdx(datetime(currentDate.year, currentDate.month, currentDate.day, tzinfo=timezone('utc'))) 3296 3297 def _findEventIdx(self, day): 3298 st = 0 3299 end = len(self._list) - 1 3300 3301 def find(st, end): 3302 current = int((st + end) / 2) 3303 if end - st > 1: 3304 if self._list[current].getStartDate() > day: 3305 return find(st, current) 3306 elif self._list[current].getStartDate() < day: 3307 return find(current, end) 3308 else: 3309 return current 3296 def getEventTimeline(self, tz): 3297 index = Catalog.getIdx('categ_conf_sd').getCategory(self._categ.getId()) 3298 today = nowutc().astimezone(timezone(tz)).replace(hour=0, minute=0, second=0) 3299 thisMonth = nowutc().astimezone(timezone(tz)).replace(hour=0, minute=0, second=0, day=1) 3300 thisMonthTS = utc_timestamp(thisMonth) 3301 todayTS = utc_timestamp(thisMonth) 3302 tomorrowTS = utc_timestamp(today + timedelta(days=1)) 3303 oneMonthTS = utc_timestamp(today - timedelta(days=30)) 3304 future = [] 3305 present = [] 3306 3307 for ts, conf in index.iteritems(thisMonthTS): 3308 if ts < tomorrowTS or len(present) < OPTIMAL_PRESENT_EVENTS: 3309 present.append(conf) 3310 3310 else: 3311 if self._list[current].getStartDate() > day: 3312 if current > 0: 3313 return current - 1 3314 else: 3315 return 0 3316 elif self._list[current].getStartDate() < day: 3317 if current + 1< len(self._list): 3318 return current + 1 3319 else: 3320 return current 3321 else: 3322 return current 3323 3324 return find(st, end) 3325 3326 def getPrevMonth(self,d): 3327 year = d.year 3328 prevMonth = (d.month - 1)%12 3329 if prevMonth == 0: 3330 prevMonth = 12 3331 year -= 1 3332 return datetime(year, prevMonth, 1, tzinfo = timezone('utc')) 3333 3334 def getNextMonth(self,d): 3335 year = d.year 3336 nextMonth = (d.month + 1)%12 3337 if d.month + 1 == 12: 3338 nextMonth = 12 3339 elif d.month + 1 > 12: 3340 year += 1 3341 return datetime(year, nextMonth, 1, tzinfo = timezone('utc')) 3342 3343 def _getEventsFromPreviousMonth(self, stIndex, previousMonthStart): 3344 newIndex = stIndex 3345 while newIndex >= 0 and self._list[newIndex].getStartDate() >= previousMonthStart: 3346 newIndex -= 1 3347 return newIndex if newIndex + 1 == len(self._list) else newIndex + 1 3348 3349 def _getEventsFromCurrentMonth(self, stIndex, currentMonthStart): 3350 nextMonthStart = self.getNextMonth(currentMonthStart) 3351 newIndex = stIndex 3352 while newIndex < len(self._list) and self._list[newIndex].getStartDate() < nextMonthStart: 3353 newIndex += 1 3354 return newIndex 3355 3356 def _getFutureEvents(self, stIndex): 3357 nextMonthStart = self.getNextMonth(self._list[stIndex + 1].getStartDate()) 3358 newIndex = stIndex 3359 while newIndex < len(self._list) and self._list[newIndex].getStartDate() < nextMonthStart: 3360 newIndex += 1 3361 return newIndex 3362 3363 def getPresentPastFutureEvents(self): 3364 currentMonth = nowutc() 3365 previousMonth = currentMonth 3366 3367 firstEventIdx = self._findFirstEventFromCurrentMonth() 3368 presentEventIdx = self._findPresentEvent() 3369 lastEventIdx = firstEventIdx 3370 3371 maxEventsShown = min([10, len(self._list)]) 3372 minFutureEventsShown = min([5, len(self._list) - presentEventIdx]) 3373 3374 lastEventIdx = self._getEventsFromCurrentMonth(lastEventIdx,currentMonth) 3375 3376 while lastEventIdx - firstEventIdx < maxEventsShown: 3377 currentMonth = self.getNextMonth(currentMonth) 3378 lastEventIdx = self._getEventsFromCurrentMonth(lastEventIdx,currentMonth) 3379 previousMonth = self.getPrevMonth(previousMonth) 3380 firstEventIdx = self._getEventsFromPreviousMonth(firstEventIdx,previousMonth) 3381 3382 while len(self._list) > lastEventIdx + 1 and lastEventIdx - presentEventIdx < minFutureEventsShown: 3383 lastEventIdx = self._getFutureEvents(lastEventIdx) 3384 3385 return list(self._list[firstEventIdx:lastEventIdx]), list(self._list[lastEventIdx:]),len(self._list) - lastEventIdx, firstEventIdx 3386 3387 def getVars( self ): 3388 vars = WTemplated.getVars( self ) 3389 vars["presentItems"], vars["futureItems"], vars["numOfEventsInTheFuture"], vars["numOfEventsInThePast"] = self.getPresentPastFutureEvents() 3311 future.append(conf) 3312 3313 if len(present) < MIN_PRESENT_EVENTS: 3314 extraEvents = list(index.itervalues(oneMonthTS, todayTS)) 3315 present += extraEvents 3316 3317 if not present: 3318 present = [elem for elem in index[index.maxKey()]] 3319 3320 numPast = self._categ.getNumConferences() - len(present) - len(future) 3321 return present, future, len(future), numPast 3322 3323 def getVars( self ): 3324 vars = WTemplated.getVars( self ) 3325 displayTZ = DisplayTZ(self._aw, self._categ, useServerTZ=1).getDisplayTZ() 3326 vars["ActiveTimezone"] = displayTZ 3327 vars["presentItems"], vars["futureItems"], vars["numOfEventsInTheFuture"], vars["numOfEventsInThePast"] = self.getEventTimeline(displayTZ) 3390 3328 vars["categ"] = self._categ 3391 vars["ActiveTimezone"] = DisplayTZ(self._aw,self._categ,useServerTZ=1).getDisplayTZ() 3329 3392 3330 vars["showPastEvents"] = self._showPastEvents 3393 3331 -
indico/core/index/__init__.py
rafb474 r080097 21 21 from indico.core.index.base import * 22 22 from indico.core.index.adapter import * 23 from indico.core.index.catalog import Catalog -
indico/core/index/base.py
r7257af r080097 23 23 24 24 from BTrees.IOBTree import IOBTree, IOTreeSet 25 from BTrees.OOBTree import OOBTree, OOTreeSet, union25 from BTrees.OOBTree import OOBTree, OOTreeSet, OOSet, union 26 26 from persistent import Persistent 27 27 28 import logging29 28 import zope.interface 30 29 … … 61 60 62 61 63 class IOIndex(Persistent): 64 """ 65 Maps integer values to objects 66 int -> set(obj, ...) 67 68 int is obtained by means of an adapter 62 class Index(Persistent): 63 pass 64 65 66 class SIndex(Index): 67 68 _fwd_class = None 69 _fwd_set_class = None 70 71 def __init__(self, adapter): 72 self._adapter = adapter 73 self._fwd_index = self._fwd_class() 74 self._num_objs = Length(0) 75 76 def _gc_entry(self, v): 77 """ 78 'Garbage collect' empty set entries 79 """ 80 if len(self._fwd_index[v]) == 0: 81 del self._fwd_index[v] 82 83 def index_obj(self, obj): 84 85 value = self._adapter(obj) 86 vset = self._fwd_index.get(value, self._fwd_set_class()) 87 88 if obj in vset: 89 raise InconsistentIndexException("%s already in fwd[%s]", (obj, value)) 90 else: 91 vset.add(obj) 92 self._num_objs.change(1) 93 94 self._fwd_index[value] = vset 95 96 def _unindex_obj_from_key(self, key, obj): 97 if key in self._fwd_index: 98 vset = self._fwd_index[key] 99 if obj in vset: 100 vset.remove(obj) 101 self._fwd_index[key] = vset 102 self._gc_entry(key) 103 else: 104 raise InconsistentIndexException("'%s' not in fwd[%s]", 105 (obj, key)) 106 else: 107 raise InconsistentIndexException("'%s' not in fwd index" % key) 108 109 def unindex_obj(self, obj): 110 """ 111 Slightly dumber than the one in DIndex, takes the indexation value (key) 112 instead of looking it up in the reverse index 113 """ 114 key = self._adapter(obj) 115 self._unindex_obj_from_key(key, obj) 116 self._num_objs.change(-1) 117 118 119 def values(self, *args): 120 res = self._fwd_set_class() 121 for s in self._fwd_index.itervalues(*args): 122 res = union(res, s) 123 return res 124 125 def itervalues(self, *args): 126 for s in self._fwd_index.itervalues(*args): 127 for t in s: 128 yield t 129 130 def iteritems(self, *args): 131 for ts, s in self._fwd_index.iteritems(*args): 132 for t in s: 133 yield ts, t 134 135 def minKey(self): 136 return self._fwd_index.minKey() 137 138 def maxKey(self): 139 return self._fwd_index.maxKey() 140 141 def __iter__(self): 142 return iter(self._fwd_index) 143 144 def __len__(self): 145 return self._num_objs() 146 147 def __getitem__(self, item): 148 return self._fwd_index[item] 149 150 def get(self, item, default=None): 151 return self._fwd_index.get(item, default) 152 153 154 155 class DIndex(SIndex): 156 """ 157 Bidirectional Index Class 69 158 70 159 objects need to implement IUniqueIdProvider as well, as an id is needed for … … 72 161 """ 73 162 163 _rev_class = None 164 _rev_set_class = None 165 74 166 def __init__(self, adapter): 75 self._fwd_index = IOBTree() 76 self._rev_index = OOBTree() 77 self._num_objs = Length(0) 78 self._adapter = adapter 79 80 def _gc_entry(self, v): 81 """ 82 'Garbage collect' empty set entries 83 """ 84 if len(self._fwd_index[v]) == 0: 85 del self._fwd_index[v] 167 super(DIndex, self).__init__(adapter) 168 self._rev_index = self._rev_class() 86 169 87 170 def index_obj(self, obj): … … 97 180 value = self._adapter(obj) 98 181 99 if uid not in self._rev_index: 100 ts = IOTreeSet() 101 self._rev_index[uid] = ts 102 103 if value in self._rev_index[uid]: 182 ts = self._rev_index.get(uid, self._rev_set_class()) 183 184 if value in ts: 104 185 raise ElementAlreadyInIndexException() 105 186 else: 106 self._rev_index[uid].add(value) 107 108 vset = self._fwd_index.get(value) 109 if vset is None: 110 vset = OOTreeSet() 111 self._fwd_index[value] = vset 112 113 if obj in vset: 114 raise InconsistentIndexException("%s already in fwd[%s]", (obj, value)) 115 else: 116 vset.insert(obj) 117 self._num_objs.change(1) 187 ts.add(value) 188 189 self._rev_index[uid] = ts 190 191 super(DIndex, self).index_obj(obj) 118 192 119 193 return (uid, value) … … 124 198 125 199 if uid in self._rev_index: 126 values = self._rev_index[uid]200 keys = self._rev_index[uid] 127 201 del self._rev_index[uid] 128 202 129 for v in values: 130 if v in self._fwd_index: 131 vset = self._fwd_index[v] 132 if obj in vset: 133 vset.remove(obj) 134 self._gc_entry(v) 135 else: 136 raise InconsistentIndexException("%s not in fwd[%s]", 137 (obj, v)) 138 else: 139 raise InconsistentIndexException("%s not in fwd index" % v) 203 for key in keys: 204 self._unindex_obj_from_key(key, obj) 140 205 else: 141 206 raise ElementNotFoundException(uid) … … 143 208 self._num_objs.change(-1) 144 209 145 def values(self, *args): 146 res = OOTreeSet() 147 for s in self._fwd_index.itervalues(*args): 148 res = union(res, s) 149 return res 150 151 def itervalues(self, *args): 152 for s in self._fwd_index.itervalues(*args): 153 for t in s: 154 yield t 155 156 def iteritems(self): 157 for ts, s in self._fwd_index.iteritems(): 158 for t in s: 159 yield ts, t 160 161 def minKey(self): 162 return self._fwd_index.minKey() 163 164 def maxKey(self): 165 return self._fwd_index.maxKey() 166 167 def __len__(self): 168 return self._num_objs() 169 170 def __getitem__(self, item): 171 return self._fwd_index[item] 172 173 def get(self, item): 174 return self._fwd_index[item] 210 211 class SIOIndex(DIndex): 212 """ 213 Maps integer keys to objects 214 int -> set(obj) 215 """ 216 _fwd_class = IOBTree 217 _fwd_set_class = OOTreeSet 218 219 220 class IOIndex(DIndex): 221 """ 222 Maps integer keys to objects 223 int -> set(obj) 224 uid(obj) -> set(int) 225 """ 226 _fwd_class = IOBTree 227 _rev_class = OOBTree 228 _fwd_set_class = OOTreeSet 229 _rev_set_class = IOTreeSet 230 231 232 class OOIndex(DIndex): 233 """ 234 Maps object keys to objects 235 obj -> set(obj) 236 uid(obj) -> set(obj) 237 """ 238 _fwd_class = OOBTree 239 _rev_class = OOBTree 240 _fwd_set_class = OOSet 241 _rev_set_class = OOSet 242 175 243 176 244 class IIIndex(FieldIndex):
Note: See TracChangeset
for help on using the changeset viewer.
