def get_list_unsubscribe_url(email): """ Generates a URL to be used for a List-Unsubscribe header. Util function. """ global _CosinnusPortal if _CosinnusPortal is None: _CosinnusPortal = apps.get_model('cosinnus', 'CosinnusPortal') domain = get_domain_for_portal(_CosinnusPortal.get_current()) return domain + reverse( 'cosinnus:user-add-email-blacklist', kwargs={ 'email': email, 'token': email_blacklist_token_generator.make_token(email) })
def get_absolute_url(self): """ Point at URL of referenced ContentType object """ if self.target_object and self.content_type.model == 'user': # patch for user model get_absolute_url pointing to nowhere return get_domain_for_portal( CosinnusPortal.get_current()) + reverse( 'cosinnus:profile-detail', kwargs={'username': self.target_object.username}) if self.target_object and hasattr(self.target_object, 'get_absolute_url'): return self.target_object.get_absolute_url() return None
def get_absolute_url(self): item_id = '%d.ideas.%s' % (self.portal_id, self.slug) return get_domain_for_portal(self.portal) + reverse('cosinnus:map') + '?item=' + item_id
def render(self, context): if not hasattr(self, 'base_view_name'): self.base_view_name = copy(self.view_name) else: self.view_name = copy(self.base_view_name) view_name = self.view_name.resolve(context) ignoreErrors = 'ignoreErrors' in self.kwargs and self.kwargs.pop( 'ignoreErrors').resolve(context) or False group_arg = self.kwargs["group"].resolve(context) group_slug = "" foreign_portal = None portal_id = getattr(self, '_portal_id', None) force_local_domain = getattr(self, '_force_local_domain', False) try: # the portal id if given to the tag can override the group's portal self._portal_id = self.kwargs["portal_id"].resolve(context) portal_id = self._portal_id del self.kwargs["portal_id"] except KeyError: pass try: # this will retain the local domain. useful for avoiding POSTs to cross-portal domains and CSRF-failing self._force_local_domain = bool( self.kwargs["force_local_domain"].resolve(context)) force_local_domain = self._force_local_domain del self.kwargs["force_local_domain"] except KeyError: pass patched_group_slug_arg = None # we accept a group object or a group slug if issubclass(group_arg.__class__, get_cosinnus_group_model()): # determine the portal from the group group_slug = group_arg.slug # if not explicitly given, learn the portal id from the group if not portal_id: portal_id = group_arg.portal_id if not portal_id == CosinnusPortal.get_current().id: foreign_portal = group_arg.portal # we patch the variable given to the tag here, to restore the regular slug-passed-url-resolver functionality patched_group_slug_arg = deepcopy(self.kwargs['group']) patched_group_slug_arg.token += '.slug' patched_group_slug_arg.var.var += '.slug' patched_group_slug_arg.var.lookups = list( self.kwargs['group'].var.lookups) + ['slug'] elif not isinstance(group_arg, six.string_types): raise TemplateSyntaxError( "'group_url' tag requires a group kwarg that is a group or a slug! Have you passed one? (You passed: 'group=%s')" % group_arg) else: group_slug = group_arg # make sure we have the foreign portal. we might not have yet retrieved it if we had a portal id explicitly set if portal_id and not portal_id == CosinnusPortal.get_current( ).id and not foreign_portal: foreign_portal = CosinnusPortal.objects.get(id=portal_id) try: try: view_name = group_aware_url_name(view_name, group_slug, portal_id) except CosinnusGroup.DoesNotExist: # ignore errors if the group doesn't exist if it is inactive (return empty link) if ignoreErrors or (not group_arg.is_active): return '' logger.error( u'Cosinnus__group_url_tag: Could not find group for: group_arg: %s, view_name: %s, group_slug: %s, portal_id: %s' % (str(group_arg), view_name, group_slug, portal_id)) raise self.view_name.var = view_name self.view_name.token = "'%s'" % view_name # to retain django core code for rendering, we patch this node to look like a proper url node, # with a slug argument. # and then restore it later, so that the node object can be reused for other group arguments # if we didn't do that, this group node's group argument would have been replaced already, and # lost to other elements that use the group_url tag in a for-loop, for example # (we cannot store anything on the object itself, down that road madness lies) if patched_group_slug_arg: self.kwargs[ 'group'], patched_group_slug_arg = patched_group_slug_arg, self.kwargs[ 'group'] ret_url = super(GroupURLNode, self).render(context) # swap back the patched arg for the original if patched_group_slug_arg: self.kwargs['group'] = patched_group_slug_arg if foreign_portal and not force_local_domain: domain = get_domain_for_portal(foreign_portal) # attach to either output or given "as" variable if self.asvar: context[self.asvar] = domain + context[self.asvar] else: ret_url = domain + ret_url return ret_url except: if ignoreErrors: return '' else: raise
def get_preview_url(self): return get_domain_for_portal(self.portal) + reverse( 'cosinnus:user-dashboard') + '?show_announcement=%d' % self.id