"""
sentry.web.views
~~~~~~~~~~~~~~~~

:copyright: (c) 2010 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from django.conf import settings as dj_settings
from django.core.urlresolvers import reverse, resolve
from django.http import HttpResponse
from django.template import loader

from sentry.conf import settings
from sentry.models import Project

def get_project_list(user=None, flag=None):
    """
    Returns a set of all projects a user has some level of access to.
    """
    projects = dict((p.pk, p) for p in Project.objects.filter(public=True))
    if user.is_authenticated():
        projects.update(dict((p.pk, p) for p in Project.objects.filter(member_set__user=user) if (not flag or p.has_perm(flag))))
    return projects

_LOGIN_URL = None
def get_login_url(reset=False):
    global _LOGIN_URL

    if _LOGIN_URL is None or reset:
        # if LOGIN_URL resolves force login_required to it instead of our own
        # XXX: this must be done as late as possible to avoid idempotent requirements
        try:
            resolve(dj_settings.LOGIN_URL)
        except:
            _LOGIN_URL = settings.LOGIN_URL
        else:
            _LOGIN_URL = dj_settings.LOGIN_URL

        if _LOGIN_URL is None:
             _LOGIN_URL = reverse('sentry-login')
    return _LOGIN_URL

def iter_data(obj):
    for k, v in obj.data.iteritems():
        if k.startswith('_') or k in ['url']:
            continue
        yield k, v

def render_to_string(template, context={}):
    context.update({
        'has_search': False,
        'MESSAGES_PER_PAGE': settings.MESSAGES_PER_PAGE,
    })

    return loader.render_to_string(template, context)

def render_to_response(template, context={}, status=200):
    response = HttpResponse(render_to_string(template, context))
    response.status_code = status

    return response

@@ -394,16 +394,32 @@
  Project
+Member, Project%0A
 %0A%0Adef ge
@@ -675,39 +675,83 @@
 update(dict(
+%0A            
 (p
+m
 .p
-k, p)
+roject_id, pm.project)%0A           
  for p
+m
  in Project.
@@ -741,32 +741,38 @@
 or pm in Project
+Member
 .objects.filter(
@@ -775,30 +775,56 @@
 ter(
-member_set__user=user)
+user=user).select_related('project')%0A           
  if 
@@ -837,16 +837,17 @@
 lag or p
+m
 .has_per
@@ -896,16 +896,18 @@
  = None%0A
+%0A%0A
 def get_
@@ -1362,17 +1362,16 @@
 s None:%0A
- 
         
@@ -1411,16 +1411,16 @@
 login')%0A
+
     retu
@@ -1434,16 +1434,17 @@
 IN_URL%0A%0A
+%0A
 def iter
@@ -1580,16 +1580,17 @@
 d k, v%0A%0A
+%0A
 def rend
@@ -1740,16 +1740,16 @@
     %7D)%0A%0A
-
     retu
@@ -1795,16 +1795,17 @@
 ntext)%0A%0A
+%0A
 def rend

Fix has_perm issue in get_project_list