Exemplo n.º 1
0
    def notify(self):

        # Notify recipient
        un = UserNotifications(self.recipient)
        un.add_friend_request(self)

        # Send email
        notify_friend_request(self.sender, self.recipient)
Exemplo n.º 2
0
Arquivo: models.py Projeto: La0/coach
  def notify(self):

    # Notify recipient
    un = UserNotifications(self.recipient)
    un.add_friend_request(self)

    # Send email
    notify_friend_request(self.sender, self.recipient)
Exemplo n.º 3
0
Arquivo: details.py Projeto: La0/coach
  def delete(self, *args, **kwargs):

    app = self.get_application()['application']

    # Notify creator the athlete has removed the plan
    un = UserNotifications(app.plan.creator)
    un.add_plan_application_removed(app)

    # Delete the application, not the plan !
    app.delete()

    return HttpResponseRedirect(reverse('report-current-month'))
Exemplo n.º 4
0
    def notify(self, message):
        '''
    Notify all recipients, without writer
    '''
        for r in self.get_recipients(exclude=message.writer):
            print ' >> Notify %s' % r.username

            # Direct notification
            un = UserNotifications(r)
            un.add_message(message)

            # Async send an email too
            notify_message.delay(message, r)
Exemplo n.º 5
0
    def accept(self):
        # Add friend to symmetric relation
        self.sender.friends.add(self.recipient)

        # Notify sender
        un = UserNotifications(self.sender)
        un.add_friend_request(self, accepted=True)

        # Send email
        notify_friend_request(self.sender, self.recipient, accepted=True)

        # Delete
        self.delete()
Exemplo n.º 6
0
Arquivo: models.py Projeto: La0/coach
  def notify(self, message):
    '''
    Notify all recipients, without writer
    '''
    for r in self.get_recipients(exclude=message.writer):
      print ' >> Notify %s' % r.username

      # Direct notification
      un = UserNotifications(r)
      un.add_message(message)

      # Async send an email too
      notify_message.delay(message, r)
Exemplo n.º 7
0
Arquivo: models.py Projeto: La0/coach
  def accept(self):
    # Add friend to symmetric relation
    self.sender.friends.add(self.recipient)

    # Notify sender
    un = UserNotifications(self.sender)
    un.add_friend_request(self, accepted=True)

    # Send email
    notify_friend_request(self.sender, self.recipient, accepted=True)

    # Delete
    self.delete()
Exemplo n.º 8
0
Arquivo: apps.py Projeto: La0/coach
  def notify_trainer(self):
    '''
    Notify trainer of new validation from user
    '''
    if self.status == 'applied':
      raise Exception('Invalid status')

    # Send UserNotification
    un = UserNotifications(self.plan_session.plan.creator)
    un.add_plan_session_applied(self)

    # Update notification date
    self.trainer_notified = timezone.now()
    self.save()
Exemplo n.º 9
0
    def notify_trainer(self):
        '''
    Notify trainer of new validation from user
    '''
        if self.status == 'applied':
            raise Exception('Invalid status')

        # Send UserNotification
        un = UserNotifications(self.plan_session.plan.creator)
        un.add_plan_session_applied(self)

        # Update notification date
        self.trainer_notified = timezone.now()
        self.save()
Exemplo n.º 10
0
  def get(self, *args, **kwargs):
    un = UserNotifications(self.request.user)
    if 'uuid' in self.kwargs:
      # Clear one notification
      notif = un.clear(self.kwargs['uuid'])

      # Redirect to link if any
      if notif and 'link' in notif:
        self.json_options = [JSON_OPTION_REDIRECT_SKIP , ]
        return HttpResponseRedirect(notif['link'])
    else:
      # Clear all notifications
      un.clear_all()

    # Reload whole page
    self.json_options = [JSON_OPTION_NO_HTML, JSON_OPTION_BODY_RELOAD, ]
    return self.render_to_response({})
Exemplo n.º 11
0
    def get(self, *args, **kwargs):
        un = UserNotifications(self.request.user)
        if 'uuid' in self.kwargs:
            # Clear one notification
            notif = un.clear(self.kwargs['uuid'])

            # Redirect to link if any
            if notif and 'link' in notif:
                self.json_options = [
                    JSON_OPTION_REDIRECT_SKIP,
                ]
                return HttpResponseRedirect(notif['link'])
        else:
            # Clear all notifications
            un.clear_all()

        # Reload whole page
        self.json_options = [
            JSON_OPTION_NO_HTML,
            JSON_OPTION_BODY_RELOAD,
        ]
        return self.render_to_response({})
Exemplo n.º 12
0
def add_pages(request):
    '''
  List menu pages, with active status
  '''
    def _p(url_tuple, caption, icon=False, lazy=False):
        url_name = isinstance(url_tuple, tuple) and url_tuple[0] or url_tuple
        url_args = isinstance(url_tuple, tuple) and url_tuple[1:] or ()
        url = reverse(url_name, args=url_args)
        active = lazy and request.path.startswith(url) or (request.path == url)
        return {'url': url, 'caption': caption, 'active': active, 'icon': icon}

    def _ext(url, caption):
        return {
            'url': url,
            'caption': caption,
            'active': False,
            'external': True
        }

    def _build_club_generic():
        return {
            'caption':
            _('Clubs'),
            'menu': [
                _p('club-list', _('View clubs')),
                _p('club-landing', _('Create a club')),
            ],
            'icon':
            'icon-star',
        }

    def _build_help():
        # Build help menu with contact & news
        submenu = {
            'caption': _('Help'),
            'menu': [],
            'icon': 'icon-help-circled',
        }
        submenu['menu'].append(_p(('page-list', 'help'), _('Help'), lazy=True))
        submenu['menu'].append(_p('vma-glossary', _('Glossary')))
        submenu['menu'].append(_p(('page-list', 'news'), _('News'), lazy=True))
        submenu['menu'].append(_p(('contact_form', ), _('Contact'), lazy=True))
        return submenu

    menu = []
    if request.user.is_authenticated():
        menu.append(_p('report-current', _('My Week'), 'icon-list'))
        menu.append(
            _p('report-current-month',
               _('My Calendar'),
               icon='icon-calendar',
               lazy=True))

        # Load memberships
        members = request.user.memberships.exclude(role__in=('archive',
                                                             'prospect'))

        # Build generic club menu
        menu.append(_build_club_generic())

        # Build Club menu
        for m in members:
            submenu = {
                'caption': m.club.name,
                'menu': [],
                'icon': 'icon-club',
            }

            # Add club list for athletes
            if m.role in ('athlete', ):
                submenu['menu'].append(
                    _p(('club-members', m.club.slug), _('Members')))
                submenu['menu'].append(
                    _p((
                        'club-groups',
                        m.club.slug,
                    ), _('Groups')))
                submenu['menu'].append('__SEPARATOR__')

            # Add club admin links for trainers
            if m.role in ('trainer', 'staff') or request.user.is_superuser:
                submenu['menu'].append(
                    _p(('club-members-name', m.club.slug, 'athletes', 'name'),
                       _('My athletes')))
                submenu['menu'].append(
                    _p((
                        'club-races',
                        m.club.slug,
                    ), _('Races'), lazy=True))
                submenu['menu'].append(
                    _p((
                        'club-groups',
                        m.club.slug,
                    ), _('Groups')))
                submenu['menu'].append(
                    _p(('club-members-name', m.club.slug, 'all', 'name'),
                       _('All the club')))

                # Manage links
                if m.club.manager == request.user or request.user.is_superuser:
                    submenu['menu'].append(
                        _p(('club-members-name', m.club.slug, 'prospects',
                            'name'), _('Newcomers')))
                    submenu['menu'].append(
                        _p(('club-members-name', m.club.slug, 'archives',
                            'name'), _('Archives')))
                    submenu['menu'].append(
                        _p(('club-manage', m.club.slug), _('Manage')))

                submenu['menu'].append('__SEPARATOR__')

            # Add public club links for everyone
            for link in m.club.links.all().order_by('position'):
                submenu['menu'].append(_ext(link.url, link.name))

            menu.append(submenu)

        # Help menu
        menu.append(_build_help())

        # Show notifications count
        un = UserNotifications(request.user)
        nb_notif = un.total()
        menu.append({
            'notifications': nb_notif,
        })

        # User menu
        submenu = {
            'caption': request.user.first_name or request.user.username,
            'menu': [],
            'icon': 'icon-user',
        }
        submenu['menu'].append(_p('message-inbox', _('My messages')))
        submenu['menu'].append(_p('user-preferences', _('My preferences')))
        submenu['menu'].append(_p('friends', _('My friends')))
        submenu['menu'].append(
            _p(('user-public-profile', request.user.username),
               _('My public profile')))
        submenu['menu'].append(_p('stats', _('My statistics'), lazy=True))
        submenu['menu'].append(_p('vma', _('My paces')))
        submenu['menu'].append(_p('user-races', _('My records')))
        submenu['menu'].append(_p('track-providers', _('My GPS services')))
        submenu['menu'].append('__SEPARATOR__')
        submenu['menu'].append(_p('logout', _('Logout')))
        menu.append(submenu)
    else:
        menu.append(_p('user-create', _('Create an account'), 'icon-plus'))
        menu.append(_build_club_generic())
        menu.append(_build_help())
        menu.append(_p('login', _('Login'), 'icon-user'))

    # Search for active main menu
    # based on sub items
    for m in menu:
        if 'menu' not in m: continue
        if len([
                l['active'] for l in m['menu']
                if isinstance(l, dict) and l['active']
        ]):
            m['active'] = True
            break

    return {
        'menu': menu,
    }
Exemplo n.º 13
0
 def get_notifications(self):
     un = UserNotifications(self.request.user)
     return {
         'total': un.total(),
         'notifications': un.fetch(),
     }
Exemplo n.º 14
0
 def get_notifications(self):
   un = UserNotifications(self.request.user)
   return {
     'total' : un.total(),
     'notifications' : un.fetch(),
   }
Exemplo n.º 15
0
def add_pages(request):
  '''
  List menu pages, with active status
  '''
  def _p(url_tuple, caption, icon=False, lazy=False):
    url_name = isinstance(url_tuple, tuple) and url_tuple[0] or url_tuple
    url_args = isinstance(url_tuple, tuple) and url_tuple[1:] or ()
    url = reverse(url_name, args=url_args)
    active = lazy and request.path.startswith(url) or (request.path == url)
    return {'url' : url, 'caption' : caption, 'active' : active, 'icon': icon}

  def _ext(url, caption):
    return {'url' : url, 'caption' : caption, 'active' : False, 'external' : True}

  def _build_club_generic():
    return {
      'caption' : _('Clubs'),
      'menu': [
        _p('club-list', _('View clubs')),
        _p('club-landing', _('Create a club')),
      ],
      'icon' : 'icon-star',
    }

  def _build_help():
    # Build help menu with contact & news
    submenu = {
      'caption' : _('Help'),
      'menu' : [],
      'icon' : 'icon-help-circled',
    }
    submenu['menu'].append(_p(('page-list', 'help'), _('Help'), lazy=True))
    submenu['menu'].append(_p('vma-glossary', _('Glossary')))
    submenu['menu'].append(_p(('page-list', 'news'), _('News'), lazy=True))
    submenu['menu'].append(_p(('contact_form',), _('Contact'), lazy=True))
    return submenu

  menu = []
  if request.user.is_authenticated():
    menu.append(_p('report-current', _('My Week'), 'icon-list'))
    menu.append(_p('report-current-month', _('My Calendar'), icon='icon-calendar', lazy=True))

    # Load memberships
    members = request.user.memberships.exclude(role__in=('archive', 'prospect'))

    # Build generic club menu
    menu.append(_build_club_generic())

    # Build Club menu
    for m in members:
      submenu = {
        'caption' : m.club.name,
        'menu' : [],
        'icon' : 'icon-club',
      }

      # Add club list for athletes
      if m.role in ('athlete', ):
        submenu['menu'].append(_p(('club-members', m.club.slug), _('Members')))
        submenu['menu'].append(_p(('club-groups', m.club.slug, ), _('Groups')))
        submenu['menu'].append('__SEPARATOR__')

      # Add club admin links for trainers
      if m.role in ('trainer', 'staff') or request.user.is_superuser:
        submenu['menu'].append(_p(('club-members-name', m.club.slug, 'athletes', 'name'), _('My athletes')))
        submenu['menu'].append(_p(('club-races', m.club.slug, ), _('Races'), lazy=True))
        submenu['menu'].append(_p(('club-groups', m.club.slug, ), _('Groups')))
        submenu['menu'].append(_p(('club-members-name', m.club.slug, 'all', 'name'), _('All the club')))

        # Manage links
        if m.club.manager == request.user or request.user.is_superuser:
          submenu['menu'].append(_p(('club-members-name', m.club.slug, 'prospects', 'name'), _('Newcomers')))
          submenu['menu'].append(_p(('club-members-name', m.club.slug, 'archives', 'name'), _('Archives')))
          submenu['menu'].append(_p(('club-manage', m.club.slug), _('Manage')))

        submenu['menu'].append('__SEPARATOR__')

      # Add public club links for everyone
      for link in m.club.links.all().order_by('position'):
        submenu['menu'].append(_ext(link.url, link.name))

      menu.append(submenu)

    # Help menu
    menu.append(_build_help())

    # Show notifications count
    un = UserNotifications(request.user)
    nb_notif = un.total()
    menu.append({
      'notifications' : nb_notif,
    })

    # User menu
    submenu = {
      'caption' : request.user.first_name or request.user.username,
      'menu' : [],
      'icon' : 'icon-user',
    }
    submenu['menu'].append(_p('message-inbox', _('My messages')))
    submenu['menu'].append(_p('user-preferences', _('My preferences')))
    submenu['menu'].append(_p('friends', _('My friends')))
    submenu['menu'].append(_p(('user-public-profile', request.user.username), _('My public profile')))
    submenu['menu'].append(_p('stats', _('My statistics'), lazy=True))
    submenu['menu'].append(_p('vma', _('My paces')))
    submenu['menu'].append(_p('user-races', _('My records')))
    submenu['menu'].append(_p('track-providers', _('My GPS services')))
    submenu['menu'].append('__SEPARATOR__')
    submenu['menu'].append(_p('logout', _('Logout')))
    menu.append(submenu)
  else:
    menu.append(_p('user-create', _('Create an account'), 'icon-plus'))
    menu.append(_build_club_generic())
    menu.append(_build_help())
    menu.append(_p('login', _('Login'), 'icon-user'))

  # Search for active main menu
  # based on sub items
  for m in menu:
    if 'menu' not in m: continue
    if len([l['active'] for l in m['menu'] if isinstance(l, dict) and l['active']]):
      m['active'] = True
      break

  return {
    'menu' : menu,
  }