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 members_show(id, **kwargs): lists = kwargs.pop('lists') member = get_member(id) data = {'member': member.to_dict(list_type='full', **kwargs)} # Imports # AllanC - cannot be imported at begining of module because of mutual coupling error from civicboom.controllers.contents import ContentsController, list_filters from civicboom.controllers.member_actions import MemberActionsController contents_controller = ContentsController() member_actions_controller = MemberActionsController() # Content Lists for list in [list for list in lists if list in list_filters]: data[list] = contents_controller.index( creator=member, list=list, limit=config['search.default.limit.sub_list'], **kwargs)['data']['list'] lists.remove( list ) # AllanC - fix; don't allow the same lists to be got from both content and member controller # Member Lists for list in [ list for list in lists if hasattr(member_actions_controller, list) ]: limit = None if list in [ 'boomed', 'assignments_accepted' ]: # AllanC - we dont want to limit member lists, but we do want to limit content lists to 3 limit = config['search.default.limit.sub_list'] data[list] = getattr(member_actions_controller, list)(member, limit=limit, **kwargs)['data']['list'] return action_ok(data=data)
def publish_scheduled_content(self, frequency_of_timed_task="hours=1"): """ query for all users in last <timedelta> and email """ frequency_of_timed_task = timedelta_from_str(frequency_of_timed_task) datetime_now = normalize_datetime(now()) from civicboom.model.content import DraftContent from civicboom.controllers.contents import ContentsController content_publish = ContentsController().update def get_content_to_publish(date_start, date_end): return Session.query(DraftContent).filter(and_(DraftContent.auto_publish_trigger_datetime >= date_start, DraftContent.auto_publish_trigger_datetime <= date_end)).all() # AllanC - calls will be made to content.py:update this will trigger the normal decorators, we need to ensure that these dont prohibit the update call's we are about to make c.authenticated_form = True # AllanC - Fake the authenticated status so that the auth decorator does not tigger c.format = 'python' for content in get_content_to_publish(datetime_now, datetime_now + frequency_of_timed_task): log.info('Auto publishing content #%s - %s' % (content.id, content.title)) # By calling the content:update method with no param with the content as a draft, it automatically pubishs the content content_publish(content, submit_publish=True) return response_completed_ok
from civicboom.lib.base import * from civicboom.controllers.contents import ContentsController from civicboom.lib.communication import messages from cbutils.misc import update_dict from civicboom.lib.qrcode import cb_qrcode content_search = ContentsController().index log = logging.getLogger(__name__) class ContentActionsController(BaseController): """ Content Actions and lists relating to an item of content """ #--------------------------------------------------------------------------- # Image - QR Code #--------------------------------------------------------------------------- @web @cacheable(time=60 * 60, anon_only=False) def qrcode(self, id, **kwargs): """ @param pixel_size optional int, default '8' The size of each cqcode module in pixels @parsm format optional string, default PNG accepts [png, jpeg, bmp, gif, tiff] @param level optional int, default 1 Error correction level 0 to 3 @return 200 a PNG """ return cb_qrcode(
from civicboom.lib.base import * from civicboom.controllers.contents import ContentsController from civicboom.controllers.members import MembersController, has_role_required from civicboom.controllers.payments import PaymentsController from civicboom.controllers.member_actions import MemberActionsController from civicboom.controllers.group_actions import GroupActionsController from civicboom.controllers.payment_actions import PaymentActionsController import copy from civicboom.model.member import group_member_roles, PaymentAccount contents_controller = ContentsController() members_controller = MembersController() payments_controller = PaymentsController() member_actions_controller = MemberActionsController() group_actions_controller = GroupActionsController() payment_actions_controller = PaymentActionsController() def get_payment_account(id): return Session.query(PaymentAccount).get(id) def check_member(member): return has_role_required( 'editor', c.logged_in_persona_role) and member == c.logged_in_persona def check_payment_account(payment_account):
from civicboom.lib.base import * from cbutils.misc import make_username from civicboom.controllers.account import AccountController set_persona = AccountController().set_persona from civicboom.model.member import Group, GroupMembership, group_member_roles, group_join_mode, group_member_visibility, group_content_visibility, Member #from civicboom.controllers.contents import _normalize_member # now part of base from civicboom.controllers.contents import ContentsController create_content = ContentsController().create from civicboom.lib.form_validators.dict_overlay import validate_dict import formencode from civicboom.lib.form_validators.base import DefaultSchema from civicboom.lib.form_validators.registration import UniqueUsernameValidator from civicboom.controllers.settings import SettingsController import re from civicboom.lib.communication.email_lib import send_email settings_update = SettingsController().update log = logging.getLogger(__name__)