def comments_count(self): from wiki.views import get_ct from threadedcomments.models import ThreadedComment, FreeThreadedComment comments = ThreadedComment.objects.filter( content_type=get_ct(self), object_id=self.id) freecomments = FreeThreadedComment.objects.filter( content_type=get_ct(self), object_id=self.id) total_comments = comments.count()+freecomments.count() return total_comments
def project(request, slug, template_name="projects/project.html"): project = get_object_or_404(Project, slug=slug) if project.deleted: raise Http404 # @@@ photos = project.photos.all() if request.user.is_authenticated() and request.method == "POST" and request.user == project.creator: if request.POST["action"] == "update": adduser_form = AddUserForm(project=project) project_form = ProjectUpdateForm(request.POST, instance=project) if project_form.is_valid(): project = project_form.save() elif request.POST["action"] == "add": project_form = ProjectUpdateForm(instance=project) adduser_form = AddUserForm(project, request.POST) if adduser_form.is_valid(): adduser_form.save(project, request.user) adduser_form = AddUserForm(project=project) # @@@ is this the right way to clear it? else: project_form = ProjectUpdateForm(instance=project) adduser_form = AddUserForm(project=project) else: adduser_form = AddUserForm(project=project) project_form = ProjectUpdateForm(instance=project) topics = project.topics.all()[:5] articles = Article.objects.filter(content_type=get_ct(project), object_id=project.id).order_by("-last_update") total_articles = articles.count() articles = articles[:5] total_tasks = project.tasks.count() tasks = project.tasks.order_by("-modified")[:10] # tweets = TweetInstance.objects.tweets_for(project).order_by("-sent") are_member = project.has_member(request.user) return render_to_response( template_name, { "project_form": project_form, "adduser_form": adduser_form, "project": project, # @@@ "photos": photos, "topics": topics, "articles": articles, "total_tasks": total_tasks, "tasks": tasks, "total_articles": total_articles, "are_member": are_member, }, context_instance=RequestContext(request), )
def org(request, org_slug): org = get_object_or_404(Circle, slug=org_slug) if request.user.is_superuser: is_member = True is_officer = True is_secretary = True else: is_member = org.has_member(request.user) is_officer = org.has_officer(request.user) is_secretary = org.has_secretary(request.user) articles = Article.objects.filter( content_type=get_ct(org), object_id=org.id).order_by('-last_update') total_articles = articles.count() articles = articles[:5] total_tasks = org.tasks.count() tasks = org.tasks.order_by("-modified")[:10] aims = org.aims.all() upcoming_meetings = org.meetings.filter(date_and_time__gte=datetime.now()) upcoming_events = org.events.filter(start__gte=datetime.now()) if upcoming_meetings: upcoming_meetings = upcoming_meetings[0:5] if upcoming_events: upcoming_events = upcoming_events[0:5] all_upcoming = [] for meeting in upcoming_meetings: all_upcoming.append(meeting) for event in upcoming_events: all_upcoming.append(event) all_upcoming.sort(lambda x, y: cmp(x.common_timestamp, y.common_timestamp)) recent_meetings = org.meetings.filter(date_and_time__lt=datetime.now()).order_by("-date_and_time") if recent_meetings: recent_meetings = recent_meetings[0:1] members = org.members.all().order_by("user__username") return render_to_response("orgs/org.html", { "org": org, "members": members, "articles": articles, "total_articles": total_articles, "total_tasks": total_tasks, "tasks": tasks, "aims": aims, "is_member": is_member, "is_officer": is_officer, "is_secretary": is_secretary, "all_upcoming": all_upcoming, "recent_meetings": recent_meetings, }, context_instance=RequestContext(request))
def tribe(request, slug, form_class=TribeUpdateForm, template_name="tribes/tribe.html"): tribe = get_object_or_404(Tribe, slug=slug) if tribe.deleted: raise Http404 # @@@ photos = tribe.photos.all() if request.user.is_authenticated() and request.method == "POST": if request.POST["action"] == "update" and request.user == tribe.creator: tribe_form = form_class(request.POST, instance=tribe) if tribe_form.is_valid(): tribe = tribe_form.save() else: tribe_form = form_class(instance=tribe) if request.POST["action"] == "join": tribe.members.add(request.user) request.user.message_set.create(message="You have joined the tribe %s" % tribe.name) if notification: notification.send([tribe.creator], "tribes_created_new_member", {"user": request.user, "tribe": tribe}) notification.send(tribe.members.all(), "tribes_new_member", {"user": request.user, "tribe": tribe}) if friends: # @@@ might be worth having a shortcut for sending to all friends notification.send((x['friend'] for x in Friendship.objects.friends_for_user(request.user)), "tribes_friend_joined", {"user": request.user, "tribe": tribe}) elif request.POST["action"] == "leave": tribe.members.remove(request.user) request.user.message_set.create(message="You have left the tribe %s" % tribe.name) if notification: pass # @@@ else: tribe_form = form_class(instance=tribe) topics = tribe.topics.all()[:5] # @@@ could make a GR articles = Article.objects.filter( content_type=get_ct(tribe), object_id=tribe.id).order_by('-last_update') total_articles = articles.count() articles = articles[:5] # @@@ tweets = TweetInstance.objects.tweets_for(tribe).order_by("-sent") are_member = request.user in tribe.members.all() return render_to_response(template_name, { "tribe_form": tribe_form, "tribe": tribe, # @@@ "photos": photos, "topics": topics, "articles": articles, # @@@ "tweets": tweets, "total_articles": total_articles, "are_member": are_member, }, context_instance=RequestContext(request))
def tribe(request, slug, form_class=TribeUpdateForm, template_name="tribes/tribe.html"): tribe = get_object_or_404(Tribe, slug=slug) if tribe.deleted: raise Http404 are_member = has_member(tribe, request.user) if tribe.private and not are_member: access = do_403_if_not_superuser(request) if access: return access photos = tribe.photos.all() if request.user.is_authenticated() and request.method == "POST": if request.POST["action"] == "update" and (request.user == tribe.creator or request.user.is_superuser): tribe_form = form_class(request.POST, instance=tribe) if tribe_form.is_valid(): tribe = tribe_form.save() else: tribe_form = form_class(instance=tribe) if request.POST["action"] == "join" and not tribe.private: try: TribeMember.objects.filter(tribe=tribe, user=request.user)[0] except: tmember = TribeMember(tribe=tribe, user=request.user) tmember.save() request.user.message_set.create(message="You have joined the tribe %s" % tribe.name) if notification: #notification.send([tribe.creator], "tribes_created_new_member", {"user": request.user, "tribe": tribe}) notification.send(tribe.member_users.all(), "tribes_new_member", {"user": request.user, "tribe": tribe}) elif request.POST["action"] == "leave": TribeMember.objects.filter(tribe=tribe, user=request.user).delete() request.user.message_set.create(message=ugettext("You have left the tribe %s") % tribe.name) if notification: pass # @@@ are_member = has_member(tribe, request.user) else: tribe_form = form_class(instance=tribe) try: tm_visit = TribeMember.objects.get(tribe=tribe, user=request.user).last_visit topics = tribe.topics.filter(modified__gte=tm_visit) articles = Article.objects.filter( content_type=get_ct(tribe), object_id=tribe.id) total_articles = articles.count() articles = articles.filter(last_update__gte=tm_visit).order_by('-last_update')[:10] documents = Document.objects.filter(tribe=tribe, date_updated__gte=tm_visit).order_by('-date_updated')[:10] except: topics = None total_articles = None articles = None documents = None topics = None articles = None total_articles = None documents = None return render_to_response(template_name, { "tribe_form" : tribe_form, "tribe" : tribe, "photos" : photos, "topics" : topics, "articles" : articles, "documents" : documents, "total_articles": total_articles, "are_member" : are_member, "are_moderator" : is_moderator(tribe, request.user), "tribe_members_count" : TribeMember.objects.filter(tribe=tribe).count(), }, context_instance=RequestContext(request))
def project(request, slug, template_name="projects/project.html"): project = get_object_or_404(Project, slug=slug) if project.deleted: raise Http404 photos = project.photos.all() if request.user.is_authenticated() and request.method == "POST" and request.user == project.creator: if request.POST["action"] == "update": user_file_form = UserFileForm(Account.objects.get(user = request.user)) adduser_form = AddUserForm(project=project) project_form = ProjectUpdateForm(request.POST, instance=project) file_form = UploadFileForm() if project_form.is_valid(): project = project_form.save() elif request.POST["action"] == "add": user_file_form = UserFileForm(Account.objects.get(user = request.user)) project_form = ProjectUpdateForm(instance=project) adduser_form = AddUserForm(project, request.POST) file_form = UploadFileForm() if adduser_form.is_valid(): adduser_form.save(project, request.user) adduser_form = AddUserForm(project=project) # @@@ is this the right way to clear it? elif request.POST["action"] == "upload": user_file_form = UserFileForm(Account.objects.get(user = request.user)) adduser_form = AddUserForm(project=project) project_form = ProjectUpdateForm(instance=project) file_form = UploadFileForm(request.POST, request.FILES) if file_form.is_valid(): uFile = handle_uploaded_file(request.FILES['file'], request.user) project.files.add(uFile) project.save() request.user.message_set.create(message="uploaded %(file)s"%{'file':request.FILES['file'].name}) elif request.POST["action"] == "remove": user_file_form = UserFileForm(Account.objects.get(user = request.user)) adduser_form = AddUserForm(project=project) project_form = ProjectUpdateForm(instance=project) file_form = UploadFileForm() fname = request.POST['file'] remove_uploaded_file(fname, project) request.user.message_set.create(message="removed %(file)s from project"%{'file':fname}) elif request.POST["action"] == "userfile": adduser_form = AddUserForm(project=project) project_form = ProjectUpdateForm(instance=project) file_form = UploadFileForm() user_file_form = UserFileForm(Account.objects.get(user = request.user)) #if user_file_form.is_valid(): acc = Account.objects.get(user = request.user) uFile = acc.files.get(name = request.POST['files']) project.files.add(uFile) project.save() request.user.message_set.create(message="added %(file)s to project"%{'file':uFile.name}) else: user_file_form = UserFileForm(Account.objects.get(user = request.user)) file_form = UploadFileForm() project_form = ProjectUpdateForm(instance=project) adduser_form = AddUserForm(project=project) elif request.user.is_authenticated() and request.user == project.creator: user_file_form = UserFileForm(Account.objects.get(user = request.user)) file_form = UploadFileForm() adduser_form = AddUserForm(project=project) project_form = ProjectUpdateForm(instance=project) else: user_file_form = UserFileForm(None) file_form = UploadFileForm() adduser_form = AddUserForm(project=project) project_form = ProjectUpdateForm(instance=project) topics = project.topics.all()[:5] articles = Article.objects.filter( content_type=get_ct(project), object_id=project.id).order_by('-last_update') total_articles = articles.count() articles = articles[:5] total_tasks = project.tasks.count() tasks = project.tasks.order_by("-modified")[:10] # tweets = TweetInstance.objects.tweets_for(project).order_by("-sent") are_member = project.has_member(request.user) return render_to_response(template_name, { "project_form": project_form, "adduser_form": adduser_form, "project": project, "photos": photos, "topics": topics, "articles": articles, "total_tasks": total_tasks, "tasks": tasks, "total_articles": total_articles, "are_member": are_member, "file_form": file_form, "user_file_form":user_file_form, }, context_instance=RequestContext(request))