# Path: ddah_web/models.py
# class DDAHInstanceWeb(DDAHInstance):
#     contact = models.EmailField(max_length=254, null=True, blank=True)
#     style = PickledObjectField(default={})
#     social_networks = PickledObjectField(default={})
# 
#     def save(self, *args, **kwargs):
#         creating = self.id is None
#         if creating:
#             default_style = getattr(settings, 'DEFAULT_STYLE', {})
#             if not self.style and default_style:
#                 self.style = default_style
#             default_social_networks = getattr(settings, 'DEFAULT_SOCIAL_NETWORKS', {})
#             if not self.social_networks and default_social_networks:
#                 self.social_networks = default_social_networks
#         if not self.label:
#             self.label = orig = slugify(self.title)
#             for x in itertools.count(1):
#                 if not DDAHInstanceWeb.objects.filter(label=self.label).exists():
#                     break
#                 self.label = '%s-%d' % (orig, x)
#         super(DDAHInstanceWeb, self).save(*args, **kwargs)
#         if creating:
#             DDAHTemplate.objects.create(instance=self)
#             if not self.style and default_style:
#                 self.style = default_style
# 
#     @property
#     def url(self):
#         try:
#             return self.ddahsiteinstance.site.domain
#         except DDAHSiteInstance.DoesNotExist:
#             return '%s.%s' % (self.label, settings.BASE_HOST)
# 
#     def _bunchify_summary(self, summary):
#         return Bunch(no_progress=summary.no_progress,
#                      accomplished=summary.accomplished,
#                      in_progress=summary.in_progress,
#                      total=summary.total,
#                      total_progress=summary.total_progress,
#                      formated_total_progress="{:10.1f}".format(summary.total_progress),
#                      accomplished_percentage=summary.accomplished_percentage,
#                      in_progress_percentage=summary.in_progress_percentage,
#                      no_progress_percentage=summary.no_progress_percentage,
#                      )
# 
#     def get_flatpages(self):
#         result = []
#         for flatpage in self.ddahflatpage_set.all():
#             bunch = Bunch(title=flatpage.title, url=flatpage.get_absolute_url())
#             result.append(bunch)
# 
#         return result
# 
#     def get_as_bunch(self):
#         home_url = reverse('instance_home')
#         home_url = '%s%s' % (self.url, home_url)
#         me = Bunch(label=self.label,
#                    title=self.title,
#                    description=self.description,
#                    url=home_url,
#                    contact=self.contact,)
#         me.flatpages = self.get_flatpages()
#         style = getattr(settings, 'DEFAULT_STYLE', {})
#         style.update(self.style)
#         me.style = Bunch.fromDict(style)
#         social_networks = getattr(settings, 'DEFAULT_SOCIAL_NETWORKS', {})
#         social_networks.update(self.social_networks)
#         me.social_networks = Bunch.fromDict(social_networks)
#         categories = []
#         for category in self.categories.all():
#             cat_bunch = Bunch(id=category.id, name=category.name, slug=category.slug)
#             categories.append(cat_bunch)
#             promises = []
#             the_promises_from_database = category.promises.all()
#             summary = the_promises_from_database.summary()
#             cat_bunch.summary = self._bunchify_summary(summary)
#             for promise in the_promises_from_database:
#                 promise_bunch = Bunch(id=promise.id,
#                                       name=promise.name,
#                                       description=markdown.markdown(promise.description),
#                                       date=promise.date
#                                       )
#                 promise_bunch.fulfillment = Bunch(percentage=promise.fulfillment.percentage,
#                                                   status=promise.fulfillment.status,
#                                                   description=markdown.markdown(promise.fulfillment.description),
#                                                   simple_accomplishment=simple_accomplishment(promise.fulfillment.percentage)
#                                                   )
#                 verification_documents = []
#                 for verification_document in promise.verification_documents.all():
#                     v_d_bunch = Bunch(id=verification_document.id,
#                                       url=verification_document.url,
#                                       display_name=verification_document.display_name,
#                                       )
#                     verification_documents.append(v_d_bunch)
#                 promise_bunch.verification_documents = verification_documents
#                 information_sources = []
#                 for information_source in promise.information_sources.all():
#                     i_s_bunch = Bunch(id=information_source.id,
#                                       url=information_source.url,
#                                       display_name=information_source.display_name,
#                                       )
#                     information_sources.append(i_s_bunch)
#                 promise_bunch.information_sources = information_sources
# 
#                 milestones = []
#                 for milestone in promise.milestones.all():
#                     milestones_bunch = Bunch(id=milestone.id,
#                                              date=milestone.date,
#                                              description=markdown.markdown(milestone.description),
#                                              )
#                     milestones.append(milestones_bunch)
#                 promise_bunch.milestones = milestones
# 
#                 promises.append(promise_bunch)
# 
#             cat_bunch.promises = promises
# 
#         me.categories = categories
#         summary = Promise.objects.filter(category__in=self.categories.all()).summary()
#         me.summary = self._bunchify_summary(summary)
#         return me
# 
#     def to_json(self):
#         bunchified = self.get_as_bunch()
#         return json.dumps(bunchified, default=default_json_encoder)
# 
#     def get_absolute_url(self):
#         sites = Site.objects.filter(ddahsiteinstance__instance=self)
#         if sites:
#             return "http://%s" % (sites.first().domain)
#         return super(DDAHInstanceWeb, self).get_absolute_url()
# 
# Path: backend/urls.py



from django.conf.urls import patterns, include, url
from ddah_web.models import DDAHInstanceWeb
from django.views.generic import ListView
from django.contrib import admin
from backend import urls as backend_urls

admin.autodiscover()

urlpatterns = patterns('',
    (r'^$', ListView.as_view(

# Path: ddah_web/models.py
# class DDAHInstanceWeb(DDAHInstance):
#     contact = models.EmailField(max_length=254, null=True, blank=True)
#     style = PickledObjectField(default={})
#     social_networks = PickledObjectField(default={})
# 
#     def save(self, *args, **kwargs):
#         creating = self.id is None
#         if creating:
#             default_style = getattr(settings, 'DEFAULT_STYLE', {})
#             if not self.style and default_style:
#                 self.style = default_style
#             default_social_networks = getattr(settings, 'DEFAULT_SOCIAL_NETWORKS', {})
#             if not self.social_networks and default_social_networks:
#                 self.social_networks = default_social_networks
#         if not self.label:
#             self.label = orig = slugify(self.title)
#             for x in itertools.count(1):
#                 if not DDAHInstanceWeb.objects.filter(label=self.label).exists():
#                     break
#                 self.label = '%s-%d' % (orig, x)
#         super(DDAHInstanceWeb, self).save(*args, **kwargs)
#         if creating:
#             DDAHTemplate.objects.create(instance=self)
#             if not self.style and default_style:
#                 self.style = default_style
# 
#     @property
#     def url(self):
#         try:
#             return self.ddahsiteinstance.site.domain
#         except DDAHSiteInstance.DoesNotExist:
#             return '%s.%s' % (self.label, settings.BASE_HOST)
# 
#     def _bunchify_summary(self, summary):
#         return Bunch(no_progress=summary.no_progress,
#                      accomplished=summary.accomplished,
#                      in_progress=summary.in_progress,
#                      total=summary.total,
#                      total_progress=summary.total_progress,
#                      formated_total_progress="{:10.1f}".format(summary.total_progress),
#                      accomplished_percentage=summary.accomplished_percentage,
#                      in_progress_percentage=summary.in_progress_percentage,
#                      no_progress_percentage=summary.no_progress_percentage,
#                      )
# 
#     def get_flatpages(self):
#         result = []
#         for flatpage in self.ddahflatpage_set.all():
#             bunch = Bunch(title=flatpage.title, url=flatpage.get_absolute_url())
#             result.append(bunch)
# 
#         return result
# 
#     def get_as_bunch(self):
#         home_url = reverse('instance_home')
#         home_url = '%s%s' % (self.url, home_url)
#         me = Bunch(label=self.label,
#                    title=self.title,
#                    description=self.description,
#                    url=home_url,
#                    contact=self.contact,)
#         me.flatpages = self.get_flatpages()
#         style = getattr(settings, 'DEFAULT_STYLE', {})
#         style.update(self.style)
#         me.style = Bunch.fromDict(style)
#         social_networks = getattr(settings, 'DEFAULT_SOCIAL_NETWORKS', {})
#         social_networks.update(self.social_networks)
#         me.social_networks = Bunch.fromDict(social_networks)
#         categories = []
#         for category in self.categories.all():
#             cat_bunch = Bunch(id=category.id, name=category.name, slug=category.slug)
#             categories.append(cat_bunch)
#             promises = []
#             the_promises_from_database = category.promises.all()
#             summary = the_promises_from_database.summary()
#             cat_bunch.summary = self._bunchify_summary(summary)
#             for promise in the_promises_from_database:
#                 promise_bunch = Bunch(id=promise.id,
#                                       name=promise.name,
#                                       description=markdown.markdown(promise.description),
#                                       date=promise.date
#                                       )
#                 promise_bunch.fulfillment = Bunch(percentage=promise.fulfillment.percentage,
#                                                   status=promise.fulfillment.status,
#                                                   description=markdown.markdown(promise.fulfillment.description),
#                                                   simple_accomplishment=simple_accomplishment(promise.fulfillment.percentage)
#                                                   )
#                 verification_documents = []
#                 for verification_document in promise.verification_documents.all():
#                     v_d_bunch = Bunch(id=verification_document.id,
#                                       url=verification_document.url,
#                                       display_name=verification_document.display_name,
#                                       )
#                     verification_documents.append(v_d_bunch)
#                 promise_bunch.verification_documents = verification_documents
#                 information_sources = []
#                 for information_source in promise.information_sources.all():
#                     i_s_bunch = Bunch(id=information_source.id,
#                                       url=information_source.url,
#                                       display_name=information_source.display_name,
#                                       )
#                     information_sources.append(i_s_bunch)
#                 promise_bunch.information_sources = information_sources
# 
#                 milestones = []
#                 for milestone in promise.milestones.all():
#                     milestones_bunch = Bunch(id=milestone.id,
#                                              date=milestone.date,
#                                              description=markdown.markdown(milestone.description),
#                                              )
#                     milestones.append(milestones_bunch)
#                 promise_bunch.milestones = milestones
# 
#                 promises.append(promise_bunch)
# 
#             cat_bunch.promises = promises
# 
#         me.categories = categories
#         summary = Promise.objects.filter(category__in=self.categories.all()).summary()
#         me.summary = self._bunchify_summary(summary)
#         return me
# 
#     def to_json(self):
#         bunchified = self.get_as_bunch()
#         return json.dumps(bunchified, default=default_json_encoder)
# 
#     def get_absolute_url(self):
#         sites = Site.objects.filter(ddahsiteinstance__instance=self)
#         if sites:
#             return "http://%s" % (sites.first().domain)
#         return super(DDAHInstanceWeb, self).get_absolute_url()
# 
# Path: backend/urls.py



# Path: project_site/non_subdomain_urls.py
from django.conf.urls import patterns, include, url
from ddah_web.models import DDAHInstanceWeb
from django.views.generic import ListView
from django.contrib import admin
from backend import urls as backend_urls


admin.autodiscover()

urlpatterns = patterns('',
    (r'^$', ListView.as_view(

        queryset=DDAHInstanceWeb.objects.all(),