def create_campaign(): import uuid from flask import url_for, redirect from campaign_manager.forms.campaign import CampaignForm from campaign_manager.models.campaign import Campaign """Get campaign details. """ form = CampaignForm(request.form) if form.validate_on_submit(): data = form.data data.pop('csrf_token') data.pop('submit') data['uuid'] = uuid.uuid4().hex Campaign.create(data, form.uploader.data) return redirect( url_for( 'campaign_manager.get_campaign', uuid=data['uuid']) ) context = dict( oauth_consumer_key=OAUTH_CONSUMER_KEY, oauth_secret=OAUTH_SECRET ) context['action'] = '/campaign_manager/create' context['campaigns'] = Campaign.all() context['categories'] = AbstractInsightsFunction.CATEGORIES context['functions'] = get_selected_functions() context['title'] = 'Create Campaign' return render_template( 'create_campaign.html', form=form, **context)
def get_campaigns(self, tag): """Returns campaign with tag. :param tag: tag to filter :type tag: str """ return Campaign.all(**{'tags': tag})
def home(): """Home page view. On this page a summary campaign manager view will shown. """ context = dict( oauth_consumer_key=OAUTH_CONSUMER_KEY, oauth_secret=OAUTH_SECRET ) context['campaigns'] = Campaign.all() # noinspection PyUnresolvedReferences return render_template('index.html', **context)
def edit_campaign(uuid): import datetime from flask import url_for, redirect from campaign_manager.forms.campaign import CampaignForm from campaign_manager.models.campaign import Campaign """Get campaign details. """ try: campaign = Campaign.get(uuid) context = campaign.to_dict() if request.method == 'GET': form = CampaignForm() form.name.data = campaign.name form.campaign_status.data = campaign.campaign_status form.coverage.data = campaign.coverage form.campaign_managers.data = campaign.campaign_managers form.description.data = campaign.description form.geometry.data = json.dumps(campaign.geometry) form.selected_functions.data = json.dumps(campaign.selected_functions) form.start_date.data = datetime.datetime.strptime( campaign.start_date, '%Y-%m-%d') if campaign.end_date: form.end_date.data = datetime.datetime.strptime( campaign.end_date, '%Y-%m-%d') else: form = CampaignForm(request.form) if form.validate_on_submit(): data = form.data data.pop('csrf_token') data.pop('submit') campaign.update_data(data, form.uploader.data) return redirect( url_for('campaign_manager.get_campaign', uuid=campaign.uuid) ) except Campaign.DoesNotExist: return Response('Campaign not found') context['oauth_consumer_key'] = OAUTH_CONSUMER_KEY context['oauth_secret'] = OAUTH_SECRET context['action'] = '/campaign_manager/edit/%s' % uuid context['campaigns'] = Campaign.all() context['categories'] = AbstractInsightsFunction.CATEGORIES context['functions'] = get_selected_functions() context['title'] = 'Edit Campaign' return render_template( 'create_campaign.html', form=form, **context)
def generate_geometry(): for campaign in Campaign.all('all'): geojson_path = Campaign.get_geojson_file(campaign.uuid) if not geojson_path: campaign.save(save_to_git=False)
def get_campaigns(self): """Returns campaigns. """ return Campaign.all(campaign_status='active')
def get_all_campaign(self, campaign_status, args): """Returns all campaign from model. """ return Campaign.all(campaign_status=campaign_status, **args)