Ejemplo n.º 1
0
Archivo: models.py Proyecto: eedeep/efo
 def save(self, *args, **kwargs):
     if not self.id:
         """
         Replace self.title with your prepopulate_from field
         """
         self.slug = SlugifyUniquely(self.title, self.__class__)
     super(Publication, self).save(*args, **kwargs)
Ejemplo n.º 2
0
 def save(self, *args, **kwargs):
     if not self.id:
         """
         Replace self.title with your prepopulate_from field
         """
         self.slug = SlugifyUniquely(self.title, self.__class__)
     # else:
     #             # current sites
     #             sites_ids = []
     #             if self.publish_on_AU:
     #                 sites_ids.append(1)
     #             if self.publish_on_NZ:
     #                 sites_ids.append(2)
     #                 
     #             sites = Site.objects.filter(pk__in=sites_ids)
     #             self.sites = sites    
     super(Base, self).save(*args, **kwargs)
Ejemplo n.º 3
0
Archivo: models.py Proyecto: eedeep/efo
    def save(self, *args, **kwargs):
        if not self.id:
            if self.issue_name:
                sluggable_string = self.issue_name
            else:
                sluggable_fields = [
                    self.magazine.title, self.issue_month, self._next_month,
                    self.issue_year, self.issue_number
                ]
                sluggable_string_values = []
                for sluggable_field in sluggable_fields:
                    if sluggable_field:
                        sluggable_string_values.append(sluggable_field)

                sluggable_string = ' '.join(sluggable_string_values)

            self.slug = SlugifyUniquely(sluggable_string, self.__class__)
        super(MagazineIssue, self).save(*args, **kwargs)
Ejemplo n.º 4
0
    def handle(self, *args, **options):
        """
        Restore missing slugs.
        """
        
        mis = MagazineIssue.objects.all()
        
        for mi in mis:

            sluggable_fields = [
                mi.magazine.title,
                mi.issue_month,
                mi._next_month]
            sluggable_string_values = []
            for sluggable_field in sluggable_fields:
                if sluggable_field:
                    sluggable_string_values.append(sluggable_field)
                
            sluggable_string = ' '.join(sluggable_string_values)
        
            mi.slug = SlugifyUniquely(sluggable_string, mi.__class__)
            print mi.slug
    def forwards(self, orm):

        # Adding field 'MagazineIssue.slug'
        db.add_column('publications_magazineissue',
                      'slug',
                      self.gf('django.db.models.fields.SlugField')(
                          max_length=250,
                          unique=True,
                          null=True,
                          db_index=True),
                      keep_default=False)

        issues = MagazineIssue.objects.all()
        for issue in issues:
            if issue.issue_name:
                sluggable_string = issue.issue_name
            else:
                sluggable_string = issue.magazine

            issue.slug = SlugifyUniquely(sluggable_string, MagazineIssue)
            print u'Saving issue slug:: %s' % issue.slug
            issue.save()
Ejemplo n.º 6
0
 def save(self, *args, **kwargs):  
     if not self.id:
         # replace self.name with your prepopulate_from field
         self.slug = SlugifyUniquely(self.name, self.__class__)
     super(BaseType, self).save(*args, **kwargs)
Ejemplo n.º 7
0
 def handle(self, *args, **options):
     images = ArticleImage.objects.all()
     for image in images:
         image.slug = SlugifyUniquely(truncate_words(image.caption, 4),
                                      ArticleImage)
         image.save()
Ejemplo n.º 8
0
    def handle(self, *args, **options):
        """
        Projects
        """
        
        articles_to_link = []
        projects_to_link = []
        unlinked_projects = []
        
        publisher = Publisher.objects.get(pk=1)
        user = User.objects.get(pk=1)
        
        l_projects = ProjectsProject.objects.all()        
    
        for l_project in l_projects:
            
            # Get related data
            sites = Site.objects.filter(pk=1)
            
            ProjectsProjectProjectCategories
            categories = ProjectsProjectcategory.objects.filter(projectsprojectprojectcategories__project_id=l_project.id)
            types = ProjectsProjecttype.objects.filter(projectsprojectprojecttypes__project_id=l_project.id)
            
            try:
                status = ProjectsProjectstatus.objects.get(projectsproject__id=l_project.id)
            except:
                status = None
            
            # print u''
            #             print u'===================================='
            #             print u''
            print u'%s' % l_project.title
            # print u''
            #             print u'::: Categories: %s ::: Types: %s ::: Status: %s' % (categories.values_list(flat=True), types.values_list(flat=True), status)
            
            
            # ============================
            # List & Create new records
            
            #### Organisations
            
            
            
            #### Projects
            
            p_kwargs = {
                'title': l_project.title,
                'building_area': l_project.building_area,
                'budget_total': l_project.budget_total,
                'city': l_project.city,
                'client': l_project.client,
                'client_website': l_project.client_website,
                'client_website_name': l_project.client_website_name,
                'construction': l_project.construction,
                'content': l_project.content,
                'country': l_project.country,
                'created': datetime.datetime.now(),
                'created_by': user,
                'design_documentation': l_project.design_documentation,
                'old_id': l_project.id,
                'is_published': True,
                'number_of_stories': l_project.number_of_stories,
                'post_code': l_project.post_code,
                'project_website': l_project.client_website,
                'published': datetime.datetime.now(),
                'published_by': user,
                'publisher': publisher,
                'short_title': l_project.title,
                'site_size': l_project.site_size,
                'slug': SlugifyUniquely(truncate_words(l_project.title, 4), Project),
                'state': l_project.state,
                'street': l_project.street,
                'suburb': l_project.suburb,
                'summary': l_project.summary
            }
            project = Project(**p_kwargs)
            
            if status:
                try:
                    project.project_status = ProjectStatus.objects.get(pk=1)
                except:
                    pass
                
            try:
                project = Project.objects.get(title=project.title)
            except ObjectDoesNotExist:
                # Create new
                try:
                    project.full_clean()
                    # pass
                except ValidationError, e:
                    # Do something based on the errors contained in e.message_dict.
                    # Display them to a user, or handle them programatically.
                    print e
                else:
                    # Save new
                    # project.save()
                    # if project.save():
                    # project.organisation_type = l_org_types
                    project.save()
                    print u'=== === === saving project %s' % project
            else:
                # Once saved, add related items == 
                print u'=== === === project exists %s' % project
                # Clean up or add
            
                # Products
                l_p_products = ProjectsProjectproduct.objects.filter(project=l_project)
                for l_p_product in l_p_products:
                    print u'--- --- %s :: %s' % (l_p_product.label, l_p_product.products)
                    pp_kwargs = {
                        'project': project,
                        'label': l_p_product.label,
                        'products': l_p_product.products
                    }
                    project_product = ProjectProduct(**pp_kwargs)
                    try:
                        project_product.full_clean()
                        # pass
                    except ValidationError, e:
                        # Do something based on the errors contained in e.message_dict.
                        # Display them to a user, or handle them programatically.
                        print e
                    else:
                        try:
                            pp = ProjectProduct.objects.get(label=l_p_product.label, project=l_project)
                        except MultipleObjectsReturned:
                            pps = ProjectProduct.objects.filter(label=l_p_product.label, project=l_project)[2:]
                            ipdb.set_trace()
                            for pp in pps:
                                pp.delete()
                                print u'=== === === deleting products :: %s' % pp
                        except ObjectDoesNotExist:
                            project_product.save()
                            print u'=== === === saving new products :: %s' % project_product
                        else:
                            print u'=== === === products already exists :: %s' % project_product

                        
                
                ##### Project Roles
                
                # Individuals
                l_p_individuals = ProjectsProjectindividual.objects.filter(project=l_project)
                # l_p_individuals = [] # prevents from processing
                for l_p_individual in l_p_individuals:
                    
                    try:
                        organisation = Organisation.objects.get(title=l_p_individual.organisation.title)
                    except ObjectDoesNotExist:
                        """
                        Does not exist, so create new.
                        """
                        o_kwargs = {
                            'title': l_p_individual.organisation.title,
                            'content': l_p_individual.organisation.content,
                            'street': l_p_individual.organisation.street,
                            'suburb': l_p_individual.organisation.suburb,
                            'city': l_p_individual.organisation.city,
                            'country': l_p_individual.organisation.country,
                            'state': l_p_individual.organisation.state,
                            'post_code': l_p_individual.organisation.post_code,
                            'phone': l_p_individual.organisation.phone,
                            'fax': l_p_individual.organisation.fax,
                            'mobile': l_p_individual.organisation.mobile,
                            'email': l_p_individual.organisation.email,
                            'website': l_p_individual.organisation.website,
                            'website_name': l_p_individual.organisation.website_name,
                        }
                    
                        organisation = Organisation(**o_kwargs)
                        print u'=== === saving %s' % organisation
                        try:
                            organisation.full_clean()
                        except ValidationError, e:
                            # Do something based on the errors contained in e.message_dict.
                            # Display them to a user, or handle them programatically.
                            print e
                        else:
                            organisation.save()
                            print u'=== === === saving %s' % organisation
                    
                    p_individual = {
                        'project': project,
                        # 'role': role_type,
                        # 'individual': None,
                        'credit': l_p_individual.credit,
                        'custom_credit': l_p_individual.role,
                        'organisation': organisation,
                    }
                    project_individual = ProjectIndividual(**p_individual)
                    try:
                        project_individual.full_clean()
                    except ValidationError, e:
                        # Do something based on the errors contained in e.message_dict.
                        # Display them to a user, or handle them programatically.
                        print e
Ejemplo n.º 9
0
         # Organisation does exist, so do any cleanups.
         print u'=== === === exists :: cleaning %s' % organisation
         if l_company.organisation.logo_image:
            organisation.logo_image = os.path.join("files", "logos", os.path.basename(l_company.organisation.logo_image))
         else:
            organisation.logo_image = None
            organisation.save()
 
 
     try:
         role_type = ProjectRoleType.objects.get(name=l_company.role)
     except ObjectDoesNotExist:
         # Create new role
         rt_kwargs = {
             'name': l_company.role,
             'slug': SlugifyUniquely(truncate_words(l_company.role, 4), ProjectRoleType),
         }
         role_type = ProjectRoleType(**rt_kwargs)
         try:
             role_type.full_clean()
         except ValidationError, e:
             # Do something based on the errors contained in e.message_dict.
             # Display them to a user, or handle them programatically.
             print e
         else:
             role_type.save()
 
     p_company = {
         'project': project,
         'role': role_type,
         # 'individual': None,
Ejemplo n.º 10
0
    def handle(self, *args, **options):
        """
        Articles
        """

        l_articles = ArticlesArticle.objects.all()

        user = User.objects.get(pk=1)

        for l_article in l_articles:
            """
            Relationships
            
                Project, Publisher, Publication, ArticleType, Users(Authors)
            """

            # try:
            #              # project = Project.objects.get(l_)
            #          except:
            project = None

            try:
                publisher = Publisher.objects.get(pk=1)
            except:
                publisher = None

            try:
                article_type = ArticleType.objects.get(
                    pk=l_article.article_type.id)
            except:
                article_type = ArticleType.objects.get(pk=1)

            l_magazines = PublicationsMagazineissue.objects.filter(
                articlesarticlemagazines=l_article)

            magazines = MagazineIssue.objects.filter(
                id__in=[l_magazine.id for l_magazine in l_magazines])

            # Tags
            l_article_tags = ArticlesArticleTags.objects.filter(
                article_id=l_article.id)
            tags = TaggitTag.objects.filter(
                id__in=l_article_tags.values_list('tag_id'))

            # Images
            #        images = []
            #
            #        import ipdb; ipdb.set_trace()
            #
            # images = ArticleImage.objects.filter()

            sites = Site.objects.filter(pk=1)
            users = User.objects.filter(pk=1)

            kwargs = {
                'article_type':
                article_type,
                'content':
                l_article.content,
                'created':
                l_article.created,
                'created_by':
                user,
                'introduction':
                l_article.summary,
                'is_published':
                l_article.is_published,
                # 'old_id': l_article.id,
                'project':
                project,
                'published':
                l_article.published,
                'published_by':
                user,
                'publisher':
                publisher,
                'short_title':
                l_article.title,  # Truncated?
                'slug':
                SlugifyUniquely(truncate_words(l_article.title, 4), Article),
                'summary':
                l_article.summary,
                'title':
                l_article.title,
                # 'articles_article_authors': users,
                # 'magazines': magazines,
                # 'tags': tags
            }

            article = Article(**kwargs)

            try:
                article.full_clean()
                # pass
            except ValidationError, e:
                # Do something based on the errors contained in e.message_dict.
                # Display them to a user, or handle them programatically.
                print e
            else:
                try:
                    article = Article.objects.get(title=article.title)
                except ObjectDoesNotExist:
                    """
                    Does not exist, so create new.
                    """
                    print u'=== saving %s' % article
                    if article.save():
                        article.users = users
                        article.magazines = magazines
                        article.tags = tags
                        print u'====== saving m2m %s' % article
                        # article.save()
                else:
                    """
                    Already exists, do other cleanups if necessary
                    """
                    print u'+++ duplicate %s' % article
                    # article.magazines = magazines
                    # article.old_id = l_article.id
                    article.slug = SlugifyUniquely(
                        truncate_words(article.title, 3), Article)
                    print u'+++ slug %s' % len(article.slug)

                    if len(article.slug) > 40:
                        print u'+++ slug too long for %s' % article.slug

                    # Images here.

                    l_images = OldArticleImage.objects.filter(
                        article__id=article.id)

                    for l_image in l_images:

                        ai_kwargs = {
                            'article_id':
                            article.id,
                            'image':
                            u'files/%s' % (l_image.image),
                            'caption':
                            l_image.caption,
                            'slug':
                            SlugifyUniquely(truncate_words(l_image.title, 4),
                                            ArticleImage),
                            'user_credit':
                            user,
                        }

                        article_image = ArticleImage(**ai_kwargs)

                        try:
                            article_image.full_clean()
                            # pass
                        except ValidationError, e:
                            # Do something based on the errors contained in e.message_dict.
                            # Display them to a user, or handle them programatically.
                            print u'******** %s ********' % e
                        else:
                            try:
                                ArticleImage.objects.get(
                                    image=article_image.image)
                            except ObjectDoesNotExist:
                                # Doesn't exist, save
                                print u':: Saving %s' % article_image
                                # article_image.save()
                            except MultipleObjectsReturned:
                                # Duplicates, need to prune
                                print u':: Multiple images here!'
                                article_images = ArticleImage.objects.filter(
                                    image=article_image.image)
                                i = 0
                                for article_image in article_images:
                                    if i > 0:
                                        # article_image.delete()
                                        print u'***** deleting :: %s' % article_image
                                    i += 1
                            else:
                                # One object. Do nothing
                                pass

                    # Clean current blank images
                    for image in ArticleImage.objects.filter(
                            article__id=article.id):
                        # print u':: Image :: %s' % image
                        if not image.image:
                            print u'============== Image missing! Delete :: %s' % image
                            # image.delete()

                        # print u'%s::%s::%s' % (article, article_image, l_image.article)
                    try:
                        article.full_clean()
                        # pass
                    except ValidationError, e:
                        # Do something based on the errors contained in e.message_dict.
                        # Display them to a user, or handle them programatically.
                        print e
                    else: