예제 #1
0
def set_screenshot(img: Image = None):
    # Make the visible screenshot small
    global tk_screenshot
    if img is None:
        try:
            img = Image.open(SCREENSHOT_LOC)
        except IOError:  # Image doesn't exist!
            # In that case, use a black image
            img = Image.new('RGB', (1, 1), color=(0, 0, 0))
    # Make a smaller image for showing in the UI..
    tk_img = img.resize((
        int(PETI_WIDTH // 3.5),
        int(PETI_HEIGHT // 3.5),
    ), Image.LANCZOS)
    tk_screenshot = ImageTk.PhotoImage(tk_img)
    UI['thumb_label']['image'] = tk_screenshot
예제 #2
0
파일: UserEdit.py 프로젝트: kamalhg/vikuit
	def execute(self):
		method = self.request.method
		user = self.values['user']

		if method == 'GET':
			self.values['google_adsense'] = self.not_none(user.google_adsense)
			self.values['google_adsense_channel'] = self.not_none(user.google_adsense_channel)
			self.values['real_name'] = self.not_none(user.real_name)
			self.values['links'] = [(link.split('##', 2)[1], link.split('##', 2)[0]) for link in user.list_urls]
			self.values['im_addresses'] =  [(link.split('##', 2)[1], link.split('##', 2)[0]) for link in user.im_addresses]
			self.values['country'] = self.not_none(user.country)
			self.values['city'] = self.not_none(user.city)
			self.values['about'] = self.not_none(user.about_user)
			self.values['personal_message'] = self.not_none(user.personal_message);
			if user.not_full_rss:
				self.values['not_full_rss'] = user.not_full_rss
			self.render('templates/module/user/user-edit.html')
		elif self.auth():
			user.google_adsense = self.get_param('google_adsense')
			user.google_adsense_channel = self.get_param('google_adsense_channel')
			user.real_name = self.get_param('real_name')
			user.personal_message = self.get_param('personal_message')
			user.country = self.get_param('country')
			if self.get_param('not_full_rss'):
				user.not_full_rss = True
			else:
				user.not_full_rss = False
			image = self.request.get("img")
			if image:
				image = images.im_feeling_lucky(image, images.JPEG)
				user.avatar = img.resize(image, 128, 128)
				user.thumbnail = img.resize(image, 48, 48)
				if not user.image_version:
					user.image_version = 1
				else:
					memcache.delete('/images/user/avatar/%s/%d' % (user.nickname, user.image_version))
					memcache.delete('/images/user/thumbnail/%s/%d' % (user.nickname, user.image_version))
					user.image_version += 1
				memcache.delete('/images/user/avatar/%s' % (user.nickname))
				memcache.delete('/images/user/thumbnail/%s' % (user.nickname))
			user.city = self.get_param('city')
			user.list_urls = []
			blog = self.get_param('blog')
			if blog:
				if not blog.startswith('http'):
					linkedin = 'http://' + blog
				user.list_urls.append(blog + '##blog')
				
			linkedin = self.get_param('linkedin')
			if linkedin:
				if not linkedin.startswith('http'):
					linkedin = 'http://' + linkedin
				user.list_urls.append(linkedin + '##linkedin')
				
			ohloh = self.get_param('ohloh')
			if ohloh:
				if not ohloh.startswith('http'):
					linkedin = 'http://' + ohloh
				user.list_urls.append(ohloh + '##ohloh')
				
			user.im_addresses = []
			msn = self.get_param('msn')
			if msn:
				user.im_addresses.append(msn + '##msn')
				
			jabber = self.get_param('jabber')
			if jabber:
				user.im_addresses.append(jabber + '##jabber')
				
			gtalk = self.get_param('gtalk')
			if gtalk:
				user.im_addresses.append(gtalk + '##gtalk')
				
			user.about_user = self.get_param('about_user')
			user.put()
			
			followers = list(self.get_followers(user=user))
			followers.append(user.nickname)
			self.create_event(event_type='user.edit', followers=followers, user=user)
			
			self.redirect('/module/user/%s' % user.nickname)
예제 #3
0
    def execute(self):
        method = self.request.method
        user = self.values['user']

        if method == 'GET':
            self.values['google_adsense'] = self.not_none(user.google_adsense)
            self.values['google_adsense_channel'] = self.not_none(
                user.google_adsense_channel)
            self.values['real_name'] = self.not_none(user.real_name)
            self.values['links'] = [(link.split('##',
                                                2)[1], link.split('##', 2)[0])
                                    for link in user.list_urls]
            self.values['im_addresses'] = [(link.split('##', 2)[1],
                                            link.split('##', 2)[0])
                                           for link in user.im_addresses]
            self.values['country'] = self.not_none(user.country)
            self.values['city'] = self.not_none(user.city)
            self.values['about'] = self.not_none(user.about_user)
            self.values['personal_message'] = self.not_none(
                user.personal_message)
            if user.not_full_rss:
                self.values['not_full_rss'] = user.not_full_rss
            self.render('templates/module/user/user-edit.html')
        elif self.auth():
            user.google_adsense = self.get_param('google_adsense')
            user.google_adsense_channel = self.get_param(
                'google_adsense_channel')
            user.real_name = self.get_param('real_name')
            user.personal_message = self.get_param('personal_message')
            user.country = self.get_param('country')
            if self.get_param('not_full_rss'):
                user.not_full_rss = True
            else:
                user.not_full_rss = False
            image = self.request.get("img")
            if image:
                image = images.im_feeling_lucky(image, images.JPEG)
                user.avatar = img.resize(image, 128, 128)
                user.thumbnail = img.resize(image, 48, 48)
                if not user.image_version:
                    user.image_version = 1
                else:
                    memcache.delete('/images/user/avatar/%s/%d' %
                                    (user.nickname, user.image_version))
                    memcache.delete('/images/user/thumbnail/%s/%d' %
                                    (user.nickname, user.image_version))
                    user.image_version += 1
                memcache.delete('/images/user/avatar/%s' % (user.nickname))
                memcache.delete('/images/user/thumbnail/%s' % (user.nickname))
            user.city = self.get_param('city')
            user.list_urls = []
            blog = self.get_param('blog')
            if blog:
                if not blog.startswith('http'):
                    linkedin = 'http://' + blog
                user.list_urls.append(blog + '##blog')

            linkedin = self.get_param('linkedin')
            if linkedin:
                if not linkedin.startswith('http'):
                    linkedin = 'http://' + linkedin
                user.list_urls.append(linkedin + '##linkedin')

            ohloh = self.get_param('ohloh')
            if ohloh:
                if not ohloh.startswith('http'):
                    linkedin = 'http://' + ohloh
                user.list_urls.append(ohloh + '##ohloh')

            user.im_addresses = []
            msn = self.get_param('msn')
            if msn:
                user.im_addresses.append(msn + '##msn')

            jabber = self.get_param('jabber')
            if jabber:
                user.im_addresses.append(jabber + '##jabber')

            gtalk = self.get_param('gtalk')
            if gtalk:
                user.im_addresses.append(gtalk + '##gtalk')

            user.about_user = self.get_param('about_user')
            user.put()

            followers = list(self.get_followers(user=user))
            followers.append(user.nickname)
            self.create_event(event_type='user.edit',
                              followers=followers,
                              user=user)

            self.redirect('/module/user/%s' % user.nickname)
예제 #4
0
	def execute(self):
		self.values['tab'] = '/group.list'
		method = self.request.method
		user = self.values['user']
		key = self.get_param('key')

		if method == 'GET':
			if key:
				# show edit form
				group = model.Group.get(key)
				if user.nickname != group.owner.nickname and user.rol != 'admin':
					self.forbidden()
					return
				self.values['key'] = key

				self.values['title'] = group.title
				self.values['description'] = group.description
				if group.all_users is not None:
					self.values['all_users'] = group.all_users
				else:
					self.values['all_users'] = True
				if group.category:
					self.values['category'] = group.category
				self.add_categories()
				self.render('templates/group-edit.html')
			else:
				# show an empty form
				self.values['title'] = 'Grupo...'
				self.values['all_users'] = True
				self.add_categories()
				self.render('templates/group-edit.html')
		elif self.auth():
			if key:
				# update group
				group = model.Group.get(key)
				if user.nickname != group.owner.nickname and user.rol != 'admin':
					self.forbidden()
					return
				# group title is not editable since many-to-many relationships are denormalizated
				# group.title = self.get_param('title')
				group.description = self.get_param('description')
				image = self.request.get("img")
				if image:
					image = images.im_feeling_lucky(image, images.JPEG)
					group.avatar = img.resize(image, 128, 128)
					group.thumbnail = img.resize(image, 48, 48)
					if not group.image_version:
						group.image_version = 1
					else:
						memcache.delete('/images/group/avatar/%s/%d' % (group.key().id(), group.image_version))
						memcache.delete('/images/group/thumbnail/%s/%d' % (group.key().id(), group.image_version))
						group.image_version += 1
					memcache.delete('/images/group/avatar/%s' % group.key().id())
					memcache.delete('/images/group/thumbnail/%s' % group.key().id())
				if self.get_param('all_users'):
					group.all_users = True
				else:
					group.all_users = False
				category = model.Category.get(self.request.get('category'))
				prev_category = group.category
				group.category = category
				group.put()
				
				if prev_category:
					prev_category.groups -= 1
					prev_category.put()
				
				category.groups += 1
				category.put()
				
				memcache.delete('index_groups')
				self.redirect('/group/%s' % (group.url_path, ))
			else:
				# new group
				title = self.get_param('title')
				url_path = '-'
				all_users = False
				if self.get_param('all_users'):
					all_users = True
				group = model.Group(owner=user,
					owner_nickname=user.nickname,
					title=title,
					description=self.get_param('description'),
					url_path=url_path,
					members=1,
					all_users = all_users,
					items=0,
					threads=0,
					responses=0,
					subscribers=[user.email],
					activity=1)
				category = model.Category.get(self.request.get('category'))
				group.category = category
				image = self.request.get("img")
				if image:
					image = images.im_feeling_lucky(image, images.JPEG)
					group.avatar = img.resize(image, 128, 128)
					group.thumbnail = img.resize(image, 48, 48)
					group.image_version = 1
				
				group.put()
				self.add_user_subscription(user, 'group', group.key().id())
				group.url_path = '%d/%s' % (group.key().id(), self.to_url_path(group.title))
				group.put()
				
				category.groups += 1
				category.put()
				
				user.groups += 1
				user.put()
				
				app = model.Application.all().get()
				if app:
					app.groups += 1
					app.put()
				memcache.delete('app')
				
				group_user = model.GroupUser(user=user,
					group=group,
					user_nickname=user.nickname,
					group_title=group.title,
					group_url_path=group.url_path)
				group_user.put()
				memcache.delete('index_groups')
				
				followers = list(self.get_followers(user=user))
				followers.append(user.nickname)
				self.create_event(event_type='group.new', followers=followers, user=user, group=group)
				
				self.add_follower(group=group, nickname=user.nickname)
				
				# TODO: update a user counter to know how many groups is owner of?
				

				self.redirect('/group/%s' % (group.url_path, ))
예제 #5
0
    def execute(self):
        method = self.request.method
        user = self.values["user"]

        if method == "GET":
            self.values["google_adsense"] = self.not_none(user.google_adsense)
            self.values["google_adsense_channel"] = self.not_none(user.google_adsense_channel)
            self.values["real_name"] = self.not_none(user.real_name)
            self.values["links"] = [(link.split("##", 2)[1], link.split("##", 2)[0]) for link in user.list_urls]
            self.values["im_addresses"] = [
                (link.split("##", 2)[1], link.split("##", 2)[0]) for link in user.im_addresses
            ]
            self.values["country"] = self.not_none(user.country)
            self.values["city"] = self.not_none(user.city)
            self.values["about"] = self.not_none(user.about_user)
            self.values["personal_message"] = self.not_none(user.personal_message)
            if user.not_full_rss:
                self.values["not_full_rss"] = user.not_full_rss
            self.render("templates/user-edit.html")
        elif self.auth():
            user.google_adsense = self.get_param("google_adsense")
            user.google_adsense_channel = self.get_param("google_adsense_channel")
            user.real_name = self.get_param("real_name")
            user.personal_message = self.get_param("personal_message")
            user.country = self.get_param("country")
            if self.get_param("not_full_rss"):
                user.not_full_rss = True
            else:
                user.not_full_rss = False
            image = self.request.get("img")
            if image:
                image = images.im_feeling_lucky(image, images.JPEG)
                user.avatar = img.resize(image, 128, 128)
                user.thumbnail = img.resize(image, 48, 48)
                if not user.image_version:
                    user.image_version = 1
                else:
                    memcache.delete("/images/user/avatar/%s/%d" % (user.nickname, user.image_version))
                    memcache.delete("/images/user/thumbnail/%s/%d" % (user.nickname, user.image_version))
                    user.image_version += 1
                memcache.delete("/images/user/avatar/%s" % (user.nickname))
                memcache.delete("/images/user/thumbnail/%s" % (user.nickname))
            user.city = self.get_param("city")
            user.list_urls = []
            blog = self.get_param("blog")
            if blog:
                if not blog.startswith("http"):
                    linkedin = "http://" + blog
                user.list_urls.append(blog + "##blog")

            linkedin = self.get_param("linkedin")
            if linkedin:
                if not linkedin.startswith("http"):
                    linkedin = "http://" + linkedin
                user.list_urls.append(linkedin + "##linkedin")

            ohloh = self.get_param("ohloh")
            if ohloh:
                if not ohloh.startswith("http"):
                    linkedin = "http://" + ohloh
                user.list_urls.append(ohloh + "##ohloh")

            user.im_addresses = []
            msn = self.get_param("msn")
            if msn:
                user.im_addresses.append(msn + "##msn")

            jabber = self.get_param("jabber")
            if jabber:
                user.im_addresses.append(jabber + "##jabber")

            gtalk = self.get_param("gtalk")
            if gtalk:
                user.im_addresses.append(gtalk + "##gtalk")

            user.about_user = self.get_param("about_user")
            user.put()

            followers = list(self.get_followers(user=user))
            followers.append(user.nickname)
            self.create_event(event_type="user.edit", followers=followers, user=user)

            self.redirect("/user/%s" % user.nickname)
예제 #6
0
    def execute(self):
        self.values['tab'] = '/group.list'
        method = self.request.method
        user = self.values['user']
        key = self.get_param('key')

        if method == 'GET':
            if key:
                # show edit form
                group = model.Group.get(key)
                if user.nickname != group.owner.nickname and user.rol != 'admin':
                    self.forbidden()
                    return
                self.values['key'] = key

                self.values['title'] = group.title
                self.values['description'] = group.description
                if group.all_users is not None:
                    self.values['all_users'] = group.all_users
                else:
                    self.values['all_users'] = True
                if group.category:
                    self.values['category'] = group.category
                self.add_categories()
                self.render('templates/group-edit.html')
            else:
                # show an empty form
                self.values['title'] = 'Grupo...'
                self.values['all_users'] = True
                self.add_categories()
                self.render('templates/group-edit.html')
        elif self.auth():
            if key:
                # update group
                group = model.Group.get(key)
                if user.nickname != group.owner.nickname and user.rol != 'admin':
                    self.forbidden()
                    return
                # group title is not editable since many-to-many relationships are denormalizated
                # group.title = self.get_param('title')
                group.description = self.get_param('description')
                image = self.request.get("img")
                if image:
                    image = images.im_feeling_lucky(image, images.JPEG)
                    group.avatar = img.resize(image, 128, 128)
                    group.thumbnail = img.resize(image, 48, 48)
                    if not group.image_version:
                        group.image_version = 1
                    else:
                        memcache.delete(
                            '/images/group/avatar/%s/%d' %
                            (group.key().id(), group.image_version))
                        memcache.delete(
                            '/images/group/thumbnail/%s/%d' %
                            (group.key().id(), group.image_version))
                        group.image_version += 1
                    memcache.delete('/images/group/avatar/%s' %
                                    group.key().id())
                    memcache.delete('/images/group/thumbnail/%s' %
                                    group.key().id())
                if self.get_param('all_users'):
                    group.all_users = True
                else:
                    group.all_users = False
                category = model.Category.get(self.request.get('category'))
                prev_category = group.category
                group.category = category
                group.put()

                if prev_category:
                    prev_category.groups -= 1
                    prev_category.put()

                category.groups += 1
                category.put()

                memcache.delete('index_groups')
                self.redirect('/group/%s' % (group.url_path, ))
            else:
                # new group
                title = self.get_param('title')
                url_path = '-'
                all_users = False
                if self.get_param('all_users'):
                    all_users = True
                group = model.Group(owner=user,
                                    owner_nickname=user.nickname,
                                    title=title,
                                    description=self.get_param('description'),
                                    url_path=url_path,
                                    members=1,
                                    all_users=all_users,
                                    items=0,
                                    threads=0,
                                    responses=0,
                                    subscribers=[user.email],
                                    activity=1)
                category = model.Category.get(self.request.get('category'))
                group.category = category
                image = self.request.get("img")
                if image:
                    image = images.im_feeling_lucky(image, images.JPEG)
                    group.avatar = img.resize(image, 128, 128)
                    group.thumbnail = img.resize(image, 48, 48)
                    group.image_version = 1

                group.put()
                self.add_user_subscription(user, 'group', group.key().id())
                group.url_path = '%d/%s' % (group.key().id(),
                                            self.to_url_path(group.title))
                group.put()

                category.groups += 1
                category.put()

                user.groups += 1
                user.put()

                app = model.Application.all().get()
                if app:
                    app.groups += 1
                    app.put()
                memcache.delete('app')

                group_user = model.GroupUser(user=user,
                                             group=group,
                                             user_nickname=user.nickname,
                                             group_title=group.title,
                                             group_url_path=group.url_path)
                group_user.put()
                memcache.delete('index_groups')

                followers = list(self.get_followers(user=user))
                followers.append(user.nickname)
                self.create_event(event_type='group.new',
                                  followers=followers,
                                  user=user,
                                  group=group)

                self.add_follower(group=group, nickname=user.nickname)

                # TODO: update a user counter to know how many groups is owner of?

                self.redirect('/group/%s' % (group.url_path, ))
예제 #7
0
파일: dset.py 프로젝트: abhishah/camo
 def im(self, frame):
   if frame not in self.im_cache:
     self.im_cache[frame] = ig.resize(np.array(ig.imread(self.im_files[frame]), 'd'), self.scale)
     
   return self.im_cache[frame].copy()
예제 #8
0
파일: dset.py 프로젝트: abhishah/camo
 def im_with_real(self, frame):
   if self.has_real():
     return ig.resize(ig.imread(self.real_file(frame)), self.scale)
   else:
     raise RuntimeError('Scan %snot contain a real cube' % self.path)
예제 #9
0
    def execute(self):
        self.values['tab'] = '/module/community.list'
        method = self.request.method
        user = self.values['user']
        key = self.get_param('key')

        if method == 'GET':
            if key:
                # show edit form
                community = model.Community.get(key)
                if user.nickname != community.owner.nickname and user.rol != 'admin':
                    self.forbidden()
                    return
                self.values['key'] = key

                self.values['title'] = community.title
                self.values['description'] = community.description
                if community.all_users is not None:
                    self.values['all_users'] = community.all_users
                else:
                    self.values['all_users'] = True
                if community.category:
                    self.values['category'] = community.category
                self.add_categories()
                self.render('templates/module/community/community-edit.html')
            else:
                # show an empty form
                self.values['title'] = "New community..."
                self.values['all_users'] = True
                self.add_categories()
                self.render('templates/module/community/community-edit.html')
        elif self.auth():
            if key:
                # update community
                community = model.Community.get(key)
                if user.nickname != community.owner.nickname and user.rol != 'admin':
                    self.forbidden()
                    return
                # community title is not editable since many-to-many relationships are denormalizated
                # community.title = self.get_param('title')
                community.description = self.get_param('description')
                image = self.request.get("img")
                if image:
                    image = images.im_feeling_lucky(image, images.JPEG)
                    community.avatar = img.resize(image, 128, 128)
                    community.thumbnail = img.resize(image, 48, 48)
                    if not community.image_version:
                        community.image_version = 1
                    else:
                        memcache.delete(
                            '/images/community/avatar/%s/%d' %
                            (community.key().id(), community.image_version))
                        memcache.delete(
                            '/images/community/thumbnail/%s/%d' %
                            (community.key().id(), community.image_version))
                        community.image_version += 1
                    memcache.delete('/images/community/avatar/%s' %
                                    community.key().id())
                    memcache.delete('/images/community/thumbnail/%s' %
                                    community.key().id())
                if self.get_param('all_users'):
                    community.all_users = True
                else:
                    community.all_users = False
                category = model.Category.get(self.request.get('category'))
                prev_category = community.category
                community.category = category
                community.put()

                if prev_category:
                    prev_category.communities -= 1
                    prev_category.put()

                category.communities += 1
                category.put()

                memcache.delete('index_communities')
                self.redirect('/module/community/%s' % (community.url_path, ))
            else:
                # new community
                title = self.get_param('title')
                url_path = '-'
                all_users = False
                if self.get_param('all_users'):
                    all_users = True
                community = model.Community(
                    owner=user,
                    owner_nickname=user.nickname,
                    title=title,
                    description=self.get_param('description'),
                    url_path=url_path,
                    members=1,
                    all_users=all_users,
                    articles=0,
                    threads=0,
                    responses=0,
                    subscribers=[user.email],
                    activity=1)
                category = model.Category.get(self.request.get('category'))
                community.category = category
                image = self.request.get("img")
                if image:
                    image = images.im_feeling_lucky(image, images.JPEG)
                    community.avatar = img.resize(image, 128, 128)
                    community.thumbnail = img.resize(image, 48, 48)
                    community.image_version = 1

                community.put()
                self.add_user_subscription(user, 'community',
                                           community.key().id())
                community.url_path = '%d/%s' % (
                    community.key().id(), self.to_url_path(community.title))
                community.put()

                category.communities += 1
                category.put()

                user.communities += 1
                user.put()

                app = model.Application.all().get()
                if app:
                    if app.communities:
                        app.communities += 1
                    else:
                        app.communities = 1
                    app.put()
                    memcache.delete('app')

                community_user = model.CommunityUser(
                    user=user,
                    community=community,
                    user_nickname=user.nickname,
                    community_title=community.title,
                    community_url_path=community.url_path)
                community_user.put()
                memcache.delete('index_communities')

                followers = list(self.get_followers(user=user))
                followers.append(user.nickname)
                self.create_event(event_type='community.new',
                                  followers=followers,
                                  user=user,
                                  community=community)

                self.add_follower(community=community, nickname=user.nickname)

                # TODO: update a user counter to know how many communities is owner of?

                self.redirect('/module/community/%s' % (community.url_path, ))
예제 #10
0
파일: dset.py 프로젝트: jwgu/camo
 def im_with_real(self, frame):
     if self.has_real():
         return ig.resize(ig.imread(self.real_file(frame)), self.scale)
     else:
         raise RuntimeError('Scan %snot contain a real cube' % self.path)
예제 #11
0
파일: dset.py 프로젝트: jwgu/camo
    def im(self, frame):
        if frame not in self.im_cache:
            self.im_cache[frame] = ig.resize(
                np.array(ig.imread(self.im_files[frame]), 'd'), self.scale)

        return self.im_cache[frame].copy()
예제 #12
0
	def execute(self):
		self.values['tab'] = '/module/community.list'
		method = self.request.method
		user = self.values['user']
		key = self.get_param('key')

		if method == 'GET':
			if key:
				# show edit form
				community = model.Community.get(key)
				if user.nickname != community.owner.nickname and user.rol != 'admin':
					self.forbidden()
					return
				self.values['key'] = key

				self.values['title'] = community.title
				self.values['description'] = community.description
				if community.all_users is not None:
					self.values['all_users'] = community.all_users
				else:
					self.values['all_users'] = True
				if community.category:
					self.values['category'] = community.category
				self.add_categories()
				self.render('templates/module/community/community-edit.html')
			else:
				# show an empty form
				self.values['title'] = "New community..."
				self.values['all_users'] = True
				self.add_categories()
				self.render('templates/module/community/community-edit.html')
		elif self.auth():
			if key:
				# update community
				community = model.Community.get(key)
				if user.nickname != community.owner.nickname and user.rol != 'admin':
					self.forbidden()
					return
				# community title is not editable since many-to-many relationships are denormalizated
				# community.title = self.get_param('title')
				community.description = self.get_param('description')
				image = self.request.get("img")
				if image:
					image = images.im_feeling_lucky(image, images.JPEG)
					community.avatar = img.resize(image, 128, 128)
					community.thumbnail = img.resize(image, 48, 48)
					if not community.image_version:
						community.image_version = 1
					else:
						memcache.delete('/images/community/avatar/%s/%d' % (community.key().id(), community.image_version))
						memcache.delete('/images/community/thumbnail/%s/%d' % (community.key().id(), community.image_version))
						community.image_version += 1
					memcache.delete('/images/community/avatar/%s' % community.key().id())
					memcache.delete('/images/community/thumbnail/%s' % community.key().id())
				if self.get_param('all_users'):
					community.all_users = True
				else:
					community.all_users = False
				category = model.Category.get(self.request.get('category'))
				prev_category = community.category
				community.category = category
				community.put()
				
				if prev_category:
					prev_category.communities -= 1
					prev_category.put()
				
				category.communities += 1
				category.put()
				
				memcache.delete('index_communities')
				self.redirect('/module/community/%s' % (community.url_path, ))
			else:
				# new community
				title = self.get_param('title')
				url_path = '-'
				all_users = False
				if self.get_param('all_users'):
					all_users = True
				community = model.Community(owner=user,
					owner_nickname=user.nickname,
					title=title,
					description=self.get_param('description'),
					url_path=url_path,
					members=1,
					all_users = all_users,
					articles=0,
					threads=0,
					responses=0,
					subscribers=[user.email],
					activity=1)
				category = model.Category.get(self.request.get('category'))
				community.category = category
				image = self.request.get("img")
				if image:
					image = images.im_feeling_lucky(image, images.JPEG)
					community.avatar = img.resize(image, 128, 128)
					community.thumbnail = img.resize(image, 48, 48)
					community.image_version = 1
				
				community.put()
				self.add_user_subscription(user, 'community', community.key().id())
				community.url_path = '%d/%s' % (community.key().id(), self.to_url_path(community.title))
				community.put()
				
				category.communities += 1
				category.put()
				
				user.communities += 1
				user.put()
				
				app = model.Application.all().get()
				if app:
					if app.communities:
						app.communities += 1
					else:
						app.communities =1
					app.put()
					memcache.delete('app')
				
				community_user = model.CommunityUser(user=user,
					community=community,
					user_nickname=user.nickname,
					community_title=community.title,
					community_url_path=community.url_path)
				community_user.put()
				memcache.delete('index_communities')
				
				followers = list(self.get_followers(user=user))
				followers.append(user.nickname)
				self.create_event(event_type='community.new', followers=followers, user=user, community=community)
				
				self.add_follower(community=community, nickname=user.nickname)
				
				# TODO: update a user counter to know how many communities is owner of?
				

				self.redirect('/module/community/%s' % (community.url_path, ))