Example #1
0
    def get_context_data(self, **kwargs):
        if self.object.group != self.contactgroup:
            # attempt to read an object from another group
            raise PermissionDenied
        if self.object.is_answer and self.object.read_date is None:
            if self.contactgroup.userperms & perms.WRITE_MSGS:
                self.object.read_date = now()
                self.object.read_by = self.request.user
                self.object.save()
            else:
                messages.add_message(
                    self.request, messages.WARNING,
                    _("You don't have the permission to mark that message as"
                      " read."))
        cg = self.contactgroup
        context = {}
        if self.object.is_answer:
            context['title'] = _(
                'Message from {contactname} in group {groupname}').format(
                contactname=self.object.contact.name,
                groupname=cg)
        else:
            context['title'] = _(
                'Message to {contactname} in group {groupname}').format(
                contactname=self.object.contact.name,
                groupname=cg)
        try:
            context['sync_info'] = json.loads(self.object.sync_info)
        except ValueError:
            context['sync_info'] = {}
        context['nav'] = cg.get_smart_navbar()
        context['nav'].add_component(('messages', _('messages')))
        context['cig_url'] = (
            self.contactgroup.get_absolute_url()
            + 'members/'
            + str(self.object.contact_id))
        context['active_submenu'] = 'messages'

        # 201505
        cig = ContactInGroup.objects.get(contact_id=self.object.contact.id,
                                         group_id=cg.id)
        if cig:
            context['membership_note'] = cig.note
        flags = perms.cig_flags_int(self.object.contact.id, cg.id)
        flags_direct = perms.cig_flags_direct_int(self.object.contact.id,
                                                  cg.id)

        membership_str = perms.int_to_text(flags_direct, flags & ~flags_direct)
        context['membership'] = perms.int_to_flags(flags_direct)
        context['membership_str'] = membership_str
        context['membership_title'] = _(
            '{contactname} in group {groupname}').format(
            contactname=self.object.contact.name,
            groupname=cg)
        if self.contactgroup.userperms & perms.WRITE_MSGS:
            context['reply_url'] = "../members/send_message?ids={}".format(
                self.object.contact_id)
        context.update(kwargs)
        return super().get_context_data(**context)
Example #2
0
 def get_context_data(self, **kwargs):
     cg = self.contactgroup
     context = {}
     context['cg'] = cg
     if cg:
         context['cg_perms'] = perms.int_to_flags(cg.userperms)
     context.update(kwargs)
     return super().get_context_data(**context)
Example #3
0
def perms_int_to_flags(intperms):
    return perms.int_to_flags(intperms)