Exemplo n.º 1
0
 def get_queryset(self, request=None):
     user = get_current_user()
     if user and user.is_authenticated:
         return super().get_queryset().filter(
             user__profile__owner=user.profile.owner, )
     else:
         return None
Exemplo n.º 2
0
	def post(self):
		user		= utils.get_current_user()
		name		= self.request.get('name', '')
		unix_name	= utils.unix_string(name)
		profile		= Profile.get(self.request.get('profile_key'))
		world		= stores.World.get_by_key_name('w:%s' % unix_name)

		if not name or not profile or not world:
			self.flash.msg = "Unknown World: %s" % name
			self.redirect(self.request.headers['REFERER'])
			return

		page_admin = utils.page_admin(profile.author.user)
		if not page_admin or not world.user_can_post(self.udata):
			self.flash.msg = "Access Denied"
			self.redirect(profile.url)
			return

		connections = profile.worldconnection_set.fetch(6)
		if len(connections) >= 6:
			self.flash.msg = "Profile: %s in too many worlds (Max = 5)" % profile.name
			self.redirect(profile.url)
			return

		if not self.add_profile(world, profile):
			self.flash.msg = "Profile: %s already in World: %s" % (profile.name, world.name)
		else:
			self.flash.msg = "Profile: %s joined World: %s" % (profile.name, world.name)

		self.redirect(profile.url)
Exemplo n.º 3
0
	def get(self):
		user = utils.get_current_user()
		sort = self.request.get('sort', 'time')
		page = self.request.get_range('page', min_value=1, default=1)
		items_per_page = self.request.get_range('items', min_value=1,
												max_value=25, default=10)
		offset = ((page - 1) * items_per_page)
		last_page = True

		link_template = '<a href="%s">%s</a>'
		sort_links = []
		sort_links.append(link_template % (self.filter_args(['sort', 'page'], sort='time'), 'Time'))
		sort_links.append(link_template % (self.filter_args(['sort', 'page'], sort='words'), 'Word Count'))
		for letter in string.ascii_uppercase:
			sort_links.append(link_template % (self.filter_args(['sort', 'page'], sort=letter.lower()), letter))

		profiles = []
		query = Profile.all()
		query.filter('public =', True)
		if sort == 'time':
			query.order('-created')
		elif sort == 'words':
			query.order('-word_count')
		else:
			query.filter('unix_name >', sort)
			query.filter('unix_name <', sort+u"\ufffd")

		profiles = query.fetch((items_per_page + 1), offset)
		if len(profiles) > items_per_page:
			last_page = False
			profiles.pop()

		self.render(['discover', 'discoverprofile'], locals())
Exemplo n.º 4
0
	def get(self):
		user = utils.get_current_user()
		sort = self.request.get('sort', 'Time')
		page = self.request.get_range('page', min_value=1, default=1)
		items_per_page = self.request.get_range('items', min_value=1,
												max_value=25, default=10)
		offset = ((page - 1) * items_per_page)
		last_page = True

		link_template = '<a href="%s">%s</a>'
		sort_links = [link_template % (self.filter_args(['sort', 'page'], sort='Time'), 'Time')]
		for letter in string.ascii_uppercase:
			sort_links.append(link_template % (self.filter_args(['sort', 'page'], sort=letter), letter))

		world_list = []
		query = World.all()
		query.filter('public =', True)
		if sort == 'Time':
			query.order('-created')
		else:
			query.filter('name >', sort)
			query.filter('name <', sort+'\x77\x78\x79')

		world_list = query.fetch((items_per_page + 1), offset)
		if len(world_list) > items_per_page:
			last_page = False
			world_list.pop()

		self.render(['discover', 'discoverworld'], locals())
Exemplo n.º 5
0
    def save(self, *args, **kwargs) -> None:
        current_user = get_current_user()
        if current_user and current_user.is_authenticated:
            if self.pk:
                self.modified_by = current_user
            else:
                self.user = current_user

        super(CommonModel, self).save(*args, **kwargs)
Exemplo n.º 6
0
	def get(self):
		user		= utils.get_current_user()
		udata		= UserData.load(user)

		context = {
			'udata': udata,
		}

		self.render(['custom', 'customcfscript'], context)
Exemplo n.º 7
0
	def post(self):
		user		= utils.get_current_user()
		udata		= UserData.load(user)
		action		= self.request.get('action', 'Cancel')
		custom_theme = self.request.get('custom_css', '')

		msg = "Changes to theme discarded"
		if action == 'Save':
			udata.custom_css = custom_theme
			udata.put()
			msg = "Theme Saved"

		self.flash.msg = msg
		self.redirect('/manage/')
Exemplo n.º 8
0
	def get(self, output='rss'):
		user 		= utils.get_current_user()
		get 		= self.request.get
		refresh_cache = get('refresh_cache', False) is not False
		sterile_url	= framework.sterilize_url(self.url)

		@framework.memoize(sterile_url, 'world_feed', refresh=refresh_cache)
		def __fetch_feed_data():
			# Orders the profiles most recently created first.
			q = World.all()
			q.filter('public =', True)
			q.order('-created')

			return q.fetch(12)

		self.context['world_data'] = {'worlds': __fetch_feed_data()}

		self.render(['feed', 'latestworlds'], output=output)
		return
Exemplo n.º 9
0
 def save(self,
          commit=True,
          _ignore_log=None,
          _current_user=None,
          _reason=None,
          _force_default=None):
     """
     Surcharge de la méthode de sauvegarde pour passer les paramètres spécifiques aux entités
     :param _ignore_log: Ignorer l'historique de modification ?
     :param _current_user: Utilisateur à l'origine de la modification
     :param _reason: Raison de la modification
     :param _force_default: Force la sauvegarde en place ?
     """
     self._ignore_log = _ignore_log or self._ignore_log
     self._current_user = _current_user or self._current_user or get_current_user(
     )
     self._reason = _reason or self._reason
     self._force_default = _force_default or self._force_default
     for form in self.forms:
         instance = form.instance
         instance._from_admin = self._from_admin
         instance._ignore_log = self._ignore_log
         instance._current_user = self._current_user
         instance._reason = self._reason
         instance._force_default = self._force_default or self._from_admin
         if hasattr(self, 'fk'):
             pk_value = getattr(self.instance,
                                self.fk.remote_field.field_name)
             setattr(instance, self.fk.get_attname(),
                     getattr(pk_value, 'pk', pk_value))
     instance = super().save(commit=commit)
     for inline in self.inlines:
         inline.instance = instance
         inline.save(commit=commit,
                     _ignore_log=self._ignore_log,
                     _current_user=self._current_user,
                     _reason=self._reason,
                     _force_default=self._force_default)
     return instance
Exemplo n.º 10
0
    def post(self):
        """Create a new comment and related messages.
		All type functions should return an unput comment."""
        get = self.request.get
        markup = get("markup", "Textile")
        type = get("type").lower()
        host = get("host")

        func_name = "_type_%s" % type
        if hasattr(self, func_name):
            # Build the comment base with common properties.
            comment = stores.Comment(markup=markup)
            # Pass the comment and the host data for final processing
            getattr(self, func_name)(comment, host)
            # Delete a previous cache entry
            logging.info("REFERER: " + self.request.headers["REFERER"])
            framework.unmemoize(self.request.headers["REFERER"], "comment_listing")
        else:
            logging.error(
                "User (%s) attempted to create an unknown type of comment (%s)" % (utils.get_current_user(), type)
            )

        self.redirect(self.request.headers["REFERER"])
Exemplo n.º 11
0
	def post(self):
		from	google.appengine.ext.webapp	import template

		user		= utils.get_current_user()
		udata		= UserData.load(user)
		action		= self.request.get('action', 'Cancel')
		cf_script = self.request.get('cf_script', '')

		if action == "Preview":
			context = {
				'cf_script': cf_script
			}

			t = template.Template("""<html>
<head>
<title>ContextFree Script Preview</title>
<script src="/js/jquery.js" type="text/javascript"></script>
<script src="/js/contextfree.js" type="text/javascript"></script>
<script src="/js/dynamicbg.js" type="text/javascript"></script>
</head>
<body>
<div id="cf_script" style="display:none;" />{{ cf_script }}</div>
<script>display();</script>
</body>
</html>""")
			self.response.out.write(t.render(context))
			return

		msg = "Changes to ContextFree Script discarded"
		if action == 'Save':
			udata.custom_cf_script = cf_script
			udata.put()
			msg = "ContextFree Script Saved"

		self.flash.msg = msg
		self.redirect('/manage/')
Exemplo n.º 12
0
def SET_OWNER(collector, field, sub_objs, using):
    if field.user == get_current_user():
        return models.CASCADE(collector, field, sub_objs, using)
    else:
        collector.add_field_update(field, field.get_owner(), sub_objs)