def remove_old_projects(): p = Project.all() old_project = p.order('-saved').get() if old_project: old_date = old_project.saved p = Project.all().filter('saved = ', old_date) db.delete(p)
def post(self): # if we don't have a user then throw # an unauthorised error user = users.get_current_user() if not user: self.render_403() return name = self.request.get("name") # check we have a value if name: # then check we have a value which isn't just spaces if name.strip(): if Project.all().filter('name =', name).count() == 0: # we also need to check if we have something with the same slug if Project.all().filter('slug =', slugify( unicode(name))).count() == 0: try: project = Project( name=name, user=users.get_current_user(), ) project.put() logging.info("project added: %s" % project.name) except db.BadValueError, e: logging.error("error adding project: %s" % e)
def get(self): output = get_cache("projects_json") if output is None: projects = Project.all().order('-created_date').fetch(50) projects_data = {} for project in projects: data = { 'internal_url': "%s/projects/%s/" % (settings.SYSTEM_URL, project.slug), 'created_date': str(project.created_date)[0:19], 'open_issues': project.open_issues.count(), 'closed_issues': project.closed_issues.count(), } if project.url: data['external_url'] = project.url projects_data[project.name] = data json = { 'date': str(datetime.now())[0:19], 'projects': projects_data, } output = simplejson.dumps(json) memcache.add("projects_json", output, 3600) self.response.headers[ "Content-Type"] = "application/javascript; charset=utf8" self.response.out.write(output)
def get(self): self.response.out.write("<html><body><h1>deleting abandoned projects</h1><ol>") # iterate over list of projects no one has access rights anymore for p in [p for p in Project.all() if len([r for r in p.projectrights_set])==0]: self.response.out.write("<li>Project: %s<ul>" % p.name) for t in p.transaction_set: self.response.out.write("<li>transaction</li>") t.delete() for a in p.person_set: self.response.out.write("<li>Account: %s<ul>" % a.name) for m in a.member_set: if m.group.key()!=a.key(): self.response.out.write("<li>Membership: %s</li>" % m.group.name) m.delete() a.delete() self.response.out.write("</ul></li>") for c in p.currency_set: self.response.out.write("<li>Currency: %s</li>" % c.name) c.delete() for t in p.ticket_set: self.response.out.write("<li>Ticket: %s</li>" % t.user) t.delete() for i in p.invitation_set: self.response.out.write("<li>Invitation: %s</li>" % i.user) i.delete() self.response.out.write("</ul></li>") p.delete() self.response.out.write("</ol></body></html>")
def get(self): projects = Project.all() return { 'projects': projects, 'Project': Project, }
def get(self): output = get_cache("projects_rss") if output is None: projects = Project.all().order('-created_date').fetch(20) rss = RSS2( title="GitBug projects", link="%s" % settings.SYSTEM_URL, description="A list of the latest 20 projects on GitBug", lastBuildDate=datetime.now()) for project in projects: rss.items.append( RSSItem(title=project.name, link="%s/projects/%s/" % (settings.SYSTEM_URL, project.slug), description="", pubDate=project.created_date)) output = rss.to_xml() memcache.add("projects_rss", output, 3600) self.response.headers[ "Content-Type"] = "application/rss+xml; charset=utf8" self.response.out.write(output)
def post(self, slug): project = Project.all().filter('slug =', slug).fetch(1)[0] key = self.request.get("key") if key == project.key(): try: payload = self.request.get("payload") representation = simplejson.loads(payload) commits = representation['commits'] for commit in commits: message = commit['message'] search = GITBUG.search(message) if search: identifier = search.group()[7:] issue = Issue.all().filter( 'project =', project).filter('identifier =', int(identifier)).fetch(1)[0] issue.fixed = True issue.put() logging.info("issue updated via webhook: %s in %s" % (issue.name, issue.project.name)) except Exception, e: logging.error("webhook error: %s" % e)
def render(self, **kwargs): projects = Project.all({'type':CONTENT_TYPE.PROJECT, \ 'status':'published'})\ .sort([('created_at', -1)]).limit(5) if projects: return self.render_string('modules/project-latest', projects=projects) else: return ''
def post(self, slug): "Create an issue against this project" project = Project.all().filter('slug =', slug).fetch(1)[0] # get details from the form name = self.request.get("name") description = self.request.get("description") email = self.request.get("email") try: if Issue.all().filter('name =', name).filter('project =', project).count() == 0: issue = Issue( name=name, description=description, project=project, ) if email: issue.email = email issue.put() mail.send_mail( sender="*****@*****.**", to=project.user.email(), subject="[GitBug] New bug added to %s" % project.name, body= """You requested to be emailed when a bug on GitBug was added: Issue name: %s Description: %s Thanks for using GitBug <http://gitbug.appspot.com>. A very simple issue tracker. """ % (issue.name, issue.description)) logging.info("issue created: %s in %s" % (name, project.name)) except Exception, e: logging.error("error adding issue: %s" % e)
def get(self, slug): "Display a confirmation page before deleting" # check the url has a trailing slash and add it if not if self.request.path[-1] != "/": self.redirect("%s/" % self.request.path, True) return project = Project.all().filter('slug =', slug).fetch(1)[0] # if we don't have a user then throw # an unauthorised error user = users.get_current_user() if project.user == user or users.is_current_user_admin(): owner = True else: self.render_403() return context = { 'project': project, 'owner': owner, } # calculate the template path output = self.render("project_delete.html", context) self.response.out.write(output)
def get(self, slug): # make sure we have a trailing slash if self.request.path[-1] != "/": self.redirect("%s/" % self.request.path, True) return try: project = Project.all().filter('slug =', slug).fetch(1)[0] except IndexError: self.render_404() return user = users.get_current_user() # check we have the permissions to be looking at settings if project.user == user or users.is_current_user_admin(): owner = True else: self.render_403() return context = { 'project': project, 'owner': owner, } # calculate the template path output = self.render("project_settings.html", context) self.response.out.write(output)
def get_close_project(budget, last_projects): """ Get a new project to tweet, but don't repeat the last. """ p = Project.all() projects = p.filter('left < ', budget).fetch(10) project = projects.pop() while project.link in last_projects: project = projects.pop() return project
def get(self, slug): output = get_cache("project_%s_json" % slug) if output is None: project = Project.all().filter('slug =', slug).fetch(1)[0] issues = Issue.all().filter( 'project =', project).order('fixed').order('created_date') issues_data = {} for issue in issues: # friendlier display of information if issue.fixed: status = "Fixed" else: status = "Open" # set structure of inner json data = { 'internal_url': "%s/projects%s" % (settings.SYSTEM_URL, issue.internal_url), 'created_date': str(project.created_date)[0:19], 'description': issue.html, 'status': status, 'identifier': "#gitbug%s" % issue.identifier, } if issue.fixed and issue.fixed_description: data['fixed_description'] = issue.fixed_description issues_data[issue.name] = data # set structure of outer json json = { 'date': str(datetime.now())[0:19], 'name': project.name, 'internal_url': "%s/projects/%s/" % (settings.SYSTEM_URL, project.slug), 'created_date': str(project.created_date)[0:19], 'issues': issues_data, } if project.url: json['external_url'] = project.url # create the json output = simplejson.dumps(json) # cache it memcache.add("project_%s_json" % slug, output, 3600) # send the correct headers self.response.headers[ "Content-Type"] = "application/javascript; charset=utf8" self.response.out.write(output)
def get_projects(budget, update=False): key = str(budget) all_projects = memcache.get(key) if all_projects is None or update: p = Project.all() all_projects = p.filter('left <= ', budget) all_projects = list(all_projects) memcache.set(key, all_projects) return all_projects
def get(self): #Wipe datastore of all projects projs = Project.all().fetch(1000) for proj in projs: proj.delete() Project(name="Sendery", graph_json = "asdf", mvp_effect = "lasers").put() self.response.out.write("done")
def update_project_counts( request, user ): n = 0 for nickname in Nickname.all(): nickname.project_count = Project.all().filter("user ="******"Projects counted for %d nicknames"%n )
def get_soon_project(budget, last_projects): """ Get a new project to tweet, but don't repeat the last. """ p = Project.all() projects = [project for project in p.filter('left < ', budget)] timeleft = lambda i: i.end - datetime.now() + timedelta(0, 14400) projects.sort(key=timeleft, reverse=True) project = projects.pop() while project.link in last_projects: project = projects.pop() return project
def get(self, slug): output = get_cache("project_%s_rss" % slug) if output is None: project = Project.all().filter('slug =', slug).fetch(1)[0] # allow query string arguments to specify filters if self.request.get("open"): status_filter = True fixed = False elif self.request.get("closed"): status_filter = True fixed = True else: status_filter = None # if we have a filter then filter the results set if status_filter: issues = Issue.all().filter('project =', project).filter( 'fixed =', fixed).order('fixed').order('created_date') else: issues = Issue.all().filter( 'project =', project).order('fixed').order('created_date') # create the RSS feed rss = RSS2(title="Issues for %s on GitBug" % project.name, link="%s/%s/" % (settings.SYSTEM_URL, project.slug), description="", lastBuildDate=datetime.now()) # add an item for each issue for issue in issues: if issue.fixed: pubDate = issue.fixed_date title = "%s (%s)" % (issue.name, "Fixed") else: pubDate = issue.created_date title = issue.name rss.items.append( RSSItem(title=title, link="%s/projects%s" % (settings.SYSTEM_URL, issue.internal_url), description=issue.html, pubDate=pubDate)) # get the xml output = rss.to_xml() memcache.add("project_%s_rss" % slug, output, 3600) # send the correct headers self.response.headers[ "Content-Type"] = "application/rss+xml; charset=utf8" self.response.out.write(output)
def post(self, slug): project = Project.all().filter('slug =', slug).fetch(1)[0] try: file = self.request.POST['file'] f = DatastoreFile(data=file.value, mimetype=file.type, project=project, name=file.filename) f.put() url = "http://%s/file/%s/%d/%s" % (self.request.host, slug, f.key().id(), f.name) except Exception, e: logging.error("error uploading file: %s" % e)
def sitemap(request): """ A sitemap for Google. """ document_list = Document.all().filter("is_published =", True).order("-publication_date") project_list = Project.all().filter("is_published =", True) context = { 'document_list': document_list, 'project_list': project_list, } return direct_to_template(request, 'sitemap.xml', context, mimetype='text/xml')
def set_project_updated( request, user ): n = 0 for project in Project.all(): if project.updated is None: project.updated = datetime.datetime.now() project.put() n += 1 return HttpResponse( "Set the Project.updated on %d records"%n )
def index(): projects = Project.all() last_image_tags = [obj.new_tag for obj in projects if obj.new_tag] last_images = Image.where_in('image_tag', last_image_tags).get() for project in projects: for image in last_images: if project.image_name == image.image_name: project.image = image break else: project.image = None return render_template('docker/index.html', projects=projects)
def welcome(request): user = users.get_current_user() if user: enter_url="/" else: enter_url=users.create_login_url("/") user_count = Nickname.all().count() project_count = Project.all().count() return render_to_response( "welcome.html", {'enter_url':enter_url, 'user_count':user_count, 'project_count':project_count} )
def get(self): user = users.get_current_user() projects = Project.all() projects.filter("owner =", user.user_id()) projects.order("title") projects = tuple(projects) # prevent re-execution when iterating context = context_dict(locals(), 'user', 'projects') context['logout_url'] = users.create_logout_url('/') page = template.render('templates/dashboard.html', context) self.response.out.write(page)
def get_projects_with_scraplists( user, scrapslength=5 ): """Returns a set of dicts, each containing useful information, a short set of scraps, and the number of remaining scraps""" projects = [] for project_entity in Project.all().filter('user ='******'user':project_entity.user, 'name':project_entity.name, 'scraps':scraps.fetch(scrapslength), 'id':project_entity.key().id(), 'remainder':scraps_remainder} ) return projects
def get(self): stats = {} stats['volunteers'] = {} stats['volunteers']['count'] = 0 stats['volunteers']['count_has_group'] = 0 stats['volunteers']['count_no_group'] = 0 stats['volunteers']['count_has_project'] = 0 stats['volunteers']['count_no_project'] = 0 users = User.all() for user in users: stats['volunteers']['count'] += 1 if user.group == None: stats['volunteers']['count_no_group'] += 1 else: stats['volunteers']['count_has_group'] += 1 if user.project == None: stats['volunteers']['count_no_project'] += 1 else: stats['volunteers']['count_has_project'] += 1 stats['groups'] = {} stats['groups']['count'] = Group.all().count() stats['groups']['total_spots'] = sum( map(lambda group: group.slots, Group.all())) stats['groups']['spots_taken'] = sum( map(lambda group: group.spots_taken, Group.all())) stats['groups']['unused_spots'] = sum( map(lambda group: group.spots_taken, Group.all())) stats['projects'] = {} stats['projects']['count'] = Project.all().count() stats['projects']['total_spots'] = sum( map(lambda project: project.max_volunteers, Project.all())) stats['projects']['spots_taken'] = sum( map(lambda project: project.spots_taken, Project.all())) stats['projects']['unused_spots'] = stats['projects'][ 'total_spots'] - stats['projects']['spots_taken'] return stats
def get(self): def make_project_dict(project, project_list): project_dict = {} project_dict['link'] = project.link + '/widget/card.html' project_dict['left'] = project.left timeleft = project.end - datetime.now() + timedelta(0, 14400) project_dict['timeleft'] = (timeleft.days * 60 * 60 * 24) + timeleft.seconds hours = str(timeleft.seconds / 3600) if timeleft.days < 0: timeleft_str = hours else: timeleft_str = str(timeleft.days) + ' days, ' + hours + ' hours' project_dict['time'] = timeleft_str project_list.append(project_dict) budget = self.request.get('b') try: budget = int(float(budget)) except ValueError: budget = 0 sort = self.request.get('sort') if sort not in ['soon', 'close']: sort = 'soon' p = Project.all() projects = p.filter('left <= ', budget) page = projects project_dicts = [] for project in page: make_project_dict(project, project_dicts) if sort == 'soon': project_dicts.sort(key=lambda i: i['timeleft']) if sort == 'close': project_dicts.sort(key=itemgetter('left')) response_dict = {} response_dict['projects'] = project_dicts json_response = json.dumps(response_dict) self.response.headers.add_header('content-type', 'application/json', charset='utf-8') self.response.out.write(json_response)
def get(self): # collect saved tasks projects_json = [] for project in Project.all(): project_json = { "id": "%s" % project.key().id_or_name(), "name": project.name, "description": project.description, "timeLeft": project.timeLeft, "createdAt": project.createdAt if project.createdAt != None else 0, "updatedAt": project.updatedAt if project.updatedAt != None else 0 } projects_json.append(project_json) # Set the response content type and dump the json self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(projects_json))
def get(self): if users.get_current_user(): # if we have a user then get their projects projects = Project.all().filter( 'user ='******'-created_date').fetch(50) context = { 'projects': projects, } output = self.render("index.html", context) else: # otherwise it's a static page so cache for a while output = get_cache("home") if output is None: output = self.render("home.html") memcache.add("home", output, 3600) self.response.out.write(output)
def get(self): # fix any references to non-existance objects users = User.all() for user in users: try: project = user.project except db.ReferencePropertyResolveError as e: logging.info( 'Resolving property resolve error on user.project for {}\'s project {}' .format(user.key(), user._project)) user.project = None user.put() try: group = user.group except db.ReferencePropertyResolveError as e: user.group = None user.put() groups = Group.all() for group in groups: try: project = group.project except db.ReferencePropertyResolveError as e: group.project = None group.put() projects = Project.all() for project in projects: volunteers = project.volunteers.filter('group =', None) num_volunteers = volunteers.count() groups = project.groups num_group_volunteers = sum([group.slots for group in groups]) spots = num_volunteers + num_group_volunteers project.setSpotsTaken(spots, True) groups = Group.all() for group in groups: members = group.members num_members = members.count() group.spots_taken = num_members group.put() return self.redirect('/admin', {'error': '1'})
def post(self, slug): # if we don't have a user then throw # an unauthorised error user = users.get_current_user() if not user: self.render_403() return project = Project.all().filter('slug =', slug).fetch(1)[0] user = users.get_current_user() if project.user == user or users.is_current_user_admin(): try: logging.info("project deleted: %s" % project.name) # delete the project project.delete() except Exception, e: logging.error("error deleting project: %s" % e)
def get(self): if self.request.path[-1] != "/": self.redirect("%s/" % self.request.path, True) return user = users.get_current_user() output = None if not user: output = get_cache("projects") if output is None: projects = Project.all().order('-created_date').fetch(50) context = { 'projects': projects, } # calculate the template path output = self.render("projects.html", context) if not user: memcache.add("projects", output, 3600) self.response.out.write(output)
def get(self, slug): # we want canonocal urls so redirect to add a trailing slash if needed if self.request.path[-1] != "/": self.redirect("%s/" % self.request.path, True) return user = users.get_current_user() output = None # if not logged in then use a cached version if not user: output = get_cache("project_%s" % slug) # if we don't have a cached version or are logged in if output is None: try: project = Project.all().filter('slug =', slug).fetch(1)[0] issues = Issue.all().filter('project =', project) files = DatastoreFile.all().filter('project =', project) except IndexError: self.render_404() return logging.info("Files in this project: %d" % files.count()) # check to see if we have admin rights over this project if project.user == user or users.is_current_user_admin(): owner = True else: owner = False context = { 'project': project, 'issues': issues, 'owner': owner, 'files': files, } output = self.render("project.html", context) if not user: # only save a cached version if we're not logged in # so as to avoid revelaving user details memcache.add("project_%s" % slug, output, 3600) self.response.out.write(output)
def get(self): self._current_user = self.require_login() if not self._current_user: self.response.out.write(json.dumps({"error": "please log in"})) return q = Queue.all().get() if not q: q = Queue() #Push onto queue if str(self._current_user.id) in q.users: self.response.out.write(json.dumps({"success": "already in queue"})) elif len(q.users) == 0: q.users = [self._current_user.id] self.response.out.write(json.dumps({"success": "added to queue"})) else: #Found a match. Pop & Serve matched = q.users[0] q.users = q.users[1:] #Randomly choose a project projects = Project.all().fetch(1000) random.seed() project = random.choice(projects) #Actually create the match match = Match(project_id = str(project.key()), users = [self._current_user.id, matched], outcome = [0, 0]) hackers = Hacker.all().filter("user IN", match.users).fetch(8) match.hacker_list = [] for hacker in hackers: match.hacker_list.append(str(hacker.key())) match.put() #Notify the users via socket broadcast(match, json.dumps({"success": "match found"})) self.response.out.write("herp") q.put()
def get(self, slug): # we want canonocal urls so redirect to add a trailing slash if needed if self.request.path[-1] != "/": self.redirect("%s/" % self.request.path, True) return user = users.get_current_user() output = None # if not logged in then use a cached version if not user: output = get_cache("project_%s" % slug) # if we don't have a cached version or are logged in if output is None: try: project = Project.all().filter('slug =', slug).fetch(1)[0] issues = Issue.all().filter('project =', project) except IndexError: self.render_404() return # check to see if we have admin rights over this project if project.user == user or users.is_current_user_admin(): owner = True else: owner = False context = { 'project': project, 'issues': issues, 'owner': owner, } output = self.render("project.html", context) if not user: # only save a cached version if we're not logged in # so as to avoid revelaving user details memcache.add("project_%s" % slug, output, 3600) self.response.out.write(output)
def post(self, slug): # if we don't have a user then throw # an unauthorised error user = users.get_current_user() if not user: self.render_403() return user = users.get_current_user() project = Project.all().filter('slug =', slug).fetch(1)[0] if project.user == user: try: other_users = self.request.get("other_users") if other_users: list_of_users = other_users.split(" ") project.other_users = list_of_users else: project.other_users = [] if self.request.get("url"): url = self.request.get("url") if not url[:7] == 'http://': url = "http://%s" % url if URL_RE.match(url): project.url = url else: project.url = None if self.request.get("description"): project.description = self.request.get("description") else: project.description = None project.put() logging.info("project modified: %s" % project.name) except db.BadValueError, e: logging.error("error modifiying project: %s" % e)
def post(self): projects = Project.all() for project in projects: project.delete()
def get(self): """Displays a list of all projects.""" return self.render('projects', {'projects': Project.all()})
async def get_all(): return await PrivateProject.from_queryset(Project.all())