from auth.models import CustomUser as User from profiles.forms import (EditUserForm, EditAccountForm, SendMessageForm, EditAvatarForm) from profiles.rpc import ProfileApiClass from apps.messages.models import Message from utils.orm import LoadRelatedQuerySet from utils.rpc import RpcRouter from teams.models import Task from subtitles.models import SubtitleLanguage from videos.models import (Action, VideoUrl, Video, VIDEO_TYPE_YOUTUBE, VideoFeed) logger = logging.getLogger(__name__) rpc_router = RpcRouter('profiles:rpc_router', {'ProfileApi': ProfileApiClass()}) VIDEOS_ON_PAGE = getattr(settings, 'VIDEOS_ON_PAGE', 30) LINKABLE_ACCOUNTS = ['youtube', 'twitter', 'facebook'] class OptimizedQuerySet(LoadRelatedQuerySet): def update_result_cache(self): videos = dict((v.id, v) for v in self._result_cache if not hasattr(v, 'langs_cache')) if videos: for v in videos.values(): v.langs_cache = [] langs_qs = SubtitleLanguage.objects.select_related('video').filter(
from utils.objectlist import object_list from utils.rpc import RpcRouter from utils.pagination import AmaraPaginator from utils.text import fmt from utils.translation import (get_user_languages_from_request, get_language_label) from teams.permissions import can_edit_video, can_add_version, can_resync from . import video_size import teams.permissions VIDEO_IN_ROW = 6 ACTIVITY_PER_PAGE = 8 rpc_router = RpcRouter('videos:rpc_router', { 'VideosApi': VideosApiClass() }) # .e.g json, nor include aliases AVAILABLE_SUBTITLE_FORMATS_FOR_DISPLAY = [ 'dfxp', 'sbv', 'srt', 'ssa', 'txt', 'vtt', ] LanguageListItem = namedtuple("LanguageListItem", "name status tags url code") class LanguageList(object): """List of languages for the video pages.""" def __init__(self, video): original_languages = []
except TeamMember.DoesNotExist: return Error(_(u'You have left this team.')) def join(self, team_id, user): if not user.is_authenticated(): return Error(_('You should be authenticated.')) try: if not team_id: raise Team.DoesNotExist team = Team.objects.get(pk=team_id) except Team.DoesNotExist: return Error(_('Team does not exist')) try: TeamMember.objects.get(team=team, user=user) return Error(_(u'You are already a member of this team.')) except TeamMember.DoesNotExist: pass if not team.is_open(): return Error(_(u'This team is not open.')) else: TeamMember(team=team, user=user).save() return Msg(_(u'You are now a member of this team.')) TeamsApi = TeamsApiClass() rpc_router = RpcRouter('teams:rpc_router', {'TeamsApi': TeamsApi})
# GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see # http://www.gnu.org/licenses/agpl-3.0.html. from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect from django.utils.http import urlencode from search.forms import SearchForm from search.rpc import SearchApiClass from utils import render_to from utils.context_processors import current_site from utils.rpc import RpcRouter rpc_router = RpcRouter('search:rpc_router', {'SearchApi': SearchApiClass()}) @render_to('search/search.html') def index(request): if request.GET: site = current_site(request) query = {} for k, v in request.GET.items(): query[k] = v # If we're at a URL with query params we just got here from a search # form on another page. If that's the case, we'll redirect to the # AJAX-style URL with the params in the hash. Then that page will take # the other branch of this if, and the search form will work its # frontend magic. url = '%s%s#/?%s' % (
from django.http import HttpResponseRedirect, HttpResponseForbidden from django.utils.http import cookie_date from django.utils.translation import ugettext_lazy as _ from django.db.models import Q from auth.models import CustomUser as User from auth.models import UserLanguage from messages.forms import SendMessageForm, NewMessageForm from messages.models import Message from messages.rpc import MessagesApiClass from messages.tasks import send_new_message_notification, send_new_messages_notifications from utils import render_to_json, render_to from utils.objectlist import object_list from utils.rpc import RpcRouter rpc_router = RpcRouter('messages:rpc_router', {'MessagesApi': MessagesApiClass()}) MAX_MEMBER_SEARCH_RESULTS = 40 MESSAGES_ON_PAGE = getattr(settings, 'MESSAGES_ON_PAGE', 30) @login_required def message(request, message_id): user = request.user messages = Message.objects.for_user_or_author(user).filter(id=message_id) if len(messages) != 1: return HttpResponseForbidden("Not allowed") hide_thread = request.GET.get('hide_thread') message_thread = Message.objects.thread(messages[0], user) message_thread_length = message_thread.count() if not hide_thread:
def save_role(self, team_slug, member_pk, role, projects, languages, user=None): team = Team.objects.get(slug=team_slug) member = team.members.get(pk=member_pk) if role == 'admin': languages = None projects = map(int, projects or []) res = save_role(team, member, role, projects, languages, user) if res: return {'success': True} else: return { 'success': False, 'errors': [_('You cannot assign that role to that member.')] } TeamsApiV2 = TeamsApiV2Class() rpc_router = RpcRouter('teams:rpc_router', { 'TeamsApi': TeamsApi, 'TeamsApiV2': TeamsApiV2, })