PageRenderTime 53ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/indico/web/http_api/fossils.py

https://repo.or.cz/cds-indico.git
Python | 470 lines | 309 code | 136 blank | 25 comment | 9 complexity | 4fb88e00218f48f075ed5623a7391dd6 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. # This file is part of Indico.
  2. # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
  3. #
  4. # Indico is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License as
  6. # published by the Free Software Foundation; either version 3 of the
  7. # License, or (at your option) any later version.
  8. #
  9. # Indico is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with Indico; if not, see <http://www.gnu.org/licenses/>.
  16. """
  17. Basic fossils for data export
  18. """
  19. from hashlib import md5
  20. from indico.modules.attachments.api.util import build_material_legacy_api_data, build_folders_api_data
  21. from indico.modules.events.notes.util import build_note_api_data
  22. from indico.util.fossilize import IFossil
  23. from indico.util.fossilize.conversion import Conversion
  24. from MaKaC.webinterface import urlHandlers
  25. from MaKaC.webinterface.linking import RoomLinker
  26. from MaKaC.fossils.conference import ISessionSlotFossil, ISessionFossil
  27. class IHTTPAPIErrorFossil(IFossil):
  28. def getMessage(self):
  29. pass
  30. class IHTTPAPIResultFossil(IFossil):
  31. def getTS(self):
  32. pass
  33. getTS.name = 'ts'
  34. def getURL(self):
  35. pass
  36. getURL.name = 'url'
  37. def getResults(self):
  38. pass
  39. class IHTTPAPIExportResultFossil(IHTTPAPIResultFossil):
  40. def getCount(self):
  41. pass
  42. # New SQL-based hooks do not use it anymore, so we deprecate it for everything.
  43. # def getComplete(self):
  44. # pass
  45. def getAdditionalInfo(self):
  46. pass
  47. class IPeriodFossil(IFossil):
  48. def startDT(self):
  49. pass
  50. startDT.convert = Conversion.datetime
  51. def endDT(self):
  52. pass
  53. endDT.convert = Conversion.datetime
  54. class ICategoryMetadataFossil(IFossil):
  55. def getId(self):
  56. pass
  57. def getName(self):
  58. pass
  59. def getLocator(self):
  60. pass
  61. getLocator.convert = Conversion.url(urlHandlers.UHCategoryDisplay)
  62. getLocator.name = 'url'
  63. class ICategoryProtectedMetadataFossil(ICategoryMetadataFossil):
  64. def getName(self):
  65. pass
  66. getName.produce = lambda x: None
  67. class IConferenceChairMetadataFossil(IFossil):
  68. def getId(self):
  69. pass
  70. def getFullName(self):
  71. pass
  72. def getEmail(self):
  73. pass
  74. getEmail.onlyIf = 'canModify'
  75. def getEmailHash(self):
  76. pass
  77. getEmailHash.produce = lambda s: md5(s.getEmail()).hexdigest()
  78. def getAffiliation(self):
  79. pass
  80. class IContributionParticipationMetadataFossil(IFossil):
  81. def getId(self):
  82. pass
  83. def getFullName(self):
  84. pass
  85. def getEmail(self):
  86. pass
  87. getEmail.onlyIf = 'canModify'
  88. def getEmailHash(self):
  89. pass
  90. getEmailHash.produce = lambda s: md5(s.getEmail()).hexdigest()
  91. def getAffiliation(self):
  92. pass
  93. class _IncludeMaterialFossil(IFossil):
  94. def getMaterial(self):
  95. pass
  96. getMaterial.produce = build_material_legacy_api_data
  97. getMaterial.convert = Conversion.addLegacyMinutes
  98. def getFolders(self):
  99. pass
  100. getFolders.produce = build_folders_api_data
  101. class _IncludeACLFossil(IFossil):
  102. def getRecursiveAllowedToAccessList(self):
  103. pass
  104. getRecursiveAllowedToAccessList.produce = Conversion.allowedList
  105. getRecursiveAllowedToAccessList.name = 'allowed'
  106. getRecursiveAllowedToAccessList.onlyIf = 'canModify'
  107. class IConferenceMetadataFossil(_IncludeMaterialFossil, _IncludeACLFossil, IFossil):
  108. def getId(self):
  109. pass
  110. def getStartDate(self):
  111. pass
  112. getStartDate.convert = Conversion.datetime
  113. def getEndDate(self):
  114. pass
  115. getEndDate.convert = Conversion.datetime
  116. def getTitle(self):
  117. pass
  118. def getDescription(self):
  119. pass
  120. def getType(self):
  121. pass
  122. def getOwner(self):
  123. pass
  124. getOwner.convert = lambda x: x.getTitle()
  125. getOwner.name = 'category'
  126. def getCategoryId(self):
  127. pass
  128. getCategoryId.produce = lambda x: x.getOwner().getId()
  129. def getTimezone(self):
  130. pass
  131. def getNote(self):
  132. pass
  133. getNote.produce = lambda x: build_note_api_data(x.note)
  134. def getChairList(self):
  135. pass
  136. getChairList.name = 'chairs'
  137. getChairList.result = IConferenceChairMetadataFossil
  138. def getLocation(self):
  139. """ Location (CERN/...) """
  140. getLocation.convert = lambda l: l and l.getName()
  141. def getLocator(self):
  142. pass
  143. getLocator.convert = Conversion.url(urlHandlers.UHConferenceDisplay)
  144. getLocator.name = 'url'
  145. def getRoom(self):
  146. """ Room (inside location) """
  147. getRoom.convert = lambda r: r and r.getName()
  148. def getRoomFullName(self):
  149. """ Conference Room """
  150. getRoomFullName.produce = lambda c: c.getRoom()
  151. getRoomFullName.convert = Conversion.roomFullName
  152. getRoomFullName.name = 'roomFullname'
  153. def getVisibility(self):
  154. pass
  155. getVisibility.name = 'visibility'
  156. getVisibility.produce = lambda x: Conversion.visibility(x)
  157. def hasAnyProtection(self):
  158. pass
  159. def getAddress(self):
  160. pass
  161. def getCreator(self):
  162. pass
  163. getCreator.result = IConferenceChairMetadataFossil
  164. def getCreationDate(self):
  165. pass
  166. def getModificationDate(self):
  167. pass
  168. def getRoomMapURL(self):
  169. pass
  170. getRoomMapURL.produce = lambda x: RoomLinker().getURL(x.getRoom(), x.getLocation())
  171. class IContributionMetadataFossil(_IncludeMaterialFossil, _IncludeACLFossil, IFossil):
  172. def getId(self):
  173. pass
  174. def getTitle(self):
  175. pass
  176. def getLocation(self):
  177. pass
  178. getLocation.convert = lambda l: l and l.getName()
  179. def getRoom(self):
  180. pass
  181. getRoom.convert = lambda r: r and r.getName()
  182. def getRoomFullName(self):
  183. """ Contribution Room """
  184. getRoomFullName.produce = lambda c: c.getRoom()
  185. getRoomFullName.convert = Conversion.roomFullName
  186. getRoomFullName.name = 'roomFullname'
  187. def getStartDate(self):
  188. pass
  189. getStartDate.convert = Conversion.datetime
  190. def getEndDate(self):
  191. pass
  192. getEndDate.convert = Conversion.datetime
  193. def getDuration(self):
  194. pass
  195. getDuration.convert = Conversion.duration
  196. def getDescription(self):
  197. pass
  198. def getSpeakerList(self):
  199. pass
  200. getSpeakerList.name = 'speakers'
  201. getSpeakerList.result = IContributionParticipationMetadataFossil
  202. def getPrimaryAuthorList(self):
  203. pass
  204. getPrimaryAuthorList.name = 'primaryauthors'
  205. getPrimaryAuthorList.result = IContributionParticipationMetadataFossil
  206. def getCoAuthorList(self):
  207. pass
  208. getCoAuthorList.name = 'coauthors'
  209. getCoAuthorList.result = IContributionParticipationMetadataFossil
  210. def getTrack( self ):
  211. pass
  212. getTrack.convert = lambda t: t and t.getTitle()
  213. def getSession( self ):
  214. pass
  215. getSession.convert = lambda s: s and s.getTitle()
  216. def getType(self):
  217. pass
  218. getType.convert = lambda t: t and t.getName()
  219. def getLocator(self):
  220. pass
  221. getLocator.convert = Conversion.url(urlHandlers.UHContributionDisplay)
  222. getLocator.name = 'url'
  223. def getKeywords(self):
  224. pass
  225. getKeywords.produce = lambda x: x.getKeywords().splitlines() if x.getKeywords().strip() else []
  226. def getNote(self):
  227. pass
  228. getNote.produce = lambda x: build_note_api_data(x.note)
  229. class ISubContributionMetadataFossil(IFossil, _IncludeACLFossil, _IncludeMaterialFossil):
  230. def getId(self):
  231. pass
  232. def getTitle(self):
  233. pass
  234. def getDuration(self):
  235. pass
  236. getDuration.convert = Conversion.duration
  237. def getSpeakerList(self):
  238. pass
  239. getSpeakerList.name = 'speakers'
  240. getSpeakerList.result = IContributionParticipationMetadataFossil
  241. def getNote(self):
  242. pass
  243. getNote.produce = lambda x: build_note_api_data(x.note)
  244. class IContributionMetadataWithSubContribsFossil(IContributionMetadataFossil):
  245. def getSubContributionList(self):
  246. pass
  247. getSubContributionList.result = ISubContributionMetadataFossil
  248. getSubContributionList.name = 'subContributions'
  249. class IConferenceMetadataWithContribsFossil(_IncludeMaterialFossil, IConferenceMetadataFossil):
  250. def getContributionList(self):
  251. pass
  252. getContributionList.result = IContributionMetadataFossil
  253. getContributionList.name = 'contributions'
  254. getContributionList.filterBy = 'access'
  255. class IConferenceMetadataWithSubContribsFossil(_IncludeMaterialFossil, IConferenceMetadataFossil):
  256. def getContributionList(self):
  257. pass
  258. getContributionList.result = IContributionMetadataWithSubContribsFossil
  259. getContributionList.name = 'contributions'
  260. getContributionList.filterBy = 'access'
  261. class ISessionMinimalFossil(_IncludeMaterialFossil, ISessionFossil):
  262. pass
  263. class ISessionMetadataBaseFossil(ISessionSlotFossil, _IncludeACLFossil):
  264. def getSession(self):
  265. pass
  266. getSession.result = ISessionMinimalFossil
  267. def getId(self):
  268. pass
  269. getId.produce = lambda ss: "{0}-{1}".format(ss.getSession().getId(), ss.getId())
  270. def getLocator(self):
  271. pass
  272. getLocator.convert = Conversion.url(urlHandlers.UHSessionDisplay)
  273. getLocator.name = 'url'
  274. def getFullTitle(self):
  275. pass
  276. getFullTitle.name = 'title'
  277. def getDescription(self):
  278. pass
  279. def getNote(self):
  280. pass
  281. getNote.produce = lambda x: build_note_api_data(x.note)
  282. class ISessionMetadataFossil(ISessionMetadataBaseFossil):
  283. def getContributionList(self):
  284. pass
  285. getContributionList.result = IContributionMetadataWithSubContribsFossil
  286. getContributionList.name = 'contributions'
  287. getContributionList.filterBy = 'access'
  288. class ISessionMetadataWithContributionsFossil(ISessionMetadataBaseFossil):
  289. def getContributionList(self):
  290. pass
  291. getContributionList.result = IContributionMetadataFossil
  292. getContributionList.name = 'contributions'
  293. getContributionList.filterBy = 'access'
  294. class ISessionMetadataWithSubContribsFossil(ISessionMetadataBaseFossil):
  295. def getContributionList(self):
  296. pass
  297. getContributionList.result = IContributionMetadataWithSubContribsFossil
  298. getContributionList.name = 'subcontributions'
  299. getContributionList.filterBy = 'access'
  300. class IConferenceMetadataWithSessionsFossil(_IncludeMaterialFossil, IConferenceMetadataFossil):
  301. def getSessionSlotList(self):
  302. pass
  303. getSessionSlotList.result = ISessionMetadataFossil
  304. getSessionSlotList.name = 'sessions'
  305. getSessionSlotList.filterBy = 'access'
  306. def getContributionListWithoutSessions(self):
  307. pass
  308. getContributionListWithoutSessions.result = IContributionMetadataWithSubContribsFossil
  309. getContributionListWithoutSessions.name = 'contributions'
  310. getContributionListWithoutSessions.filterBy = 'access'
  311. class IBasicConferenceMetadataFossil(IFossil):
  312. def getId(self):
  313. pass
  314. def getStartDate(self):
  315. pass
  316. getStartDate.convert = Conversion.datetime
  317. def getEndDate(self):
  318. pass
  319. getEndDate.convert = Conversion.datetime
  320. def getTitle(self):
  321. pass
  322. def getType(self):
  323. pass
  324. def getOwner(self):
  325. pass
  326. getOwner.convert = lambda x: x.getTitle()
  327. getOwner.name = 'category'
  328. def getCategoryId(self):
  329. pass
  330. getCategoryId.produce = lambda x: x.getOwner().getId()
  331. def getLocator(self):
  332. pass
  333. getLocator.convert = Conversion.url(urlHandlers.UHConferenceDisplay)
  334. getLocator.name = 'url'