Skip to content

Instantly share code, notes, and snippets.

@ddemid
Created December 15, 2014 17:55
Show Gist options
  • Save ddemid/1a198b90102343d257d0 to your computer and use it in GitHub Desktop.
Save ddemid/1a198b90102343d257d0 to your computer and use it in GitHub Desktop.
def detail(request, company_slug, template_name="companies/detail.html"):
office = get_object_or_404(CompanyOffice, slug=company_slug)
if not (office.active and office.is_subscribed) and request.user != office.user:
raise PermissionDenied()
followers = Following.objects.followers(office)
news = News.objects.all_active().filter(office=office)
if office.company:
videos = Work.objects.all_active().filter(
Q(Q(office__in=office.company.offices.all(), is_group_shared=True) | Q(office=office),
notube_id__isnull=False, is_visible=True))
# links = CompanyOfficeLink.objects.filter(office__in=office.company.offices.all())
else:
videos = Work.objects.all_active().filter(office=office)
links = CompanyOfficeLink.objects.filter(office=office)
if office.company:
associated = office.company.offices.exclude(pk=office.pk)
else:
associated = CompanyOffice.objects.get_empty_query_set()
hits = HitCount.objects.filter(
Q(content_type=ContentType.objects.get_for_model(CompanyOffice), object_id=office.pk) |
Q(content_type=ContentType.objects.get_for_model(News),
object_id__in=office.news.all().values('pk')) |
Q(content_type=ContentType.objects.get_for_model(Work),
object_id__in=office.work.all().values('pk')) |
Q(content_type=ContentType.objects.get_for_model(Event),
object_id__in=office.events.all().values('pk')) |
Q(content_type=ContentType.objects.get_for_model(Job),
object_id__in=office.jobs.all().values('pk'))
).aggregate(Sum('hits'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment