def profile(request): ''' View for User Profile ''' #Getting Gravatar Image email = request.user.email size=150 gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(email.lower()).hexdigest() + "?" gravatar_url += urllib.urlencode({'s':str(size)}) #Getting User Status for App status = "Active" if request.user.is_active==True else "Gone Fishin'" # If form is already submitted if request.method == 'POST': #The constructor has been overridden. [] necessary form = forms.Profile(request.POST) if form.is_valid(): # set Profile Details old_name = mmclient.getUserName(email) msg = mmclient.setProfileDetails(email, form.cleaned_data) messages.info(request, msg) #Change all occurances of old_name to new_name in the db msg = MessageRenderer.updateScreenname(old_name,form.cleaned_data['display_name']) return HttpResponseRedirect("/profile") else: #Get dictionary from mmclient profile_details = mmclient.getProfileDetails(email) form = forms.Profile(profile_details) # Create new form pwdform = forms.ChangePwd() return render_to_response('profile.html', {'gurl': gravatar_url, 'form':form, 'pwdform':pwdform, 'status':status}, context_instance=RequestContext(request))
def publicprofile(request, profile_email): ''' Render public profile of user with email id = profile_email ''' #Getting Gravatar Image email = profile_email size=150 gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(email.lower()).hexdigest() + "?" gravatar_url += urllib.urlencode({'s':str(size)}) #Getting User Status for App u = User.objects.get(email__exact=email) status = "Active" if u.is_active==True else "Gone Fishin'" #Getting User's Display Name display_name = mmclient.getUserName(email) return render_to_response('publicprofile.html', {'gurl': gravatar_url, 'status':status, 'display_name':display_name}, context_instance=RequestContext(request))
def archive_message(mlist, message): """See `IArchiver`.""" log.info("MI: Archive_message") try: #Temporary variables used in this function msg_date="" msg_body = "" try: timestamp = time.mktime(email.utils.parsedate(message['Date'])) msg_date = datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d') # To get the body from multipart messages for part in message.walk(): if part.get_content_type(): msg_body = msg_body + part.get_payload(decode=True) except: msg_date = datetime.date.today().strftime('%Y-%m-%d') # Get the Screen-name of the ID corresponding to this author author_name="" author_email="" try: email_id = message['From'] # If the email_id is of the form root<*****@*****.**>, extract the actual emailid if '<' in email_id and '>' in email_id: pos1 = email_id.find('<')+1 pos2 = email_id.find('>') email_id = email_id[pos1:pos2] author_email = email_id author_name = mmclient.getUserName(email_id) except Exception as ex: log.info("MI:Exception", ex) author_name = email_id # If the message is a reply, generate threadid if 'In-Reply-To' in message.keys(): # Implies is a reply # Get id of message replied to # Get threadid of message replied to # Assign this thread id to current message replied_to = message['In-Reply-To'] temp = models.MIMessage.objects.filter(msgid=replied_to)[0] log.info(temp.threadid) # Create MessageRenderer model object msg = models.MIMessage(subject=message['Subject'], email=author_email, author=author_name, date=msg_date,listname=mlist.fqdn_listname, msg=msg_body, msgid=message['Message-ID'], threadid=temp.threadid) else: log.info("ELSE") # Is a new message. Use message-id as thread-id unique_id = message['Message-ID'] msg = models.MIMessage(subject=message['Subject'], email=author_email, author=author_name, date=msg_date,listname=mlist.fqdn_listname, msg=msg_body, msgid=message['Message-ID'], threadid=unique_id) # Save to DB msg.save() log.info("MI: Message Saved") except Exception,ex: log.exception(ex)