def ViewAttachment(objHere): # print "View attachment" strThreadId = GetParameter(objHere.REQUEST, 'ThreadId') strMessageId = GetParameter(objHere.REQUEST, 'MessageId') if strMessageId: objMessage = SearchOne(objHere, 'E3Messages', 'id', strMessageId) else: objMessage = SearchOne(objHere, 'E3Messages', 'id', strThreadId) strAttachmentId = GetParameter(objHere.REQUEST, 'Attachment') # print strAttachmentId objAttachment = objMessage.unrestrictedTraverse(strAttachmentId) if 'image' in objAttachment.content_type: return "Can't show images yet" # return objAttachment.__call__(objAttachment) # return objAttachment # print dir(objAttachment) # return objAttachment.content_type # print dir(objHere.REQUEST.response.headers) # objHere.REQUEST.Response.content-encoding = objAttachment.content_type # print "content type:", objAttachment.content_type objHere.REQUEST.response.setHeader('content-type', """%s; name="%s" """ % (objAttachment.content_type, objAttachment.title)) # objHere.REQUEST.response.setHeader('content-type', """%s""" % objAttachment.content_type) objHere.REQUEST.response.setHeader('content-length', len(objAttachment.data)) objHere.REQUEST.response.setHeader('Accept-Ranges', 'bytes') if "image" in objAttachment.content_type: return objAttachment # objHere.REQUEST.response.setHeader('content-transfer-encoding', 'base64') # return base64.encodestring(objAttachment) # return base64.encodestring(objAttachment.data) return objAttachment.data
def AddEmailAddress(self, strEmailAddress): if not strEmailAddress: return (None, "No email address entered") strEmailAddress = strEmailAddress.strip().replace(" ", "").lower() objValidator = StringValidator(strEmailAddress) if not objValidator.isEmail(): return (None, """'%s' is not a valid email address. Please try again or <a href="/ContactDetails">contact the list owner</a>""" % strEmailAddress) objOldEmailAddress = SearchOne(self, "E3EmailAddress", "EmailAddress", strEmailAddress) if objOldEmailAddress: if objOldEmailAddress in self.objectValues(): return (None, "You have already registered this address (%s)" % strEmailAddress) else: objOldMember = objOldEmailAddress.unrestrictedTraverse('..') if objOldMember.ParkingMember(): self.ClaimEmailAddress(objOldEmailAddress, objOldMember) return (objOldEmailAddress, "New email address registered") else: return(None, """This email address belongs to someone else. Please <a href="/ContactDetails">contact the list owner</a>""") else: dodEmailAddress = GetDOD(self, "E3EmailAddress") objNewEmailAddress = dodEmailAddress.NewObject(self) objNewEmailAddress.EmailAddress = strEmailAddress objNewEmailAddress.Confirmed = False objNewEmailAddress.RequestConfirmation() objCatalogue = GetDataFolder(self, 'E3EmailAddress').Catalogue Catalogue(objNewEmailAddress) return (objNewEmailAddress, """New email address registered<br> A confirmation request has been sent to you. Please confirm your email address by following the instructions in the email""")
def FinishE3Conf08Booking(objWorldPayCall, strCurrency, fltAmount, strPaymentType, strWPContents): strConfBookingId = objWorldPayCall.PaymentType objConfBooking = SearchOne(objWorldPayCall, "E3Conf08Booking", "id", strConfBookingId) dtmNow = datetime.datetime.today() intAmount = objWorldPayCall.Amount AddToRegistrationHistory(objConfBooking, "Online payment of GBP%s" % intAmount) objConfBooking.PaidAmount += intAmount objConfBooking.RemainingAmount -= intAmount if objConfBooking.RemainingAmount: AddToRegistrationHistory(objConfBooking, "Total payment(s): GBP%s, remaining: GBP%s" % (objConfBooking.PaidAmount, objConfBooking.RemainingAmount)) else: AddToRegistrationHistory(objConfBooking, "Total payment(s): GBP%s, fully paid" % objConfBooking.PaidAmount) strResult = GetWelcomeBlock(objConfBooking.InProgressForCC, objConfBooking.InProgressForSatEve, objConfBooking.InProgressForSunAm, objConfBooking, False) if objConfBooking.RemainingAmount: strExtraPaymentLine = "<p>The remaining amount of £%s must be paid by Wednesday 10th September</p>" % objConfBooking.RemainingAmount else: strExtraPaymentLine = "" strResult += """ <fieldset> <legend>Thanks for your payment</legend> <p>Thanks for your payment of %s%s for the conference. A receipt has been emailed to %s</p> %s %s </fieldset>""" % (strCurrency, fltAmount, objConfBooking.EmailAddress, strExtraPaymentLine, strWPContents) objConfBooking.InvoiceNumber = NextInvoiceNumber(objWorldPayCall) blnFullAmount = (objConfBooking.RemainingAmount == 0) SendConf08Receipt(objWorldPayCall, objConfBooking.EmailAddress, objConfBooking.Name, objConfBooking.InvoiceNumber, intAmount, blnFullAmount, objConfBooking.RemainingAmount) SendBookingEmails(objWorldPayCall, objConfBooking, "Online", objConfBooking.InProgressForCC, objConfBooking.InProgressForSatEve, objConfBooking.InProgressForSunAm, intAmount) return strResult
def UnicodeTest(objHere): objMember = SearchOne(objHere, 'E3Member', 'Username', 'CoachCoen') print "Name: ", objMember.Name print "Type: ", type(objMember.Name) # strName = objMember.Name # ucName = unicode(strName) # print ucName # print "Type: ", type(ucName) # objMember.Name = ucName print objMember.propertyMap() StringsToUnicode(objMember)
def ProcessOneReaderCategoryLink(objLink): if objLink.TableName == "book_readercategory": strBookId = CleanLinkId(objLink.FromId) strReaderCategoryId = CleanLinkId(objLink.ToId) objBook = SearchOne(objLink, "MCIBook", "SourceId", strBookId) objReaderCategory = SearchOne(objLink, "MCIReaderCategory", "SourceId", strReaderCategoryId) if not objBook: print "Reader category, book not found: %s" % strBookId if not objReaderCategory: print "ReaderCategory not found: %s" % strReaderCategoryId if objBook and objReaderCategory: objBook.ReaderCategories = AddToLines(objBook.ReaderCategories, objReaderCategory.id)
def ReportOnePostingAddress(objHere, strEmailAddress): objEmailAddress = SearchOne(objHere, 'E3EmailAddress', 'EmailAddress', strEmailAddress) strLine = strEmailAddress if objEmailAddress.Bouncing: strLine += ", bouncing" objMember = objEmailAddress.unrestrictedTraverse('..') if objMember.NoMail: strLine += ", member on nomail" if objMember.MembershipType == 'None': strLine += ", none membership" strDeliveryMode = objEmailAddress.DeliveryMode() strLine += ", " + strDeliveryMode print strLine
def ProcessOneBookAuthorLink(objLink): if objLink.TableName == "book_author": strBookId = CleanLinkId(objLink.FromId) objBook = SearchOne(objLink, "MCIBook", "SourceId", strBookId) if not objBook: print "Book not found: %s" % strBookId else: strAuthorId = CleanLinkId(objLink.ToId) objAuthor = SearchOne(objLink, "MCIAuthor", "SourceId", strAuthorId) if not objAuthor: print "Author not found: %s" % strAuthorId else: objBook.Authors = AddToLines(objBook.Authors, objAuthor.Name.strip())
def ProcessOneReaderCategoryLink(objLink): if objLink.TableName == 'book_readercategory': strBookId = CleanLinkId(objLink.FromId) strReaderCategoryId = CleanLinkId(objLink.ToId) objBook = SearchOne(objLink, 'MCIBook', 'SourceId', strBookId) objReaderCategory = SearchOne(objLink, 'MCIReaderCategory', 'SourceId', strReaderCategoryId) if not objBook: print "Reader category, book not found: %s" % strBookId if not objReaderCategory: print "ReaderCategory not found: %s" % strReaderCategoryId if objBook and objReaderCategory: objBook.ReaderCategories = AddToLines(objBook.ReaderCategories, objReaderCategory.id) Catalogue(objBook) DeleteObject(objLink)
def ProcessOneBookAuthorLink(objLink): if objLink.TableName == 'book_author': strBookId = CleanLinkId(objLink.FromId) objBook = SearchOne(objLink, 'MCIBook', 'SourceId', strBookId) if not objBook: print "Book not found: %s" % strBookId else: strAuthorId = CleanLinkId(objLink.ToId) objAuthor = SearchOne(objLink, 'MCIAuthor', 'SourceId', strAuthorId) if not objAuthor: print "Author not found: %s" % strAuthorId else: objBook.Authors = AddToLines(objBook.Authors, objAuthor.Name.strip()) Catalogue(objBook) DeleteObject(objLink)
def ListForCategory(objRequest, objHere): strNavigation = "" intMaxBooks = 20 intOffset = 0 strCategoryId = GetParameter(objRequest, 'CategoryId') strOffset = GetParameter(objRequest, "Offset") if not strCategoryId: return "Incorrect category" objCategory = SearchOne(objHere, 'MCIBookCategory', 'id', strCategoryId) if not objCategory: return "Incorrect category" if strOffset and isinstance(strOffset, int): intOffset = int(strOffset) lstBooks = SearchMany(objHere, 'MCIBook', 'Categories', strCategoryId) for objSubCategory in objCategory.objectValues(): lstBooks = MergeLists(lstBooks, SearchMany(objHere, 'MCIBook', 'Categories', objSubCategory.id)) strResult = CreateListOfBooks(objHere, lstBooks, strCategoryId, intOffset) return strResult
def SetPublicPrivate(objHere, objMember, blnMakeItPublic): strThreadId = GetParameter(objHere.REQUEST, 'ThreadId') if not strThreadId: SetMessage(objHere, "Message not found", "") return intThreadId = str(strThreadId) strMessageId = GetParameter(objHere.REQUEST, 'MessageId') if strMessageId: intMessageId = int(strMessageId) else: intMessageId = 0 strThreadId = GetParameter(objHere.REQUEST, 'ThreadId') objThread = SearchOne(objHere, 'E3Messages', 'id', strThreadId) if not objThread: SetMessage(objHere, "Message not found", "") return if intMessageId: strMessageId = GetParameter(objHere.REQUEST, 'MessageId') objMessage = SearchOne(objHere, 'E3Messages', 'id', strMessageId) else: objMessage = objThread if not objMessage: SetMessage(objHere, "Message not found", "") return if objMessage.UserId <> objMember.id: SetMessage(objHere, "Message belongs to someone else", "") return dtmDate = objMessage.mailDate intMonth = dtmDate.month() intYear = dtmDate.year() if blnMakeItPublic: objMessage.Private = False SetMessage(objHere, "", "Message set to public") ChangeMonthCount(objHere, intYear, intMonth, 1, True) else: objMessage.Private = True SetMessage(objHere, "", "Message set to private") ChangeMonthCount(objHere, intYear, intMonth, -1, True)
def EnsureAddressIsMine(self, strEmailAddress): objExistingEmailAddress = SearchOne(self, 'E3EmailAddress', 'EmailAddress', strEmailAddress) if objExistingEmailAddress: objExistingMember = objExistingEmailAddress.unrestrictedTraverse('..') if objExistingMember.ParkingMember(): objEmailAddress = self.ClaimEmailAddress(objExistingEmailAddress, objExistingMember) return (True, False, objEmailAddress) elif objExistingMember == self: return (True, False, objExistingEmailAddress) else: SetMessage(self, """%s is already in use by someone else. Please <a href="/ContactDetails">contact the list owner</a>""" % strEmailAddress, "") return (False, False, None) else: dodEmailAddress = GetDOD(self, 'E3EmailAddress') objEmailAddress = dodEmailAddress.NewObject(self) objEmailAddress.EmailAddress = strEmailAddress Catalogue(objEmailAddress) return (True, True, objEmailAddress)
def UpdateThread(objHere, objMember): if not ManagerLoggedIn(objHere): SetMessage(objHere, "Only a manager can change this", "") return strThreadId = GetParameter(objHere.REQUEST, "ThreadId") strSubject = GetParameter(objHere.REQUEST, "ThreadSubject") strSummary = GetParameter(objHere.REQUEST, "ThreadSummary") blnPublish = objHere.REQUEST.has_key("ThreadPublish") strTopicId = GetParameter(objHere.REQUEST, "TopicId") objThread = SearchOne(objHere, "E3Thread", "id", strThreadId) if not objThread: SetMessage(objHere, "Thread not found", "") return objThread.Subject = strSubject objThread.Summary = strSummary objThread.Publish = blnPublish objThread.TopicId = strTopicId Catalogue(objThread) SetMessage(objHere, "", """Details updated. <a href="/admin/E3ThreadMaintenance">Return to list</a>""")
def ViewThreadContents(objHere, objRequest): # print "Request: ", objRequest.REQUEST intThreadId = str(GetParameter(objRequest, 'ThreadId')) intMonth = str(GetParameter(objRequest, 'Month')) intYear = str(GetParameter(objRequest, 'Year')) # print "Thread: ", intThreadId # print "Month: ", intMonth # print "Year: ", intYear strAttachment = GetParameter(objRequest, 'Attachment') strMessageId = GetParameter(objRequest, 'MessageId') if strMessageId: intMessageId = int(strMessageId) else: intMessageId = 0 strThreadId = GetParameter(objRequest, 'ThreadId') objThread = SearchOne(objHere, 'E3Messages', 'id', strThreadId) if intMessageId: strMessageId = GetParameter(objRequest, 'MessageId') objMessage = SearchOne(objHere, 'E3Messages', 'id', strMessageId) else: objMessage = objThread if not objThread: return "<p>Message not found. Please contact the list owner</p>" if strAttachment: objAttachment = objMessage.unrestrictedTraverse(strAttachment) return objMessage.unrestrictedTraverse(strAttachment) strSubject = ClearSubjectHeader(objMessage.mailSubject) # strThreads = GetThreads(objThread, intThreadId, intMessageId) strThreads = "" strDate = objMessage.mailDate.strftime(cnShortDateFormat + " %H:%M") objMember = GetCurrentMember(objHere) # if objMessage.Private and not objMember: strSender = GetSenderIdentification(objThread, IsFullMember(objHere)) # else: # strSender = ClearSender(objMessage.mailFrom) strHTML = GetHTML(objMessage) objMember = GetCurrentMember(objHere) strPrivatePublic = "" if objMember: if objMember.id == objMessage.UserId: if objMessage.Private: strPrivatePublic = """<p>For list members only. <a href="%s&Action=SetPublic">Click here to make this a public message</a>. Note: Only make a message public if you have personally written the whole message</p>""" else: strPrivatePublic = """<p>Public message, visible to anyone. <a href="%s&Action=SetPrivate">Click here to make this a private message, visible to list members only</a></p>""" strPrivatePublic = strPrivatePublic % FullURL(objHere) if strHTML: strBody = strHTML else: strBody = InsertBrs(objMessage.mailBody) strAttachments = ListAttachments(objMessage, intThreadId, intMessageId) strAttachments = ToUnicode(strAttachments) strSubject = ToUnicode(strSubject) strSender = ToUnicode(strSender) strBody = ToUnicode(strBody) strThreads = ToUnicode(strThreads) strAttachments = ToUnicode(strAttachments) strResult = u""" <fieldset> <legend>%s by %s</legend> """ % (strDate, strSender) strResult += u"<h2>%s</h2>\n" % strSubject strResult += strPrivatePublic + "\n" strResult += strThreads + "\n" strResult += strAttachments + "\n" strResult += u"""</fieldset> <fieldset> <legend>Message</legend> <p>%s</p> </fieldset> """ % strBody # strResult = u""" # # <fieldset> # <legend>%(Date)s by %(Sender)s</legend> # <h2>%(Subject)s</h2> # %(PrivatePublic)s # %(Threads)s # %(Attachments)s # </fieldset> # <fieldset> # <legend>Message</legend> # <p>%(Body)s</p> # </fieldset>""" % {'Subject': strSubject, # 'Threads': strThreads, # 'Date': strDate, # 'Sender': strSender, # 'Body': strBody, # 'PrivatePublic': strPrivatePublic, # 'Attachments': strAttachments} # strResult = unicode(strResult, 'ascii', 'replace') return strResult
def FinishPayment(objHere, objRequest): strWPContents = """<p> </p> <p>Here is the response from WorldPay:</p> <WPDISPLAY ITEM=banner> """ strErrorPage = """<h2>Payment problem</h2> <p>There was a problem processing your payment</p> <p>The site owner will contact you at %s to find out what happened, to help him solve the problem</p>""" + strWPContents strErrorPageNoDetails = """<h2>Payment problem</h2> <p>There was a problem processing your payment</p> <p>Please go to <a href="/ContactDetails">the contact page</a> to contact the list owner with a brief description of what happened, to help him solve the problem for you. Go to the contact page</p>""" + strWPContents strCancellationPage = """<h2>Payment cancelled</h2> <p>It seems that you have cancelled your payment</p> <p>If you have any questions please <a href="/ContactDetails">contact the list owner</a></p>""" + strWPContents objForm = objRequest.form try: intCartId = int(objForm['cartId']) strEmailAddress = objForm['email'] except: SendErrorEmail(objHere, "WorldPayCall problem, no contact details") return strErrorPageNoDetails objWorldPayCall = SearchOne(objHere, 'E3WorldPayCall', 'CartId', intCartId) if not objWorldPayCall: SendErrorEmail(objHere, "Can't find WorldPayCall, for cartId = %s, email address = %s" % (intCartId, strEmailAddress)) return strErrorPage % strEmailAddress if objWorldPayCall.Status == "Success": SendErrorEmail(objHere, "WorldPayCall processed twice, for cartId = %s, email address = %s" % (intCartId, strEmailAddress)) return strErrorPage % strEmailAddress SavePaymentDetails(objWorldPayCall, objForm) (blnCorrect, strErrorMessage) = CheckPaymentForm(objForm) if blnCorrect: if objForm['transStatus'] == 'C': objWorldPayCall.Status = 'Cancelled' return strCancellationPage objWorldPayCall.Status = 'Success' strCurrency = objForm['authCurrency'] strAmount = objForm['authAmount'] fltAmount = float(strAmount) strEmailAddress = objForm['email'] strName = objForm['name'] try: strPaymentType = objWorldPayCall.PaymentType except: strPaymentType = "ECL" if strPaymentType == "ECL": return FinishECLPayment(objWorldPayCall, strCurrency, fltAmount, strEmailAddress) + strWPContents elif strPaymentType[:3] == "CBA": return FinishCBAPayment(objWorldPayCall, strCurrency, fltAmount, strEmailAddress, strName, strPaymentType) + strWPContents elif strPaymentType[:15] == "E3Conf08Booking": return FinishE3Conf08Booking(objWorldPayCall, strCurrency, fltAmount, strPaymentType, strWPContents) else: objWorldPayCall.Status = "Failed" SendErrorEmail(objHere, "Payment processing, unknown payment type: %s, %s" % (strPaymentType, objWorldPayCall.id)) return strErrorPage % strEmailAddress else: objWorldPayCall.Status = 'Failed' SendErrorEmail(objHere, strErrorMessage + ", for cartId = %s, email address = %s" % (intCartId, strEmailAddress)) return strErrorPage % (strEmailAddress)