def action(content): if content.get('type') == "assignment": return content_creator_name + _("Created a _assignment") elif content.get('parent'): return content_creator_name + _("Wrote a response") elif content.get('type') == "article": return content_creator_name + _("Wrote _article")
def send_verifiy_email(user, controller='account', action='verify_email', message=None, subject=None): if not subject: subject = _('verify e-mail address') if not message: message = _('verify this email address') # Session.refresh(user) validation_link = validation_url(user, controller, action) message = _('Please %s by clicking on, or copying the following link into your browser: %s') % (message, validation_link) if action == 'verify_email': send_email(user.email_unverified, subject=subject, content_text=message) else: user.send_email(subject=subject, content_text=message)
def get_action_objects_for_url(action_url=None): """ If signing in and performing an action Will return () """ from civicboom.lib.helpers import get_object_from_action_url from civicboom.controllers.members import MembersController from civicboom.controllers.contents import ContentsController content_show = ContentsController().show member_show = MembersController().show actions_list = [ # url identifyer , action , description (re.compile('/signout'), 'signout', _('sign out')), (re.compile('/accept'), 'accept', _('accept a _assignment')), (re.compile('/follow'), 'follow', _('follow a _member')), (re.compile('/boom'), 'boom', _('boom _content')), (re.compile('/contents/new\?parent_id='), 'new_respose', _('create a response')), (re.compile('/contents/new\?target_type=article'), 'new_article', _('post a _article')), (re.compile('/contents\?(.*?)type=comment(.*?)parent_id='), 'comment', _('make a comment') ), #AllanC - I weep at the inefficency and code duplication (re.compile('/contents\?(.*?)parent_id=(.*?)type=comment'), 'comment', _('make a comment')), (re.compile('/contents/new'), 'new_article', _('create new content')), # Failsafe for new aticle is all ] # If performing an action we may want to display a custom message with the login if not action_url: action_url = current_url() for action_identifyer, action_action, action_description in actions_list: if action_identifyer.search(action_url): args, kwargs = get_object_from_action_url(action_url) action_object = { } # Set this in case we cant recover an action object action_object_frag_url = '' if args and kwargs: # Generate action object frag URL kwargs['format'] = 'frag' action_object_frag_url = url(*args, **kwargs) # Find action object if 'content' in args and 'id' in kwargs: action_object = content_show(id=kwargs['id']).get('data') if 'member' in args and 'id' in kwargs: action_object = member_show(id=kwargs['id']).get('data') return dict( action=action_action, description=action_description, action_object=action_object, frag_url=action_object_frag_url, ) return {}
def associate_janrain_account(user, type, token): """ Associate a login record for a Janrain account This is called at: 1.) Registration 2.) Linking multiple login accounts to a single Civicboom account """ login = None try: login = Session.query(UserLogin).filter(UserLogin.token == token).filter(UserLogin.type == type).one() except: pass if login: if login.user == user: return # If login already belongs to this user then abort if login.user: # Warn existing user that account is being reallocated login.user.send_email(subject=_('login account reallocated'), content_text=_('your %s account has been allocated to the user %s') % (type, user.username)) if not config['development_mode']: janrain('unmap', identifier=login.token, primaryKey=login.member_id) login.user = user else: login = UserLogin() login.user = user login.type = type login.token = token Session.add(login) Session.commit() if not config['development_mode']: janrain('map', identifier=login.token, primaryKey=login.member_id) # Let janrain know this users primary key id, this is needed for agrigation posts
def validate_dict(data, schema, dict_to_validate_key=None, template_error=None): # Prepare dict to validate if dict_to_validate_key == None and len( data ) == 1: # If dict only contains 1 key then validate that one key dict_to_validate_key = data.keys()[0] if dict_to_validate_key: dict_to_validate = data[dict_to_validate_key] # Validate try: dict_validated = schema.to_python(dict_to_validate) # Validation Failed except formencode.Invalid as error: dict_validated = error.value dict_validated_errors = error.error_dict or {} # Record errors in data['invalid'] invalid_dict = {} data['invalid'] = invalid_dict #log.debug(dict_validated) #log.debug(dict_validated_errors) invalid_text = "" for key in dict_validated_errors: e = dict_validated_errors[key] if hasattr(e, 'msg'): e = e.msg invalid_dict[key] = e invalid_text += " %s-%s" % (key, e) # Raise Validation Error log.debug("Validation fail:" + pprint.pformat(data)) raise action_error( status='invalid', code=400, message=_('failed validation: %s' % invalid_text), data=data, template=template_error, ) # Overlay validated dict back over data and return if dict_to_validate_key: data[dict_to_validate_key] = dict_validated return data
def action_links(content): action_links = [] action_links.append({ 'href': url('new_content', parent_id=content['id'], sub_domain='www', qualified=True), 'text': _('Write a response') }) if content.get('type') == "assignment": action_links.append({ 'href': url('content_action', action='accept', id=content['id'], sub_domain='www', qualified=True), 'text': _('Accept _assignment') }) return action_links
def get_list_titles(list_name): contents_list_titles = [ # list name, icon, description ('all', 'article', _('all').capitalize()), ('drafts', 'draft', _("Drafts")), ('assignments_active', 'assignment', _("Requests I want you to respond to")), ('assignments_previous', 'assignment', _('previous _assignments').capitalize()), ('responses', 'response', _("Responses I've written")), ('articles', 'article', _("My news")), ] for (list, icon, description) in contents_list_titles: if list == list_name: return (icon, description) return (list_name, list_name)
def aggregation_dict(content, safe_strings=True): """ Gets a Python dict summary version of this content for aggregation via Janrain https://rpxnow.com/docs#api_activity safe_strings will escape all harful characters. This is used for constructing a javascript representaion for the Janrain Widget in javascript code """ content_preview = {} content_url = url('content', id=content['id'], sub_domain='www', qualified=True) content_creator_name = content.get('creator', {}).get('name', '') def action(content): if content.get('type') == "assignment": return content_creator_name + _("Created a _assignment") elif content.get('parent'): return content_creator_name + _("Wrote a response") elif content.get('type') == "article": return content_creator_name + _("Wrote _article") def description(content): return "%s: %s" % (action(content), content.get('title')) def action_links(content): action_links = [] action_links.append({ 'href': url('new_content', parent_id=content['id'], sub_domain='www', qualified=True), 'text': _('Write a response') }) if content.get('type') == "assignment": action_links.append({ 'href': url('content_action', action='accept', id=content['id'], sub_domain='www', qualified=True), 'text': _('Accept _assignment') }) return action_links def media(content): media_list = [] if not content.get('attachments'): media_list.append({ 'href': content_url, 'type': "image", 'src': content.get('thumbnail_url') }) else: for media in content.get('attachments'): if media.get('type') == "image": media_list.append({ 'href': content_url, 'type': "image", 'src': media.get('thumbnail_url') }) if media.get('subtype') == "mp3": media_list.append({ 'href': content_url, 'type': "mp3", 'src': media.get('media_url') }) return media_list def properties(content): properties = {} if content.get('type') == "article": properties['Rating'] = content.get('rating') # TODO: Additional properties #"Location": { # "href": "http:\/\/bit.ly\/3fkBwe", # "text": "North Portland" #}, return properties content_preview['url'] = content_url content_preview['title'] = content.get('title') content_preview['action'] = action(content) content_preview['description'] = description(content) content_preview['user_generated_content'] = truncate( safe_python_strings(strip_html_tags(content['content'])), length=100, indicator=_('... read more'), whole_word=True) content_preview['action_links'] = action_links(content) content_preview['media'] = media(content) content_preview['properties'] = properties(content) if safe_strings: content_preview = safe_python_strings(content_preview) return content_preview
def setting_titles(): return { 'password': _('Password and mobile access'), 'help_adverts': _('Help and guides') }