Beispiel #1
0
    def process_post_data(self):
        """process all the incoming data. raises ProcessingError in case there is a failure.
        This method should only be called on post"""

        # unfortunately it's doubled here.
        regform = self.registration_form
        userform = self.user_registration_form

        if not self.logged_in and not userform.validate():
            print "user is not logged in and userform does not validate"
            raise ProcessingError(
                "user is not logged in and userform does not validate")

        if not regform.validate():
            print "registration form does not validate"
            raise ProcessingError("registration form does not validate")

        # do we have events? If not then this is not valid
        eids = self.request.form.getlist("_bcevents")
        if not eids:
            print "no events selected"
            raise ProcessingError("no events selected")

        # do we have a new user?
        new_user = not self.logged_in
        if not self.logged_in:

            # create new user and get the UID
            mod = self.app.module_map['userbase']
            user = mod.register(userform.data, create_pw=False)

            # double opt in should be done already, we only have to remember
            # to tell the user after registration
            uid = unicode(user._id)
            self.log.debug("created new user", uid=uid)

        else:
            uid = unicode(self.user._id)

        # store registration details
        self.barcamp.registration_data[uid] = regform.data

        # register for all the selected events
        if self.logged_in:
            reg = RegistrationService(self, self.user)

            for eid in eids:
                event = self.barcamp.get_event(eid)
                try:
                    reg.set_status(eid, "going")
                except RegistrationError, e:
                    self.log.exception("a registration error occurred")
                    print "unknown registration error"
                    raise ProcessingError(str(e))
                    return
Beispiel #2
0
    def post(self, slug=None):
        """add a user to the participant or maybe list"""

        reg = RegistrationService(self, self.user)

        eid = self.request.form.get("eid")
        uid = unicode(self.user._id)
        event = self.barcamp.get_event(eid)
        status = self.request.form.get("status")  # can be join, maybe, not

        try:
            reg.set_status(eid, status)
        except RegistrationError, e:
            return {
                'status': 'error',
                'message': 'registration is not possible'
            }
Beispiel #3
0
    def post(self, slug = None, eid = None):
        """handle users and lists

        you have to provide a userid as uid and a status in the form data
        status can be ``going``, ``maybe``, ``notgoing`` and ``waitinglist``

        """
        uid = self.request.form.get("uid")
        status = self.request.form.get("status") # can be join, maybe, notgoubg
        event = self.barcamp.get_event(eid)
        
        user = self.app.module_map.userbase.get_user_by_id(uid)

        reg = RegistrationService(self, user)
        try:
            status = reg.set_status(eid, status, force=True)
        except RegistrationError, e:
            print "a registration error occurred", e
            raise ProcessingError(str(e))
            return 
Beispiel #4
0
    def get(self):
        """show the registration form"""
        mod = self.app.module_map['userbase']
        cfg = mod.config

        code = self.request.args.get("code", None)
        if self.request.method == 'POST':
            code = self.request.form.get("code", "")
        else:
            code = self.request.args.get("code", None)
        if code is not None:
            user = mod.get_user_by_activation_code(code)
            if user is not None:
                user.activate()

                # log user in
                mod.login(self, user=user, save=False)
                user.save()

                # default url to return to on activation
                url_for_params = cfg.urls.activation_success
                return_url = self.url_for(**url_for_params)

                # now register user for barcamps if some are give
                if "barcamp" in user.registered_for:
                    slug = user.registered_for['barcamp']
                    barcamp = self.config.dbs.barcamps.by_slug(slug)
                    if barcamp is None:
                        self.flash(self._(
                            "Unfortunately we couldn't find the barcamp you tried to register for. Please search for it on the homepage and register again"
                        ),
                                   category="danger")
                    else:
                        failed = False

                        # check for ticket mode
                        if barcamp.ticketmode_enabled:
                            ticketservice = TicketService(self,
                                                          user,
                                                          barcamp=barcamp)
                            for tc_id in user.registered_for.get(
                                    'tickets', []):
                                try:
                                    status = ticketservice.register(
                                        tc_id, new_user=user)
                                except TicketError, e:
                                    self.log.error(
                                        "an exception when registering a ticket occurred",
                                        error_msg=e.msg)
                                    failed = True

                        else:
                            reg = RegistrationService(self,
                                                      user,
                                                      barcamp=barcamp)
                            for eid in user.registered_for.get('eids', []):
                                event = barcamp.get_event(eid)
                                try:
                                    reg.set_status(eid, "going")
                                except RegistrationError, e:
                                    failed = True
                        if failed:
                            self.flash(self._(
                                "We could not register you for all selected events. Please check your email and the events page"
                            ),
                                       category="warning")
                        else:
                            self.flash(
                                self.
                                _("Your account has been successfully activated and you have been registered for the barcamp"
                                  ) % user)
                        return_url = self.url_for("barcamps.index",
                                                  slug=barcamp.slug)
Beispiel #5
0
    def get(self, slug = None, eid = None):
        """show the event details"""
        event = self.barcamp.get_event(eid)

        # copy event location over to form

        event['location_name'] = event.location['name']
        event['location_street'] = event.location['street']
        event['location_city'] = event.location['city']
        event['location_zip'] = event.location['zip']
        event['location_country'] = event.location['country']
        event['location_email'] = event.location['email']
        event['location_phone'] = event.location['phone']
        event['location_url'] = event.location['url']
        event['location_description'] = event.location['description']
        event['location_lat'] = event.location['lat']
        event['location_lng'] = event.location['lng']

        form = EventForm(self.request.form, obj = event, config = self.config)

        # get countries and translate them
        try:
            trans = gettext.translation('iso3166', pycountry.LOCALES_DIR,
                languages=[str(self.babel_locale)])
        except IOError:
            # en only has iso3166_2
            trans = gettext.translation('iso3166_2', pycountry.LOCALES_DIR,
                languages=[str(self.babel_locale)])
        
        countries = [(c.alpha_2, trans.ugettext(c.name)) for c in pycountry.countries]
        form.location_country.choices = countries

        if self.barcamp.public:
            # the minimum size should be the old event size
            min_count = event.size
            choices = [(str(n),str(n)) for n in range(event.size, 500)]
            form['size'].validators = [validators.Required(), 
                validators.NumberRange(min=min_count, message=self._("you cannot reduce the participant number, the minimum amount is %s") %min_count)]
            form['size'].choices = choices

        if self.request.method == 'POST' and form.validate():
            f = form.data
            f['location'] = {
                'name'      : f['location_name'],
                'street'    : f['location_street'],
                'city'      : f['location_city'],
                'zip'       : f['location_zip'],
                'country'   : f['location_country'],
                'email'     : f['location_email'],
                'phone'     : f['location_phone'],
                'url'       : f['location_url'],
                'description' : f['location_description'],
                'lat'       : f['location_lat'] or None,
                'lng'       : f['location_lng'] or None,
            }



            # remember old values
            old_street = event.location['street']
            old_zip = event.location['zip']
            old_city = event.location['city']
            old_country = event.location['country']

            # now update event
            event.update(f)

            # check location only if it actually has changed
            # only check if we are not in unit test and if own location is selected
            # also don't retrieve it if user has set own coordinates
            if self.request.form.get('own_coords', "no") != "yes":
                # computing coords from address
                changed = (f['location_city'] != old_city or
                    f['location_street'] != old_street or
                    f['location_zip'] != old_zip or
                    f['location_country'] != old_country)

                if ( changed and not self.config.testing and f['own_location']):
                    street = event.location['street']
                    city = event.location['city']
                    zip = event.location['zip']
                    country = event.location['country']
                    try:
                        lat, lng = self.retrieve_location(street, zip, city, country)
                        event.location['lat'] = lat
                        event.location['lng'] = lng
                    except LocationNotFound:
                        self.flash(self._("the city was not found in the geo database"), category="danger")
            else:
                    # using user provided coordinates
                    event.update(f)

            reg = RegistrationService(self, None)
            reg.check_waitinglist(event)

            # update event and barcamp
            self.barcamp.events[eid] = event
            self.barcamp.save()
            self.flash(self._("The event has been successfully updated"), category="info")

            return redirect(self.url_for(".event", slug=slug, eid = event._id))        
        return self.render(form = form, slug = slug, events = self.barcamp.events, event=event, eid = event._id)