Example #1
0
File: forum.py Project: bklang/GO2
    def get(self):
        item_key_str = self.request.get("p", None)
        if item_key_str is None:
            logging.error('no object passed to TogglePinHandler')
            return self.redirect('/')

        parent_key_str = self.request.get("t", None)
        if parent_key_str is None:
            parent_key_str.error('no topic passed to TogglePinHandler')
            return self.redirect('/')

        the_item = ndb.Key(urlsafe=item_key_str).get()
        the_parent = ndb.Key(urlsafe=parent_key_str).get()

        if not member.member_is_superuser(self.user):
            logging.error(
                "non-admin trying to toggle pin state in TogglePinHandler")
            return self.redirect('/')

        if the_item is None:
            logging.error("no item found in TogglePinHandler")
            return self.redirect('/')

        if the_parent is None:
            logging.error("no parent found in TogglePinHandler")
            return self.redirect('/')

        the_item.pinned = not the_item.pinned
        the_item.put()

        if type(the_parent) is ForumTopic:
            return self.redirect('/forum_topic?tk={0}'.format(parent_key_str))
        else:
            return self.redirect('/forum?fk={0}'.format(parent_key_str))
Example #2
0
File: forum.py Project: bklang/GO2
    def get(self):

        topic_key_str = self.request.get("tk", None)
        if topic_key_str is None:
            logging.error('no topic key in ForumTopicHandler')
            return self.redirect('/')

        the_topic_key = ndb.Key(urlsafe=topic_key_str)
        the_topic = the_topic_key.get()

        the_band_key = the_topic_key.parent().parent()

        # is the current user a band admin?
        user_is_band_admin = assoc.get_admin_status_for_member_for_band_key(
            self.user, the_band_key)

        if not (user_is_band_admin or member.member_is_superuser(self.user)):
            logging.error(
                "non-admin trying to toggle topic state in TopicToggleOpenHandler"
            )
            return self.redirect('/')

        the_topic.open = not the_topic.open
        the_topic.put()

        return self.redirect('/forum_topic?tk={0}'.format(topic_key_str))
Example #3
0
    def _make_page(self,the_user,the_band=None):
        """ produce the info page """
        
        # find the band we're interested in
        if the_band is None:
            band_key_str = self.request.get("bk", None)
            if band_key_str is None:
                self.response.write('no band key passed in!')
                return # todo figure out what to do if there's no ID passed in
            the_band_key = band.band_key_from_urlsafe(band_key_str)
            the_band = band.get_band(the_band_key)

        if the_band is None:
            self.response.write('did not find a band!')
            return # todo figure out what to do if we didn't find it
            
        if the_user is None:
            the_user_is_associated = False
            the_user_is_confirmed = False
            the_user_admin_status = False
            the_user_is_superuser = False
        else:
            the_user_is_associated = assoc.get_associated_status_for_member_for_band_key(the_user, the_band_key)
            the_user_is_confirmed = assoc.get_confirmed_status_for_member_for_band_key(the_user, the_band_key)
            the_user_admin_status = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key)   
            the_user_is_superuser = member.member_is_superuser(the_user)

        if the_user_admin_status or the_user_is_superuser:
            the_pending = assoc.get_pending_members_from_band_key(the_band_key)
            the_invited_assocs = assoc.get_invited_member_assocs_from_band_key(the_band_key)
            the_invited = [(x.key, member.get_member(x.member).name) for x in the_invited_assocs]
        else:
            the_pending = []
            the_invited = []

        member_links=None
        if the_band.member_links:
            member_links=[]
            link_list = the_band.member_links.split('\n')
            for l in link_list:
                link_info = l.split(':',1)
                if len(link_info) == 2:
                    member_links.append([link_info[0].strip(), link_info[1].strip()])

        template_args = {
            'the_band' : the_band,
            'the_user_is_associated': the_user_is_associated,
            'the_user_is_confirmed': the_user_is_confirmed,
            'the_user_is_band_admin': the_user_admin_status,
            'the_pending_members': the_pending,
            'the_invited_members': the_invited,
            'the_member_links': member_links,
            'num_sections': len(the_band.sections)

        }
        self.render_template('band_info.html', template_args)
Example #4
0
    def make_page(self, the_user):

        # make sure I'm an admin or a superuser
        the_user_is_superuser = member.member_is_superuser(the_user)

        if self.request.get("new", None) is not None:
            #  creating a new band
            if not the_user_is_superuser:
                return self.redirect('/')
            the_band = None
            is_new = True
        else:
            is_new = False
            the_band_key_str = self.request.get("bk", '0')

            if the_band_key_str == '0':
                return
            else:
                the_band_key = band.band_key_from_urlsafe(the_band_key_str)

                the_user_admin_status = assoc.get_admin_status_for_member_for_band_key(
                    the_user, the_band_key)
                if not the_user_admin_status and not the_user_is_superuser:
                    return self.redirect('/')

                the_band = band.get_band(the_band_key)
                if the_band is None:
                    self.response.write('did not find a band!')
                    return  # todo figure out what to do if we didn't find it

        template_args = {
            'the_band': the_band,
            'timezones': pytz.common_timezones,
            'newmember_is_active': is_new,
            'is_new': is_new
        }
        self.render_template('band_edit.html', template_args)
Example #5
0
    def make_page(self, the_user):

        # make sure I'm an admin or a superuser
        the_user_is_superuser = member.member_is_superuser(the_user)

        if self.request.get("new",None) is not None:
            #  creating a new band
            if not the_user_is_superuser:
                return self.redirect('/')
            the_band=None
            is_new=True
        else:
            is_new=False
            the_band_key_str=self.request.get("bk", '0')

            if the_band_key_str == '0':
                return
            else:
                the_band_key = band.band_key_from_urlsafe(the_band_key_str)
            
                the_user_admin_status = assoc.get_admin_status_for_member_for_band_key(the_user, the_band_key)   
                if not the_user_admin_status and not the_user_is_superuser:
                    return self.redirect('/')

                the_band = band.get_band(the_band_key)
                if the_band is None:
                    self.response.write('did not find a band!')
                    return # todo figure out what to do if we didn't find it

        template_args = {
            'the_band': the_band,
            'timezones': pytz.common_timezones,
            'newmember_is_active': is_new,
            'is_new': is_new
        }
        self.render_template('band_edit.html', template_args)
Example #6
0
 def get(self):
     if member.member_is_superuser(self.user):
         self._make_page(the_user=self.user)
     else:
         return self.redirect('/')
Example #7
0
    def _make_page(self, the_user, the_band=None):
        """ produce the info page """

        # find the band we're interested in
        if the_band is None:
            band_key_str = self.request.get("bk", None)
            if band_key_str is None:
                self.response.write('no band key passed in!')
                return  # todo figure out what to do if there's no ID passed in
            the_band_key = band.band_key_from_urlsafe(band_key_str)
            the_band = band.get_band(the_band_key)

        if the_band is None:
            self.response.write('did not find a band!')
            return  # todo figure out what to do if we didn't find it

        if the_user is None:
            the_user_is_associated = False
            the_user_is_confirmed = False
            the_user_admin_status = False
            the_user_is_superuser = False
        else:
            the_user_is_associated = assoc.get_associated_status_for_member_for_band_key(
                the_user, the_band_key)
            the_user_is_confirmed = assoc.get_confirmed_status_for_member_for_band_key(
                the_user, the_band_key)
            the_user_admin_status = assoc.get_admin_status_for_member_for_band_key(
                the_user, the_band_key)
            the_user_is_superuser = member.member_is_superuser(the_user)

        if the_user_admin_status or the_user_is_superuser:
            the_pending = assoc.get_pending_members_from_band_key(the_band_key)
            the_invited_assocs = assoc.get_invited_member_assocs_from_band_key(
                the_band_key)
            the_invited = [(x.key, member.get_member(x.member).name)
                           for x in the_invited_assocs]
        else:
            the_pending = []
            the_invited = []

        member_links = None
        if the_band.member_links:
            member_links = []
            link_list = the_band.member_links.split('\n')
            for l in link_list:
                link_info = l.split(':', 1)
                if len(link_info) == 2:
                    member_links.append(
                        [link_info[0].strip(), link_info[1].strip()])

        template_args = {
            'the_band': the_band,
            'the_user_is_associated': the_user_is_associated,
            'the_user_is_confirmed': the_user_is_confirmed,
            'the_user_is_band_admin': the_user_admin_status,
            'the_pending_members': the_pending,
            'the_invited_members': the_invited,
            'the_member_links': member_links,
            'num_sections': len(the_band.sections)
        }
        self.render_template('band_info.html', template_args)
Example #8
0
 def get(self):
     if member.member_is_superuser(self.user):
         self._make_page(the_user=self.user)
     else:
         return self.redirect('/')