Beispiel #1
0
def update_dos(request, dos_id):
    dos = models.DOS.safe_get_by_id(int(dos_id), request=request)
    # TODO: actually show an error message instead of just redirecting
    if not dos:
        view_common.log_access_violation('update_dos')
        return HttpResponseRedirect(reverse('show_client'))
    client = dos.clientinfo
    if request.method == 'POST':
        form = models.DOSFormNoClientSelect(request.POST,
                                            initial=db.to_dict(dos))
        if form.is_valid():
            dos.update_model(form.cleaned_data)
            view_common.save_entity(request, dos)
            return HttpResponseRedirect(client.get_absolute_url())
    else:
        form = models.DOSFormNoClientSelect(initial=db.to_dict(dos))
    render_to_response_dict = {
        "client": client,
        "dos_form": form,
        "form_dest": dos.get_absolute_url(),
        "dos_id": int(dos_id),
        "form_button": "Update DOS",
    }
    render_to_response_dict.update(get_common_dos_fields(request, client,
                                                         curr_dos=dos))

    return render_to_response("show_specific_client_template.html",
                              render_to_response_dict,
                              context_instance=RequestContext(request))
    def test_with_filter_factory(self):
        SHARD_COUNT = 10
        FF_PATH = \
            "test_mapreduce_utils.DatastoreQueryInputReaderTest." \
            "simple_parametrized_filter_factory"

        params = {
            "input_reader": {
                "entity_kind": self.TEST_ENTITY_IMPORT_PATH,
                "filter_factory_spec": {
                    "name": FF_PATH,
                    "args": ["B"]
                }
            }
        }
        mapper_spec = model.MapperSpec(
            "FooHandler",
            "mapreduce_utils.DatastoreQueryInputReader",
            params,
            SHARD_COUNT)

        ds_input_readers = DatastoreQueryInputReader.split_input(mapper_spec)
        got = reduce(operator.add,
            (list(reader) for reader in ds_input_readers))
        self.assertEqual(2, len(got))
        data1, data2, = filter(lambda i: i['type'] == "B", self.dataSet)
        got.sort(key=lambda i: i.name)
        self.assertDictEqual(data1, db.to_dict(got.pop(0)))
        self.assertDictEqual(data2, db.to_dict(got.pop(0)))
Beispiel #3
0
    def to_dict(self):
        result = to_dict(self)

        result['id'] = self.key().id()
        result['effect'] = int(result['effect'])

        try:
            result['advertisement'] = to_dict(self.advertisement)
        except:
            result['advertisement'] = {}

        try:
            result['venue'] = to_dict(self.venue)
        except:
            result['venue'] = {}

        try:
            result['background'] = to_dict(self.background)
        except:
            result['background'] = {}

        try:
            del result['venue']['location_geocells']
        except:
            pass

        return result
Beispiel #4
0
    def default(self, obj): # pylint: disable=E0202
        if isinstance(obj, datetime.datetime):
            return obj.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
        elif isinstance(obj, datetime.date):
            return obj.strftime("%Y-%m-%dT00:00:00Z")
        elif isinstance(obj, models.Event):
            obj_dict = db.to_dict(obj)
            obj_dict['key'] = obj.key()
            obj_dict['roles'] = {
                evt_role.role.role_type: evt_role.role_num
                for evt_role in obj.eventrole_set.ancestor(obj).run()}
            obj_dict = ConvertDictKeysToCamelCase(obj_dict)
            return obj_dict
        elif isinstance(obj, models.Person):
            obj_dict = db.to_dict(obj)
            obj_dict['key'] = obj.key()
            obj_dict['roles'] = [
                evt_role.role for evt_role in obj.roles.ancestor(obj).run()
                if evt_role.active]
            obj_dict = ConvertDictKeysToCamelCase(obj_dict)
            return obj_dict
        elif isinstance(obj, db.Model):
            obj_dict = db.to_dict(obj)
            obj_dict = ConvertDictKeysToCamelCase(obj_dict)
            obj_dict['key'] = obj.key()

            return obj_dict
        elif isinstance(obj, db.Key):
            return str(obj)
        else:
            return super(CustomJsonEncoder, self).default(obj)
Beispiel #5
0
def _gather_events_for_customer(customer_key, cap_key, organization_type):
    customer = Customer.get(customer_key)
    if not customer.service_email:
        logging.debug('This customer has no service yet: %s',
                      db.to_dict(customer))
        return
    if cap_key.parent().name() == customer.service_email:
        # do not gather own events
        return
    sln_settings = get_solution_settings(customer.service_user)
    if SolutionModule.AGENDA not in sln_settings.modules:
        return
    if sln_settings.default_calendar is None:
        logging.error(
            'This customer has no default calendar!\n\nSolutionSettings: %s\n\nCustomer: %s',
            db.to_dict(sln_settings),
            db.to_dict(customer),
            _suppress=False)
        return
    sc = SolutionCalendar.get_by_id(
        sln_settings.default_calendar,
        parent_key(customer.service_user, sln_settings.solution))
    if not sc:
        return

    event_items = []
    for event in sc.events:
        event_item = EventItemTO.fromEventItemObject(event)
        event_item.calendar_id = organization_type
        event_items.append(event_item)

    if event_items:
        new_events = serialize_complex_value(event_items, EventItemTO, True)
        gather_events_key = u"%s" % organization_type

        def trans():
            cap = CityAppProfile.get(cap_key)
            stream = cap.gather_events.get(gather_events_key)
            if stream:
                json_list = json.load(stream)
            else:
                json_list = list()
            json_list.extend(new_events)
            with closing(StringIO()) as stream:
                json.dump(json_list, stream)
                cap.gather_events[gather_events_key] = stream
            cap.put()

        db.run_in_transaction(trans)
        sln_settings.put_identity_pending = True
        sln_settings.put()
Beispiel #6
0
def debug():
    dump = []
    [dump.append(user_to_json(user)) for user in User.all()]
    [dump.append(ticket_to_json(ticket)) for ticket in Support_Ticket.all()]
    [dump.append(note_to_json(note)) for note in Note.all()]
    for user in User.all():
        logging.info(db.to_dict(user))
    for ticket in Support_Ticket.all():
        logging.info(db.to_dict(ticket))
    for note in Note.all():
        logging.info(db.to_dict(note))
    return Response(
            response=json.dumps(dump),
            mimetype="application/json")
Beispiel #7
0
    def get( self, country = None ):

        sitesQuery = SiteReport.all()
        sitesQuery.order( '-score' )

	# self.addJavaScript( '/scripts/flotr2/flotr2.min.js' )
	self.addJavaScript( '/scripts/Chart.min.js' )
	self.addJavaScript( '/scripts/stats.js' )
        
        sites = []
        i = 0
        for entity in sitesQuery.run():
            i += 1
            site = db.to_dict( entity, { 'position': i, 'lastReportUrl': uriFor( 'staticReport', domainUrl = entity.url ) } ) 
            sites.append( site )

	domainTlds = StatCounter.all().filter( 'category = ', 'domain_tld' ).filter('report_date =', None ).order( '-count' )
	htmlDocumentTypes = StatCounter.all().filter( 'category = ', 'html_document_type').filter('report_date =', None ).order( '-count' )

        values = {
		'pageTitle': 'SEO, WPO, security, social and domain website statistics - %(siteName)s' % { 'siteName': self.current_instance['name'] },
		'pageDescription': 'Discover what are the most successful websites in terms of their UX, SEO/SEM and WPO practices. Learn from their reports for free.',
		'sites': sites,
		'domainTlds': domainTlds,
		'htmlDocumentTypes': htmlDocumentTypes
        }
        
        html = self.renderTemplate( 'stats.html', values)

        self.writeResponse( html )
Beispiel #8
0
 def post(self,location):
   self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
   logging.info("doing word post")
   word_id = location.lstrip('/')
   if len(word_id) == 0:
     logging.error("no word id given, dont know which word to update")
     retval = dict(code="badinput", message="word id missing, cant update anything - Please add the id of the word to update to the url, like POST /word/17")
   elif not(word_id.isdigit()): #id is not numeric
     retval = dict(code="badinput", message="word id has to be numeric")
   else:
     logging.info("looking for word with id: " + word_id)
     found_word = model_word.WordModel.get_by_id(int(word_id))
     if (found_word):
       try:
         rawrequest = self.request.body
         payload = json.loads(rawrequest)
         logging.info("from_request: " + str(payload))
         #BETA avoid hardcoding word attributes - is there a way to get all declared attributes from a class?
         word_attributes = ["version","de","es","comment"] #difficulty and lastquiy can not be set by client
         for cur_attribute in word_attributes:
           if cur_attribute in payload:
             setattr(found_word,cur_attribute, payload[cur_attribute])
             logging.debug("word was changed to: " + json.dumps(db.to_dict(found_word)) )
             #found_word[cur_attribute] = payload[cur_attribute]
         found_word.put()
         retval = dict(code="ok", message="word with id " + word_id + " was updated")
       except (ValueError, TypeError) as payloaderror:
         logging.info(payloaderror)
         retval = dict(code="badinput", message="could not read input as json representation of a word, input was: " + rawrequest)
     else:
       retval = dict(code="notfound", message="No word found for id " + word_id)
   
   jsontext = json.dumps(retval)
   self.response.out.write(jsontext)
class JSONEncoder(json.JSONEncoder):
    def default(self, o):
        # If this is a key, you might want to grab the actual model.
        if isinstance(o, db.Key):
            o = db.get(o)

        if isinstance(o, Score):
            d = db.to_dict(o)
            # some json strings in the 'extra' field use the wrong
            # quote type (a bug on the client side). we fix that.
            d["extra"] = d['extra'].replace("'", '"')
            # then convert json encoded string field into a dict, if possible
            if d["extra"]:
                try:
                    d["extra"] = json.loads(d["extra"])
                except ValueError, e:
                    pass
            k = o.key()
            d["__key__"] = str(k)
            d["__id__"] = k.id()
            d["__name__"] = k.name()
            return d
        elif isinstance(o, db.Model):
            d = db.to_dict(o)
            k = o.key()
            d["__key__"] = str(k)
            d["__id__"] = k.id()
            d["__name__"] = k.name()
            return d
	def GET(self, loginMethod):
		web.header("Cache-Control", "no-store, no-cache, must-revalidate")

		if not web.ctx.session.has_key('loginprovider'): # we don't have a preferred provider stored
			if not loginMethod: # and we don't see one specified in the query
				return _to_provider_selection() # ask which login method to use
			else:
				web.ctx.session['loginprovider'] = loginMethod

		regform = dataform()

		auth_engine = _get_login_method()
		if auth_engine is None:
			return "Invalid login mechanism"

		user = auth_engine.get_current_user()
		logging.info("user is %s" % repr(user))
		if not user: # user is not logged in. forward to login page, with breadcrumb
			raise web.seeother( auth_engine.create_login_url(web.ctx.home + web.ctx.path), absolute=True)
		userrec = SPOTUser.get_by_key_name(user.user_id())
		if userrec is not None:
			from google.appengine.ext import db
			regform.fill( db.to_dict(userrec) )
			regform['userDispName'].attrs['readonly'] = "readonly"
			return _to_data_form(user, regform=regform, hasimage=userrec.key())

		return _to_data_form(user, regform=regform)
Beispiel #11
0
def update_client(request, client_id):
    client = models.ClientInfo.safe_get_by_id(int(client_id), request)
    # TODO: actually show an error message instead of just redirecting
    if not client:
        view_common.log_access_violation('update_client')
        return HttpResponseRedirect(reverse('show_client'))
    if request.method == 'POST':
        form = models.ClientForm(request.POST)
        if form.is_valid():
            client.update_model(form.cleaned_data)
            view_common.save_entity(request, client)
            return HttpResponseRedirect(client.get_absolute_url())
    else:
        client_dict = db.to_dict(client)
        for key in client_dict:
            value = client_dict[key]
            field = models.EncryptedField(value)
            try:
                client_dict[key] = field.make_value_from_datastore(value)
            except TypeError:
                pass
        form = models.ClientForm(initial=client_dict)
    render_to_response_dict = {
        "form": form,
        "submit_link": reverse(update_client, kwargs={'client_id': client_id}),
    }
    render_to_response_dict.update(get_common_client_form_fields(request,
                                                                 client))
    return render_to_response("add_client_template.html",
                              render_to_response_dict,
                              context_instance=RequestContext(request))
Beispiel #12
0
def edit_snippet(request, snippet_id=None):
    "Edits an existing code snippet"

    if snippet_id is None:
        raise Http404()

    template_name = "snippets/edit.html"

    if request.method == "POST":
        form = CodeSnippetForm(request.POST)
        if form.is_valid():
            snippet = get_snippet_or_404(snippet_id)
            snippet = copy_snippet_from_form(form, snippet=snippet)
            snippet.put()
            index_snippet_with_search(snippet)

            return HttpResponseRedirect(reverse("snippets:snippet-detail", kwargs={"snippet_id": snippet.key().id()}))
    else:
        initial_data = {}
        snippet = get_snippet_or_404(snippet_id)
        initial_data.update(db.to_dict(snippet))
        form = CodeSnippetForm(initial=initial_data, auto_id=False)

    ctx = {}
    ctx["form"] = form
    ctx["form_action"] = reverse("snippets:edit-snippet", kwargs={"snippet_id": snippet_id})

    return render_to_response(template_name, context_instance=RequestContext(request, ctx))
Beispiel #13
0
def datastore_map(entity_type):
  data = db.to_dict(entity_type)
  resultlist = [data.get('product_id'),
                timestamp_to_posix(data.get('date')),
                data.get('store')]
  result = ','.join(['"%s"' % field for field in resultlist])
  yield("%s\n" % result)
Beispiel #14
0
  def get(self):
    if self.request.get('secret') != appengine_config.USER_KEY_HANDLER_SECRET:
      raise exc.HTTPForbidden()

    user = User.get_or_create(self.request.get('uri'))
    self.response.headers['Content-Type'] = 'application/json'
    self.response.out.write(json.dumps(db.to_dict(user), indent=2))
Beispiel #15
0
	def get(self, slug):

		response = {}
		try:
			mp = MP.all().filter('slug =', slug)[0]
			response['mp'] = utils.mp_to_dict(mp)
		except:
			self.returnJSON(404, response)
			return

		self.query = MPVote.all().filter('mp_slug =', slug)
		self.filterQueryOnParam('question')
		self.filterQueryOnParam('selection')

		response['votes'] = []
		for vote in self.query:
			d = db.to_dict(vote)
			d['question'] = utils.question_to_dict(vote.parent())
			del d['mp_party']
			del d['mp_constituency']
			del d['mp_slug']
			del d['mp_name']
			response['votes'].append(d)
		response['total'] = len(response['votes'])

		self.returnJSON(200, response)
Beispiel #16
0
    def get(self, queue_name):
        queue_state = QueueState.get_by_key_name(queue_name)

        if not queue_state:
            self.response.set_status(404)
            return

        tasks = (TaskState.all().ancestor(queue_state).order("-deferred_at").
                 with_cursor(start_cursor=self.request.GET.get('cursor')))

        ctx = db.to_dict(queue_state)

        stats = queue_state.get_queue_statistics()
        ctx['stats'] = {
            k: getattr(stats, k)
            for k in (
                "tasks",
                "executed_last_minute",
                "in_flight",
                "enforced_rate",
            )
        }
        if stats.oldest_eta_usec:
            ctx['stats']['oldest_eta'] = datetime.datetime.utcfromtimestamp(
                stats.oldest_eta_usec / 1e6)

        ctx['tasks'] = map(db.to_dict,
                           tasks[:int(self.request.GET.get('limit', 1000))])
        ctx['cursor'] = tasks.cursor()

        self.response.content_type = "application/json"
        self.response.write(dump(ctx))
Beispiel #17
0
def print_all(request):




    logging.info("fetch qcards")
    qcard_list=QCard.list_my(request.auth_info.email)
    logging.info("fetch done")
    if qrg.qrg_cfg_get_on():
        logging.info("qrg is on")
        li = []
        for qc in qcard_list:
            li += [db.to_dict(qc)]
        rd = qrg.qrg_post("cards",li)
        pdfdata = base64.b64decode(rd["data"]) 
        r =  HttpResponse(pdfdata, mimetype='application/pdf')
        file_name = urllib.quote("karty.pdf")
        logging.info(file_name)
        r['Content-Disposition'] = "attachment; filename*=UTF-8''%s"%file_name

    else:
        logging.info("qrg is off")
        r =  HttpResponse(mimetype='application/pdf')
        file_name = urllib.quote("karty.pdf")
        logging.info(file_name)
        r['Content-Disposition'] = "attachment; filename*=UTF-8''%s"%file_name
        pdf.students_qcard(r,qcard_list)

    return r
Beispiel #18
0
    def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return obj.strftime(datetime_format)
        elif isinstance(obj, datetime.date):
            return obj.strftime(date_format)
        elif isinstance(obj, db.Key):
            return str(obj)
        elif isinstance(obj, db.Model):
            properties = obj.properties()

            #Resolve the object to a dictionary
            #(only works for explicitly defined properties)
            kvs = db.to_dict(obj)

            #Get implicitly defined references (this is such a bitch)
            for attr in dir(obj):
                if isinstance(getattr(obj, attr), db.Query):
                    kvs[attr] = list(getattr(obj, attr).run(keys_only=True))
            
            kvs.pop('password', None)
            kvs.pop('binary', None)

            for key in kvs:
                if key == 'dateofbirth':
                    kvs[key] = kvs[key].date()

            kvs['id'] = obj.key()
            return kvs
        else:
            try:
                return json.JSONEncoder.default(self, obj)
            except TypeError:
                return 'CANNOT_SERIALIZE'
Beispiel #19
0
    def get(self, slug):

        response = {}
        try:
            mp = MP.all().filter('slug =', slug)[0]
            response['mp'] = utils.mp_to_dict(mp)
        except:
            self.returnJSON(404, response)
            return

        self.query = MPVote.all().filter('mp_slug =', slug)
        self.filterQueryOnParam('question')
        self.filterQueryOnParam('selection')

        response['votes'] = []
        for vote in self.query:
            d = db.to_dict(vote)
            d['question'] = utils.question_to_dict(vote.parent())
            del d['mp_party']
            del d['mp_constituency']
            del d['mp_slug']
            del d['mp_name']
            response['votes'].append(d)
        response['total'] = len(response['votes'])

        self.returnJSON(200, response)
Beispiel #20
0
  def get(self):
    """Handles GET requests."""
    log_type = self.request.get('log_type')
    base_handler.VerifyPermissions(
        permissions.MASTER, base.GetCurrentUser(), log_type)

    start = self.request.get('start_next', None)
    log_model = models_util.TypeNameToLogModel(log_type)
    logs_query = log_model.all()
    logs_query.order('-paginate_mtime')
    if start:
      logs_query.filter('paginate_mtime <', start)

    logs = logs_query.fetch(PER_PAGE + 1)
    more = len(logs) == PER_PAGE + 1
    start_next = None
    if more:
      start_next = logs[-1].paginate_mtime

    logs = [db.to_dict(log) for log in logs[:PER_PAGE]]
    for log in logs:
      log['user'] = str(log['user'])
      log['mtime'] = str(log['mtime'])
    params = {
        'logs': logs,
        'log_type': log_type,
        'more': more,
        'start': start,
        'start_next': start_next,
    }

    self.response.out.write(util.ToSafeJson(params))
Beispiel #21
0
    def run(self):
        query = FormSubmission.all()
        query.filter('form_name IN', [
            'exit_survey_1', 'exit_survey_2', 'exit_survey_3',
            'exit_survey_features'
        ])
        query.order('user')

        for student, all_responses in itertools.groupby(
                query.run(), FormSubmission.user.get_value_for_datastore):
            # all_responses may contain more than one submission per form,
            # we need to choose the most recent one for each form.
            sorted_responses = sorted(list(all_responses),
                                      key=lambda x: x.submitted,
                                      reverse=True)

            row = {'student': student.name()}
            seen = set()

            for response in sorted_responses:
                if response.form_name not in seen:
                    row.update(db.to_dict(response))
                    seen.add(response.form_name)

            yield row
def datastore_map(entity_type):
  data = db.to_dict(entity_type)
  resultlist = [data.get('product_id'),
                timestamp_to_posix(data.get('date')),
                data.get('store')]
  result = ','.join(['"%s"' % field for field in resultlist])
  yield("%s\n" % result)
Beispiel #23
0
	def to_dict(self):
	    tempdict1 = dict([(p, unicode(getattr(self, p))) for p in self.properties()])
	    tempdict2 = {'key':unicode(self.key())}
	    tempdict3 = db.to_dict(self, {'id':self.key().id()})
	    tempdict2.update(tempdict3)
	    tempdict1.update(tempdict2)
	    return tempdict1
Beispiel #24
0
	def get(self, j=None):
		#logging.info("DEBUG: ====>" + "BlogPage.get(): json=<%s>" % j)
		#for e in entries:
		#	debug = db.to_dict(e)
		#	logging.info("DEBUG: ====>" + str(debug) + " ::: ")
		#logging.info("DEBUG: ====>" + "BlogPage.get()")
		key = "top"
		data = memcache.get(key)
		cache_age=0
		if data is None:
			logging.error("DB QUERY")
			entries = db.GqlQuery("SELECT * FROM BlogEntry ORDER BY created DESC LIMIT 10")
			memcache.set(key, (entries, datetime.datetime.now()))
		else:
			entries, saving_time = data[0], data[1]
			logging.error("used CACHE with key=" + key)
			diff = datetime.datetime.now() - saving_time
			cache_age = diff.seconds
		cache_age_message = "Queried %s seconds ago" % cache_age
		if not j:
			self.render_front("unit5_blog.html", entries=entries, cache_age_message=cache_age_message)
		else:
			r = []
			for e in entries:
				debug = db.to_dict(e)
				logging.info("DEBUG: ====>" + str(debug) + " ::: ")
				tmp = {}
				tmp["id"]      = e.key().id()
				tmp["content"] = debug["body"] 
				tmp["subject"] = debug["title"]
				tmp["created"]      = format_date_for_json(debug["created"])
				tmp["last_modified"] = format_date_for_json(debug["created"])
				r.append(tmp)
			self.render_json(json.dumps(r))
Beispiel #25
0
 def put(self,location):
   logging.info("read request" + self.request.body)
   requestbody = self.request.body
   if len(requestbody) == 0:
     logging.info("wordlist PUT: empty request body, cannot continue")
     self.response.status = 415
     self.response.status_message = self.word_wrong_input_message
   elif requestbody == "ping":
     new_word = model_word.WordModel(version=1, de='bla', es='bla')
     new_word.put()
     self.response.status = 200
   else:   
       try:
         from_request = json.loads(self.request.body)
         logging.info("from_request: " + str(from_request))
         new_word = model_word.WordModel(version=1, de='bla', es='bla')
         logging.info("new_word raw: " + str(new_word))
         new_word.de = from_request["de"]
         new_word.es = from_request["es"]
         if "comment" in from_request:
           new_word.comment = from_request["comment"]
         logging.info("new_word with data: " + str(new_word))
         new_word.put()
         logging.info("was put in db")
         word_dict = db.to_dict(new_word)
         jsontext = json.dumps(word_dict)
         logging.info("was serialized")
         self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
         self.response.out.write(jsontext)
       except (ValueError, TypeError) as error:
         logging.info(error)
         self.response.status = 415
         self.response.status_message = self.word_wrong_input_message
Beispiel #26
0
def dbo2json(dbo, skips=[]):
    # email is not write only because it needs to be retrieved by the user
    # for their completion certificate links.  For members, the admin
    # already has the email address when they added them so that's also ok.
    write_only_fields = ["password"]
    props = db.to_dict(dbo)
    for prop, val in props.iteritems():
        if prop in write_only_fields or prop in skips:
            props[prop] = ""  # leave key in dict so it is clear it was nuked
            continue
        # Associated images are fetched separately, not via JSON
        if (isinstance(val, Blob)):
            props[prop] = str(dbo.key().id())
        # JavaScript max integer value is smaller than database integer
        # value so return it as a string.  By convention all database fields
        # referencing other database instance ids end with "id".
        if (isinstance(val, (int, long)) and (prop.endswith("id"))):
            props[prop] = str(props[prop])
    jsontxt = json.dumps(props, True)
    # Include instance id as a field for reference in JavaScript
    instid = "1234567890"
    if dbo.is_saved():
        instid = str(dbo.key().id())
    jsontxt = "{\"instid\":\"" + instid + "\", " + jsontxt[1:]
    return jsontxt
Beispiel #27
0
	def createNewsEntry(self):
		entry = NewsEntry()
		entry.title = self.request.get('title')
		entry.content = self.request.get('content')
		entry.created = datetime.now()
		entry.put()
		self.res['content'] = db.to_dict(entry)
Beispiel #28
0
 def get(self):
     allInstances = model.StoredTranslations.all()
     instanceList = []
     for p in allInstances:
         instanceList.append(db.to_dict(p))
     jsonModel = json.dumps((instanceList))
     self.response.write(jsonModel)
Beispiel #29
0
	def spendSkillPoint(self):
		characterName = self.request.get('characterName')
		attr = self.request.get("attribute")
		# user = self.getUser()
		toon = Toon.get_by_key_name(key_names=characterName)
		if toon:
			if toon.skillpoints > 0:
				if attr == 'strength':
					toon.strength += 1
				elif attr == 'intelligence':
					toon.intelligence += 1
				elif attr == 'defense':
					toon.defense += 1
				elif attr == 'endurance':
					toon.endurance += 1
				toon.skillpoints -=1
				toon.put()

				self.res['content'] = db.to_dict(toon)
				self.res['skillpoints'] = toon.skillpoints
			else:
				self.res['success'] = False
				self.res['error'] = 'not enough skill points'

		else:
			self.res['success'] = False
			self.res['error'] = 'no toon with that name'
 def GetListDict(self, objectinstance):
     dct = {}
     List = self.GetList(objectinstance)
     newlist = []
     for ls in List:
         newlist.append(db.to_dict(ls))
     return newlist
Beispiel #31
0
    def get(self):
        if self.request.get(
                'secret') != appengine_config.USER_KEY_HANDLER_SECRET:
            raise exc.HTTPForbidden()

        user = User.get_or_create(self.request.get('uri'))
        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps(db.to_dict(user), indent=2))
Beispiel #32
0
def user_to_dict(user):
    u = db.to_dict(user)
    if isinstance(user.birth_date, datetime.date):
        u['birth_date'] = user.birth_date.isoformat()
    u['details'] = '/users/%s' % user.username
    del u['constituency_score']
    del u['mp_score']
    return u
Beispiel #33
0
def get_player(player_id):
    player = Player.get_by_id(player_id)
    game_players = GamePlayer.all().filter('player =', player)
    games = [game_player.game for game_player in game_players]
    info = {}
    for game in games:
        info[str(game.key().id())] = to_dict(game)
    return jsonify(**info)
Beispiel #34
0
 def get(self):
     q = db.Query(Task, projection=('data_id', 'task_name'))
     db_data = q.order('-addTime').fetch(50)
     data = []
     for f in db_data:
         data.append(db.to_dict(f))
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(json.dumps(data))
Beispiel #35
0
    def to_dict(self):
        cst = pytz.timezone('US/Central')

        result = to_dict(self)
        result['id'] = self.key().id()
        result['timestamp'] = self.created.replace(tzinfo=pytz.utc).astimezone(cst)
        result['created'] = self.created.strftime("%Y-%m-%dT%H:%M:%S")
        return result
Beispiel #36
0
def create_prospect_from_customer(customer):
    azzert(customer.prospect_id is None and customer.service_email)

    contact = Contact.get_one(customer.key())
    azzert(contact)

    si = get_default_service_identity(users.User(customer.service_email))

    prospect = Prospect(key_name=str(uuid.uuid4()) + str(uuid.uuid4()))
    prospect.name = customer.name
    prospect.address = ', '.join(filter(None, [customer.address1 + ((' ' + customer.address2) if customer.address2 else ''),
                                               customer.zip_code,
                                               customer.city,
                                               OFFICIALLY_SUPPORTED_COUNTRIES.get(customer.country, customer.country)]))
    prospect.phone = contact.phone_number
    prospect.email = contact.email
    prospect.type = ['establishment']
    if customer.organization_type == OrganizationType.EMERGENCY:
        prospect.type.append('health')
    prospect.customer_id = customer.id
    prospect.status = Prospect.STATUS_CUSTOMER
    prospect.app_id = si.app_id
    
    solution_server_settings = get_solution_server_settings()
    prospect.add_comment(u'Converted customer to prospect', users.User(solution_server_settings.shop_no_reply_email)) 
    try:
        result = geo_code(prospect.address)
    except GeoCodeZeroResultsException:
        try:
            result = geo_code(' '.join(filter(None, [customer.zip_code,
                                                     customer.city,
                                                     OFFICIALLY_SUPPORTED_COUNTRIES.get(customer.country,
                                                                                        customer.country)])))
        except GeoCodeZeroResultsException:
            logging.warn('Could not geo_code customer: %s', db.to_dict(customer))
            return

    prospect.geo_point = db.GeoPt(result['geometry']['location']['lat'],
                                  result['geometry']['location']['lng'])

    customer.prospect_id = prospect.id
    prospect.customer_id = customer.id

    logging.info('Creating prospect: %s', db.to_dict(prospect, dict(prospect_id=prospect.id)))
    put_and_invalidate_cache(customer, prospect)
    return prospect
Beispiel #37
0
def user_to_dict(user):
	u = db.to_dict(user)
	if isinstance(user.birth_date, datetime.date):
		u['birth_date'] = user.birth_date.isoformat()
	u['details'] = '/users/%s' % user.username
	del u['constituency_score']
	del u['mp_score']
	return u
Beispiel #38
0
	def login(self):
		id = self.request.get('id')
		user = User.get_by_key_name(key_names=id)
		if not user:
			user = User(key_name=id,id=id)
			user.put()
		self.res['user'] = db.to_dict(user)
		self.__getCharacters(user)
    def test_get_custom_prop(self):
        class MyModel(CompressedIntegerListExpando):
            _attribute_prefix = 'test'

        m = MyModel.get_by_key_name('test')
        self.assertListEqual(TestCase.l, m.test)

        dict_repr = db.to_dict(m)
        self.assertTrue(isinstance(dict_repr['test'], basestring))
    def test_filters(self):
        data1, data2, data3 = self.dataSet[:3]

        query = KeyRange().make_ascending_query(
            self.TestEntity,
            filters=[("name", "=", data1["name"])])
        got = list(query)
        self.assertEqual(1, len(got))
        self.assertDictEqual(data1, db.to_dict(got.pop()))

        query = KeyRange().make_query(
            self.TestEntity,
            filters=[("name", "IN", [data1["name"], data2["name"]])],
            order=['name'])
        got = list(query)
        self.assertEqual(2, len(got))
        self.assertDictEqual(data1, db.to_dict(got.pop(0)))
        self.assertDictEqual(data2, db.to_dict(got.pop(0)))
def get_error_details(error_key):
    e = MobicageError.get(error_key)
    s = StringIO()
    for prop_name, prop_value in sorted(db.to_dict(e).iteritems()):
        s.write(prop_name)
        s.write(": ")
        s.write(prop_value if isinstance(prop_value, basestring) else str(prop_value))
        s.write("\n\n")
    return s.getvalue()
Beispiel #42
0
    def default(self, o):
        # If this is a key, you might want to grab the actual model.
        if isinstance(o, db.Key):
            o = db.get(o)

        if isinstance(o, db.Model):
            return db.to_dict(o)
        elif isinstance(o, (datetime, date, time)):
            return str(o)  # Or whatever other date format you're OK with...
	def getSerializeable(self):
		outdict = db.to_dict(self)
		outdict['latitude'] = outdict['location'].lat
		outdict['longitude'] = outdict['location'].lon
		del outdict['location']
		outdict['spotuser'] = str(outdict['spotuser'])
		outdict['timestamp'] = outdict['timestamp'].strftime("%Y-%m-%dT%H:%M:%S")
		outdict['key'] = str(self.key()) # to_dict doesn't actually include this because it's not a property
		return outdict
Beispiel #44
0
 def to_dict_full(self):
     d = db.to_dict(self)
     d["basic_info"] = self.basic_info.to_dict()
     d["id_upload"] = self.id_upload.to_dict()
     d["pep_check"] = self.pep_check.to_dict()   
     d["domicile_info"] = self.domicile_info.to_dict()
     d["financial_info"] = self.financial_info.to_dict()
     d["bitcoin_info"] = self.bitcoin_info.to_dict()
     return d
Beispiel #45
0
def model_to_dict(model):
    d = db.to_dict(model)
    if 'pdf' in d:
        del d['pdf']
    for k, v in d.iteritems():
        if isinstance(v, users.User):
            d[k] = v.email()
    d['_key'] = str(model.key())
    return d
Beispiel #46
0
    def to_dict(self):
        ''' Creates serializable dictionary object from the message
        Returns: Serializable dictionary object
        '''

        d = db.to_dict(self)
        d['id'] = str(self.key().id())
        d['created_at'] = str(d['created_at'])  # dates aren't serializable
        del d['conversation']  # remove as it f's up serialization
        return d
Beispiel #47
0
    def get(self):
        response = {'constituencies': []}

        for const in Constituency.all():
            c = db.to_dict(const)
            c['details'] = '/constituencies/%s' % const.slug

            response['constituencies'].append(c)

        self.returnJSON(200, response)
Beispiel #48
0
    def run(self):
        for s in Student.all().run(limit=9999):
            d = db.to_dict(s)
            d['email'] = s.key().name()
            if d.get('is_participant', False):
                d['can_use_location'] = find_can_use_location(s)

            for p in d.keys():
                if type(d[p]) is list:
                    d[p] = u", ".join(d[p])
            yield d
Beispiel #49
0
    def get(self, slug):

        response = {}

        try:
            response['constituency'] = db.to_dict(Constituency.all().filter(
                'slug =', slug)[0])
        except:
            response['error'] = 'Cannot find constituency'
            self.returnJSON(404, response)

        self.returnJSON(200, response)
Beispiel #50
0
    def get(self, slug):

        response = {}

        try:
            response['mp'] = db.to_dict(MP.all().filter('slug =', slug)[0])
            response['mp']['vote_details'] = '/mps/%s/votes' % slug
        except:
            response['error'] = 'Cannot find mp'
            self.returnJSON(404, response)

        self.returnJSON(200, response)
Beispiel #51
0
    def default(self, obj):
        """Converts an object to a JSON-compatible type."""

        # Pack entities as JSON Objects.
        if isinstance(obj, db.Model):
            record, klass = db.to_dict(obj), obj.__class__
            record["__ent__"] = (klass.__module__, klass.__name__)
            if obj.is_saved():
                record["key_name"] = obj.key().name()
            return record

        return obj
Beispiel #52
0
def bank_steel_daily_transaction_data(request):
    """
       返回json数据
    """
    all_data = TransData.all().order('trans_date').fetch(9999)
    result = {}
    items = []
    for t in all_data:
        items.append(db.to_dict(t))
    result['list'] = items

    return HttpResponse(json.dumps(result, default=my_converter),
                        content_type="application/json")
    def test_with_query_filters(self):
        SHARD_COUNT = 10
        mapper_spec = model.MapperSpec(
            "FooHandler",
            "mapreduce_utils.DatastoreQueryInputReader",
            {
                "input_reader": {
                    "entity_kind": self.TEST_ENTITY_IMPORT_PATH,
                    "filters": [("type", "=", "C")],
                }
            },
            SHARD_COUNT)

        ds_input_readers = DatastoreQueryInputReader.split_input(mapper_spec)
        got = reduce(operator.add,
            (list(reader) for reader in ds_input_readers))
        self.assertEqual(3, len(got))
        data1, data2, data3 = filter(lambda i: i['type'] == "C", self.dataSet)
        got.sort(key=lambda i: i.name)
        self.assertDictEqual(data1, db.to_dict(got.pop(0)))
        self.assertDictEqual(data2, db.to_dict(got.pop(0)))
        self.assertDictEqual(data3, db.to_dict(got.pop(0)))
Beispiel #54
0
    def get_sites_by_user_reviews(self):
        sites = []

        site_ratings = SiteRating.all()
        site_ratings.order('-rating_overall')

        for result in site_ratings.run(limit=20):
            site = db.to_dict(result, {
                'lastReportUrl':
                uriFor('staticReport', domainUrl=result.domain)
            })
            sites.append(site)

        return sites
Beispiel #55
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        #self.response.out.write(json.dumps(rssloader.rssdata))

        week_date = '2012-06-16'

        # read
        songs = Song.gql("WHERE ANCESTOR IS :1 "
                         "ORDER BY rank DESC LIMIT 10", week_key(week_date))
        res = {}
        res[week_date] = [db.to_dict(song) for song in songs]
        #res[week_date] = [dictify.to_dict(song) for song in songs]

        self.response.out.write(json.dumps(res, default=dthandler))