Ejemplo n.º 1
0
    def process_objects(self, author):
        # Circuit
        circuit = Circuit(
            name=self.cleaned_data.get('name', ''),
            category=self.cleaned_data.get('category', ''),
            description=self.clean_description(),
            author=author,
            adult_content=self.cleaned_data['adult_content']
        )

        circuit.save()
        # Topics
        new_topics = []
        all_topics = []
        topic_names = Topic.parse_names(self.cleaned_data('topics', []))
        for tn in topic_names:
            if not Topic.exists(tn):
                topic = Topic.get_or_create(tn)
                new_topics.append(topic)
            else:
                topic = Topic.get_by_name(tn)
            all_topics.append(topic)
        multiple = False
        if len(new_topics) > 0:
            multiple = True
        # Add topics to circuit
        for topic in all_topics:
            circuit.topics.add(topic)
        circuit.save()
        return {
            'circuit': circuit,
            'all_topics': all_topics,
            'new_topics': new_topics,
            'multiple': multiple
        }
Ejemplo n.º 2
0
    def run(self, new_users=None):

        if new_users == None:
            #SELECT id, circuits_to_create FROM users
            #WHERE circuits_to_create > 0;
            all_users = SimUser.objects.filter(circuits_to_create__gt=0)
        else:
            #all_users = SimUser.objects.order_by((SimUser.id).desc()).limit(new_users)
            pass

        cct_name = 'circuit_'
        cct_count = 0
        new_circuits = 0

        session_counter = 0
        print colored.white("Generating circuits:")
        for usuario in progress.bar(all_users):
            for i_circuit in xrange(usuario.circuits_to_create):

                circuit = Circuit(name=cct_name + str(cct_count),
                                  author=usuario.user,
                                  rating=0,
                                  category=random.randint(0, 25))

                cct_count += 1
                session_counter += 1
                circuit.save()
                new_circuits += 1

                if session_counter >= 5000:
                    session_counter = 0
                    transaction.commit()

        transaction.commit()
Ejemplo n.º 3
0
Archivo: forms.py Proyecto: biznixcn/WR
    def process_objects(self, author):
        name = self.cleaned_data.get('name', u'')
        category = self.cleaned_data.get('category',
            constants.DEFAULT_CIRCUIT_CATEGORY)
        description = self.cleaned_data.get('description', u'')

        # Trimming more than one 2 linebreaks to one
        line_breaks = re.search('.*?(\s{2,}).*?', description)
        if line_breaks is not None:
            trimmed_description = description
            for line_break in line_breaks.groups():
                trimmed_description = description.replace(line_break, u'\r\n')
            description = trimmed_description

        # Circuit
        circuit = Circuit(
            name=name,
            category=category,
            description=description,
            author=author,
            adult_content=self.cleaned_data.get('adult_content', False)
        )
        circuit.save()

        # Topics
        new_topics = []
        all_topics = []
        topic_names = Topic.parse_names(self.cleaned_data.get('topics', []))
        for tn in topic_names:
            if not Topic.exists(tn):
                topic = Topic.get_or_create(tn)
                new_topics.append(topic)
            else:
                topic = Topic.get_by_name(tn)
            all_topics.append(topic)

        multiple = False
        if len(new_topics) > 0:
            multiple = True

        # Add topics to circuit
        for topic in all_topics:
            circuit.topics.add(topic)

        circuit.save()

        return {
            'circuit': circuit,
            'all_topics': all_topics,
            'new_topics': new_topics,
            'multiple': multiple
        }
Ejemplo n.º 4
0
    def process_objects(self, author):
        name = self.cleaned_data.get('name', u'')
        category = self.cleaned_data.get('category',
                                         constants.DEFAULT_CIRCUIT_CATEGORY)
        description = self.cleaned_data.get('description', u'')

        # Trimming more than one 2 linebreaks to one
        line_breaks = re.search('.*?(\s{2,}).*?', description)
        if line_breaks is not None:
            trimmed_description = description
            for line_break in line_breaks.groups():
                trimmed_description = description.replace(line_break, u'\r\n')
            description = trimmed_description

        # Circuit
        circuit = Circuit(name=name,
                          category=category,
                          description=description,
                          author=author,
                          adult_content=self.cleaned_data.get(
                              'adult_content', False))
        circuit.save()

        # Topics
        new_topics = []
        all_topics = []
        topic_names = Topic.parse_names(self.cleaned_data.get('topics', []))
        for tn in topic_names:
            if not Topic.exists(tn):
                topic = Topic.get_or_create(tn)
                new_topics.append(topic)
            else:
                topic = Topic.get_by_name(tn)
            all_topics.append(topic)

        multiple = False
        if len(new_topics) > 0:
            multiple = True

        # Add topics to circuit
        for topic in all_topics:
            circuit.topics.add(topic)

        circuit.save()

        return {
            'circuit': circuit,
            'all_topics': all_topics,
            'new_topics': new_topics,
            'multiple': multiple
        }
Ejemplo n.º 5
0
def add_circuits():
    ct = CommunicationsType()
    ct.comm_type = 'Dynamic T1'
    ct.save()
    
    ct2 = CommunicationsType()
    ct2.comm_type = 'EVDO'
    ct2.save()
    
    circuit = Circuit()
    circuit.store = Store.objects.get(pk=2942)
    circuit.primary_vendor = Vendor.objects.all()[0]
    circuit.primary_circuit_id = 'A1awr23'
    circuit.communications_type = CommunicationsType.objects.all()[0]
    circuit.circuit_type = 'P'
    circuit.save()
    
    circuit = Circuit()
    circuit.store = Store.objects.get(pk=2583)
    circuit.primary_vendor = Vendor.objects.all()[0]
    circuit.primary_circuit_id = 'A345-12'
    circuit.communications_type = CommunicationsType.objects.all()[0]
    circuit.circuit_type = 'P'
    circuit.save()
    
    circuit = Circuit()
    circuit.store = Store.objects.get(pk=2811)
    circuit.primary_vendor = Vendor.objects.all()[0]
    circuit.primary_circuit_id = 'A3aer2345'
    circuit.communications_type = CommunicationsType.objects.all()[0]
    circuit.circuit_type = 'P'
    circuit.save()
Ejemplo n.º 6
0
    def run(self, new_users=None):   
     
        if new_users == None:        
            #SELECT id, circuits_to_create FROM users
            #WHERE circuits_to_create > 0;
            all_users = SimUser.objects.filter(circuits_to_create__gt = 0)
        else:
            #all_users = SimUser.objects.order_by((SimUser.id).desc()).limit(new_users)
            pass
    
        cct_name = 'circuit_'
        cct_count = 0
        new_circuits = 0

        session_counter = 0
        print colored.white("Generating circuits:")
        for usuario in progress.bar(all_users):
            for i_circuit in xrange(usuario.circuits_to_create):

                circuit = Circuit(
                    name=cct_name + str(cct_count),
                    author=usuario.user,
                    rating=0,
                    category = random.randint(0,25)
                )    

                cct_count += 1
                session_counter += 1
                circuit.save()
                new_circuits += 1

                if session_counter >= 5000:
                    session_counter = 0
                    transaction.commit()

        transaction.commit()
Ejemplo n.º 7
0
    def read_from_file(self, filename):
        """
        reads places from file
        """
        with open(filename, 'r') as FILE:
            for line in FILE:
                #line = FILE.readline()
                # eliminate \n at end
                line = line.strip()
                self.number_lines += 1
                if line == '@#':
                    guide_title = FILE.next().strip()
                    self.number_lines += 1
                    guide_title = guide_title.replace('-', ' ')
                    guide_author = FILE.next().strip()
                    self.number_lines += 1
                    # returns a user, finding it or creating it
                    author = self.create_or_find_author(guide_author)
                    location = FILE.next().strip()
                    self.number_lines += 1
                    location = location.split('\t')
                    location = location[-1]
                    description = FILE.next().strip().replace('-', ' ')
                    self.number_lines += 1
                    # create circuit
                    # FIXME: decription migth be 'NO-DESCRIPTION' and
                    # category should be somehow matched to a proper category
                    try:
                        new_ct = Circuit.objects.get(
                            name=guide_title,
                            author=author,
                        )
                    except Circuit.DoesNotExist:
                        new_ct = Circuit(
                            name=guide_title,
                            category=4,
                            author=author,
                            description=description[:399],
                            published=True,
                            source=3,
                        )
                    print 'Creating circuit ' + guide_title
                    new_ct.save()
                    # move line 1 position forward so place can read from here
                    line = FILE.next().strip()
                    self.number_lines += 1

                # a place
                fields = line.split('\t')
                place_name = fields[0].replace('-', ' ')
                lat = fields[1]
                lng = fields[2]
                try:
                    desc = fields[3]
                except IndexError:
                    dec = ''
                # invoke process_search and pass fields
                self.process_search(circuit=new_ct,
                                    place_name=place_name,
                                    lat=lat,
                                    lng=lng,
                                    location=location,
                                    description=desc)
Ejemplo n.º 8
0
 def read_from_file(self, filename):
     """
     reads places from file
     """
     with open(filename, 'r') as FILE:
         for line in FILE:
             #line = FILE.readline()
             # eliminate \n at end
             line = line.strip()
             self.number_lines += 1
             if line == '@#':
                 guide_title = FILE.next().strip()
                 self.number_lines += 1
                 guide_title = guide_title.replace('-', ' ')
                 guide_author = FILE.next().strip()
                 self.number_lines += 1
                 # returns a user, finding it or creating it
                 author = self.create_or_find_author(guide_author)
                 location = FILE.next().strip()
                 self.number_lines += 1
                 location = location.split('\t')
                 location = location[-1]
                 description = FILE.next().strip().replace('-', ' ')
                 self.number_lines += 1
                 # create circuit
                 # FIXME: decription migth be 'NO-DESCRIPTION' and
                 # category should be somehow matched to a proper category
                 try:
                     new_ct = Circuit.objects.get(
                         name=guide_title,
                         author=author,
                     )
                 except Circuit.DoesNotExist:
                     new_ct = Circuit(
                         name=guide_title,
                         category=4,
                         author=author,
                         description=description[:399],
                         published=True,
                         source=3,
                     )
                 print 'Creating circuit ' + guide_title
                 new_ct.save()
                 # move line 1 position forward so place can read from here
                 line = FILE.next().strip()
                 self.number_lines += 1
             
             # a place
             fields = line.split('\t')
             place_name = fields[0].replace('-', ' ')
             lat = fields[1]
             lng = fields[2]
             try:
                 desc = fields[3]
             except IndexError:
                 dec = ''
             # invoke process_search and pass fields
             self.process_search(
                 circuit=new_ct,
                 place_name=place_name, 
                 lat=lat, 
                 lng=lng, 
                 location=location,
                 description=desc
             )