コード例 #1
0
ファイル: views.py プロジェクト: ayoubar/aperta-cms
def r_add(r):

    if r.POST:
        rf = RoleForm(r.POST)
        if rf.is_valid():
            R = rf.save()

            # add member to group board if role is of type A AND saison is current
            if R.type.type == RoleType.A and R.year == getSaison():
                add_to_board(R.member)

            # board members
            update_board()

            # update ML
            ML_updates()

            # all fine -> done
            return TemplateResponse(
                r, settings.TEMPLATE_CONTENT['members']['roles']['add']['done']
                ['template'], {
                    'title':
                    settings.TEMPLATE_CONTENT['members']['roles']['add']
                    ['done']['title'],
                })

        # form not valid -> error
        else:
            return TemplateResponse(
                r, settings.TEMPLATE_CONTENT['members']['roles']['add']['done']
                ['template'], {
                    'title':
                    settings.TEMPLATE_CONTENT['members']['roles']['add']
                    ['done']['title'],
                    'error_message':
                    settings.TEMPLATE_CONTENT['error']['gen'] +
                    ' ; '.join([e for e in rf.errors]),
                })

    # no post yet -> empty form
    else:
        form = RoleForm(initial={
            'year': getSaison(),
        })
        return TemplateResponse(
            r,
            settings.TEMPLATE_CONTENT['members']['roles']['add']['template'], {
                'title':
                settings.TEMPLATE_CONTENT['members']['roles']['add']['title'],
                'desc':
                settings.TEMPLATE_CONTENT['members']['roles']['add']['desc'],
                'submit':
                settings.TEMPLATE_CONTENT['members']['roles']['add']['submit'],
                'form':
                form,
            })
コード例 #2
0
ファイル: getemails.py プロジェクト: ayoubar/aperta-cms
    def handle(self, *groups, **options):
        out = ''
        query = None

        # get members based on requested "group"
        for g in groups:
            if g == 'all':
                query = Member.objects.filter(
                    status=Member.ACT) | Member.objects.filter(
                        status=Member.HON) | Member.objects.filter(
                            status=Member.WBE) | Member.objects.filter(
                                status=Member.STB)
            if g == 'members':
                query = Member.objects.filter(
                    status=Member.ACT) | Member.objects.filter(
                        status=Member.WBE)
            elif g == 'board':
                query = Member.objects.filter(role__year=getSaison())


#        query = Role.objects.filter(year=getSaison()).values('member')
            else:
                query = None

        # create list of emails for "group"
        if query is not None:
            for m in query:
                out += '"' + m.first_name + ' ' + m.last_name + '" <' + m.email + '>, '

        self.stdout.write(self.style.SUCCESS(re.sub('\, $', '', out)))
コード例 #3
0
ファイル: views.py プロジェクト: psteichen/aperta-cms
def r_add(r):

  if r.POST:
    rf = RoleForm(r.POST)
    if rf.is_valid():
      R = rf.save()

      # add member to group board of role is board too
      if R.type.type == RoleType.A: 
        U = R.member.user
        g = Group.objects.get(name='BOARD') 
        g.user_set.add(U)

      # all fine -> done
      return TemplateResponse(r, settings.TEMPLATE_CONTENT['members']['roles']['add']['done']['template'], {
                'title': settings.TEMPLATE_CONTENT['members']['roles']['add']['done']['title'],
                })

    # form not valid -> error
    else:
      return TemplateResponse(r, settings.TEMPLATE_CONTENT['members']['roles']['add']['done']['template'], {
                'title': settings.TEMPLATE_CONTENT['members']['roles']['add']['done']['title'],
                'error_message': settings.TEMPLATE_CONTENT['error']['gen'] + ' ; '.join([e for e in rf.errors]),
                })

  # no post yet -> empty form
  else:
    form = RoleForm(initial = { 'year' : getSaison(), })
    return TemplateResponse(r, settings.TEMPLATE_CONTENT['members']['roles']['add']['template'], {
                'title': settings.TEMPLATE_CONTENT['members']['roles']['add']['title'],
                'desc': settings.TEMPLATE_CONTENT['members']['roles']['add']['desc'],
                'submit': settings.TEMPLATE_CONTENT['members']['roles']['add']['submit'],
                'form': form,
                })
コード例 #4
0
def update_board():
  # update board group based on roles
  board = Group.objects.get(name='BOARD') 
  users = User.objects.all()
  for u in users:
    board.user_set.remove(u)
    R = Role.objects.filter(member__user=u,year=getSaison())
    for r in R:
      if r.type.type == RoleType.A: board.user_set.add(u)
コード例 #5
0
ファイル: tables.py プロジェクト: ayoubar/aperta-cms
 def render_role(self, value, record):
     roles = u''
     try:
         R = Role.objects.filter(member__id=record.id, year=getSaison())
         for r in R:
             roles += str(r.type.title)
             if r != R.last(): roles += u' ; '
         return roles
     except Role.DoesNotExist:
         return ''
コード例 #6
0
ファイル: tables.py プロジェクト: psteichen/aperta-cms
 def render_role(self, value, record):
   roles = u''
   try:
     R = Role.objects.filter(member__id=record.id,year=getSaison())
     for r in R:
       roles += str(r.type.title)
       if r != R.last(): roles += u' ; '
     return roles
   except Role.DoesNotExist:
     return ''
コード例 #7
0
ファイル: tables.py プロジェクト: ayoubar/aperta-cms
    def render_name(self, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
        except Role.DoesNotExist:
            pass

        return record.last_name + ' ' + record.first_name + '( ' + roles + ')'
コード例 #8
0
ファイル: tables.py プロジェクト: psteichen/aperta-cms
  def render_photo(self, value, record):
    roles = u''
    try:
      R = Role.objects.filter(member__id=record.id,year=getSaison())
      for r in R:
        roles += str(r.type.title)
        if r != R.last(): roles += u' ; '
    except Role.DoesNotExist:
      pass

    picture = u'<i class="fa-stack"><a href="#{id}Modal" data-toggle="modal"><img src="{pic}" alt="Photo" class="img-responsive img-circle" /></a></i>'.format(id=record.pk,pic=settings.MEDIA_URL+str(value)) + view_modal(record,roles)

    return mark_safe(picture)
コード例 #9
0
def gen_member_fullname_n_role(member):
  roles = u''
  try:
    R = Role.objects.filter(member__id=member.id,year=getSaison())
    for r in R:
      roles += str(r.type.title)
      if r != R.last(): roles += u' ; '
  except Role.DoesNotExist:
    pass

  if roles != u'': 
    return str(member.first_name) + u' ' + str.upper(member.last_name) + u' (' + roles + ') '
  else:
    return str(member.first_name) + u' ' + str.upper(member.last_name)
コード例 #10
0
ファイル: functions.py プロジェクト: psteichen/aperta-cms
def gen_member_fullname_n_role(member):
  roles = u''
  try:
    R = Role.objects.filter(member__id=member.id,year=getSaison())
    for r in R:
      roles += str(r.type.title)
      if r != R.last(): roles += u' ; '
  except Role.DoesNotExist:
    pass

  if roles != u'': 
    return str(member.first_name) + u' ' + str.upper(member.last_name) + u' (' + roles + ') '
  else:
    return str(member.first_name) + u' ' + str.upper(member.last_name)
コード例 #11
0
ファイル: tables.py プロジェクト: psteichen/aperta-cms
  def render_view(self, record):
    roles = u''
    try:
      R = Role.objects.filter(member__id=record.id,year=getSaison())
      for r in R:
        roles += str(r.type.title)
        if r != R.last(): roles += u' ; '
    except Role.DoesNotExist:
      pass

#    link = u'<a class="btn btn-info btn-sm" href="#{id}Modal" data-toggle="modal"><i class="fa fa-eye"></i></a>'.format(id=record.pk) + view_modal(record,roles)
    link = u'<a class="btn btn-info btn-sm" href="/members/profile/{user}/"><i class="fa fa-eye"></i></a>'.format(user=record.user)

    return mark_safe(link)
コード例 #12
0
ファイル: tables.py プロジェクト: ayoubar/aperta-cms
    def render_view(self, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
        except Role.DoesNotExist:
            pass

#    link = u'<a class="btn btn-info btn-sm" href="#{id}Modal" data-toggle="modal"><i class="fa fa-eye"></i></a>'.format(id=record.pk) + view_modal(record,roles)
        link = u'<a class="btn btn-info btn-sm" href="/members/profile/{user}/"><i class="fa fa-eye"></i></a>'.format(
            user=record.user)

        return mark_safe(link)
コード例 #13
0
ファイル: tables.py プロジェクト: ayoubar/aperta-cms
    def render_photo(self, value, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
        except Role.DoesNotExist:
            pass

        picture = u'<i class="fa-stack"><a href="#{id}Modal" data-toggle="modal"><img src="{pic}" alt="Photo" class="img-responsive img-circle" /></a></i>'.format(
            id=record.pk, pic=settings.MEDIA_URL + str(value)) + view_modal(
                record, roles)

        return mark_safe(picture)
コード例 #14
0
ファイル: tables.py プロジェクト: psteichen/aperta-cms
  def render_view(self, record):
    roles = u''
    try:
      R = Role.objects.filter(member__id=record.id,year=getSaison())
      for r in R:
        roles += str(r.type.title)
        if r != R.last(): roles += u' ; '
    except Role.DoesNotExist:
      pass

#    link = u'<a class="btn btn-info btn-sm" href="#{id}Modal" data-toggle="modal"><i class="fa fa-eye"></i></a>'.format(id=record.pk) + view_modal(record,roles)
    link = u'<a class="btn btn-info btn-sm" href="/members/profile/#{user}/"><i class="fa fa-eye"></i></a>'.format(user=record.user)

    mod = ''
    if self.username == record.user.username: 
      mod = '<a class="btn btn-danger btn-sm pull-right" href="/members/profile/modify/{}/"><i class="fa fa-pencil"></i></a>'.format(escape(record.user))

    return mark_safe(link + mod)
コード例 #15
0
ファイル: tables.py プロジェクト: ayoubar/aperta-cms
    def render_view(self, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
        except Role.DoesNotExist:
            pass

#    link = u'<a class="btn btn-info btn-sm" href="#{id}Modal" data-toggle="modal"><i class="fa fa-eye"></i></a>'.format(id=record.pk) + view_modal(record,roles)
        link = u'<a class="btn btn-info btn-sm" href="/members/profile/#{user}/"><i class="fa fa-eye"></i></a>'.format(
            user=record.user)

        mod = ''
        if self.username == record.user.username:
            mod = '<a class="btn btn-danger btn-sm pull-right" href="/members/profile/modify/{}/"><i class="fa fa-pencil"></i></a>'.format(
                escape(record.user))

        return mark_safe(link + mod)
コード例 #16
0
ファイル: getemails.py プロジェクト: psteichen/aperta-cms
  def handle(self, *groups, **options):
    out=''
    query = None

    # get members based on requested "group"
    for g in groups:
      if g == 'all':
        query =  Member.objects.filter(status=Member.ACT) | Member.objects.filter(status=Member.HON) | Member.objects.filter(status=Member.WBE) | Member.objects.filter(status=Member.STB)
      if g == 'members':
        query =  Member.objects.filter(status=Member.ACT) | Member.objects.filter(status=Member.WBE)
      elif g == 'board':
        query = Member.objects.filter(role__year=getSaison())
#        query = Role.objects.filter(year=getSaison()).values('member')
      else:
        query = None

    # create list of emails for "group"
    if query is not None:
      for m in query:
        out += '"' + m.first_name + ' ' + m.last_name + '" <' + m.email + '>, '

    self.stdout.write(self.style.SUCCESS(re.sub('\, $', '', out)))
コード例 #17
0
    def handle(self, *args, **options):
        query = None
        group = str(options.get('group'))
        subject = settings.EMAILS['tag'] + ' [' + str.upper(group) + '] '
        emails = ()

        # get raw email message
        message = email.message_from_string(options.get('message').read())
        mail = mailparser.parse_from_string(options.get('message').read())

        # get email parts from raw source
        #    body = message.get_body()
        #    attachments = message.iter_attchments()
        #    body = ''
        #    attachments = []
        #    if message.is_multipart():
        #      for part in message.walk():
        #        if part.get_content_maintype() == 'multipart':
        #          if part.get('Content-Disposition') is None:
        #            filename = part.get_filename()
        #            payload = part.get_payload(decode=True)
        #            attachments.append({'name':filename,'content':payload})
        #          else:
        #            body += part.get_payload()
        #    else:
        #      body = message.part.get_payload()

        sender = str(message['from'])
        dest = str(message['to'])
        try:
            message.replace_header('Reply-To',
                                   group + '@' + settings.EMAILS['domain'])
        except KeyError:
            message.add_header('Reply-To',
                               group + '@' + settings.EMAILS['domain'])

        subject += str(message['subject']).replace(subject, '')
        message.replace_header('Subject', subject)

        #    self.stdout.write(self.style.NOTICE('''Groupmail from <'''+str(sender)+'''> to group: <'''+str(group)+'''>'''))

        # get members based on requested "group"
        query = None
        if group == 'all':
            query = Member.objects.filter(
                Q(status=Member.ACT) | Q(status=Member.HON)
                | Q(status=Member.WBE) | Q(status=Member.STB))
        if group == 'members':
            query = Member.objects.filter(
                Q(status=Member.ACT) | Q(status=Member.WBE))
        if group == 'board':
            query = Member.objects.filter(role__year=getSaison())

        # send(forward) mail to people of selected group
        server = smtplib.SMTP('localhost')
        if query is not None:
            for m in query:
                message.replace_header("To", m.email)
                server.sendmail(sender, m.email, message.as_string())

#        notify_by_email(
#		sender,
#		m.email,
#		subject,
#		body,
#		False,
#		attachments,
#		False
#        )
#        emails += (
#	  (
#          	subject,
#          	msg.as_string(),
#        	sender,
#          	[m.email,],
#	  ),
#	)
#        self.stdout.write(self.style.NOTICE('Prepared message for <'+str(m)+'>'))
#        self.stdout.write(self.style.NOTICE('Sending message for <'+str(m)+'>'))

#    send_mass_mail(emails)
        server.quit()
コード例 #18
0
ファイル: tables.py プロジェクト: ayoubar/aperta-cms
class MemberTable(Table):
    role = Column(verbose_name=u'Rôle(s) [' + getSaison() + '] ',
                  empty_values=())
    meetings = Column(verbose_name=u'RS (présent / excusé)', empty_values=())
    view = Column(verbose_name=u'Visualiser', empty_values=())

    def __init__(self, *args, **kwargs):
        if kwargs["username"]:
            self.username = kwargs["username"]
            kwargs.pop('username', False)
        super(Table, self).__init__(*args, **kwargs)

    def render_photo(self, value, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
        except Role.DoesNotExist:
            pass

        picture = u'<i class="fa-stack"><a href="#{id}Modal" data-toggle="modal"><img src="{pic}" alt="Photo" class="img-responsive img-circle" /></a></i>'.format(
            id=record.pk, pic=settings.MEDIA_URL + str(value)) + view_modal(
                record, roles)

        return mark_safe(picture)

    def render_last_name(self, value):
        return str.upper(value)

    def render_role(self, value, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
            return roles
        except Role.DoesNotExist:
            return ''

    def render_meetings(self, record):
        MA = Meeting_Attendance.objects.filter(member=record)
        ma = ' {} / {} '.format(
            MA.filter(present=True).count(),
            MA.filter(present=False).count())
        return mark_safe(ma)

    def render_view(self, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
        except Role.DoesNotExist:
            pass

#    link = u'<a class="btn btn-info btn-sm" href="#{id}Modal" data-toggle="modal"><i class="fa fa-eye"></i></a>'.format(id=record.pk) + view_modal(record,roles)
        link = u'<a class="btn btn-info btn-sm" href="/members/profile/#{user}/"><i class="fa fa-eye"></i></a>'.format(
            user=record.user)

        mod = ''
        if self.username == record.user.username:
            mod = '<a class="btn btn-danger btn-sm pull-right" href="/members/profile/modify/{}/"><i class="fa fa-pencil"></i></a>'.format(
                escape(record.user))

        return mark_safe(link + mod)

    class Meta:
        model = Member
        fields = (
            'photo',
            'first_name',
            'last_name',
            'email',
            'mobile',
            'status',
            'role',
            'meetings',
        )
        attrs = {"class": "table table-striped"}
コード例 #19
0
ファイル: groupmail.py プロジェクト: psteichen/aperta-cms
  def handle(self, *args, **options):
    query = None
    group = str(options.get('group'))
    subject = settings.EMAILS['tag'] + ' [' + str.upper(group) + '] '
    emails = ()

    # get raw email message
    message = email.message_from_string(options.get('message').read())
    mail = mailparser.parse_from_string(options.get('message').read())

    # get email parts from raw source
#    body = message.get_body()
#    attachments = message.iter_attchments()
#    body = ''
#    attachments = []
#    if message.is_multipart():
#      for part in message.walk():
#        if part.get_content_maintype() == 'multipart':
#          if part.get('Content-Disposition') is None:
#            filename = part.get_filename()
#            payload = part.get_payload(decode=True)
#            attachments.append({'name':filename,'content':payload})
#          else:
#            body += part.get_payload()
#    else:
#      body = message.part.get_payload()

    sender = str(message['from'])
    dest = str(message['to'])
    try:
      message.replace_header('Reply-To', group+'@'+settings.EMAILS['domain'])
    except KeyError:
      message.add_header('Reply-To', group+'@'+settings.EMAILS['domain'])

    subject += str(message['subject']).replace(subject,'')
    message.replace_header('Subject', subject)

#    self.stdout.write(self.style.NOTICE('''Groupmail from <'''+str(sender)+'''> to group: <'''+str(group)+'''>'''))

    # get members based on requested "group"
    query = None
    if group == 'all':
      query = Member.objects.filter(Q(status=Member.ACT) | Q(status=Member.HON) | Q(status=Member.WBE) | Q(status=Member.STB)) 
    if group == 'members':
      query = Member.objects.filter(Q(status=Member.ACT) | Q(status=Member.WBE))
    if group == 'board':
      query = Member.objects.filter(role__year=getSaison())

    # send(forward) mail to people of selected group
    server = smtplib.SMTP('localhost')
    if query is not None:
      for m in query:
        message.replace_header("To", m.email)
        server.sendmail(sender, m.email, message.as_string())

#        notify_by_email(
#		sender,
#		m.email,
#		subject,
#		body,
#		False,
#		attachments,
#		False
#        )
#        emails += (
#	  (
#          	subject,
#          	msg.as_string(),
#        	sender,
#          	[m.email,],
#	  ),
#	)
#        self.stdout.write(self.style.NOTICE('Prepared message for <'+str(m)+'>'))
#        self.stdout.write(self.style.NOTICE('Sending message for <'+str(m)+'>'))

#    send_mass_mail(emails)
    server.quit()
コード例 #20
0
ファイル: tables.py プロジェクト: ayoubar/aperta-cms
class MgmtMemberTable(Table):
    row_class = Column(visible=False,
                       empty_values=())  #used to highlight some rows
    role = Column(verbose_name=u'Rôle(s) [' + getSaison() + '] ',
                  empty_values=())
    meetings = Column(verbose_name=u'RS (présent / excusé)', empty_values=())
    view = Column(verbose_name=u'Visualiser', empty_values=())
    modify = Column(verbose_name=u'Modifier', empty_values=())

    def render_row_class(self, value, record):
        cl = ''
        if record.status == Member.ACT:
            cl = 'success'
        if record.status == Member.WBE:
            cl = 'info'

        att = record.attendance.all().count()
        exc = record.excused.all().count()
        if att == 0:
            cl = 'warning'
        if record.end_date or record.status == Member.STB or (att == 0
                                                              and exc == 0):
            cl = 'danger'

        return cl

    def render_photo(self, value, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
        except Role.DoesNotExist:
            pass

        picture = u'<i class="fa-stack"><a href="#{id}Modal" data-toggle="modal"><img src="{pic}" alt="Photo" class="img-responsive img-circle"/></a></i>'.format(
            id=record.pk, pic=settings.MEDIA_URL + str(value)) + view_modal(
                record, roles)

        return mark_safe(picture)

    def render_last_name(self, value):
        return str.upper(value)

#  def render_start_date(self, value):
#    return format_datetime(value)

#  def render_end_date(self, value):
#    return format_datetime(value)

    def render_role(self, value, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
            return roles
        except Role.DoesNotExist:
            return ''

    def render_meetings(self, record):
        MA = Meeting_Attendance.objects.filter(member=record)
        return '{} / {}'.format(
            MA.filter(present=True).count(),
            MA.filter(present=False).count())

    def render_view(self, record):
        roles = u''
        try:
            R = Role.objects.filter(member__id=record.id, year=getSaison())
            for r in R:
                roles += str(r.type.title)
                if r != R.last(): roles += u' ; '
        except Role.DoesNotExist:
            pass

#    link = u'<a class="btn btn-info btn-sm" href="#{id}Modal" data-toggle="modal"><i class="fa fa-eye"></i></a>'.format(id=record.pk) + view_modal(record,roles)
        link = u'<a class="btn btn-info btn-sm" href="/members/profile/{user}/"><i class="fa fa-eye"></i></a>'.format(
            user=record.user)

        return mark_safe(link)

    def render_modify(self, record):
        link = '<a class="btn btn-danger btn-sm" href="/members/modify/{}/"><i class="fa fa-pencil"></i></a>'.format(
            escape(record.pk))
        return mark_safe(link)

    class Meta:
        model = Member
        fields = (
            'photo',
            'first_name',
            'last_name',
            'email',
            'mobile',
            'status',
            'role',
            'meetings',
        )
        attrs = {"class": "table table-striped"}