コード例 #1
0
ファイル: mail.py プロジェクト: auvipy/flowgram.com
def send_invitations(user, invitees, personal_message=""):
    sender_email = user.email
    subject = "%s has invited you try Flowgram.com" % sender_email
    t = get_template('emails/invite.txt')
    use_regcode = FEATURE['use_regcode']
    successes = []
    failures = []
    for email in invitees:
        r = Regcode.objects.create(sender=user)
        c = Context({
            'user' : user,
            'regcode': r.code,
            'use_regcode': use_regcode,
            'to': email,
            'URL_BASE' : URL_BASE,
            'personal_message' : personal_message
            })
        body = t.render(c)
        try:
            log.debug("send_mail from send_invitations to " + email)
            add_to_mail_queue(sender_email, email, subject, body)
            successes.append(email)
        except:
            failures.append(email)
    return successes, failures
コード例 #2
0
ファイル: controller.py プロジェクト: auvipy/flowgram.com
def store_fgcomented_event(data):
    """
    Stores Flowgram Commented event in UserHistory
    """
    
    try:
        # Unpack dict
        currentUser = data['commentor']
        eventCode = data['eventCode']
        flowgramIdStr = data['fg_id']
        fg = Flowgram.objects.get(pk=flowgramIdStr)# Get Flowgram info from flowgramID
        
        # if the fg is private, we need to kill this here
        if fg.public == True:
            flowgramTitle = fg.title
            targetUser = fg.owner
        
            # HTML CODE BUILD
            iconHtmlCode = get_icon_code(eventCode) # img icon
            currentUserLink = create_user_link(currentUser) # user link
            targetUserLink = create_user_link(targetUser) # user link
            flowgramLink = create_fg_details_link(flowgramIdStr, flowgramTitle) # fg link
        
            # Determine proper message and add html code sets
            secondPersonPresent = "%s <span>You commented on %s's Flowgram named %s.</span>" % (iconHtmlCode,targetUserLink,flowgramLink) 
            secondPersonPast = "%s <span>%s commented on your Flowgram named %s.</span>" % (iconHtmlCode,currentUserLink,flowgramLink)          
            thirdPersonPast = "%s <span>%s commented on %s's Flowgram named %s.</span>" % (iconHtmlCode,currentUserLink,targetUserLink,flowgramLink) 
        
            # save event obj to UserHistory
            #UserHistory.objects.create(user=commentor,targetUser=target_user,ThirdPersonMsg=ThirdPerson,ThirdPersonYouMsg=ThirdPersonYou,FirstPersonMsg=FirstPerson,rawData=raw)
            UserHistory.objects.create(currentUser=currentUser,targetUser=targetUser,eventCode=eventCode,flowgramId=flowgramIdStr,thirdPersonPast=thirdPersonPast,secondPersonPast=secondPersonPast,secondPersonPresent=secondPersonPresent)
    except:
        log.debug("Attempted to create FG_COMMENTED event FAILED")# log error
コード例 #3
0
ファイル: controller.py プロジェクト: auvipy/flowgram.com
def store_fgtagged_event(data):
    """
    Stores Flowgram Tagged event in UserHistory
    """
    try:
        # Unpack dict
        currentUser = data['current_user']
        eventCode = data['eventCode']
        flowgramIdStr = data['fg_id']
        fg = Flowgram.objects.get(pk=flowgramIdStr) 
        
        # if the fg is private, we need to kill this here
        if fg.public == True:
        
            # Get Flowgram info from fg_id
            flowgramTitle = fg.title
            targetUser = fg.owner
        
            iconHtmlCode = get_icon_code(eventCode) # Get icon html based on eventCode
            currentUserLink = create_user_link(currentUser)
            targetUserLink = create_user_link(targetUser)
            flowgramLink = create_fg_details_link(flowgramIdStr, flowgramTitle) # Get fg html link
            
            # Determine proper message and add html code sets
            secondPersonPresent = "%s <span>You tagged %s's Flowgram named %s.</span>" % (iconHtmlCode,targetUserLink,flowgramLink) 
            thirdPersonPast = "%s <span>%s tagged %s's Flowgram named %s.</span>" % (iconHtmlCode,currentUserLink,targetUserLink,flowgramLink) 
            secondPersonPast = "%s <span>%s tagged your Flowgram named %s.</span>" % (iconHtmlCode,currentUserLink,flowgramLink)            
        
            # save event obj to UserHistory
            UserHistory.objects.create(currentUser=currentUser,targetUser=targetUser,eventCode=eventCode,flowgramId=flowgramIdStr,thirdPersonPast=thirdPersonPast,secondPersonPast=secondPersonPast,secondPersonPresent=secondPersonPresent)
    except Exception:
        log.debug("Attempted to create FG_TAGGED UserHistory obj FAILED")# log error	
コード例 #4
0
ファイル: controller.py プロジェクト: auvipy/flowgram.com
def store_badge_fgviews_event(data):
	"""
	Stores Badge event in UserHistory
	"""
	try:
		# Unpack dict & Get User / Flowgram info
		eventCode = data['eventCode']
		flowgramIdStr = "none"
		flowgramViewsCount = data['fg_views']
		currentUser = data['current_user'] 
		targetUser = currentUser
		
		# Get HTML code
		iconHtmlCode = get_icon_code(eventCode)
		currentUserLink = create_user_link(currentUser)
		
		# Determine proper message and add html code sets
		secondPersonPresent = "%s <span>Congrats! Your Flowgrams have reached %s views!</span>" % (iconHtmlCode,flowgramViewsCount) 
		thirdPersonPast = "%s <span>Wow! %s's Flowgrams have reached %s views.</span>" % (iconHtmlCode,currentUserLink,flowgramViewsCount) 
		secondPersonPast = "" # no case for this msg type
		
		# save event obj to UserHistory
		UserHistory.objects.create(currentUser=currentUser,targetUser=targetUser,eventCode=eventCode,flowgramId=flowgramIdStr,thirdPersonPast=thirdPersonPast,secondPersonPast=secondPersonPast,secondPersonPresent=secondPersonPresent)
	except Exception:
		log.debug("Attempted to create BADGE_FGVIEWS UserHistory event FAILED")# log error		
コード例 #5
0
ファイル: controller.py プロジェクト: auvipy/flowgram.com
def check_fgviews_landmark(user, new_count):
	"""
	Determines if the new flowgram view count causes total views to surpass a set increment 
	if so, store the event in UserHistory
	"""
	# increments taken from views/show_user
	if (new_count == 100) or (new_count == 500) or (new_count == 1000)  or (new_count == 5000) or (new_count == 10000):
		try: # UserHistory: BADGE_FGVIEWS
		    if new_count >= 10000:
		        eventCode = "BADGE_FGVIEWS_10k"
		    elif new_count >= 5000:
		        eventCode = "BADGE_FGVIEWS_5k"
		    elif new_count >= 1000:
		        eventCode = "BADGE_FGVIEWS_1k"
		    elif new_count >= 500:
		        eventCode = "BADGE_FGVIEWS_500"
		    elif new_count >= 100:
		        eventCode = "BADGE_FGVIEWS_100"
		    else:
		        eventCode = "BADGE_FGVIEWS_generic"
		
		    data = {'current_user':user,'fg_views':new_count,'eventCode':eventCode} # Build dict for UserHistory Event
		    store_badge_fgviews_event(data)

		
		except:
			log.debug("attempted to send BADGE_FGVIEWS event to store_badge_fgviews_event -- FAILED")# log error
コード例 #6
0
ファイル: controller.py プロジェクト: auvipy/flowgram.com
def get_working_flowgram(user):
    profile = user.get_profile()

    try:
        log.debug("get_working_flowgram for user %s with working_flowgram_id = %s" % (str(user.id), profile.working_flowgram_id))
        
        if profile.just_published and profile.working_flowgram_id != "":
            log.critical("User %s has just_published AND working_flowgram_id = %s." % (user, profile.working_flowgram_id))

        working_flowgram = None
        if profile.working_flowgram_id != "":
            working_flowgram = Flowgram.objects.get(id=profile.working_flowgram_id)

        if profile.just_published or (working_flowgram and not permissions.can_edit(user, working_flowgram)):
            flowgram = new_flowgram(user)
            set_working_flowgram(user, flowgram)
            
            profile.just_published = False
            profile.save()
            
            return (flowgram, True)
    
        if working_flowgram:
            return (working_flowgram, False)
    except Flowgram.DoesNotExist:
        pass

    # Finally, return their latest-modified Flowgram if one exists, or else a new flowgram
    try:
        return (Flowgram.objects.filter(owner=user, published=False).latest('modified_at'), False)
    except Flowgram.DoesNotExist:
        flowgram = new_flowgram(user)
        set_working_flowgram(user, flowgram)
        
        return (flowgram, True)
コード例 #7
0
ファイル: controller.py プロジェクト: auvipy/flowgram.com
def create_page_to_flowgram(flowgram, page, html, do_make_thumbnail=True, set_position=True):
    """Expects a page object with title and source_url already set."""
    # TODO(andrew): move functionality into or out of this awkward function?
    
    # put it at the end of the flowgram:
    if set_position:
        page.position = get_next_position(flowgram)

    log.debug("create_page_to_flowgram: " + str(flowgram))
    page.flowgram = flowgram
    page.save()
    
    # save the file:
    filename = page_filename(page)
    add_file_to_flowgram(flowgram, filename, html, PAGEFILE_ENCODING)
    
    # Set the title of the flowgram if this is the first page:
    if flowgram.title == DEFAULT_FG_TITLE:
        flowgram.title = page.title
        flowgram.save()  
                
    
    if do_make_thumbnail:
        make_thumbnail(page)
    add_default_time(page)
    
    return page
コード例 #8
0
ファイル: controller.py プロジェクト: auvipy/flowgram.com
def store_subscription_event(data):
	""" 
	Stores subscription event in UserHisotry
	"""
	try:
		# Unpack dict
		currentUser = data['user']
		targetUser = data['target_user']
		eventCode = data['eventCode']
		#raw = "%s" % (data)
		flowgramId = "none"
		
		# HTML CODE BUILD
		iconHtmlCode = get_icon_code(eventCode) # Get icon image path + html based on eventCode
		currentUserLink = create_user_link(currentUser) # returns html link to user
		targetUserLink = create_user_link(targetUser) # returns html link to user
		
		# Determine proper message and add html code sets
		if eventCode == "SUB":
			secondPersonPresent = "%s <span>You subscribed to %s.</span>" % (iconHtmlCode,targetUserLink) 
			thirdPersonPast = "%s <span>%s subscribed to %s.</span>" % (iconHtmlCode,currentUserLink,targetUserLink) 
			secondPersonPast = "%s %s subscribed to you." % (iconHtmlCode,currentUserLink) 
		else: #assumes eventCode == "UNSUB"
			secondPersonPresent = "%s <span>You unsubscribed from %s.</span>" % (iconHtmlCode,targetUserLink) 
			thirdPersonPast = "%s <span>%s unsubscribed from %s.</span>" % (iconHtmlCode,currentUserLink,targetUserLink) 
			secondPersonPast = "%s <span>%s unsubscribed from you.</span>" % (iconHtmlCode,currentUserLink) 
		
		# save event obj to UserHistory
		UserHistory.objects.create(currentUser=currentUser,targetUser=targetUser,eventCode=eventCode,flowgramId=flowgramId,thirdPersonPast=thirdPersonPast,secondPersonPast=secondPersonPast,secondPersonPresent=secondPersonPresent)
	except:
		log.debug("Attempted to create (UN)SUB UserHistory event FAILED") # log error
コード例 #9
0
ファイル: tags.py プロジェクト: auvipy/flowgram.com
 def __init__(self, flowgram, width, height, mode, linkurl, additional_params=None):
     self.flowgram = Variable(flowgram)
     self.width = width
     self.height = height
     self.mode = mode
     self.linkurl = linkurl
     self.additional_params = additional_params
     log.debug("Initializing WidgetNode with linkurl=%s" % self.linkurl)
コード例 #10
0
ファイル: controller.py プロジェクト: auvipy/flowgram.com
def set_working_flowgram(user, fg):
    if permissions.can_edit(user, fg):
        profile = user.get_profile()
        profile.working_flowgram_id = fg.id
        
        profile.save()
        
        log.debug("Action log: set_working_flowgram to %s for %s" % (fg.id, str(user.id)))
コード例 #11
0
ファイル: flowgrams.py プロジェクト: auvipy/flowgram.com
def create_flowgram(request, title):
    flowgram = controller.new_flowgram(request.user, title)
    controller.set_working_flowgram(request.user, flowgram)

    log.debug("Action log: create_flowgram %s for %s" % (flowgram.id, request.user.username))

    return data_response.create(request.POST.get('enc', 'json'),
                                'ok',
                                encode.flowgram_encoder.to_dict(flowgram, True, request.user))
コード例 #12
0
ファイル: views.py プロジェクト: auvipy/flowgram.com
def play_flowgram(request, flowgram_id, hash=None):
    log.debug("user agent found : play_flowgram" + request.META.get("HTTP_USER_AGENT", ""))
    user_agent=request.META.get("HTTP_USER_AGENT", "")
    if user_agent.lower().find(settings.GOOGLEBOT_UA) >= 0:
        # it is robot, need to find out yahoo robot too
        return HttpResponse(controller.reponse_non_user_agent(flowgram_id, hash)) 
    else:
        # it is real user
        #fg = get_object_or_404(Flowgram, pk=flowgram_id)
        #return HttpResponseRedirect(fg.play_url(hash))
        return HttpResponse(controller.html_for_static_flex_file('p.html'))
コード例 #13
0
ファイル: models.py プロジェクト: sdia/flowgram.com
    def delete(self):
        log.debug("deleting flowgram %s with owner %s" % (self.id, self.owner.id))

        profiles = UserProfile.objects.filter(working_flowgram_id=self.id)

        for p in profiles:
            log.debug("clearing working_flowgram_id of user %s profile %s" % (p.user.id, p.id))

            p.working_flowgram_id = ""
            p.save()
        # ReIndexGather.objects.save_re_index(1, 1, self.id)
        super(Flowgram, self).delete()
コード例 #14
0
ファイル: mail.py プロジェクト: auvipy/flowgram.com
def announce_feedback(feedback):
    sender = DEFAULT_SENDER
    recipients = [FEEDBACK_RECIPIENT]
    subject = ""
    text = "URL: %s\nEmail: %s\nSystem info:\n%s\nComments: %s\n" % (feedback.url, feedback.email, feedback.sys_info, feedback.comments)
    try:
        log.debug("send_mail from announce_feedback to " + FEEDBACK_RECIPIENT)
        for recipient in recipients:
            add_to_mail_queue(sender, recipient, subject, text)
    except:
        log.error("Failure in announce_feedback:")
        log.trace()
コード例 #15
0
ファイル: mail.py プロジェクト: auvipy/flowgram.com
def announce_flag(request, flowgram):
    flagger = request.user.username or request.META['REMOTE_ADDR']
    subect = "%s FLAGGED by %s" % (flowgram.title, flagger)
    sender = DEFAULT_SENDER
    text = "See the flagged flowgram at %s" % flowgram.url()
    recipients = ['*****@*****.**']
    try:
        log.debug("send_mail from announce_flag to " + '*****@*****.**')
        for recipient in recipients:
            add_to_mail_queue(sender, recipient, subject, text)
    except:
        log.error("Failure in announce_flag:")
        log.trace()
コード例 #16
0
ファイル: servicechecker.py プロジェクト: auvipy/flowgram.com
def report_to_dashboard(serviceType, oldReqUnprocessed):
    try:
        record = DashboardServiceRecord.objects.get(service_type=serviceType)
    except DashboardServiceRecord.DoesNotExist:
        log.debug('create a new entry in dashboard service record table %s' % serviceType)
        record = DashboardServiceRecord.objects.create(service_type=serviceType,
                                                       service_status=True,
                                                       latest_checkedtime=current_time)
        
    if oldReqUnprocessed:
        log.debug('there are unprocessed jobs pending in %s' % serviceType)
        error_record = record
        error_record.service_status = False
        error_record.latest_checkedtime = current_time
        error_record.save()
        
        try:
            add_to_mail_queue(
                          '*****@*****.**',
                          '*****@*****.**',
                          '[STATUS UPDATE] %s -Slow/Not Working' % serviceType,
                          'You need to check db table of: %s . Service found Slow/Not Working at %s.' % (serviceType, error_record.latest_checkedtime))
        except Exception, e:
            log.debug(e)
            log.debug('email service is down')
コード例 #17
0
ファイル: fix.py プロジェクト: sdia/flowgram.com
def process_page(html, url):
    # Site specific hacks
    log.debug("Called process_page on %s" % (url))
    if url.startswith("http://youtube.com/watch") or url.startswith("http://www.youtube.com/watch"):
        log.debug("Calling fix_youtube")
        html, url = fix_youtube(html, url)
    elif url.startswith("http://maps.google.com"):
        log.debug("Calling fix_google_maps")
        html, url = fix_google_maps(html, url)
    elif url.startswith("http://gallery.mac.com/"):
        log.debug("Calling fix_mac_gallery")
        html, url = fix_mac_gallery(html, url)
    elif url.startswith("http://www.techcrunch.com/2008/07/03/flowgram-reinvents-the-screencast-1000-beta-invites"):
        html, url = fix_techcrunch_flowgram_article(html, url)
    # elif url == "http://www.flowgram.com/" or url == "http://www.flowgram.com" or url == "http://dev.flowgram.com" or url == "http://dev.flowgram.com/" :
    # log.debug('Calling fix_flowgram_own_homepage')
    # html, url = fix_flowgram(html, url)
    # elif url.startswith("http://www.flowgram.com/fg/"):
    # log.debug('Calling fix_flowgram_widget_fg')
    # html, url = fix_flowgram_widget_fg(html, url)

    html, url = remove_self_targets(html, url)
    html, url = add_base(html, url)
    html, url = add_base_target(html, url)
    html, url = add_page_css(html, url)
    html = remove_script_tags(html, url)

    return (html, url)
コード例 #18
0
ファイル: flowgrams.py プロジェクト: auvipy/flowgram.com
def can_edit_fg(request, flowgram_id):
    try:
        log.debug('[can_edit_fg flowgram_id: %s]' % flowgram_id)
        flowgram = models.Flowgram.objects.get(id=flowgram_id)
        log.debug('(1 %s)' % request.user.username)
    except models.Flowgram.DoesNotExist:
        return HttpResponse('0 fg does not exist')

    log.debug('(2)')
    if permissions.can_edit(request.user, flowgram):
        log.debug('(3)')
        return HttpResponse('1')
    else:
        log.debug('(4)')
        return HttpResponse('0 user can\'t edit')
コード例 #19
0
ファイル: favorites.py プロジェクト: auvipy/flowgram.com
def add_favorite(request, flowgram):
	try:
		models.Favorite.objects.get(owner=request.user, flowgram=flowgram)
	except:
		# If the specified Flowgram is not already a favorite, add it.
		models.Favorite.objects.create(owner=request.user, flowgram=flowgram)
		controller.record_stat(request, 'add_favorite_website', '0', flowgram.id)

		# UserHistory: FG_FAVED
		if localsettings.FEATURE['notify_fw']:
			try: 
				controller.store_fgfaved_event({
                    'current_user': request.user,
                    'fg_id': flowgram.id,
                    'eventCode': 'FG_FAVED'})
			except:
				log.debug("In api/views.py, attempted to send FG_FAVED event to controller.py/store_fgfaved_event -- FAILED")
コード例 #20
0
ファイル: audio.py プロジェクト: auvipy/flowgram.com
def add_audio_fms(request, page, time, duration):
    file_path = '%s/%s/%s/%d.flv' % (localsettings.FMS_STREAM_DIR, page.flowgram.id, page.id, time)
    
    if os.path.isfile(file_path):
        audio = models.Audio.objects.create(page=page, time=time, duration=duration)
        audio.path = file_path
        
        helpers.set_modified(page.flowgram)
        
        s3.save_filename_to_bucket(localsettings.S3_BUCKET_AUDIO, '%s.flv' % audio.id, file_path)
        
        return data_response.create(request.POST.get('enc', 'json'), 'ok', audio.id)
    else:
        log.debug('add_audio_fms called with page.id=%s, time=%d, and duration=%d but file_path=%s DNE' % \
                      (page.id, time, duration, file_path))
        
        return error_response.create(request.POST.get('enc', 'json'), 'flv does not exist.')
コード例 #21
0
ファイル: views.py プロジェクト: auvipy/flowgram.com
def dashboard_index(request):
    error_records = []
    pass_records = []
    records = DashboardServiceRecord.objects.all()
    if not records:
       log.debug('dashboard service recorder not running, check servicechecker.py in /flowgram/flowgram/core/dashboard')
       
    for record in records:
        if record.service_status == False:
            error_records.append(record)
        else:
            pass_records.append(record)
            
    return req_render_to_response(request, "dashboard/index.html", {
        'error_records': error_records,
        'pass_records':pass_records
    })
     
コード例 #22
0
ファイル: mail.py プロジェクト: auvipy/flowgram.com
def announce_new_flowgram(flowgram):
    creator = flowgram.owner
    url = flowgram.full_url()
    log.debug("announce_new_flowgram")    
    for profile in creator.subscribers.all():
        subject = "%s (Flowgram.com)" % (flowgram)
        text = "%s's latest Flowgram was published to the web at %s." % (creator, url)
        try:
            email_user(profile.user, subject, text)
        except:
            log.error("announce_feed_message failed to email user " + profile.username)
    if creator.get_profile().subscribed_to_self:
        subject = "\"%s\" -- your latest Flowgram has been posted!" % (flowgram.title)
        text = "Your latest Flowgram, %s, was published to the web at %s." %(flowgram.title, url)
        try:
            email_user(creator, subject, text)
        except:
            log.error("announce_feed_message failed to email user " + profile.username)
コード例 #23
0
ファイル: cached_sets.py プロジェクト: auvipy/flowgram.com
def get_related(flowgram, request):
    if FEATURE['use_HEsearch']:
        expiration_time = datetime.datetime.now() - RELATED_FLOWGRAM_EXPIRATION_DELTA
        flowgram_related_record = FlowgramRelated.objects.filter(flowgram=flowgram, timestamp__gte=expiration_time)
        flowgram_related_record = flowgram_related_record[0] if len(flowgram_related_record) else None
        if not flowgram_related_record:
            log.debug("need to re-calculate the related flowgrams record of %s" % flowgram.id)
            return get_related_fg_changed(flowgram, request)
        
        related_ids = flowgram_related_record.related
        related_flowgrams = []
        if related_ids:
            for fg_id in related_ids.split(';'):
                one_flowgram = get_object_or_404(Flowgram, pk=fg_id)
                related_flowgrams.append(one_flowgram)
        return related_flowgrams
    else:
        return get_featured(feat.FEATURED_PAGE)
コード例 #24
0
ファイル: powerpoint.py プロジェクト: auvipy/flowgram.com
def upload(request, enc):
    if request.FILES.has_key('file'):
        # do later in queue once per slide
        # adds a page to the fg
        # html will be like before but embed a swf that is centered
        # page = Page.objects.create(title=request.FILES['file']['filename'], position=255)
        # page = controller.create_page_to_flowgram(fg, page, html)

        (fg, new) = controller.get_working_flowgram(request.user)
        if new:
            log.debug("Action log: new working flowgram %s created during add_page" % fg.id)

        # create queue item
        ppt_import_request = models.PptImportRequest.objects.create(flowgram=fg)

        #     2. Send to S3
        ppt_import_request.save_ppt_to_s3(request.FILES['file']['content'])
        
        return data_response.create(enc, 'ok', ppt_import_request.id)
    else:
        return error_response.create(enc, 'No file was uploaded.')
コード例 #25
0
ファイル: tags.py プロジェクト: auvipy/flowgram.com
    def render(self, context):
        flowgram = self.flowgram.resolve(context)
        fgid = flowgram.id
        thislink = self.linkurl
        if thislink == '/create/':
            thislink += '?homeWidgetID=%s' % fgid
            log.debug("WidgetNode appending homeWidgetID arg -- now %s" % (self.linkurl))
        else:
            log.debug("WidgetNode not appending homeWidgetID arg -- linkurl=%s" % self.linkurl)

        if self.additional_params:
            additional_params = ',' + ','.join(['%s: "%s"' % (key, self.additional_params[key]) \
                                                    for key in self.additional_params.keys()])
        else:
            additional_params = ''

        return 'swfobject.embedSWF("/widget/flexwidget.swf", \
               "alt_%s", "%d", "%d", "%s", "/flex/playerProductInstall.swf", \
               {fgid: "%s", linkurl: "%s"%s}, \
               {wmode: "%s", allowScriptAccess: "always"}, \
               {id: "fwidget_%s"});' % \
               (fgid, self.width, self.height, WIDGET_VERSION, fgid, thislink, additional_params, self.mode, fgid)
コード例 #26
0
ファイル: cached_sets.py プロジェクト: auvipy/flowgram.com
def get_related_fg_changed(flowgram, request):
    if FEATURE['use_HEsearch']:
        non_alpha_charaters = re.compile(r'[a-zA-Z]+')
        tags = Tag.objects.filter(flowgram=flowgram)
        searchphrase_list = [tag.name for tag in tags] + non_alpha_charaters.findall(flowgram.title)
        searchphrase_list = [word for word in searchphrase_list if word not in non_search_words and word not in punctuation]
        
        searchphrase = ' OR '.join(searchphrase_list)
        
        related_flowgrams = []
        log.debug('use hyperestraier, the searchphrase is: ' + searchphrase)
        he_documents = searcher.search(str(searchphrase))
        for he_doc in he_documents:
            if searcher.get_attr(he_doc, '@flowgram_type') == 'flowgram':
                fg_id = searcher.get_attr(he_doc, '@flowgram_id')
                one_flowgram = get_object_or_404(Flowgram, pk=fg_id)
                if one_flowgram.public or \
                        request.user.is_authenticated() and request.user == one_flowgram.owner:
                    if one_flowgram != flowgram:
                        related_flowgrams.append(one_flowgram)

        related_flowgrams = related_flowgrams[:10]
        related_flowgrams_string = ";".join([fg.id for fg in related_flowgrams])

        # flowgram changed, update the related flowgrams in db
        flowgram_need_update = FlowgramRelated.objects.filter(flowgram=flowgram)
        flowgram_need_update = flowgram_need_update[0] if len(flowgram_need_update) else None
        if flowgram_need_update:
            flowgram_need_update.related = related_flowgrams_string
            flowgram_need_update.timestamp = datetime.datetime.now()
            flowgram_need_update.save()
        else:
            FlowgramRelated.objects.create(flowgram=flowgram, related=related_flowgrams_string)
            
        return related_flowgrams
    else:
        return get_featured(feat.FEATURED_PAGE)
コード例 #27
0
ファイル: fix.py プロジェクト: sdia/flowgram.com
def fix_google_maps(html, url):
    log.debug("Called fix_google_maps on %s" % (url))
    try:
        link_elem = html.index('id="link"')
        log.debug("Found link_elem: %s" % (link_elem))
    except ValueError:
        try:
            link_elem = html.index("id=link")
        except ValueError:
            return (html, url)  # can't find maps, so don't do anything

    try:
        link_elem = html.rindex("<", 0, link_elem)
        link_begin = html.index('href="', link_elem) + 6
        link_end = html.index('"', link_begin)
    except ValueError:
        return (html, url)  # malformed html, so don't do anything

    url = unescape(html[link_begin:link_end])
    log.debug("Got URL: %s" % (url))
    return (html, url)
コード例 #28
0
ファイル: mail.py プロジェクト: auvipy/flowgram.com
def email_user_html(recipient, subject, html, sender=DEFAULT_SENDER):
    """Emails a user. If you call email_user, it is your responsibility to try/except"""
    if isinstance(sender, User):
        sender = "\"%s @ Flowgram\" <%s>" % (sender.username, sender.email)
    log.debug("send_mail from email_user to %s" % sender)
    add_to_mail_queue(sender, recipient.email, subject, '', html, 'text/html')
コード例 #29
0
ファイル: audio.py プロジェクト: auvipy/flowgram.com
def clear_audio(request, page):
    models.Audio.objects.filter(page=page).delete()
    log.debug('Action log: clear_audio on page %s for %s' % (page.id, request.user.username))
コード例 #30
0
ファイル: servicechecker.py プロジェクト: auvipy/flowgram.com
#!/usr/local/bin/python

import datetime
from flowgram.core.models import AddPageRequest, GetCssRequest, PptImportRequest, SendEmailRequest, ImportMediaRequest, DashboardServiceRecord
from flowgram.queueprocessors.sendemailrequestprocessor import add_to_mail_queue
from flowgram.core import log

#check every 10 mins
CHECK_GAP = 600

current_time = datetime.datetime.now()
log.debug('servicechecker.py starts at %s' % current_time)

old_req_unprocessed_addpagerequest = AddPageRequest.objects.filter(timestamp__gte=current_time - datetime.timedelta(seconds=CHECK_GAP*2), 
                                                                   timestamp__lte=current_time - datetime.timedelta(seconds=CHECK_GAP), 
                                                                   status_code=0)
#log.debug('AddPageRequest %s' % old_req_unprocessed_addpagerequest)

old_req_unprocessed_getcssrequest = GetCssRequest.objects.filter(timestamp__gte=current_time - datetime.timedelta(seconds=CHECK_GAP*2), 
                                                                     timestamp__lte=current_time - datetime.timedelta(seconds=CHECK_GAP), 
                                                                     status_code=0)
#log.debug('GetCssRequest %s' % old_req_unprocessed_getcssrequest)

old_req_unprocessed_pptimportrequest = PptImportRequest.objects.filter(timestamp__gte=current_time - datetime.timedelta(seconds=CHECK_GAP*2), 
                                                                     timestamp__lte=current_time - datetime.timedelta(seconds=CHECK_GAP), 
                                                                     status_code=0)
#log.debug('PptImportRequest %s' % old_req_unprocessed_pptimportrequest)

old_req_unprocessed_sendemailrequest = SendEmailRequest.objects.filter(timestamp__gte=current_time - datetime.timedelta(seconds=CHECK_GAP*2), 
                                                                     timestamp__lte=current_time - datetime.timedelta(seconds=CHECK_GAP), 
                                                                     status_code=0)