Пример #1
0
    def post(self):
        """ post handler - wants an ak and sk """

        the_user = self.user

        the_section_keyurl=self.request.get('sk','0')
        the_member_keyurl=self.request.get('mk','0')
        the_band_keyurl=self.request.get('bk','0')

        if the_section_keyurl=='0' or the_member_keyurl=='0' or the_band_keyurl=='0':
            return # todo figure out what to do

        the_section_key=ndb.Key(urlsafe=the_section_keyurl)
        the_member_key=ndb.Key(urlsafe=the_member_keyurl)
        the_band_key=ndb.Key(urlsafe=the_band_keyurl)

        oktochange=False
        if (the_user.key == the_member_key or the_user.is_superuser):
            oktochange=True
        else:
            the_assoc = assoc.get_assoc_for_band_key_and_member_key(the_user.key, the_band_key)
            if the_assoc is not None and the_assoc.is_band_admin:
                oktochange=True

        if (oktochange):
            assoc.set_default_section(the_member_key, the_band_key, the_section_key)
Пример #2
0
    def post(self):
        """ post handler - wants an ak and sk """

        the_user = self.user

        the_section_keyurl = self.request.get('sk', '0')
        the_member_keyurl = self.request.get('mk', '0')
        the_band_keyurl = self.request.get('bk', '0')

        if the_section_keyurl == '0' or the_member_keyurl == '0' or the_band_keyurl == '0':
            raise Exception("Section, member and band must all be specified.")

        the_section_key = band.section_key_from_urlsafe(the_section_keyurl)
        the_member_key = member.member_key_from_urlsafe(the_member_keyurl)
        the_band_key = band.band_key_from_urlsafe(the_band_keyurl)

        oktochange = False
        if (the_user.key == the_member_key or the_user.is_superuser):
            oktochange = True
        else:
            the_assoc = assoc.get_assoc_for_band_key_and_member_key(
                the_user.key, the_band_key)
            if the_assoc is not None and the_assoc.is_band_admin:
                oktochange = True

        if (oktochange):
            assoc.set_default_section(the_member_key, the_band_key,
                                      the_section_key)
Пример #3
0
    def post(self):
        """ post handler - wants an ak and sk """

        the_user = self.user

        the_section_keyurl=self.request.get('sk','0')
        the_member_keyurl=self.request.get('mk','0')
        the_band_keyurl=self.request.get('bk','0')

        if the_section_keyurl=='0' or the_member_keyurl=='0' or the_band_keyurl=='0':
            raise Exception("Section, member and band must all be specified.")

        the_section_key = band.section_key_from_urlsafe(the_section_keyurl)
        the_member_key = member.member_key_from_urlsafe(the_member_keyurl)
        the_band_key = band.band_key_from_urlsafe(the_band_keyurl)

        oktochange=False
        if (the_user.key == the_member_key or the_user.is_superuser):
            oktochange=True
        else:
            the_assoc = assoc.get_assoc_for_band_key_and_member_key(the_user.key, the_band_key)
            if the_assoc is not None and the_assoc.is_band_admin:
                oktochange=True

        if (oktochange):
            assoc.set_default_section(the_member_key, the_band_key, the_section_key)
Пример #4
0
    def get(self, *args, **kwargs):
        try:
            gig_id = kwargs["gig_id"]
            the_gig = gig.gig_key_from_urlsafe(gig_id).get()
        except:
            self.abort(404)

        # are we authorized to see the gig?
        if assoc.get_assoc_for_band_key_and_member_key(self.user.key, the_gig.key.parent(), confirmed_only=False) is None:
            self.abort(401)

        return gig.rest_gig_info(the_gig, include_id=False)
Пример #5
0
def set_sections_for_empty_plans(the_gig):
    """ For this gig, get all plans. For plans with no section set, get the users default and set it """
    """ This is used when freezing a gig's plans """
    
    the_plan_keys = plan.get_plans_for_gig_key(the_gig.key, keys_only=True)
    the_band_key = the_gig.key.parent()
    for a_plan_key in the_plan_keys:
        a_plan = a_plan_key.get()
        if a_plan.section is None:
            the_member_key = a_plan.member
            the_assoc = assoc.get_assoc_for_band_key_and_member_key(the_member_key, the_band_key)
            if the_assoc:
                a_plan.section = the_assoc.default_section
                a_plan.put()
Пример #6
0
def set_sections_for_empty_plans(the_gig):
    """ For this gig, get all plans. For plans with no section set, get the users default and set it """
    """ This is used when freezing a gig's plans """
    
    the_plan_keys = plan.get_plans_for_gig_key(the_gig.key, keys_only=True)
    the_band_key = the_gig.key.parent()
    for a_plan_key in the_plan_keys:
        a_plan = a_plan_key.get()
        if a_plan.section is None:
            the_member_key = a_plan.member
            the_assoc = assoc.get_assoc_for_band_key_and_member_key(the_member_key, the_band_key)
            if the_assoc:
                a_plan.section = the_assoc.default_section
                a_plan.put()
Пример #7
0
    def get(self, *args, **kwargs):
        try:
            gig_id = kwargs["gig_id"]
            the_gig = gig.gig_key_from_urlsafe(gig_id).get()
        except:
            self.abort(404)

        # are we authorized to see the gig?
        if assoc.get_assoc_for_band_key_and_member_key(
                self.user.key, the_gig.key.parent(),
                confirmed_only=False) is None:
            self.abort(401)

        return gig.rest_gig_info(the_gig, include_id=False)
Пример #8
0
    def get(self, *args, **kwargs):
        try:
            gig_id = kwargs["gig_id"]
            the_gig = gig.gig_key_from_urlsafe(gig_id).get()
        except:
            self.abort(404)

        # are we authorized to see the gig?
        if assoc.get_assoc_for_band_key_and_member_key(self.user.key, the_gig.key.parent(), confirmed_only=False) is None:
            self.abort(401)

        the_band_key = the_gig.key.parent()
        the_plans, the_plan_counts, the_sections, band_has_sections = _makeInfoPageInfo(self.user, the_gig, the_band_key)

        return gig.rest_gig_plan_info(the_plans)
Пример #9
0
    def post(self):    
        """ makes a new assoc for a member """

        the_member_key = member.lookup_member_key(self.request)
        the_band_key=self.request.get('bk','0')
        if the_band_key=='0':
            raise Exception("Band not specified")
            
        the_member = the_member_key.get()
        the_band = band.band_key_from_urlsafe(the_band_key).get()
        
        if assoc.get_assoc_for_band_key_and_member_key(the_band_key = the_band.key, the_member_key = the_member_key) is None:
            assoc.new_association(the_member, the_band)        
            goemail.send_new_member_email(the_band,the_member)
        
        # since our bands are changing, invalidate the band list in our session
        self.user.invalidate_member_bandlists(self, the_member.key)
Пример #10
0
    def post(self):    
        """ makes a new assoc for a member """

        the_member_key = lookup_member_key(self.request)
        the_band_key=self.request.get('bk','0')
        if the_band_key=='0':
            raise Exception("Band not specified")
            
        the_member=the_member_key.get()
        the_band=ndb.Key(urlsafe=the_band_key).get()
        
        if assoc.get_assoc_for_band_key_and_member_key(the_band_key = the_band.key, the_member_key = the_member_key) is None:
            assoc.new_association(the_member, the_band)        
            goemail.send_new_member_email(the_band,the_member)
        
        # since our bands are changing, invalidate the band list in our session
        self.user.invalidate_member_bandlists(self, the_member.key)
Пример #11
0
    def get(self, *args, **kwargs):
        try:
            gig_id = kwargs["gig_id"]
            the_gig = gig.gig_key_from_urlsafe(gig_id).get()
        except:
            self.abort(404)

        # are we authorized to see the gig?
        if assoc.get_assoc_for_band_key_and_member_key(
                self.user.key, the_gig.key.parent(),
                confirmed_only=False) is None:
            self.abort(401)

        the_band_key = the_gig.key.parent()
        the_plans, the_plan_counts, the_sections, band_has_sections = _makeInfoPageInfo(
            self.user, the_gig, the_band_key)

        return gig.rest_gig_plan_info(the_plans)
Пример #12
0
    def get(self, *args, **kwargs):
        try:
            band_id = kwargs["band_id"]
            the_band_key = band.band_key_from_urlsafe(band_id)
        except webapp2.HTTPException:
            raise
        except:
            self.abort(404)

        # are we authorized to see the band?
        the_assoc = assoc.get_assoc_for_band_key_and_member_key(self.user.key, the_band_key, confirmed_only=False)
        if the_assoc is None:
            self.abort(401)

        try:
            info = band.rest_band_info(band.get_band(the_assoc.band), the_assoc=the_assoc, include_id=False)
        except:
            self.abort(404)
        return info
Пример #13
0
 def post(self):    
     """ makes a new assoc for a member """
     
     the_user = self.user
     
     the_member_key=self.request.get('mk','0')
     the_band_key=self.request.get('bk','0')
     
     if the_member_key=='0' or the_band_key=='0':
         return # todo figure out what to do
         
     the_member=ndb.Key(urlsafe=the_member_key).get()
     the_band=ndb.Key(urlsafe=the_band_key).get()
     
     if assoc.get_assoc_for_band_key_and_member_key(the_band_key = the_band.key, the_member_key = the_member.key) is None:
         assoc.new_association(the_member, the_band)        
         goemail.send_new_member_email(the_band,the_member)
     
     # since our bands are changing, invalidate the band list in our session
     self.user.invalidate_member_bandlists(self, the_member_key)
Пример #14
0
    def get(self, *args, **kwargs):

        try:
            band_id = kwargs["band_id"]
            the_band_key = band.band_key_from_urlsafe(band_id)
        except webapp2.HTTPException:
            raise
        except:
            self.abort(404)

        # are we authorized to see the band?
        the_assoc = assoc.get_assoc_for_band_key_and_member_key(self.user.key, the_band_key, confirmed_only=False)
        if the_assoc is None:
            self.abort(401)

        the_assocs = assoc.get_confirmed_assocs_of_band_key(the_band_key, include_occasional=True)
        member_keys = [a.member for a in the_assocs]
        members = member.get_member(member_keys)
        info = [member.rest_member_info(m, True) for m in members]
        return info
Пример #15
0
    def get(self, *args, **kwargs):

        try:
            band_id = kwargs["band_id"]
            the_band_key = band.band_key_from_urlsafe(band_id)
        except webapp2.HTTPException:
            raise
        except:
            self.abort(404)

        # are we authorized to see the band?
        the_assoc = assoc.get_assoc_for_band_key_and_member_key(
            self.user.key, the_band_key, confirmed_only=False)
        if the_assoc is None:
            self.abort(401)

        the_assocs = assoc.get_confirmed_assocs_of_band_key(
            the_band_key, include_occasional=True)
        member_keys = [a.member for a in the_assocs]
        members = member.get_member(member_keys)
        info = [member.rest_member_info(m, True) for m in members]
        return info
Пример #16
0
    def get(self, *args, **kwargs):
        try:
            band_id = kwargs["band_id"]
            the_band_key = band.band_key_from_urlsafe(band_id)
        except webapp2.HTTPException:
            raise
        except:
            self.abort(404)

        # are we authorized to see the band?
        the_assoc = assoc.get_assoc_for_band_key_and_member_key(
            self.user.key, the_band_key, confirmed_only=False)
        if the_assoc is None:
            self.abort(401)

        try:
            info = band.rest_band_info(band.get_band(the_assoc.band),
                                       the_assoc=the_assoc,
                                       include_id=False)
        except:
            self.abort(404)
        return info
Пример #17
0
    def get(self):
        """ post handler - wants an ak """
        
        the_user = self.user

        the_member_keyurl=self.request.get('mk','0')
        the_band_keyurl=self.request.get('bk','0')

        if the_member_keyurl=='0' or the_band_keyurl=='0':
            return # todo figure out what to do

        the_member_key = member.member_key_from_urlsafe(the_member_keyurl)
        the_band_key = band.band_key_from_urlsafe(the_band_keyurl)
        
        if not is_authorized_to_edit_band(the_band_key,the_user):
            return                
        
        # find the association between band and member
        the_assoc=assoc.get_assoc_for_band_key_and_member_key(the_member_key, the_band_key)
        assoc.delete_association_from_key(the_assoc.key)
        gig.reset_gigs_for_contact_key(the_member_key, the_band_key)

        return self.redirect('/band_info.html?bk={0}'.format(the_band_keyurl))
Пример #18
0
    def get(self):
        """ post handler - wants an ak """

        the_user = self.user

        the_member_keyurl = self.request.get('mk', '0')
        the_band_keyurl = self.request.get('bk', '0')

        if the_member_keyurl == '0' or the_band_keyurl == '0':
            return  # todo figure out what to do

        the_member_key = member.member_key_from_urlsafe(the_member_keyurl)
        the_band_key = band.band_key_from_urlsafe(the_band_keyurl)

        if not is_authorized_to_edit_band(the_band_key, the_user):
            return

        # find the association between band and member
        the_assoc = assoc.get_assoc_for_band_key_and_member_key(
            the_member_key, the_band_key)
        assoc.delete_association_from_key(the_assoc.key)
        gig.reset_gigs_for_contact_key(the_member_key, the_band_key)

        return self.redirect('/band_info.html?bk={0}'.format(the_band_keyurl))
Пример #19
0
    def _make_page(self,the_user):
        """ construct page for agenda view """
        
        # find the bands this member is associated with
        the_assocs = assoc.get_confirmed_assocs_of_member(the_user)
        the_band_keys = [a.band for a in the_assocs]
        
        if the_band_keys is None or len(the_band_keys)==0:
            return self.redirect('/member_info.html?mk={0}'.format(the_user.key.urlsafe()))

        if the_user.show_long_agenda:
            num_to_put_in_upcoming=1000
        else:
            num_to_put_in_upcoming=5

        show_canceled=True
        if the_user.preferences and the_user.preferences.hide_canceled_gigs:
            show_canceled=False
            
        all_gigs=[]
        for bk in the_band_keys:
            b = bk.get()                       
            today_date = datetime.datetime.combine(datetime.datetime.now(tz=pytz.timezone(b.timezone)), datetime.time(0,0,0))
#         the_gigs = gig.get_gigs_for_bands(the_bands, num=num_to_put_in_upcoming, start_date=today_date)
            some_gigs = gig.get_gigs_for_band_keys(bk, show_canceled=show_canceled, start_date=today_date)
            all_gigs = all_gigs + some_gigs

        all_gigs = sorted(all_gigs, key=lambda gig: gig.date)

        upcoming_plans = []
        weighin_plans = []        

        if all_gigs:
            for i in range(0, len(all_gigs)):
                a_gig = all_gigs[i]
                the_plan = plan.get_plan_for_member_for_gig(the_user, a_gig)

                info_block={}
                info_block['the_gig_key'] = a_gig.key
                info_block['the_plan_key'] = the_plan.key
                info_block['the_member_key'] = the_user.key
                a_band_key = a_gig.key.parent()
                a_band = None
                for test_band_key in the_band_keys:
                    if test_band_key == a_band_key:
                        a_band_key = test_band_key
                        break
                if a_band_key == None:
                    logging.error('agenda.MainPage error: no band for gig')
                    continue
                info_block['the_band'] = a_band_key.get()
                info_block['the_assoc'] = assoc.get_assoc_for_band_key_and_member_key(the_user.key, a_band_key)
                if the_plan.section is None:
                    info_block['the_section'] = info_block['the_assoc'].default_section
                else:
                    info_block['the_section'] = the_plan.section
                if num_to_put_in_upcoming and i<num_to_put_in_upcoming and (the_plan.value or a_gig.status == 2): #include gigs for which we've weighed in or have been cancelled
                    upcoming_plans.append( info_block )
                else:            
                    if (the_plan.value == 0 ):
                        weighin_plans.append( info_block )

        number_of_bands = len(the_band_keys)


        template_args = {
            'upcoming_plans' : upcoming_plans,
            'weighin_plans' : weighin_plans,
            'show_band' : number_of_bands>1,
            'long_agenda' : the_user.show_long_agenda,
            'the_date_formatter' : member.format_date_for_member,
            'agenda_is_active' : True,
            'colors' : colors
        }
        self.render_template('agenda.html', template_args)
Пример #20
0
Файл: agenda.py Проект: Beuh/GO2
def _get_agenda_contents_for_member(the_user):
    # find the bands this member is associated with
    the_assocs = assoc.get_confirmed_assocs_of_member(the_user,
                                                      include_hidden=False)
    the_band_keys = [a.band for a in the_assocs]

    if the_band_keys is None or len(the_band_keys) == 0:
        raise Exception("no agenda")

    if the_user.show_long_agenda:
        num_to_put_in_upcoming = 1000
    else:
        num_to_put_in_upcoming = 5

    show_canceled = True
    if the_user.preferences and the_user.preferences.hide_canceled_gigs:
        show_canceled = False

    all_gigs = gig.get_sorted_gigs_from_band_keys(
        the_band_keys=the_band_keys, include_canceled=show_canceled)

    upcoming_plans = []
    weighin_plans = []

    if all_gigs:
        for i in range(0, len(all_gigs)):
            a_gig = all_gigs[i]
            the_plan = plan.get_plan_for_member_for_gig(the_user, a_gig)

            info_block = {}
            info_block['the_gig'] = a_gig
            info_block['the_plan'] = the_plan
            info_block['the_member'] = the_user
            a_band_key = a_gig.key.parent()
            a_band = None
            for test_band_key in the_band_keys:
                if test_band_key == a_band_key:
                    a_band_key = test_band_key
                    break
            if a_band_key == None:
                logging.error('agenda.MainPage error: no band for gig')
                continue
            info_block['the_band'] = a_band_key.get()
            info_block[
                'the_assoc'] = assoc.get_assoc_for_band_key_and_member_key(
                    the_user.key, a_band_key)
            if the_plan.section is None:
                if info_block['the_assoc']:
                    info_block['the_section_key'] = info_block[
                        'the_assoc'].default_section
                else:
                    logging.error(
                        'agenda page: plan exists but no assoc: {0}'.format(
                            the_plan.key.urlsafe()))
                    info_block['the_section_key'] = None

            else:
                info_block['the_section_key'] = the_plan.section
            if num_to_put_in_upcoming and i < num_to_put_in_upcoming and (
                    the_plan.value or a_gig.status == 2
            ):  #include gigs for which we've weighed in or have been cancelled
                upcoming_plans.append(info_block)
            else:
                if (the_plan.value == 0):
                    weighin_plans.append(info_block)

    number_of_bands = len(the_band_keys)

    return (upcoming_plans, weighin_plans, number_of_bands)
Пример #21
0
def _get_agenda_contents_for_member(the_user):
    # find the bands this member is associated with
    the_assocs = assoc.get_confirmed_assocs_of_member(the_user, include_hidden=False)
    the_band_keys = [a.band for a in the_assocs]

    if the_band_keys is None or len(the_band_keys)==0:
        raise Exception("no agenda")

    if the_user.show_long_agenda:
        num_to_put_in_upcoming=1000
    else:
        num_to_put_in_upcoming=5

    show_canceled=True
    if the_user.preferences and the_user.preferences.hide_canceled_gigs:
        show_canceled=False
        

    all_gigs = gig.get_sorted_gigs_from_band_keys(the_band_keys=the_band_keys, include_canceled=show_canceled)

    upcoming_plans = []
    weighin_plans = []        

    if all_gigs:
        for i in range(0, len(all_gigs)):
            a_gig = all_gigs[i]
            the_plan = plan.get_plan_for_member_for_gig(the_user, a_gig)

            info_block={}
            info_block['the_gig'] = a_gig
            info_block['the_plan'] = the_plan
            info_block['the_member'] = the_user
            a_band_key = a_gig.key.parent()
            a_band = None
            for test_band_key in the_band_keys:
                if test_band_key == a_band_key:
                    a_band_key = test_band_key
                    break
            if a_band_key == None:
                logging.error('agenda.MainPage error: no band for gig')
                continue
            info_block['the_band'] = a_band_key.get()
            info_block['the_assoc'] = assoc.get_assoc_for_band_key_and_member_key(the_user.key, a_band_key)
            if the_plan.section is None:
                if info_block['the_assoc']:
                    info_block['the_section_key'] = info_block['the_assoc'].default_section
                else:
                    logging.error('agenda page: plan exists but no assoc: {0}'.format(the_plan.key.urlsafe()))
                    info_block['the_section_key'] = None

            else:
                info_block['the_section_key'] = the_plan.section
            if num_to_put_in_upcoming and i<num_to_put_in_upcoming and (the_plan.value or a_gig.status == 2): #include gigs for which we've weighed in or have been cancelled
                upcoming_plans.append( info_block )
            else:            
                if (the_plan.value == 0 ):
                    weighin_plans.append( info_block )

    number_of_bands = len(the_band_keys)

    return (upcoming_plans, weighin_plans, number_of_bands)