Export Users using the current search filters into a CSV.
428246
public function csv_export()
    {
        $search = $this->app->make('Concrete\Controller\Search\Users');
        $result = $search->getCurrentSearchObject();

        $headers = [
            'Content-Type' => 'text/csv',
            'Content-Disposition' => 'attachment; filename=concrete5_users.csv',
        ];
        $app = $this->app;
        $config = $this->app->make('config');
        $bom = $config->get('concrete.export.csv.include_bom') ? $config->get('concrete.charset_bom') : '';

        return StreamedResponse::create(
            function () use ($app, $result, $bom) {
                $writer = $app->build(
                    UserExporter::class,
                    [
                        'writer' => $this->app->make(WriterFactory::class)->createFromPath('php://output', 'w'),
                    ]
                );
                echo $bom;
                $writer->setUnloadDoctrineEveryTick(50);
                $writer->insertHeaders();
                $writer->insertList($result->getItemListObject());
            },
            200,
            $headers);
    }
763439
def rows(self, csv=False):
        

        # Store the index of each field against its ID for building each
        # entry row with columns in the correct order. Also store the IDs of
        # fields with a type of FileField or Date-like for special handling of
        # their values.
        field_indexes = {}
        file_field_ids = []
        date_field_ids = []
        for field in self.form_fields:
            if self.cleaned_data["field_%s_export" % field.id]:
                field_indexes[field.id] = len(field_indexes)
                if field.is_a(fields.FILE):
                    file_field_ids.append(field.id)
                elif field.is_a(*fields.DATES):
                    date_field_ids.append(field.id)
        num_columns = len(field_indexes)
        include_entry_time = self.cleaned_data["field_0_export"]
        if include_entry_time:
            num_columns += 1

        # Get the field entries for the given form and filter by entry_time
        # if specified.
        field_entries = FieldEntry.objects.filter(
            entry__form=self.form).order_by(
            "-entry__id").select_related("entry")
        if self.cleaned_data["field_0_filter"] == FILTER_CHOICE_BETWEEN:
            time_from = self.cleaned_data["field_0_from"]
            time_to = self.cleaned_data["field_0_to"]
            if time_from and time_to:
                field_entries = field_entries.filter(
                    entry__entry_time__range=(time_from, time_to))

        # Loop through each field value ordered by entry, building up each
        # entry as a row. Use the ``valid_row`` flag for marking a row as
        # invalid if it fails one of the filtering criteria specified.
        current_entry = None
        current_row = None
        valid_row = True
        for field_entry in field_entries:
            if field_entry.entry_id != current_entry:
                # New entry, write out the current row and start a new one.
                if valid_row and current_row is not None:
                    if not csv:
                        current_row.insert(0, current_entry)
                    yield current_row
                current_entry = field_entry.entry_id
                current_row = [""] * num_columns
                valid_row = True
                if include_entry_time:
                    current_row[-1] = field_entry.entry.entry_time
            field_value = field_entry.value or ""
            # Check for filter.
            field_id = field_entry.field_id
            filter_type = self.cleaned_data.get("field_%s_filter" % field_id)
            filter_args = None
            if filter_type:
                if filter_type == FILTER_CHOICE_BETWEEN:
                    f, t = "field_%s_from" % field_id, "field_%s_to" % field_id
                    filter_args = [self.cleaned_data[f], self.cleaned_data[t]]
                else:
                    field_name = "field_%s_contains" % field_id
                    filter_args = self.cleaned_data[field_name]
                    if filter_args:
                        filter_args = [filter_args]
            if filter_args:
                # Convert dates before checking filter.
                if field_id in date_field_ids:
                    y, m, d = field_value.split(" ")[0].split("-")
                    dte = date(int(y), int(m), int(d))
                    filter_args.append(dte)
                else:
                    filter_args.append(field_value)
                filter_func = FILTER_FUNCS[filter_type]
                if not filter_func(*filter_args):
                    valid_row = False
            # Create download URL for file fields.
            if field_entry.value and field_id in file_field_ids:
                url = reverse("admin:form_file", args=(field_entry.id,))
                field_value = self.request.build_absolute_uri(url)
                if not csv:
                    parts = (field_value, split(field_entry.value)[1])
                    field_value = mark_safe("<a href=\"%s\">%s</a>" % parts)
            # Only use values for fields that were selected.
            try:
                current_row[field_indexes[field_id]] = field_value
            except KeyError:
                pass
        # Output the final row.
        if valid_row and current_row is not None:
            if not csv:
                current_row.insert(0, current_entry)
            yield current_row
1272643
def construct_user_list(raw_users=None):
        """"""
        users = Users(oktypes=User)
        for user_dict in raw_users:
            public_keys = None
            if user_dict.get('public_keys'):
                public_keys = [PublicKey(b64encoded=x, raw=None)
                               for x in user_dict.get('public_keys')]
            users.append(User(name=user_dict.get('name'),
                              passwd=user_dict.get('passwd'),
                              uid=user_dict.get('uid'),
                              gid=user_dict.get('gid'),
                              home_dir=user_dict.get('home_dir'),
                              gecos=user_dict.get('gecos'),
                              shell=user_dict.get('shell'),
                              public_keys=public_keys,
                              sudoers_entry=user_dict.get('sudoers_entry')))
        return users
680753
def format_users():
    ''''''
    lines = []
    u = users()
    count = u['count']
    if not count:
        raise DapiCommError('Could not find any users on DAPI.')
    for user in u['results']:
        line = user['username']
        if user['full_name']:
            line += ' (' + user['full_name'] + ')'
        lines.append(line)
    return lines
230440
def format_results(self, raw_data, options):
        '''
        
        '''
        page_data = self.paginate_results(raw_data, options)
        results = {}
        meta = options.copy()
        meta['more'] = _('Show more results')
        if page_data and page_data.has_next():
            meta['next_page'] = page_data.next_page_number()
        if page_data and page_data.has_previous():
            meta['prev_page'] = page_data.previous_page_number()
        results['data'] = [self.format_item(item) for item in page_data.object_list]
        results['meta'] = meta
        return results
1185051
public function export()
	{
		$view = $this->getView();
		$context = $this->getContext();

		try
		{
			$params = $this->storeSearchParams( $view->param(), 'order' );
			$msg = ['sitecode' => $context->getLocale()->getSite()->getCode()];

			if( isset( $params['filter'] ) ) {
				$msg['filter'] = $this->getCriteriaConditions( $params['filter'] );
			}

			if( isset( $params['sort'] ) ) {
				$msg['sort'] = $this->getCriteriaSortations( $params['sort'] );
			}

			$mq = $context->getMessageQueueManager()->get( 'mq-admin' )->getQueue( 'order-export' );
			$mq->add( json_encode( $msg ) );

			$msg = $context->getI18n()->dt( 'admin', 'Your export will be available in a few minutes for download' );
			$view->info = $view->get( 'info', [] ) + ['order-item' => $msg];
		}
		catch( \Aimeos\MShop\Exception $e )
		{
			$error = array( 'order-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
			$view->errors = $view->get( 'errors', [] ) + $error;
			$this->logException( $e );
		}
		catch( \Exception $e )
		{
			$error = array( 'order-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
			$view->errors = $view->get( 'errors', [] ) + $error;
			$this->logException( $e );
		}

		return $this->search();
	}
435781
function (req, res, next) {
    var profile = req.profile;
    var filter = { or: [{ yahoo: profile.guid }, { email: profile.email }] };

    User.find({ where: filter }, function(err, users) {
      var user = users[0];

      if (user) {
        if (!user.yahoo) {
          user.yahoo = body.profile.guid;
          user.displayName = user.displayName || body.profile.name;
          user.save(function() {
            req.user = user;
            next();
          });
          return;
        }

        req.user = user;
        next();
        return;
      }

      User.create({
        displayName: body.profile.name,
        yahoo: body.profile.guid,
        email: body.profile.email,
        password: body.profile.guid
      }, function (err, user) {
        req.user = user;
        next();
      });

    });
  }
185323
def convert_context_to_csv(self, context):
        """"""
        content = []
        date_headers = context['date_headers']

        headers = ['Name']
        headers.extend([date.strftime('%m/%d/%Y') for date in date_headers])
        headers.append('Total')
        content.append(headers)

        summaries = context['summaries']

        summary = summaries.get(self.export, [])

        for rows, totals in summary:
            for name, user_id, hours in rows:
                data = [name]
                data.extend(hours)
                content.append(data)
            total = ['Totals']
            total.extend(totals)
            content.append(total)
        return content
881671
def get_export_queryset(self, request):
        
        list_display = self.get_list_display(request)
        list_display_links = self.get_list_display_links(request, list_display)
        list_filter = self.get_list_filter(request)
        search_fields = self.get_search_fields(request)
        if self.get_actions(request):
            list_display = ['action_checkbox'] + list(list_display)

        ChangeList = self.get_changelist(request)
        changelist_kwargs = {
            'request': request,
            'model': self.model,
            'list_display': list_display,
            'list_display_links': list_display_links,
            'list_filter': list_filter,
            'date_hierarchy': self.date_hierarchy,
            'search_fields': search_fields,
            'list_select_related': self.list_select_related,
            'list_per_page': self.list_per_page,
            'list_max_show_all': self.list_max_show_all,
            'list_editable': self.list_editable,
            'model_admin': self,
        }
        if django.VERSION >= (2, 1):
            changelist_kwargs['sortable_by'] = self.sortable_by
        cl = ChangeList(**changelist_kwargs)

        return cl.get_queryset(request)
1749
def format_search_results(self, search_results):
        
        formatted_lines = []

        for search_result in search_results:
            lines = self._format_search_result(search_result)
            formatted_lines.extend(lines)

        return formatted_lines
760096
private void exportToCsv(File exportFile) {
        FileWriter fileWriter = null;
        exportStatus=true;
        try {
            fileWriter = new FileWriter(exportFile);
            CSVWriter writer = new CSVWriter(fileWriter);
            List<Marker> markers = datastore.getBookmarksAsMarkers(getmMapView());
            String[] headers = new String[] {"Latitude","Longitude","Description","Title"};
            writer.writeNext(headers);
            for (Marker m: markers) {
                String[] items = new String[4];
                items[0] = m.getPosition().getLatitude()+"";
                items[1] = m.getPosition().getLongitude()+"";
                items[2] = m.getSubDescription();
                items[3] = m.getTitle();
                writer.writeNext(items);
            }
        }catch (Exception ex) {
            exportStatus=false;
            ex.printStackTrace();
        } finally {
            if (fileWriter!=null)
                try {
                    fileWriter.close();
                }catch (Exception ex) {}
        }
        final Activity act = getActivity();
        if (act!=null) {
            act.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (exportStatus) {
                        Toast.makeText(act, "Export Complete", Toast.LENGTH_LONG).show();
                    } else
                        Toast.makeText(act, "Export Failed", Toast.LENGTH_LONG).show();
                }
            });
        }
    }
34730
public static function export_user_data(approved_contextlist $contextlist) {
        global $DB;

        // Plugin search_simpledb uses the default document object (core_search\document) which uses FORMAT_PLAIN.
        $textformat = FORMAT_PLAIN;

        $userid = $contextlist->get_user()->id;

        $ctxfields = \context_helper::get_preload_record_columns_sql('ctx');
        list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);
        $sql = "SELECT ssi.*, $ctxfields FROM {search_simpledb_index} ssi
                  JOIN {context} ctx ON ctx.id = ssi.contextid
                 WHERE ssi.contextid $contextsql AND (ssi.userid = :userid OR ssi.owneruserid = :owneruserid)";
        $params = ['userid' => $userid, 'owneruserid' => $userid] + $contextparams;

        $records = $DB->get_recordset_sql($sql, $params);
        foreach ($records as $record) {

            \context_helper::preload_from_record($record);
            $context = \context::instance_by_id($record->contextid);
            $document = (object)[
                'title' => format_string($record->title, true, ['context' => $context]),
                'content' => format_text($record->content, $textformat, ['context' => $context]),
                'description1' => format_text($record->description1, $textformat, ['context' => $context]),
                'description2' => format_text($record->description2, $textformat, ['context' => $context]),
                'context' => $context->get_context_name(true, true),
                'modified' => transform::datetime($record->modified),

            ];

            $path = [get_string('search', 'search'), $record->docid];
            writer::with_context($context)->export_data($path, $document);
        }
        $records->close();
    }
667619
def get_submissions():
    """"""
    print(request.args.to_dict())
    print(request.args.get('search[value]'))
    print(request.args.get('draw', 1))
    # submissions  = session.query(Submission).all()
    if request.args.get('correct_filter', 'all') == 'all':
        correct_filter = [True, False]
    elif request.args['correct_filter'] == 'correct':
        correct_filter = [True]
    else:
        correct_filter = [False]
    
    if request.args.get('order[0][column]', '0') == '0':
        column = 'id'
    elif request.args['order[0][column]'] == '1':
        column = 'text'
    else:
        column = 'primary_error'
        
    order_str = "{} {}".format(column, request.args.get('order[0][dir]', 'desc'))

    search_val = request.args.get('search[value]')
    draw = request.args.get('draw', 1)
    filtered_len = session.query(Submission)\
            .filter(Submission.text.startswith(search_val))\
            .filter(Submission.correct.in_(correct_filter))\
            .count()
    subs = \
            session.query(Submission).filter(Submission.text.startswith(search_val))\
            .filter(Submission.correct.in_(correct_filter))\
            .order_by(order_str)\
            .offset(request.args.get('start', 0))\
            .limit(request.args.get('length', 10))\
            .all()
    submissions = {'draw': draw, 'recordsTotal':0, 'recordsFiltered':0, 'data':[]}
    i = 0
    for i, submission in enumerate(subs):
       submissions['data'].append([submission.id, submission.text,
           submission.primary_error, submission.correct]) 
    submissions['recordsTotal'] = session.query(Submission).count() 
    submissions['recordsFiltered'] = filtered_len 

    return jsonify(submissions)
881882
def tofile(self, f):
        """"""
        f.write(pack(self.FILE_FMT, self.scale, self.ratio,
                     self.initial_capacity, self.error_rate))

        # Write #-of-filters
        f.write(pack(b'<l', len(self.filters)))

        if len(self.filters) > 0:
            # Then each filter directly, with a header describing
            # their lengths.
            headerpos = f.tell()
            headerfmt = b'<' + b'Q'*(len(self.filters))
            f.write(b'.' * calcsize(headerfmt))
            filter_sizes = []
            for filter in self.filters:
                begin = f.tell()
                filter.tofile(f)
                filter_sizes.append(f.tell() - begin)

            f.seek(headerpos)
            f.write(pack(headerfmt, *filter_sizes))
298792
def user_search_results(self):
        
        results = super(SharingView, self).user_search_results()
        ws = IWorkspace(self.context)
        roles_mapping = ws.available_groups
        roles = roles_mapping.get(self.context.participant_policy.title())

        for result in results:
            if result["id"] in ws.members:
                groups = ws.get(result["id"]).groups
                for role in roles:
                    result["roles"][role] = "acquired"
                if "Admins" in groups:
                    title = "administrator"
                    result["roles"]["TeamManager"] = "acquired"
                else:
                    title = "member"
                result["title"] = "%s [%s]" % (result["title"], title)

        return results
763012
def describe_users(self, users_filter=None):
        """"""
        user_list = Users(oktypes=User)
        for user in self._user_list:
            if users_filter and (users_filter.get('name') == user.name or users_filter.get('uid') == user.uid):
                user_list.append(user)
        return user_list
1095102
def export(group, bucket, prefix, start, end, role, poll_period=120,
           session=None, name="", region=None):
    """"""
    start = start and isinstance(start, six.string_types) and parse(start) or start
    end = (end and isinstance(start, six.string_types) and
           parse(end) or end or datetime.now())
    start = start.replace(tzinfo=tzlocal()).astimezone(tzutc())
    end = end.replace(tzinfo=tzlocal()).astimezone(tzutc())

    if session is None:
        session = get_session(role, region)

    client = session.client('logs')

    paginator = client.get_paginator('describe_log_groups')
    for p in paginator.paginate():
        found = False
        for _group in p['logGroups']:
            if _group['logGroupName'] == group:
                group = _group
                found = True
                break
        if found:
            break

    if not found:
        raise ValueError("Log group %s not found." % group)

    if prefix:
        prefix = "%s/%s" % (prefix.rstrip('/'), group['logGroupName'].strip('/'))
    else:
        prefix = group['logGroupName']

    named_group = "%s:%s" % (name, group['logGroupName'])
    log.info(
        "Log exporting group:%s start:%s end:%s bucket:%s prefix:%s size:%s",
        named_group,
        start.strftime('%Y/%m/%d'),
        end.strftime('%Y/%m/%d'),
        bucket,
        prefix,
        group['storedBytes'])

    t = time.time()
    days = [(
        start + timedelta(i)).replace(minute=0, hour=0, second=0, microsecond=0)
        for i in range((end - start).days)]
    day_count = len(days)
    s3 = boto3.Session().client('s3')
    days = filter_extant_exports(s3, bucket, prefix, days, start, end)

    log.info("Group:%s filtering s3 extant keys from %d to %d start:%s end:%s",
             named_group, day_count, len(days),
             days[0] if days else '', days[-1] if days else '')
    t = time.time()

    retry = get_retry(('SlowDown',))

    for idx, d in enumerate(days):
        date = d.replace(minute=0, microsecond=0, hour=0)
        export_prefix = "%s%s" % (prefix, date.strftime("/%Y/%m/%d"))
        params = {
            'taskName': "%s-%s" % ("c7n-log-exporter",
                                   date.strftime("%Y-%m-%d")),
            'logGroupName': group['logGroupName'],
            'fromTime': int(time.mktime(
                date.replace(
                    minute=0, microsecond=0, hour=0).timetuple()) * 1000),
            'to': int(time.mktime(
                date.replace(
                    minute=59, hour=23, microsecond=0).timetuple()) * 1000),
            'destination': bucket,
            'destinationPrefix': export_prefix
        }

        # if stream_prefix:
        #    params['logStreamPrefix'] = stream_prefix
        try:
            s3.head_object(Bucket=bucket, Key=prefix)
        except ClientError as e:
            if e.response['Error']['Code'] != '404':  # Not Found
                raise
            s3.put_object(
                Bucket=bucket,
                Key=prefix,
                Body=json.dumps({}),
                ACL="bucket-owner-full-control",
                ServerSideEncryption="AES256")

        t = time.time()
        counter = 0
        while True:
            counter += 1
            try:
                result = client.create_export_task(**params)
            except ClientError as e:
                if e.response['Error']['Code'] == 'LimitExceededException':
                    time.sleep(poll_period)
                    # log every 30m of export waiting
                    if counter % 6 == 0:
                        log.debug(
                            "group:%s day:%s waiting for %0.2f minutes",
                            named_group, d.strftime('%Y-%m-%d'),
                            (counter * poll_period) / 60.0)
                    continue
                raise
            retry(
                s3.put_object_tagging,
                Bucket=bucket, Key=prefix,
                Tagging={
                    'TagSet': [{
                        'Key': 'LastExport',
                        'Value': d.isoformat()}]})
            break

        log.info(
            "Log export time:%0.2f group:%s day:%s bucket:%s prefix:%s task:%s",
            time.time() - t,
            named_group,
            d.strftime("%Y-%m-%d"),
            bucket,
            params['destinationPrefix'],
            result['taskId'])

    log.info(
        ("Exported log group:%s time:%0.2f days:%d start:%s"
         " end:%s bucket:%s prefix:%s"),
        named_group,
        time.time() - t,
        len(days),
        start.strftime('%Y/%m/%d'),
        end.strftime('%Y/%m/%d'),
        bucket,
        prefix)