Пример #1
0
 def calculate_over_40(self):
     from profile.models import Profile
     try:
         ## try to get the user's DOB from their profile, if no profile
         # is made, assume they are over 40
         dob = Profile.get_for_user(self.user).dob
     except AttributeError, Profile.DoesNotExist:
         dob = datetime.date(1915,7,21)
Пример #2
0
 def calculate_over_40(self):
     from profile.models import Profile
     try:
         ## try to get the user's DOB from their profile, if no profile
         # is made, assume they are over 40
         dob = Profile.get_for_user(self.user).dob
     except AttributeError, Profile.DoesNotExist:
         dob = datetime.date(1915, 7, 21)
Пример #3
0
def bargraph_image(request, column, func, agg):

    import bargraph as g

    if agg == "person":
        Graph = g.PersonBarGraph

    elif agg == "student":
        Graph = g.StudentBarGraph

    elif agg == "captain":
        Graph = g.CaptainBarGraph

    elif agg == "first_officer":
        Graph = g.FOBarGraph

    elif agg == "instructor":
        Graph = g.InstructorBarGraph

    elif agg == "type":
        Graph = g.PlaneTypeBarGraph

    elif agg == "tailnumber":
        Graph = g.TailnumberBarGraph

    elif agg == "manufacturer":
        Graph = g.ManufacturerBarGraph

    elif agg == "category_class":
        Graph = g.CatClassBarGraph

    elif agg == "model":
        Graph = g.ModelBarGraph

    elif agg == "year":
        Graph = g.YearBarGraph

    elif agg == "month":
        Graph = g.MonthBarGraph

    elif agg == "day_of_the_week":
        Graph = g.DOWBarGraph

    elif agg == "month_year":
        Graph = g.MonthYearBarGraph

    else:
        assert False, "Agg not added to generator view"

    graph = Graph(request.display_user, column, agg, func)

    from profile.models import Profile

    graph.color_profile = Profile.get_for_user(request.display_user).style

    return graph.as_png()
Пример #4
0
def bargraph_image(request, column, func, agg):

    import bargraph as g

    if agg == 'person':
        Graph = g.PersonBarGraph

    elif agg == 'student':
        Graph = g.StudentBarGraph

    elif agg == 'captain':
        Graph = g.CaptainBarGraph

    elif agg == 'first_officer':
        Graph = g.FOBarGraph

    elif agg == 'instructor':
        Graph = g.InstructorBarGraph

    elif agg == 'type':
        Graph = g.PlaneTypeBarGraph

    elif agg == 'tailnumber':
        Graph = g.TailnumberBarGraph

    elif agg == 'manufacturer':
        Graph = g.ManufacturerBarGraph

    elif agg == 'category_class':
        Graph = g.CatClassBarGraph

    elif agg == 'model':
        Graph = g.ModelBarGraph

    elif agg == 'year':
        Graph = g.YearBarGraph

    elif agg == 'month':
        Graph = g.MonthBarGraph

    elif agg == 'day_of_the_week':
        Graph = g.DOWBarGraph

    elif agg == 'month_year':
        Graph = g.MonthYearBarGraph

    else:
        assert False, "Agg not added to generator view"

    graph = Graph(request.display_user, column, agg, func)

    from profile.models import Profile
    graph.color_profile = Profile.get_for_user(request.display_user).style

    return graph.as_png()
Пример #5
0
def proper_ad(request):
    u = getattr(request, "display_user", None) or request.user
    style = Profile.get_for_user(u).style
    
    if True: #random.choice([True] * 20 + [False]):
        ad_text = GOOGLE_ADS[style]
    else:
        ad_text = WIKI_ADS[style]
    
    #######
    
    import os
    CSS_URL = os.path.join(settings.MEDIA_URL, "css", "style-%s" % style)
    
    return {"proper_ad": ad_text, 'CSS_URL': CSS_URL}
Пример #6
0
def proper_ad(request):
    u = getattr(request, "display_user", None) or request.user
    style = Profile.get_for_user(u).style

    if True:  #random.choice([True] * 20 + [False]):
        ad_text = GOOGLE_ADS[style]
    else:
        ad_text = WIKI_ADS[style]

    #######

    import os
    CSS_URL = os.path.join(settings.MEDIA_URL, "css", "style-%s" % style)

    return {"proper_ad": ad_text, 'CSS_URL': CSS_URL}
Пример #7
0
def css_path(request):
    """ Return the path to the CSS directory based on the display user's
        profile. if no display user, it falls back to request.user
    """
    
    return {}
    
    u = getattr(request, "display_user", None) or request.user

    from profile.models import Profile
    style = Profile.get_for_user(u).style
    
    import os
    CSS_URL = os.path.join(settings.MEDIA_URL, "css", "style-%s" % style)
         
    return {"CSS_URL": CSS_URL}
Пример #8
0
    def determine(self, view, field, request, *args, **kwargs):
        
        if not getattr(request, 'shared'):
            ## if it's not shared, then do nothing (user is viewing their
            ## own account)
            return view(request, *args, **kwargs)
        
        user = request.display_user
        
        from profile.models import Profile
        profile = Profile.get_for_user(user)
        
        if not field == 'NEVER':
            from django.conf import settings
            if getattr(user, "id", 0) == settings.DEMO_USER_ID:
                ## demo user, let them go hog wild
                return view(request, *args, **kwargs)
                
            go_ahead = getattr(profile, "%s_share" % field)

        
        ## can not view page because the user doesn't want it shared,
        ## either redirect to a page that can be shared, or redirect
        ## to the root page
        if field == 'NEVER' or not go_ahead:
            from django.http import HttpResponseRedirect
            from django.core.urlresolvers import reverse
            
            if getattr(profile, "logbook_share"):
                url = reverse('logbook', kwargs={"username": user.username})
            elif getattr(profile, "other_share"):
                url = reverse('linegraphs', kwargs={"username": user.username})
            else:
                url = "/"
                
            return HttpResponseRedirect(url)
        
        # passes validation, render the view    
        return view(request, *args, **kwargs) 
Пример #9
0
    def determine(self, view, field, request, *args, **kwargs):

        if not getattr(request, 'shared'):
            ## if it's not shared, then do nothing (user is viewing their
            ## own account)
            return view(request, *args, **kwargs)

        user = request.display_user

        from profile.models import Profile
        profile = Profile.get_for_user(user)

        if not field == 'NEVER':
            from django.conf import settings
            if getattr(user, "id", 0) == settings.DEMO_USER_ID:
                ## demo user, let them go hog wild
                return view(request, *args, **kwargs)

            go_ahead = getattr(profile, "%s_share" % field)

        ## can not view page because the user doesn't want it shared,
        ## either redirect to a page that can be shared, or redirect
        ## to the root page
        if field == 'NEVER' or not go_ahead:
            from django.http import HttpResponseRedirect
            from django.core.urlresolvers import reverse

            if getattr(profile, "logbook_share"):
                url = reverse('logbook', kwargs={"username": user.username})
            elif getattr(profile, "other_share"):
                url = reverse('linegraphs', kwargs={"username": user.username})
            else:
                url = "/"

            return HttpResponseRedirect(url)

        # passes validation, render the view
        return view(request, *args, **kwargs)